mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-03 00:59:47 +02:00
cmake: add support for include-what-you-use to check #include's
The output is currently very verbose and includes many false positives. Adding a mapping file should solve this. See https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md
This commit is contained in:
parent
7e1da8dc0a
commit
a40a2706a9
@ -23,7 +23,7 @@ set(CTEST_BUILD_NAME "experimental_script-${SHORT_COMMIT}")
|
||||
ctest_start("Experimental")
|
||||
ctest_configure(
|
||||
OPTIONS
|
||||
"-DBUILD_VIEWER=1;-DBUILD_TESTS=1;-DTEST_COVERAGE=1;-DRW_VERBOSE_DEBUG_MESSAGES=1;-DSEPERATE_TEST_SUITES=1"
|
||||
"-DBUILD_VIEWER=1;-DBUILD_TESTS=1;-DTEST_COVERAGE=1;-DRW_VERBOSE_DEBUG_MESSAGES=1;-DSEPERATE_TEST_SUITES=1;-DCHECK_INCLUDES=1"
|
||||
)
|
||||
ctest_build()
|
||||
ctest_test()
|
||||
|
29
cmake/modules/FindIncludeWhatYouUse.cmake
Normal file
29
cmake/modules/FindIncludeWhatYouUse.cmake
Normal file
@ -0,0 +1,29 @@
|
||||
find_program(
|
||||
INCLUDE_WHAT_YOU_USE_PROGRAM
|
||||
NAMES include_what_you_use iwyu
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(IncludeWhatYouUse
|
||||
REQUIRED_VARS
|
||||
INCLUDE_WHAT_YOU_USE_PROGRAM
|
||||
)
|
||||
|
||||
if(INCLUDEWHATYOUUSE_FOUND)
|
||||
include(CMakeParseArguments)
|
||||
|
||||
function(iwyu_check)
|
||||
cmake_parse_arguments("IWYU" "" "TARGET" "EXTRA_OPTS" ${ARGN})
|
||||
set(IWYU_CMD "${INCLUDE_WHAT_YOU_USE_PROGRAM}")
|
||||
foreach(OPT ${IWYU_EXTRA_OPTS})
|
||||
list(APPEND IWYU_CMD "-Xiwyu" ${OPT})
|
||||
endforeach()
|
||||
set_target_properties("${IWYU_TARGET}"
|
||||
PROPERTIES
|
||||
C_INCLUDE_WHAT_YOU_USE
|
||||
"${IWYU_CMD}"
|
||||
CXX_INCLUDE_WHAT_YOU_USE
|
||||
"${IWYU_CMD}"
|
||||
)
|
||||
endfunction()
|
||||
endif()
|
@ -90,3 +90,18 @@ if(TEST_COVERAGE)
|
||||
gcov
|
||||
)
|
||||
endif()
|
||||
|
||||
include(CMakeParseArguments)
|
||||
|
||||
if(CHECK_INCLUDES)
|
||||
find_package(IncludeWhatYouUse REQUIRED)
|
||||
endif()
|
||||
|
||||
function(openrw_target_apply_options)
|
||||
cmake_parse_arguments("OPENRW_APPLY" "" "TARGET" "" ${ARGN})
|
||||
if(CHECK_INCLUDES)
|
||||
iwyu_check(TARGET "${OPENRW_APPLY_TARGET}"
|
||||
EXTRA_OPTS
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
@ -15,8 +15,10 @@ set(BIN_DIR "bin" CACHE STRING "Prefix subdirectory to put the binaries in.")
|
||||
set(DOC_DIR "share/doc/openrw" CACHE STRING "Prefix subdirectory to put the documentation in.")
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release")
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release")
|
||||
endif()
|
||||
|
||||
option(CHECK_INCLUDES "Analyze #includes in C and C++ source files")
|
||||
|
||||
option(TEST_COVERAGE "Enable coverage analysis (implies CMAKE_BUILD_TYPE=Debug)")
|
||||
option(SEPERATE_TEST_SUITES "Add each test suite as seperate test")
|
||||
|
@ -158,3 +158,5 @@ target_include_directories(rwengine
|
||||
PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||
)
|
||||
|
||||
openrw_target_apply_options(TARGET rwengine)
|
||||
|
@ -63,4 +63,6 @@ target_link_libraries(rwgame
|
||||
SDL2::SDL2
|
||||
)
|
||||
|
||||
openrw_target_apply_options(TARGET rwgame)
|
||||
|
||||
install(TARGETS rwgame RUNTIME DESTINATION "${BIN_DIR}")
|
||||
|
@ -61,3 +61,5 @@ target_link_libraries(rwlib
|
||||
${Boost_FILESYSTEM_LIBRARY}
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
)
|
||||
|
||||
openrw_target_apply_options(TARGET rwlib)
|
||||
|
@ -31,6 +31,8 @@ target_link_libraries(rwviewer
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
openrw_target_apply_options(TARGET rwviewer)
|
||||
|
||||
install(TARGETS rwviewer
|
||||
RUNTIME DESTINATION "${BIN_DIR}"
|
||||
)
|
||||
|
@ -86,6 +86,8 @@ target_link_libraries(run_tests
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
)
|
||||
|
||||
openrw_target_apply_options(TARGET run_tests)
|
||||
|
||||
if(SEPERATE_TEST_SUITES)
|
||||
foreach(TEST ${TESTS})
|
||||
add_test(
|
||||
|
Loading…
Reference in New Issue
Block a user