]> git.saurik.com Git - apt.git/blame_incremental - CMake/Misc.cmake
CMake: Cache CURRENT_VENDOR and make it configurable
[apt.git] / CMake / Misc.cmake
... / ...
CommitLineData
1include(CheckCXXCompilerFlag)
2
3# Flatten our header structure
4function(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})
9endfunction()
10
11
12function(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()
19endfunction()
20
21# Substitute vendor references in a file
22function(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})
27 message(STATUS "Configuring vendor file ${AVF_OUTPUT}")
28
29 FILE(READ ${CMAKE_CURRENT_SOURCE_DIR}/${AVF_INPUT} input)
30 foreach(variable ${AVF_VARIABLES})
31 execute_process(COMMAND ../vendor/getinfo ${variable} OUTPUT_VARIABLE value OUTPUT_STRIP_TRAILING_WHITESPACE)
32 string(REPLACE "&${variable};" "${value}" input "${input}")
33 endforeach()
34 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT} "${input}")
35
36 execute_process(COMMAND chmod ${AVF_MODE} ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT})
37endfunction()
38
39# Add symbolic links to a file
40function(add_slaves destination master)
41 set(slaves "")
42 foreach(slave ${ARGN})
43 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${slave}
44 COMMAND ${CMAKE_COMMAND} -E create_symlink ${master} ${CMAKE_CURRENT_BINARY_DIR}/${slave})
45 list(APPEND slaves ${CMAKE_CURRENT_BINARY_DIR}/${slave})
46 endforeach()
47
48 STRING(REPLACE "/" "-" master "${master}")
49 add_custom_target(${master}-slaves ALL DEPENDS ${slaves})
50 install(FILES ${slaves} DESTINATION ${destination})
51endfunction()
52
53# Generates a simple version script versioning everything with current SOVERSION
54function(add_version_script target)
55 get_target_property(soversion ${target} SOVERSION)
56 set(script "${CMAKE_CURRENT_BINARY_DIR}/${target}.versionscript")
57 string(REPLACE "-" "" name "${target}_${soversion}")
58 string(TOUPPER "${name}" name)
59 add_custom_command(OUTPUT "${script}"
60 COMMAND echo "${name} {global: *; };" > "${script}"
61 VERBATIM )
62 add_custom_target(${target}-versionscript DEPENDS "${script}")
63 target_link_libraries(${target} PRIVATE -Wl,-version-script="${script}")
64 add_dependencies(${target} ${target}-versionscript)
65endfunction()