summaryrefslogtreecommitdiffstats
path: root/CMake/Misc.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 09:59:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 09:59:37 +0000
commit76e2632459410dec81337edb6a9fee33c9a660f3 (patch)
treea73345df208eede4a4daad340515c9328f34625c /CMake/Misc.cmake
parentInitial commit. (diff)
downloadapt-76e2632459410dec81337edb6a9fee33c9a660f3.tar.xz
apt-76e2632459410dec81337edb6a9fee33c9a660f3.zip
Adding upstream version 2.7.12.upstream/2.7.12
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'CMake/Misc.cmake')
-rw-r--r--CMake/Misc.cmake101
1 files changed, 101 insertions, 0 deletions
diff --git a/CMake/Misc.cmake b/CMake/Misc.cmake
new file mode 100644
index 0000000..8cb18b6
--- /dev/null
+++ b/CMake/Misc.cmake
@@ -0,0 +1,101 @@
+include(CheckCXXCompilerFlag)
+
+# Flatten our header structure
+function(flatify target headers)
+ foreach(header ${headers})
+ get_filename_component(tgt ${header} NAME)
+ configure_file(${header} ${target}/${tgt} COPYONLY)
+ endforeach(header ${headers})
+endfunction()
+
+
+function(add_optional_compile_options flags)
+ foreach(flag ${flags})
+ check_cxx_compiler_flag(-${flag} have-compiler-flag:-${flag})
+ if (have-compiler-flag:-${flag})
+ add_compile_options("-${flag}")
+ endif()
+ endforeach()
+endfunction()
+
+# Substitute vendor references in a file
+function(add_vendor_file)
+ set(options)
+ set(oneValueArgs OUTPUT INPUT MODE)
+ set(multiValueArgs VARIABLES)
+ cmake_parse_arguments(AVF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ set(in ${CMAKE_CURRENT_SOURCE_DIR}/${AVF_INPUT})
+ set(out ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT})
+
+ add_custom_command(
+ OUTPUT ${out}
+ COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
+ "-DVARS=${AVF_VARIABLES}"
+ -DCURRENT_VENDOR=${CURRENT_VENDOR}
+ -DIN=${in}
+ -DOUT=${out}
+ -P ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake
+ COMMAND chmod ${AVF_MODE} ${out}
+ DEPENDS ${in}
+ ${PROJECT_SOURCE_DIR}/doc/apt-verbatim.ent
+ ${PROJECT_SOURCE_DIR}/vendor/${CURRENT_VENDOR}/apt-vendor.ent
+ ${PROJECT_SOURCE_DIR}/vendor/getinfo
+ ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake
+ VERBATIM
+ )
+
+ # Would like to use ${AVF_OUTPUT} as target name, but then ninja gets
+ # cycles.
+ add_custom_target(vendor-${AVF_OUTPUT} ALL DEPENDS ${out})
+endfunction()
+
+# Add symbolic links to a file
+function(add_links directory target)
+ set(link_names "")
+ foreach(link_name ${ARGN})
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${link_name}
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${target} ${CMAKE_CURRENT_BINARY_DIR}/${link_name})
+ list(APPEND link_names ${CMAKE_CURRENT_BINARY_DIR}/${link_name})
+ endforeach()
+
+ STRING(REPLACE "/" "-" target "${target}")
+ add_custom_target(${target}-link_names ALL DEPENDS ${link_names})
+ install(FILES ${link_names} DESTINATION ${directory})
+endfunction()
+
+# Generates a simple version script versioning everything with current SOVERSION
+function(add_version_script target)
+ get_target_property(soversion ${target} SOVERSION)
+ set(script "${CMAKE_CURRENT_BINARY_DIR}/${target}.versionscript")
+ string(REPLACE "-" "" name "${target}_${soversion}")
+ string(TOUPPER "${name}" name)
+ add_custom_command(OUTPUT "${script}"
+ COMMAND echo "${name} {global: *; };" > "${script}"
+ VERBATIM )
+ add_custom_target(${target}-versionscript DEPENDS "${script}")
+ target_link_libraries(${target} PRIVATE -Wl,-version-script="${script}")
+ add_dependencies(${target} ${target}-versionscript)
+endfunction()
+
+function(path_join out path1 path2)
+ string(SUBSTRING ${path2} 0 1 init_char)
+ if ("${init_char}" STREQUAL "/")
+ set(${out} "${path2}" PARENT_SCOPE)
+ else()
+ set(${out} "${path1}/${path2}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+# install_empty_directories(path ...)
+#
+# Creates empty directories in the install destination dir. Paths may be
+# absolute or relative; in the latter case, the value of CMAKE_INSTALL_PREFIX
+# is prepended.
+function(install_empty_directories)
+ foreach(path ${ARGN})
+ path_join(full_path "${CMAKE_INSTALL_PREFIX}" "${path}")
+ INSTALL(CODE "MESSAGE(STATUS \"Creating directory: \$ENV{DESTDIR}${full_path}\")"
+ CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${full_path})")
+ endforeach()
+endfunction()