]> git.proxmox.com Git - ceph.git/blob - ceph/cmake/modules/CTags.cmake
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / cmake / modules / CTags.cmake
1 find_program(CTAGS_EXECUTABLE ctags)
2
3 function(add_tags name)
4 cmake_parse_arguments(TAGS "" "SRC_DIR;TAG_FILE" "EXCLUDE_OPTS;EXCLUDES" ${ARGN})
5 set(excludes ${TAGS_EXCLUDES})
6 if(TAGS_EXCLUDE_OPTS)
7 # always respect EXCLUDES_OPTS
8 list(APPEND excludes ${TAGS_EXCLUDE_OPTS})
9 else()
10 # exclude the submodules under SRC_DIR by default
11 execute_process(
12 COMMAND git config --file .gitmodules --get-regexp path
13 COMMAND awk "/${TAGS_SRC_DIR}/ { print $2 }"
14 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
15 RESULT_VARIABLE result_code
16 OUTPUT_VARIABLE submodules
17 OUTPUT_STRIP_TRAILING_WHITESPACE)
18 if(${result_code} EQUAL 0)
19 string(REPLACE "${TAGS_SRC_DIR}/" "" submodules ${submodules})
20 # cmake list uses ";" as the delimiter, so split the string manually
21 # before iterating in it.
22 string(REPLACE "\n" ";" submodules ${submodules})
23 list(APPEND excludes ${submodules})
24 endif()
25 endif()
26 message(STATUS "exclude following files under ${TAGS_SRC_DIR}: ${excludes}")
27 # add_custom_target() accepts a list after "COMMAND" keyword, so we should
28 # make exclude_arg a list, otherwise cmake will quote it. and ctags will
29 # take it as as a single argument.
30 foreach(exclude ${excludes})
31 list(APPEND exclude_args --exclude=${exclude})
32 endforeach()
33 add_custom_target(${name}
34 COMMAND ${CTAGS_EXECUTABLE} -R --c++-kinds=+p --fields=+iaS --extra=+q ${exclude_args}
35 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/${TAGS_SRC_DIR}
36 COMMENT "Building ctags file ${TAGS_TAG_FILE}"
37 VERBATIM)
38 set_source_files_properties(${CMAKE_SOURCE_DIR}/${TAGS_TAG_FILE} PROPERTIES
39 GENERATED true)
40 endfunction()