]>
Commit | Line | Data |
---|---|---|
f3de2dba JAK |
1 | include(CheckCXXCompilerFlag) |
2 | ||
3 | # Flatten our header structure | |
4 | function(flatify target headers) | |
5 | foreach(header ${headers}) | |
6 | get_filename_component(tgt ${header} NAME) | |
7 | configure_file(${header} ${target}/${tgt} @ONLY) | |
8 | endforeach(header ${headers}) | |
9 | endfunction() | |
10 | ||
11 | ||
12 | function(add_optional_compile_options flags) | |
13 | foreach(flag ${flags}) | |
14 | check_cxx_compiler_flag(-${flag} have-compiler-flag:-${flag}) | |
15 | if (have-compiler-flag:-${flag}) | |
16 | add_compile_options("-${flag}") | |
17 | endif() | |
18 | endforeach() | |
19 | endfunction() | |
20 | ||
21 | # Substitute vendor references in a file | |
22 | function(add_vendor_file) | |
23 | set(options) | |
24 | set(oneValueArgs OUTPUT INPUT MODE) | |
25 | set(multiValueArgs VARIABLES) | |
26 | cmake_parse_arguments(AVF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | |
f3de2dba | 27 | |
7d33e7c7 JAK |
28 | set(in ${CMAKE_CURRENT_SOURCE_DIR}/${AVF_INPUT}) |
29 | set(out ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT}) | |
30 | ||
31 | add_custom_command( | |
32 | OUTPUT ${out} | |
33 | COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} | |
34 | "-DVARS=${AVF_VARIABLES}" | |
35 | -DCURRENT_VENDOR=${CURRENT_VENDOR} | |
36 | -DIN=${in} | |
37 | -DOUT=${out} | |
38 | -P ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake | |
39 | COMMAND chmod ${AVF_MODE} ${out} | |
40 | DEPENDS ${in} | |
41 | ${PROJECT_SOURCE_DIR}/doc/apt-verbatim.ent | |
42 | ${PROJECT_SOURCE_DIR}/vendor/${CURRENT_VENDOR}/apt-vendor.ent | |
43 | ${PROJECT_SOURCE_DIR}/vendor/getinfo | |
44 | ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake | |
45 | VERBATIM | |
46 | ) | |
f3de2dba | 47 | |
7d33e7c7 JAK |
48 | # Woud like to use ${AVF_OUTPUT} as target name, but then ninja gets |
49 | # cycles. | |
50 | add_custom_target(vendor-${AVF_OUTPUT} ALL DEPENDS ${out}) | |
f3de2dba JAK |
51 | endfunction() |
52 | ||
53 | # Add symbolic links to a file | |
54 | function(add_slaves destination master) | |
55 | set(slaves "") | |
56 | foreach(slave ${ARGN}) | |
57 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${slave} | |
58 | COMMAND ${CMAKE_COMMAND} -E create_symlink ${master} ${CMAKE_CURRENT_BINARY_DIR}/${slave}) | |
59 | list(APPEND slaves ${CMAKE_CURRENT_BINARY_DIR}/${slave}) | |
60 | endforeach() | |
61 | ||
62 | STRING(REPLACE "/" "-" master "${master}") | |
63 | add_custom_target(${master}-slaves ALL DEPENDS ${slaves}) | |
64 | install(FILES ${slaves} DESTINATION ${destination}) | |
65 | endfunction() | |
66 | ||
67 | # Generates a simple version script versioning everything with current SOVERSION | |
68 | function(add_version_script target) | |
69 | get_target_property(soversion ${target} SOVERSION) | |
70 | set(script "${CMAKE_CURRENT_BINARY_DIR}/${target}.versionscript") | |
71 | string(REPLACE "-" "" name "${target}_${soversion}") | |
72 | string(TOUPPER "${name}" name) | |
73 | add_custom_command(OUTPUT "${script}" | |
74 | COMMAND echo "${name} {global: *; };" > "${script}" | |
75 | VERBATIM ) | |
76 | add_custom_target(${target}-versionscript DEPENDS "${script}") | |
77 | target_link_libraries(${target} PRIVATE -Wl,-version-script="${script}") | |
78 | add_dependencies(${target} ${target}-versionscript) | |
79 | endfunction() | |
0d04a498 JAK |
80 | |
81 | function(path_join out path1 path2) | |
82 | string(SUBSTRING ${path2} 0 1 init_char) | |
83 | if ("${init_char}" STREQUAL "/") | |
84 | set(${out} "${path2}" PARENT_SCOPE) | |
85 | else() | |
86 | set(${out} "${path1}/${path2}" PARENT_SCOPE) | |
87 | endif() | |
88 | endfunction() |