1 |
# |
2 |
# (C) Copyright 2018 Tillmann Heidsieck |
3 |
# |
4 |
# SPDX-License-Identifier: MIT |
5 |
# |
6 |
|
7 |
find_program(CTAGS ctags) |
8 |
|
9 |
function(tags_add_dir _dir) |
10 |
get_property(_subdirlist DIRECTORY "${_dir}" PROPERTY SUBDIRECTORIES) |
11 |
foreach(_sd ${_subdirlist}) |
12 |
tags_add_dir(${_sd}) |
13 |
endforeach() |
14 |
|
15 |
get_property(_targets_list DIRECTORY "${_dir}" PROPERTY |
16 |
BUILDSYSTEM_TARGETS) |
17 |
foreach(_tgt ${_targets_list}) |
18 |
get_property(_t_files TARGET ${_tgt} PROPERTY SOURCES) |
19 |
list(FILTER _t_files EXCLUDE REGEX TARGET_OBJECTS) |
20 |
get_property(_t_defs TARGET ${_tgt} PROPERTY |
21 |
COMPILE_DEFINITIONS) |
22 |
|
23 |
list(APPEND _all_source_files ${_t_files}) |
24 |
string(REGEX REPLACE "${CMAKE_SOURCE_DIR}/" "" _t_files |
25 |
"${_t_files}") |
26 |
string(REGEX REPLACE ";" "\n" _t_files "${_t_files}") |
27 |
|
28 |
string(REGEX REPLACE ";" "\n" _t_defs "${_t_defs}") |
29 |
string(REGEX REPLACE "^([^=]+)$" "\\1=1" _t_defs "${_t_defs}") |
30 |
endforeach() |
31 |
set(_all_source_files ${_all_source_files} PARENT_SCOPE) |
32 |
set(_all_definitions ${_all_definitions} PARENT_SCOPE) |
33 |
endfunction() |
34 |
|
35 |
if(CTAGS) |
36 |
set(SOURCES_LIST "${CMAKE_BINARY_DIR}/sources_list") |
37 |
set(_all_source_files "") |
38 |
set(_all_definitions "") |
39 |
|
40 |
file(REMOVE "${SOURCES_LIST}") |
41 |
|
42 |
tags_add_dir(${CMAKE_SOURCE_DIR}) |
43 |
|
44 |
list(SORT _all_source_files) |
45 |
list(REMOVE_DUPLICATES _all_source_files) |
46 |
string(REGEX REPLACE "${CMAKE_SOURCE_DIR}/" "" _asf |
47 |
"${_all_source_files}") |
48 |
string(REGEX REPLACE ";" "\n" _asf "${_asf}") |
49 |
file(APPEND ${SOURCES_LIST} "\n${_asf}") |
50 |
|
51 |
string(REGEX REPLACE ";" "\n" _all_definitions "${_all_definitions}") |
52 |
string(REGEX REPLACE "^([^=]+)$" "\\1=1" _all_definitions |
53 |
"${_all_definitions}") |
54 |
|
55 |
add_custom_target(TAGS DEPENDS ${CMAKE_SOURCE_DIR}/TAGS) |
56 |
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/TAGS |
57 |
COMMAND ctags -e --language-force=fortran -L ${SOURCES_LIST} |
58 |
DEPENDS ${_all_source_files} |
59 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
60 |
VERBATIM) |
61 |
endif() |