Skip to content

Commit 738d2ed

Browse files
Add RUNTIME_DESTINATION variable (#45)
* Add RUNTIME_DESTINATION It's possible to put libraries and binaries directly to bin/ and lib/ (using RUNTIME_DESTINATION /) instead of bin/<name-version> and lib/<name-version> * Add tests for RUNTIME_DESTINATION feature * Update README.md * Update .cmake-format * Update .github/workflows/test.yml Refactor: move test to it's own step Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com> * Fix: syntax error in test.yml --------- Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
1 parent 5f51898 commit 738d2ed

9 files changed

Lines changed: 79 additions & 8 deletions

File tree

.cmake-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ parse:
5858
EXPORT_HEADER: 1
5959
DISABLE_VERSION_SUFFIX: 1
6060
CPACK: 1
61+
RUNTIME_DESTINATION: 1
6162
DEPENDENCIES: +

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: jwlawson/actions-setup-cmake@v1.13
2929
with:
3030
cmake-version: 3.18.4
31-
31+
3232
- name: test and install local build
3333
run: |
3434
cmake -S test -B build/local
@@ -58,7 +58,7 @@ jobs:
5858
uses: jwlawson/actions-setup-cmake@v1.13
5959
with:
6060
cmake-version: 3.18.4
61-
61+
6262
- name: build for packaging
6363
run: |
6464
cmake -S test -B build/local -DTEST_CPACK=YES
@@ -68,6 +68,9 @@ jobs:
6868
cpack -G DEB .
6969
dpkg -I *deb | grep "Maintainer: Foo Bar <foo@bar.local>"
7070
sudo -E dpkg -i *.deb
71+
72+
- name: check if we can explicitly set the runtime destination
73+
run: test -e /usr/lib/libruntime_destination_dependency.a
7174

7275
- name: test installed build
7376
run: |

CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function(packageProject)
1212
cmake_parse_arguments(
1313
PROJECT
1414
""
15-
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;EXPORT_HEADER;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT;INCLUDE_HEADER_PATTERN;CPACK;"
15+
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;EXPORT_HEADER;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT;INCLUDE_HEADER_PATTERN;CPACK;RUNTIME_DESTINATION"
1616
"DEPENDENCIES"
1717
${ARGN}
1818
)
@@ -128,17 +128,22 @@ function(packageProject)
128128
COMPATIBILITY ${PROJECT_COMPATIBILITY} ${wbpvf_extra_args}
129129
)
130130

131+
# set default runtime install subdirectory (RUNTIME_DESTINATION)
132+
if(NOT DEFINED PROJECT_RUNTIME_DESTINATION)
133+
set(PROJECT_RUNTIME_DESTINATION ${PROJECT_NAME}${PROJECT_VERSION_SUFFIX})
134+
endif()
135+
131136
install(
132137
TARGETS ${PROJECT_NAME}
133138
EXPORT ${PROJECT_NAME}Targets
134-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
139+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_RUNTIME_DESTINATION}
135140
COMPONENT "${PROJECT_NAME}_Runtime"
136141
NAMELINK_COMPONENT "${PROJECT_NAME}_Development"
137-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
142+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_RUNTIME_DESTINATION}
138143
COMPONENT "${PROJECT_NAME}_Development"
139-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
144+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_RUNTIME_DESTINATION}
140145
COMPONENT "${PROJECT_NAME}_Runtime"
141-
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}
146+
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}/${PROJECT_RUNTIME_DESTINATION}
142147
COMPONENT "${PROJECT_NAME}_Runtime"
143148
PUBLIC_HEADER DESTINATION ${PROJECT_INCLUDE_DESTINATION} COMPONENT "${PROJECT_NAME}_Development"
144149
INCLUDES

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ packageProject(
3030
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
3131
# (optional) option to install only header files with matching pattern
3232
INCLUDE_HEADER_PATTERN "*.h"
33+
# relative install directory for runtimes: bins, libs, archives
34+
# if omitted, by default libs will be installed to <...>/lib/<packagename-version>/
35+
# / - means relative to <...>/lib, i.e. install libs to <...>/lib/, bins to <...>/bin/, etc
36+
RUNTIME_DESTINATION /
3337
# semicolon separated list of the project's dependencies
3438
DEPENDENCIES "fmt 7.1.3;cxxopts 2.2.0"
3539
# (optional) create a header containing the version info

test/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if(TEST_INSTALLED_VERSION)
1313
find_package(header_only 1.0 REQUIRED)
1414
find_package(namespaced_dependency 4.5.6 REQUIRED)
1515
find_package(transitive_dependency 7.8.9 REQUIRED)
16+
find_package(runtime_destination_dependency 1.5 REQUIRED)
1617
else()
1718
if(TEST_CPACK)
1819
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Foo Bar <foo@bar.local>")
@@ -21,13 +22,14 @@ else()
2122
add_subdirectory(header_only)
2223
add_subdirectory(namespaced_dependency)
2324
add_subdirectory(transitive_dependency)
25+
add_subdirectory(runtime_destination_dependency)
2426
endif()
2527

2628
add_executable(main main.cpp)
2729

2830
target_link_libraries(
2931
main dependency header_only ns::namespaced_dependency
30-
transitive_dependency::transitive_dependency
32+
transitive_dependency::transitive_dependency runtime_destination_dependency
3133
)
3234

3335
enable_testing()

test/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <header_only/version.h>
55
#include <namespaced_dependency/namespaced_dependency.h>
66
#include <namespaced_dependency/version.h>
7+
#include <runtime_destination_dependency/dependency.h>
8+
#include <runtime_destination_dependency/version.h>
79
#include <transitive_dependency/transitive_dependency.h>
810
#include <transitive_dependency/version.h>
911

@@ -13,6 +15,7 @@ int main() {
1315
dependencyFunction();
1416
ns::namespacedDependencyFunction();
1517
transitiveDependencyFunction();
18+
runtimeDestinationDependency();
1619
auto result = true;
1720
result &= DEPENDENCY_VERSION == std::string("1.2");
1821
result &= DEPENDENCY_VERSION_MAJOR == 1;
@@ -35,5 +38,10 @@ int main() {
3538
result &= HEADER_ONLY_VERSION_MINOR == 0;
3639
result &= HEADER_ONLY_VERSION_PATCH == 0;
3740
result &= HEADER_ONLY_VERSION_TWEAK == 0;
41+
result &= RUNTIME_DESTINATION_DEPENDENCY_VERSION == std::string("1.5");
42+
result &= RUNTIME_DESTINATION_DEPENDENCY_VERSION_MAJOR == 1;
43+
result &= RUNTIME_DESTINATION_DEPENDENCY_VERSION_MINOR == 5;
44+
result &= RUNTIME_DESTINATION_DEPENDENCY_VERSION_PATCH == 0;
45+
result &= RUNTIME_DESTINATION_DEPENDENCY_VERSION_TWEAK == 0;
3846
return result ? 0 : 1;
3947
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.14...3.22)
2+
3+
project(
4+
runtime_destination_dependency
5+
VERSION 1.5
6+
LANGUAGES CXX
7+
DESCRIPTION "A dependency for testing RUNTIME_DESTINATION in PackageProject.cmake"
8+
)
9+
10+
add_library(runtime_destination_dependency STATIC source/dependency.cpp)
11+
12+
target_include_directories(
13+
runtime_destination_dependency
14+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
15+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
16+
)
17+
18+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)
19+
20+
packageProject(
21+
NAME ${PROJECT_NAME}
22+
VERSION ${PROJECT_VERSION}
23+
BINARY_DIR ${PROJECT_BINARY_DIR}
24+
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
25+
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
26+
VERSION_HEADER "runtime_destination_dependency/version.h"
27+
RUNTIME_DESTINATION / # this is relative path to <...>/lib
28+
DEPENDENCIES ""
29+
CPACK YES
30+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
void runtimeDestinationDependency();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <runtime_destination_dependency/version.h>
2+
3+
#include <iostream>
4+
5+
void runtimeDestinationDependency() {
6+
std::cout << "Using dependency version " << RUNTIME_DESTINATION_DEPENDENCY_VERSION << std::endl;
7+
std::cout << "Dependency version major: " << RUNTIME_DESTINATION_DEPENDENCY_VERSION_MAJOR
8+
<< std::endl;
9+
std::cout << "Dependency version minor: " << RUNTIME_DESTINATION_DEPENDENCY_VERSION_MINOR
10+
<< std::endl;
11+
std::cout << "Dependency version patch: " << RUNTIME_DESTINATION_DEPENDENCY_VERSION_PATCH
12+
<< std::endl;
13+
std::cout << "Dependency version build: " << RUNTIME_DESTINATION_DEPENDENCY_VERSION_TWEAK
14+
<< std::endl;
15+
}

0 commit comments

Comments
 (0)