Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wn_bin pkg: Rewrite using modern cmake #354

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 20 additions & 73 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -420,71 +420,31 @@ set( WN_PKG_DIR "${CMAKE_BINARY_DIR}/dds-wrk-bin" )
set( WN_PKG_NAME_ARCH "${WN_PKG_NAME}.tar.gz" )
set( WN_PKG_REMOTE_DIR "/u/ddswww/web-docs/releases/add/${DDS_VERSION}" )

set(DDS_BOOST_LIB_DIR ${Boost_LIBRARY_DIRS})
if("${DDS_BOOST_LIB_DIR}" STREQUAL "")
set(DDS_BOOST_LIB_DIR ${Boost_LIBRARY_DIR_RELEASE})
endif()

if(ENV{DDS_LD_LIBRARY_PATH})
# because of SIP on macOS we can't use (DY)LD_LIBRARY_PATH.
# But we need to search also in custom location for libstdc++ in case if user installs a custom version of gcc/clang.
# WORKAROUND: We therefore introduce DDS_LD_LIBRARY_PATH, which user can use to specify custom library path(s)
file(TO_CMAKE_PATH "$ENV{DDS_LD_LIBRARY_PATH}" ENV_LD_LIBRARY_PATH)
else()
file(TO_CMAKE_PATH "$ENV{LD_LIBRARY_PATH}" ENV_LD_LIBRARY_PATH)
# top-level executables to package in wn pkg
list(APPEND WN_PKG_TARGETS
$<TARGET_FILE:dds-agent>
$<TARGET_FILE:dds-user-defaults> )
if(BUILD_TESTS)
list(APPEND WN_PKG_TARGETS $<TARGET_FILE:dds_topology_lib-tests>)
endif()
separate_arguments(CLI_WN_PKG_TARGETS
UNIX_COMMAND "${WN_PKG_TARGETS}" )

set(PREREQ_DIRS "$<TARGET_FILE_DIR:dds-user-defaults>::$<TARGET_FILE_DIR:dds_protocol_lib>::$<TARGET_FILE_DIR:dds_intercom_lib>::$<TARGET_FILE_DIR:dds_topology_lib>::$<TARGET_FILE_DIR:dds_misc_lib>::${DDS_BOOST_LIB_DIR}")
foreach(p IN LISTS ENV_LD_LIBRARY_PATH)
set(PREREQ_DIRS "${PREREQ_DIRS}::${p}")
endforeach()
foreach(p IN LISTS DDS_LD_LIBRARY_PATH)
set(PREREQ_DIRS "${PREREQ_DIRS}::${p}")
endforeach()

set(DDS_AGENT_BIN_PATH $<TARGET_FILE:dds-agent>)
set(DDS_PREREQ_SOURCE_BIN_PATH $<TARGET_FILE:dds-commander>)

set(PREREQ_DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")

# WORKAROUND: don't generate helper script when building an xcode project
# The reason: "Evaluation file to be written multiple times for different configurations or languages with different content"
if (NOT CMAKE_GENERATOR STREQUAL "Xcode")
#
# WORKAROUND: the issue is configure_file currently does not appear to honor generator expressions,
# but it is still needed to configure @...@ expressions.
# We therefore use two-step procedure to configure a file.
#
# 1. Deal with @...@ configurable items:
configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/DDS_CollectPrerequisitesGen.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/modules/DDS_CollectPrerequisitesGen.cmake.configured @ONLY)
# 2. Deal with items configured with generator expressions (variables like "$<TARGET_FILE_DIR:" evaluted on this stage):
FILE(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/modules/DDS_CollectPrerequisitesGen.cmake
INPUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/modules/DDS_CollectPrerequisitesGen.cmake.configured CONDITION 1)

if( BUILD_TESTS )
set(DDS_PREREQ_SOURCE_BIN_PATH $<TARGET_FILE:dds_topology_lib-tests>)
#
# WORKAROUND: the issue is configure_file currently does not appear to honor generator expressions,
# but it is still needed to configure @...@ expressions.
# We therefore use two-step procedure to configure a file.
#
# 1. Deal with @...@ configurable items:
configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/DDS_CollectPrerequisitesGen.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/modules/DDS_CollectPrerequisitesGen_Tests.cmake.configured @ONLY)
# 2. Deal with items configured with generator expressions (variables like "$<TARGET_FILE_DIR:" evaluted on this stage):
FILE(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/modules/DDS_CollectPrerequisitesGen_Tests.cmake
INPUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/modules/DDS_CollectPrerequisitesGen_Tests.cmake.configured CONDITION 1)
endif( BUILD_TESTS )
endif()
# Generate a list of what CMake considers to be system prefixes
list(APPEND WN_PKG_EXCLUDED_SYSTEM_PREFIXES
${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}
${CMAKE_INSTALL_LIBDIR} )
list(REMOVE_DUPLICATES WN_PKG_EXCLUDED_SYSTEM_PREFIXES)
separate_arguments(CLI_WN_PKG_EXCLUDED_SYSTEM_PREFIXES
UNIX_COMMAND "${WN_PKG_EXCLUDED_SYSTEM_PREFIXES}" )

#
# TODO: replace DDS_CollectPrerequisites.cmake by DDS_CollectPrerequisitesGen.cmake and make the script more generic
#
add_custom_target( wn_bin
COMMAND ${CMAKE_COMMAND} -E make_directory ${WN_PKG_DIR}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:dds-agent> "${WN_PKG_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:dds-user-defaults> "${WN_PKG_DIR}"
COMMAND ${CMAKE_COMMAND} -DPREREQ_DESTINATION=${WN_PKG_DIR} -DDDS_AGENT_BIN_PATH=${DDS_AGENT_BIN_PATH}
-DPREREQ_DIRS=${PREREQ_DIRS} -DDDS_BOOST_LIB_DIR=${DDS_BOOST_LIB_DIR} -P "${CMAKE_SOURCE_DIR}/cmake/modules/DDS_CollectPrerequisites.cmake"
COMMAND ${CMAKE_COMMAND}
-DEXECUTABLES=${CLI_WN_PKG_TARGETS}
-DDESTINATION=${WN_PKG_DIR}
-DEXCLUDED_SYSTEM_PREFIXES=${CLI_WN_PKG_EXCLUDED_SYSTEM_PREFIXES}
-P "${CMAKE_SOURCE_DIR}/cmake/DDSCollectWNPkgFiles.cmake"
COMMAND ${CMAKE_COMMAND} -E tar czf ${WN_PKG_NAME_ARCH} "${WN_PKG_DIR}"
COMMAND chmod go+xr ${WN_PKG_NAME_ARCH}
COMMENT "Generate WN binary package"
Expand All @@ -507,19 +467,6 @@ add_dependencies( wn_bin_upload

INSTALL(FILES ${CMAKE_BINARY_DIR}/${WN_PKG_NAME_ARCH} DESTINATION "${PROJECT_INSTALL_BINDIR}/wn_bins" OPTIONAL)


# WORKAROUND: don't generate helper script when building an xcode project
# The reason: "Evaluation file to be written multiple times for different configurations or languages with different content"
if (NOT CMAKE_GENERATOR STREQUAL "Xcode")
# WORKAROUND: create destination "lib" directory.
# INSTALL SCRIPT is called before any other lib is installed, therefore we need to create a dest. dir.
INSTALL(DIRECTORY DESTINATION "${PROJECT_INSTALL_LIBDIR}")
INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/cmake/modules/DDS_CollectPrerequisitesGen.cmake)
if( BUILD_TESTS )
INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/cmake/modules/DDS_CollectPrerequisitesGen_Tests.cmake)
endif( BUILD_TESTS )
endif()

#
# Package
#
Expand Down
24 changes: 24 additions & 0 deletions cmake/DDSCollectWNPkgFiles.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2017-2022 GSI, Inc. All rights reserved.
#
#

###################################################
## Collect WN PKG files
###################################################

# Collect non-system dependencies
file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR deps
EXECUTABLES ${EXECUTABLES} )

# Generate regex that excludes system prefixes
list(JOIN EXCLUDED_SYSTEM_PREFIXES "|" excluded_system_prefix_regex)
set(excluded_system_prefix_regex "^(${excluded_system_prefix_regex})/")

# Copy dependencies to wn pkg staging directory
foreach(file IN LISTS EXECUTABLES deps)
if(NOT file MATCHES ${excluded_system_prefix_regex})
message("WN PKG prerequisite='${file}'")
file(COPY ${file} DESTINATION ${DESTINATION})
endif()
endforeach()
37 changes: 0 additions & 37 deletions cmake/modules/DDS_CollectPrerequisites.cmake

This file was deleted.

57 changes: 0 additions & 57 deletions cmake/modules/DDS_CollectPrerequisitesGen.cmake.in

This file was deleted.