Skip to content

Commit 5a91a4c

Browse files
committed
cmake: Add option to run include-what-you-use with compiler
1 parent df323b5 commit 5a91a4c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON)
132132
option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND})
133133
option(SECP256K1_BUILD_EXAMPLES "Build examples." OFF)
134134

135+
if(CMAKE_VERSION VERSION_GREATER 3.2)
136+
option(SECP256K1_ENABLE_IWYU "Run include-what-you-use (IWYU) with the compiler." OFF)
137+
if(SECP256K1_ENABLE_IWYU)
138+
find_program(INCLUDE_WHAT_YOU_USE_COMMAND NAMES include-what-you-use)
139+
if(NOT INCLUDE_WHAT_YOU_USE_COMMAND)
140+
message(FATAL_ERROR "SECP256K1_ENABLE_IWYU is ON but include-what-you-use is not found.")
141+
endif()
142+
set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${INCLUDE_WHAT_YOU_USE_COMMAND}")
143+
endif()
144+
endif()
145+
135146
# Redefine configuration flags.
136147
# We leave assertions on, because they are only used in the examples, and we want them always on there.
137148
if(MSVC)
@@ -269,6 +280,9 @@ get_directory_property(definitions COMPILE_DEFINITIONS)
269280
string(REPLACE ";" " " definitions "${definitions}")
270281
message("Preprocessor defined macros ........... ${definitions}")
271282
message("C compiler ............................ ${CMAKE_C_COMPILER}")
283+
if(SECP256K1_ENABLE_IWYU)
284+
message("Run IWYU with the compiler ............ ${CMAKE_C_INCLUDE_WHAT_YOU_USE}")
285+
endif()
272286
message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
273287
get_directory_property(compile_options COMPILE_OPTIONS)
274288
string(REPLACE ";" " " compile_options "${compile_options}")

0 commit comments

Comments
 (0)