Skip to content

Commit eb2e027

Browse files
authored
Merge pull request #584 from sebproell/iwyu-option
CMake: option FOUR_C_ENABLE_IWYU
2 parents caafd35 + 8c3aa1f commit eb2e027

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cmake/functions/four_c_auto_define_module.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ function(four_c_auto_define_module)
3838
# them on other users of the library.
3939
target_link_libraries(${_target}_objs PRIVATE four_c_private_compile_interface)
4040

41+
if(FOUR_C_ENABLE_IWYU)
42+
set_target_properties(
43+
${_target}_objs PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ${FOUR_C_IWYU_EXECUTABLE}
44+
)
45+
endif()
46+
4147
if(FOUR_C_ENABLE_DEVELOPER_MODE AND _parsed_NO_CYCLES)
4248
# Define an additional library built from the sources. In developer mode, we link unit tests against this library which can
4349
# be faster to build than lib4C.

cmake/setup_global_options.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ else()
152152
enable_compiler_flag_if_supported("-fno-trapping-math")
153153
endif()
154154

155+
four_c_process_global_option(FOUR_C_ENABLE_IWYU "Enable include-what-you-use" OFF)
156+
if(FOUR_C_ENABLE_IWYU)
157+
find_program(FOUR_C_IWYU_EXECUTABLE NAMES include-what-you-use iwyu)
158+
if(NOT FOUR_C_IWYU_EXECUTABLE)
159+
message(
160+
FATAL_ERROR "Option FOUR_C_ENABLE_IWYU is ON but include-what-you-use/iwyu is not found."
161+
"You can specify the path in the CMake variable FOUR_C_IWYU_EXECUTABLE."
162+
)
163+
endif()
164+
endif()
165+
155166
##
156167
# Optimization flags
157168
# These flags are reasonable defaults. Users may amend them by setting FOUR_C_CXX_FLAGS and/or FOUR_C_CXX_FLAGS_<CONFIG>.

0 commit comments

Comments
 (0)