Skip to content

Commit 3cd948a

Browse files
committed
cmake: Add option to run include-what-you-use with compiler
1 parent c90ee43 commit 3cd948a

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
@@ -134,6 +134,17 @@ option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON)
134134
option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND})
135135
option(SECP256K1_BUILD_EXAMPLES "Build examples." OFF)
136136

137+
if(CMAKE_VERSION VERSION_GREATER 3.2)
138+
option(SECP256K1_RUN_IWYU "Run include-what-you-use (IWYU) with the compiler." OFF)
139+
if(SECP256K1_RUN_IWYU)
140+
find_program(INCLUDE_WHAT_YOU_USE_COMMAND NAMES include-what-you-use)
141+
if(NOT INCLUDE_WHAT_YOU_USE_COMMAND)
142+
message(FATAL_ERROR "SECP256K1_RUN_IWYU is ON but include-what-you-use is not found.")
143+
endif()
144+
set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${INCLUDE_WHAT_YOU_USE_COMMAND}")
145+
endif()
146+
endif()
147+
137148
# Redefine configuration flags.
138149
if(MSVC)
139150
string(REPLACE "/DNDEBUG" "" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
@@ -263,6 +274,9 @@ get_directory_property(definitions COMPILE_DEFINITIONS)
263274
string(REPLACE ";" " " definitions "${definitions}")
264275
message("Preprocessor defined macros ........... ${definitions}")
265276
message("C compiler ............................ ${CMAKE_C_COMPILER}")
277+
if(SECP256K1_RUN_IWYU)
278+
message("Run IWYU with the compiler ............ ${CMAKE_C_INCLUDE_WHAT_YOU_USE}")
279+
endif()
266280
message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
267281
get_directory_property(compile_options COMPILE_OPTIONS)
268282
string(REPLACE ";" " " compile_options "${compile_options}")

0 commit comments

Comments
 (0)