From 5a91a4c536c3c927f85d96608255ed829f7cf191 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 8 Mar 2023 16:30:32 +0000 Subject: [PATCH] cmake: Add option to run `include-what-you-use` with compiler --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19844da27e..4e7ac574e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,17 @@ option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON) option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND}) option(SECP256K1_BUILD_EXAMPLES "Build examples." OFF) +if(CMAKE_VERSION VERSION_GREATER 3.2) + option(SECP256K1_ENABLE_IWYU "Run include-what-you-use (IWYU) with the compiler." OFF) + if(SECP256K1_ENABLE_IWYU) + find_program(INCLUDE_WHAT_YOU_USE_COMMAND NAMES include-what-you-use) + if(NOT INCLUDE_WHAT_YOU_USE_COMMAND) + message(FATAL_ERROR "SECP256K1_ENABLE_IWYU is ON but include-what-you-use is not found.") + endif() + set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${INCLUDE_WHAT_YOU_USE_COMMAND}") + endif() +endif() + # Redefine configuration flags. # We leave assertions on, because they are only used in the examples, and we want them always on there. if(MSVC) @@ -269,6 +280,9 @@ get_directory_property(definitions COMPILE_DEFINITIONS) string(REPLACE ";" " " definitions "${definitions}") message("Preprocessor defined macros ........... ${definitions}") message("C compiler ............................ ${CMAKE_C_COMPILER}") +if(SECP256K1_ENABLE_IWYU) + message("Run IWYU with the compiler ............ ${CMAKE_C_INCLUDE_WHAT_YOU_USE}") +endif() message("CFLAGS ................................ ${CMAKE_C_FLAGS}") get_directory_property(compile_options COMPILE_OPTIONS) string(REPLACE ";" " " compile_options "${compile_options}")