File tree Expand file tree Collapse file tree
dependency/include/dependency
namespaced_dependency/include/namespaced_dependency
include/transitive_dependency Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010
1111env :
1212 CTEST_OUTPUT_ON_FAILURE : 1
13+ CPM_SOURCE_CACHE : ${{ github.workspace }}/cpm_modules
1314
1415jobs :
1516 build :
16-
1717 runs-on : ubuntu-latest
18-
18+
1919 steps :
20- - uses : actions/checkout@v2
21-
22- - name : test local build
23- run : |
24- cmake -S test -B build/local
25- cmake --build build/local
26- ./build/local/test
20+ - uses : actions/checkout@v2
21+
22+ - uses : actions/cache@v2
23+ with :
24+ path : " **/cpm_modules"
25+ key : ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}
2726
28- - name : install dependencies
29- run : |
30- cmake -S test/dependency -B build/dependency
31- sudo cmake --build build/dependency --target install
32- cmake -S test/namespaced_dependency -B build/namespaced_dependency
33- sudo cmake --build build/namespaced_dependency --target install
27+ - name : test and install local build
28+ run : |
29+ cmake -S test -B build/local
30+ cmake --build build/local
31+ ./ build/local/test
32+ sudo cmake --build build/local --target install
3433
35- - name : test installed build
36- run : |
37- cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1
38- cmake --build build/installed
39- ./build/installed/test
34+ - name : test installed build
35+ run : |
36+ cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1
37+ cmake --build build/installed
38+ ./build/installed/test
Original file line number Diff line number Diff line change 22
33include (CMakeFindDependencyMacro )
44
5- foreach (dependency @PROJECT_DEPENDENCIES@)
6- find_dependency (${dependency} )
5+ string (REGEX MATCHALL "[^;]+" SEPARATE_DEPENDENCIES "@PROJECT_DEPENDENCIES@" )
6+
7+ foreach (dependency ${SEPARATE_DEPENDENCIES} )
8+ string (REPLACE " " ";" args "${dependency} " )
9+ find_dependency (${args} )
710endforeach ()
811
912include ("${CMAKE_CURRENT_LIST_DIR} /@PROJECT_NAME@Targets.cmake" )
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ See [here](https://github.com/TheLartians/ModernCppStarter/blob/master/CMakeList
1616CPMAddPackage(
1717 NAME PackageProject.cmake
1818 GITHUB_REPOSITORY TheLartians/PackageProject.cmake
19- VERSION 1.4
19+ VERSION 1.4.1
2020)
2121
2222packageProject(
@@ -31,7 +31,7 @@ packageProject(
3131 # should match the target's INSTALL_INTERFACE include directory
3232 INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
3333 # semicolon separated list of the project's dependencies
34- DEPENDENCIES ""
34+ DEPENDENCIES "fmt 7.1.3;cxxopts 2.2.0 "
3535 # (optional) create a header containing the version info
3636 # note that the path should be lowercase
3737 VERSION_HEADER "${PROJECT_NAME}/version.h"
Original file line number Diff line number Diff line change @@ -10,10 +10,18 @@ project(PackageProjectTest
1010if (TEST_INSTALLED_VERSION)
1111 find_package (dependency 1.2.3 REQUIRED )
1212 find_package (namespaced_dependency 4.5.6 REQUIRED )
13+ find_package (transitive_dependency 7.8.9 REQUIRED )
1314else ()
1415 add_subdirectory (dependency )
1516 add_subdirectory (namespaced_dependency )
17+ add_subdirectory (transitive_dependency )
1618endif ()
1719
1820add_executable (test main.cpp )
19- target_link_libraries (test dependency ns::namespaced_dependency )
21+
22+ target_link_libraries (test
23+ dependency
24+ ns::namespaced_dependency
25+ transitive_dependency::transitive_dependency
26+ )
27+
Original file line number Diff line number Diff line change 11#pragma once
22
3- #include < iostream>
4-
53void dependencyFunction ();
Original file line number Diff line number Diff line change 22#include < dependency/version.h>
33#include < namespaced_dependency/namespaced_dependency.h>
44#include < namespaced_dependency/version.h>
5+ #include < transitive_dependency/transitive_dependency.h>
6+ #include < transitive_dependency/version.h>
57#include < string>
68
79int main () {
810 dependencyFunction ();
911 ns::namespacedDependencyFunction ();
10- return DEPENDENCY_VERSION == std::string (" 1.2.3" ) && NAMESPACED_DEPENDENCY_VERSION == std::string (" 4.5.6" ) ? 0 : 1 ;
12+ transitiveDependencyFunction ();
13+ auto result = true ;
14+ result &= DEPENDENCY_VERSION == std::string (" 1.2.3" );
15+ result &= NAMESPACED_DEPENDENCY_VERSION == std::string (" 4.5.6" );
16+ result &= TRANSITIVE_DEPENDENCY_VERSION == std::string (" 7.8.9" );
17+ return result ? 0 : 1 ;
1118}
Original file line number Diff line number Diff line change 11#pragma once
22
3- #include < iostream>
4-
53namespace ns {
64
75 void namespacedDependencyFunction ();
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.14 FATAL_ERROR )
2+
3+ project (transitive_dependency
4+ VERSION 7.8.9
5+ LANGUAGES CXX
6+ )
7+
8+ include (cmake/CPM.cmake )
9+
10+ CPMAddPackage (
11+ NAME fmt
12+ GIT_TAG 7.1.3
13+ GITHUB_REPOSITORY fmtlib/fmt
14+ OPTIONS "FMT_INSTALL YES"
15+ )
16+
17+ CPMAddPackage (
18+ NAME cxxopts
19+ GITHUB_REPOSITORY jarro2783/cxxopts
20+ VERSION 2.2.0
21+ OPTIONS "CXXOPTS_BUILD_EXAMPLES Off" "CXXOPTS_BUILD_TESTS Off"
22+ )
23+
24+ add_library (${PROJECT_NAME} source /transitive_dependency.cpp )
25+ target_compile_features (${PROJECT_NAME} PRIVATE cxx_std_17 )
26+ target_link_libraries (${PROJECT_NAME} fmt cxxopts )
27+
28+ target_include_directories (transitive_dependency
29+ PUBLIC
30+ $<BUILD_INTERFACE :${PROJECT_SOURCE_DIR} /include >
31+ $<INSTALL_INTERFACE :include /${PROJECT_NAME} -${PROJECT_VERSION} >
32+ )
33+
34+ add_subdirectory (${CMAKE_CURRENT_LIST_DIR} /../.. ${CMAKE_CURRENT_BINARY_DIR} /PackageProject )
35+
36+ packageProject (
37+ NAME ${PROJECT_NAME}
38+ VERSION ${PROJECT_VERSION}
39+ NAMESPACE ${PROJECT_NAME}
40+ BINARY_DIR ${PROJECT_BINARY_DIR}
41+ INCLUDE_DIR ${PROJECT_SOURCE_DIR} /include
42+ INCLUDE_DESTINATION include /${PROJECT_NAME}-${PROJECT_VERSION}
43+ VERSION_HEADER "transitive_dependency/version.h"
44+ DEPENDENCIES "fmt 7.1.3;cxxopts 2.2.0"
45+ )
Original file line number Diff line number Diff line change 1+ set (CPM_DOWNLOAD_VERSION 0.28.3)
2+
3+ if (CPM_SOURCE_CACHE)
4+ # Expand relative path. This is important if the provided path contains a tilde (~)
5+ get_filename_component (CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE )
6+ set (CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE} /cpm/CPM_${CPM_DOWNLOAD_VERSION} .cmake" )
7+ elseif (DEFINED ENV{CPM_SOURCE_CACHE})
8+ set (CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE} /cpm/CPM_${CPM_DOWNLOAD_VERSION} .cmake" )
9+ else ()
10+ set (CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR} /cmake/CPM_${CPM_DOWNLOAD_VERSION} .cmake" )
11+ endif ()
12+
13+ if (NOT (EXISTS ${CPM_DOWNLOAD_LOCATION} ))
14+ message (STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION} " )
15+ file (DOWNLOAD
16+ https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
17+ ${CPM_DOWNLOAD_LOCATION}
18+ )
19+ endif ()
20+
21+ include (${CPM_DOWNLOAD_LOCATION} )
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include <fmt/format.h>
4+
5+ void transitiveDependencyFunction ();
You can’t perform that action at this time.
0 commit comments