fix installation for QuickJS in CI
[liba.git] / cmake / FindIWYU.cmake
blobabd0026abd66fd94fcef0a27d34756bc4b14ce40
1 #.rst:
2 # FindIWYU
3 # --------
5 # Find include-what-you-use executable.
7 # Result Variables
8 # ^^^^^^^^^^^^^^^^
10 # This module defines the following variables:
12 # ``IWYU_FOUND``
14 # ``IWYU_EXECUTABLE``
16 # ``IWYU_VERSION``
18 # Functions
19 # ^^^^^^^^^
21 # .. command:: add_include_what_you_use
23 #   ::
25 #     add_include_what_you_use([OPTIONS opt] [TARGETS tgt ...] [tgt ...])
27 include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
28 find_program(IWYU_EXECUTABLE NAMES include-what-you-use)
29 mark_as_advanced(IWYU_EXECUTABLE)
31 if(EXISTS "${IWYU_EXECUTABLE}")
32   execute_process(COMMAND ${IWYU_EXECUTABLE} --version OUTPUT_VARIABLE IWYU_VERSION)
33   string(REGEX REPLACE ".*use ([^\n ]+).*" "\\1" IWYU_VERSION "${IWYU_VERSION}")
34 endif()
36 find_package_handle_standard_args(IWYU
37   FOUND_VAR
38     IWYU_FOUND
39   REQUIRED_VARS
40     IWYU_EXECUTABLE
41   VERSION_VAR
42     IWYU_VERSION
45 if(IWYU_FOUND)
46   function(add_include_what_you_use)
47     if(CMAKE_VERSION VERSION_LESS 3.3)
48       return()
49     endif()
50     cmake_parse_arguments(IWYU "" "" "TARGETS;OPTIONS" ${ARGN})
51     list(APPEND IWYU_TARGETS ${IWYU_UNPARSED_ARGUMENTS})
52     set_target_properties(${IWYU_TARGETS} PROPERTIES C_INCLUDE_WHAT_YOU_USE "${IWYU_EXECUTABLE};${IWYU_OPTIONS}")
53     set_target_properties(${IWYU_TARGETS} PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXECUTABLE};${IWYU_OPTIONS}")
54   endfunction()
55 endif()