Now I am totally confused.
What means install(RUNTIME_DEPENDENCY_SET libDeps)
really?
With this CMakeLists.txt:
cmake_minimum_required(VERSION 3.21...3.28)
project(
CPMExampleBoost
VERSION 0.1.2
LANGUAGES CXX
)
set(stageDir ${CMAKE_CURRENT_BINARY_DIR}/stage)
include(GNUInstallDirs)
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_BINDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_LIBDIR})
endif()
option(CPM_USE_LOCAL_PACKAGES "yes/no" YES)
option(BUILD_SHARED_LIBS "yes/no" YES)
if(BUILD_SHARED_LIBS)
if(APPLE)
set(base @loader_path)
else()
set(base $ORIGIN)
endif()
file(RELATIVE_PATH relDir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
set(CMAKE_INSTALL_RPATH ${base} ${base}/${relDir})
endif()
set(CMAKE_INSTALL_MESSAGE LAZY)
# ---- Create binary ----
add_executable(CPMExampleBoost main.cpp)
target_compile_features(CPMExampleBoost PRIVATE cxx_std_17)
# ---- Dependencies ----
include(../../cmake/CPM.cmake)
CPMAddPackage(
NAME Boost
VERSION 1.83
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
URL_MD5 893b5203b862eb9bbd08553e24ff146a
FIND_PACKAGE_ARGUMENTS "COMPONENTS thread\;date_time\;filesystem"
EXCLUDE_FROM_ALL ON
SYSTEM ON
)
target_link_libraries(CPMExampleBoost PUBLIC Boost::headers Boost::date_time Boost::filesystem)
if(PROJECT_IS_TOP_LEVEL)
enable_testing()
add_test(NAME CPMExampleBoost COMMAND CPMExampleBoost)
endif()
# ---- Create a library ----
add_library(scoped_lock scoped_lock.cpp scoped_lock.hpp)
target_compile_features(scoped_lock PUBLIC cxx_std_17)
target_link_libraries(scoped_lock PUBLIC Boost::thread)
target_include_directories(
scoped_lock PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
)
if(NOT CMAKE_SKIP_INSTALL_RULES)
# ---- Install the binary and its runtime dependency set ----
install(
TARGETS CPMExampleBoost
# boost_headers boost_date_time boost_filesystem # XXX ... boost_context boost_coroutine
RUNTIME_DEPENDENCY_SET appDeps EXPORT scoped_lockTargets
)
if(BUILD_SHARED_LIBS)
install(RUNTIME_DEPENDENCY_SET appDeps POST_INCLUDE_REGEXES
[[${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libboost_.*]] EXPORT scoped_lockTargets
)
endif()
# ---- Install the library ----
install(FILES scoped_lock.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
if(NOT CPM_USE_LOCAL_PACKAGES)
install(TARGETS boost_headers EXPORT scoped_lockTargets)
elseif(BOOST_SRC_DIR)
install(TARGETS boost_thread EXPORT scoped_lockTargets)
endif()
install(TARGETS scoped_lock RUNTIME_DEPENDENCY_SET libDeps)
# PackageProject.cmake will be used to export our cmake config packages
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.11.0")
packageProject(
NAME scoped_lock
VERSION ${PROJECT_VERSION}
NAMESPACE ${PROJECT_NAME}
BINARY_DIR ${PROJECT_BINARY_DIR}
COMPATIBILITY AnyNewerVersion
DISABLE_VERSION_SUFFIX YES
DEPENDENCIES "Boost 1.83"
)
if(BUILD_SHARED_LIBS)
install(RUNTIME_DEPENDENCY_SET libDeps POST_INCLUDE_REGEXES
[[${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libboost_.*]] EXPORT scoped_lockTargets
)
endif()
set(CPACK_PACKAGE_INSTALL_DIRECTORY /)
set(CPACK_GENERATOR TBZ2)
include(CPack)
endif()
It will result to this:
bash-5.2$ cmake -G Ninja -B build -S . --fresh
-- The CXX compiler identification is Clang 17.0.6
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at /Users/clausklein/cmake/TheLartians/CPM.cmake/cmake/CPM.cmake:76 (message):
CPM: Your project is using an unstable development version of CPM.cmake.
Please update to a recent release if possible. See
https://github.com/cpm-cmake/CPM.cmake for details.
Call Stack (most recent call first):
CMakeLists.txt:46 (include)
-- CPM: Using local package Boost@1.83.0
-- Found Git: /usr/local/bin/git (found version "2.43.0")
-- CPM: Adding package PackageProject.cmake@1.11.0 (v1.11.0 at /Users/clausklein/.cache/CPM/packageproject.cmake/fc402989ee6e628476b3d8661f8f96774d89df74)
-- Configuring done (1.7s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/cmake/TheLartians/CPM.cmake/examples/boost/build
bash-5.2$ cd build
bash-5.2$ ninja
[4/4] Linking CXX executable stage/bin/CPMExampleBoost
bash-5.2$ ctest
Test project /Users/clausklein/cmake/TheLartians/CPM.cmake/examples/boost/build
Start 1: CPMExampleBoost
1/1 Test #1: CPMExampleBoost .................. Passed 1.39 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 1.41 sec
bash-5.2$ ll stage/
total 0
drwxr-xr-x 4 clausklein 128 Jan 1 21:52 ./
drwxr-xr-x 3 clausklein 96 Jan 1 21:52 lib/
drwxr-xr-x 3 clausklein 96 Jan 1 21:53 bin/
drwxr-xr-x 18 clausklein 576 Jan 1 21:53 ../
bash-5.2$ tree stage/
stage/
|-- bin
| `-- CPMExampleBoost
`-- lib
`-- libscoped_lock.dylib
3 directories, 2 files
bash-5.2$ cpack
CPack: Create package using TBZ2
CPack: Install projects
CPack: - Install project: CPMExampleBoost []
CPack: Create package
CPack: - package: /Users/clausklein/cmake/TheLartians/CPM.cmake/examples/boost/build/CPMExampleBoost-0.1.2-Darwin.tar.bz2 generated.
bash-5.2$ tree _CPack_Packages/
_CPack_Packages/
`-- Darwin
`-- TBZ2
|-- CPMExampleBoost-0.1.2-Darwin
| |-- bin
| | `-- CPMExampleBoost
| |-- include
| | `-- CPMExampleBoost
| | `-- scoped_lock.hpp
| `-- lib
| |-- cmake
| | `-- scoped_lock
| | |-- scoped_lockConfig.cmake
| | |-- scoped_lockConfigVersion.cmake
| | |-- scoped_lockTargets-noconfig.cmake
| | `-- scoped_lockTargets.cmake
| |-- libboost_atomic-mt.dylib
| |-- libboost_date_time-mt.dylib
| |-- libboost_filesystem-mt.dylib
| |-- libboost_thread-mt.dylib
| |-- libscoped_lock.dylib
| `-- scoped_lock
| `-- libscoped_lock.dylib
`-- CPMExampleBoost-0.1.2-Darwin.tar.bz2
11 directories, 13 files
bash-5.2$ make install
make: *** No rule to make target `install'. Stop.
bash-5.2$ ninja install
[0/1] Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/CPMExampleBoost
-- Installing: /usr/local/lib/libscoped_lock.dylib
-- Installing: /usr/local/lib/scoped_lock/libscoped_lock.dylib
-- Old export file "/usr/local/lib/cmake/scoped_lock/scoped_lockTargets.cmake" will be replaced. Removing files [/usr/local/lib/cmake/scoped_lock/scoped_lockTargets-noconfig.cmake].
-- Installing: /usr/local/lib/cmake/scoped_lock/scoped_lockTargets.cmake
-- Installing: /usr/local/lib/cmake/scoped_lock/scoped_lockTargets-noconfig.cmake
-- Installing: /usr/local/lib/cmake/scoped_lock/scoped_lockConfigVersion.cmake
-- Installing: /usr/local/lib/cmake/scoped_lock/scoped_lockConfig.cmake
bash-5.2$