Computer Assited Medical Intervention Tool Kit  version 4.1
CamiTKIncludeWhatYouUse.h
Go to the documentation of this file.
1 #------------------------------------------
2 # Manage Include what you use
3 #-------------------------------------------
4 
5 # see https://stackoverflow.com/a/30951493
6 # and https://blog.kitware.com/static-checks-with-cmake-cdash-iwyu-clang-tidy-lwyu-cpplint-and-cppcheck/
7 
8 # Flag CMAKE_CXX_INCLUDE_WHAT_YOU_USE is only available in CMake 3.3 and above
9 if(${CMAKE_VERSION} VERSION_GREATER "3.3" OR ${CMAKE_VERSION} VERSION_EQUAL "3.3")
10 
11  option(CAMITK_INCLUDE_WHAT_YOU_USE "Enable the header analysis on you code, CMake version 3.3 or greater is needed" OFF)
12 
13  if (CAMITK_INCLUDE_WHAT_YOU_USE)
14 
15  find_program(IWYU_EXECUTABLE NAMES include-what-you-use iwyu)
16 
17  if(IWYU_EXECUTABLE)
18 
19  set(IWYU_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/iwyu.out" CACHE PATH "Output filename for include-what-you-use")
20 
21  # set the cmake flag in order to generate include-what-you-use report all the time
22  set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXECUTABLE})
23 
24  #-- define a target that generate the include-what-you-use report for all the project
25 
26  # determine cmake macro path
27  if (NOT EXISTS ${SDK_TOP_LEVEL_SOURCE_DIR})
28  # this macro is called outside the sdk
29  set(CAMITK_CMAKE_MACRO_PATH ${CAMITK_CMAKE_DIR}/macros/camitk/test)
30  if(NOT IS_DIRECTORY ${CAMITK_CMAKE_MACRO_PATH})
31  # inside communityedition but not in sdk (modeling or imaging)
32  set(CAMITK_CMAKE_MACRO_PATH ${CMAKE_SOURCE_DIR}/sdk/cmake/modules/macros/camitk/test)
33  endif()
34  else()
35  # directly use the macro source dir
36  set(CAMITK_CMAKE_MACRO_PATH ${SDK_TOP_LEVEL_SOURCE_DIR}/cmake/modules/macros/camitk/test)
37  endif()
38 
39  add_custom_target(camitk-ce-iwyu
40  COMMAND ${CMAKE_COMMAND} -E echo "Running include-what-you-use. Results can be found in ${IWYU_OUTPUT}"
41  COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR} --target clean
42  COMMAND ${CMAKE_COMMAND} "-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=${IWYU_EXECUTABLE}" ${CMAKE_SOURCE_DIR}
43  COMMAND ${CMAKE_COMMAND}
44  -DMAKE_ERROR_OUTPUT_FILE=${IWYU_OUTPUT}
45  -P ${CAMITK_CMAKE_MACRO_PATH}/CamiTKMakeWithRedirectedError.cmake
46  COMMAND ${CMAKE_COMMAND} "-UCMAKE_CXX_INCLUDE_WHAT_YOU_USE" ${CMAKE_SOURCE_DIR}
47  COMMENT "Running include-what-you-use for all project"
48  )
49 
50  else ()
51  message(FATAL_ERROR "Could not find the program include-what-you-use")
52  endif()
53  else()
54  unset(CMAKE_CXX_INCLUDE_WHAT_YOU_USE)
55  endif()
56 
57 endif()
58 
test result unset(PREVIOUS_ATTEMPTS) file(GLOB ALL_OUTPUT_FILES $
Definition: CamiTKTestActionStateMachine.h:43
Definition: Action.cpp:36
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
#define a
static void include(QRect &r, const QRect &rect)
Definition: canvas_typed/qtcanvas.cpp:98