1 include(CheckCXXCompilerFlag)
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} COPYONLY)
8 endforeach(header ${headers})
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}")
21 # Substitute vendor references in a file
22 function(add_vendor_file)
24 set(oneValueArgs OUTPUT INPUT MODE)
25 set(multiValueArgs VARIABLES)
26 cmake_parse_arguments(AVF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
28 set(in ${CMAKE_CURRENT_SOURCE_DIR}/${AVF_INPUT})
29 set(out ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT})
33 COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
34 "-DVARS=${AVF_VARIABLES}"
35 -DCURRENT_VENDOR=${CURRENT_VENDOR}
38 -P ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake
39 COMMAND chmod ${AVF_MODE} ${out}
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
48 # Woud like to use ${AVF_OUTPUT} as target name, but then ninja gets
50 add_custom_target(vendor-${AVF_OUTPUT} ALL DEPENDS ${out})
53 # Add symbolic links to a file
54 function(add_slaves destination master)
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})
62 STRING(REPLACE "/" "-" master "${master}")
63 add_custom_target(${master}-slaves ALL DEPENDS ${slaves})
64 install(FILES ${slaves} DESTINATION ${destination})
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}"
76 add_custom_target(${target}-versionscript DEPENDS "${script}")
77 target_link_libraries(${target} PRIVATE -Wl,-version-script="${script}")
78 add_dependencies(${target} ${target}-versionscript)
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)
86 set(${out} "${path1}/${path2}" PARENT_SCOPE)