From 636a6a2fb808752f3105f86160d9318748eca561 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 8 Feb 2022 11:11:03 -0500 Subject: [PATCH] Meta: Add a CPack installation target for js(1) This adds a CPack configuration to generate a release package for js(1). Our current CMake requirement is 3.16, which doesn't have a great story for automatically installing a binary target's library dependencies. If we eventually require CMake 3.21 or above, we can remove the helper .cmake file added here in lieu of RUNTIME_DEPENDENCIES. --- Meta/Lagom/CMakeLists.txt | 20 ++++++++++-- Meta/Lagom/get_linked_lagom_libraries.cmake | 34 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 Meta/Lagom/get_linked_lagom_libraries.cmake diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index e2eed966f4..2b42dfa1fb 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -304,7 +304,7 @@ if (BUILD_LAGOM) ) # ELF - # FIXME: Excluding arm64 is a temporary hack to circumvent a build problem + # FIXME: Excluding arm64 is a temporary hack to circumvent a build problem # for Lagom on Apple M1 if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") file(GLOB LIBELF_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibELF/*.cpp") @@ -462,7 +462,7 @@ if (BUILD_LAGOM) ) # x86 - # FIXME: Excluding arm64 is a temporary hack to circumvent a build problem + # FIXME: Excluding arm64 is a temporary hack to circumvent a build problem # for Lagom on Apple M1 if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") file(GLOB LIBX86_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibX86/*.cpp") @@ -484,7 +484,7 @@ if (BUILD_LAGOM) set_target_properties(adjtime_lagom PROPERTIES OUTPUT_NAME adjtime) target_link_libraries(adjtime_lagom LagomCore LagomMain) - # FIXME: Excluding arm64 is a temporary hack to circumvent a build problem + # FIXME: Excluding arm64 is a temporary hack to circumvent a build problem # for Lagom on Apple M1 if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") add_executable(disasm_lagom ../../Userland/Utilities/disasm.cpp) @@ -658,6 +658,20 @@ if (BUILD_LAGOM) PASS_REGULAR_EXPRESSION "PASS" ) endforeach() + + # FIXME: When we are using CMake >= 3.21, the library installations can be replaced with RUNTIME_DEPENDENCIES. + # https://cmake.org/cmake/help/latest/command/install.html + include(get_linked_lagom_libraries.cmake) + get_linked_lagom_libraries(js_lagom js_lagom_libraries) + + install(TARGETS js_lagom ${js_lagom_libraries} COMPONENT js) + + set(CPACK_GENERATOR "TGZ") + set(CPACK_STRIP_FILES TRUE) + set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) + set(CPACK_COMPONENTS_ALL js) + set(CPACK_PACKAGE_FILE_NAME serenity-js) + include(CPack) endif() endif() diff --git a/Meta/Lagom/get_linked_lagom_libraries.cmake b/Meta/Lagom/get_linked_lagom_libraries.cmake new file mode 100644 index 0000000000..a77928bbfb --- /dev/null +++ b/Meta/Lagom/get_linked_lagom_libraries.cmake @@ -0,0 +1,34 @@ +function(add_lagom_library list item) + list(FIND "${list}" "${item}" item_is_present) + + if (item_is_present EQUAL -1) + set("${list}" "${${list}}" "${item}" PARENT_SCOPE) + endif() +endfunction() + +function(get_linked_lagom_libraries_impl target output) + if (NOT TARGET "${target}") + return() + endif() + + get_target_property(target_type "${target}" TYPE) + + if ("${target_type}" STREQUAL "SHARED_LIBRARY") + add_lagom_library("${output}" "${target}") + elseif ("${target_type}" STREQUAL "INTERFACE_LIBRARY") + return() + endif() + + get_target_property(target_libraries "${target}" LINK_LIBRARIES) + + foreach(target_library IN LISTS target_libraries) + get_linked_lagom_libraries_impl("${target_library}" "${output}") + endforeach() + + set("${output}" "${${output}}" PARENT_SCOPE) +endfunction() + +function(get_linked_lagom_libraries target output) + get_linked_lagom_libraries_impl(${target} ${output}) + set("${output}" "${${output}}" PARENT_SCOPE) +endfunction()