-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.cmake
74 lines (66 loc) · 2.12 KB
/
util.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
include_guard(GLOBAL)
function(clone_executable old_target new_target)
if(NOT TARGET ${old_target})
message(FATAL_ERROR "${old_target} is not a target")
return()
endif()
get_target_property(property_var ${old_target} TYPE)
if(NOT property_var STREQUAL EXECUTABLE)
message(FATAL_ERROR "${old_target} is not an executable")
return()
endif()
get_target_property(source_files ${old_target} SOURCES)
add_executable(${new_target} ${source_files})
# get all properties
execute_process(COMMAND ${CMAKE_COMMAND} --help-property-list
OUTPUT_VARIABLE CMAKE_PROPERTY_LIST)
# Convert command output into a CMake list
string(REGEX REPLACE "[\n\r]" ";" CMAKE_PROPERTY_LIST
"${CMAKE_PROPERTY_LIST}")
foreach(property IN LISTS CMAKE_PROPERTY_LIST)
if(property STREQUAL "" OR property MATCHES ".*LOCATION.*")
continue()
endif()
set(SKIPPED_PROPERTIES
"TYPE;NAME;ALIAS_GLOBAL;BINARY_DIR;CXX_MODULE_SETS;IMPORTED;INTERFACE_CXX_MODULE_SETS;LOCATION;SOURCE_DIR"
)
if(property IN_LIST SKIPPED_PROPERTIES)
continue()
endif()
get_target_property(property_value ${old_target} "${property}")
if(NOT property_value)
continue()
endif()
set_target_properties(${new_target} PROPERTIES "${property}"
"${property_value}")
endforeach()
endfunction()
function(get_all_sources_and_headers)
set(get_all_sources_and_headers
[=[
#!/bin/sh
if command -v gsed >/dev/null
then
sed_cmd=gsed
else
sed_cmd=sed
fi
for source_file in $(grep '"file":' $1 | ${sed_cmd} -e 's/"file"://' | ${sed_cmd} -e 's/[^"]*"\([^"]*\)"/\1/' | grep -v 'pb.h' | grep -v 'pb.cc')
do
source_dir=$(dirname ${source_file})
for head in $(${sed_cmd} -n -e 's/^\s*#include[^"]*"\([^"]*\)"/\1/p' ${source_file})
do
if test -f "${source_dir}/${head}"
then
realpath "${source_dir}/${head}"
fi
done
if test -f "${source_file}"
then
realpath "${source_file}"
fi
done
]=])
file(WRITE ${CMAKE_BINARY_DIR}/get_all_sources_and_headers.sh
${get_all_sources_and_headers})
endfunction()