Add checkAPI calls to CMake.
[metze/wireshark/wip.git] / cmake / modules / UseCheckAPI.cmake
1 # Add a target to call checkAPIs.pl on the specified source files
2 # The target is excluded from the ALL targte so must be manually
3 # specified in a build command.
4 # The target is added to the top-level checkAPIs target
5 #
6 # Parameters:
7 #   NAME:       The name of the target, must be unique
8 #   SWITCHES:   Switches to be supplied to the script
9 #   SOURCES:    The sources to be checked
10
11 include(CMakeParseArguments)
12
13 macro( CHECKAPI )
14         cmake_parse_arguments(CHECKAPI "DEBUG" "" "NAME;SWITCHES;SOURCES" ${ARGN} )
15
16         if (CHECKAPI_UNPARSED_ARGUMENTS)
17                 message(FATAL_ERROR "CHECKAPIS Unknown argument: ${CHECKAPI_UNPARSED_ARGUMENTS}")
18         endif()
19
20         if( CHECKAPI_DEBUG )
21                 set (CHECKAPI_SWITCHES ${CHECKAPI_SWITCHES --debug)
22         endif()
23
24         set(TARGET_NAME checkAPI_${CHECKAPI_NAME})
25         add_custom_target(${TARGET_NAME}
26                 COMMAND ${PERL_EXECUTABLE}
27                   ${CMAKE_SOURCE_DIR}/tools/checkAPIs.pl
28                   ${CHECKAPI_SWITCHES}
29                   ${CHECKAPI_SOURCES}
30                 WORKING_DIRECTORY
31                   ${CMAKE_CURRENT_SOURCE_DIR}
32                 COMMENT
33                   "Running ${TARGET_NAME}"
34         )
35         add_dependencies(checkAPI ${TARGET_NAME})
36         set_target_properties(${TARGET_NAME}
37                 PROPERTIES FOLDER "Auxiliary/CheckAPIs"
38                 EXCLUDE_FROM_ALL True
39                 EXCLUDE_FROM_DEFAULT_BUILD True
40         )
41 ENDMACRO()