Skip to content

Commit

Permalink
wn_bin pkg: Rewrite using modern cmake
Browse files Browse the repository at this point in the history
Modern cmake has better tools to collect the prereqs of
binaries. Let's use them.

The original patches are by Dennis Klein. He deserves most
of the credit for developing this.
  • Loading branch information
ChristianTackeGSI committed Mar 8, 2021
1 parent 99ac14e commit d397069
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 159 deletions.
93 changes: 22 additions & 71 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ set(DDS_PROTOCOL_VERSION "2")
#
# Check if cmake has the required version
#
cmake_minimum_required( VERSION 3.11.0 FATAL_ERROR )
cmake_minimum_required( VERSION 3.16.0 FATAL_ERROR )
cmake_policy(VERSION 3.16)

string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)

Expand Down Expand Up @@ -409,68 +410,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_DIR})
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_EXECUTABLES
$<TARGET_FILE:dds-agent>
$<TARGET_FILE:dds-user-defaults> )
if(BUILD_TESTS)
list(APPEND $<TARGET_FILE:dds_topology_lib-tests>)
endif()
separate_arguments(CLI_WN_PKG_EXECUTABLES
UNIX_COMMAND "${WN_PKG_EXECUTABLES}" )

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_ncf>::${DDS_BOOST_LIB_DIR}")
foreach(p IN LISTS ENV_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_EXECUTABLES}
-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 @@ -493,19 +457,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-2021 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.

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

This file was deleted.

0 comments on commit d397069

Please sign in to comment.