Skip to content

Commit 81256fa

Browse files
authored
Merge pull request #5 from aminya/install
2 parents 89e9716 + aff7ae5 commit 81256fa

6 files changed

Lines changed: 23 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ jobs:
9898
vcpkg: true
9999
ccache: true
100100
clangtidy: true
101+
make: true
101102

102103
cppcheck: true
103104

@@ -132,6 +133,9 @@ jobs:
132133
133134
gcovr -j ${{env.nproc}} --delete --root ./ --print-summary --xml-pretty --xml coverage.xml ./build --gcov-executable '${{ matrix.gcov_executable }}'
134135
136+
# test installation
137+
make test_install
138+
135139
- name: Windows - Test and coverage
136140
if: runner.os == 'Windows'
137141
run: |
@@ -140,6 +144,8 @@ jobs:
140144
cd ./build/my_header_lib/test; ctest -C ${{matrix.build_type}} --output-on-failure; cd ../../../
141145
cd ./build/my_lib/test; ctest -C ${{matrix.build_type}} --output-on-failure; cd ../../../
142146
'
147+
# test installation
148+
make test_install
143149
144150
- name: Perform CodeQL Analysis
145151
if: ${{ contains(matrix.os, 'ubuntu') && contains(matrix.compiler, 'llvm') }}

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ add_subdirectory(./my_exe)
8181
add_subdirectory(./my_lib)
8282
add_subdirectory(./my_header_lib)
8383

84+
# the variables set using CACHE STRING "" are passed to package_project
85+
8486
# Package the project
8587
package_project(
8688
TARGETS

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ test_release:
2424
(cd build/my_header_lib/test && ctest -C RelWithDebInfo --output-on-failure)
2525
(cd build/my_lib/test && ctest -C RelWithDebInfo --output-on-failure)
2626

27+
test_install:
28+
cmake --install ./build --prefix ./install
29+
2730
docs:
2831
cmake ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE:STRING=Debug -DFEATURE_DOCS:BOOL=ON -DFEATURE_TESTS:BOOL=OFF
2932
cmake --build ./build --target doxygen-docs --config Debug

my_exe/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ target_link_libraries(my_exe PRIVATE project_options project_warnings) # link pr
33

44
# Includes
55
# because my_exe includes are private, it uses absolute paths.
6-
set(my_exe_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
6+
set(my_exe_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "")
77
target_include_directories(my_exe PRIVATE "${my_exe_INCLUDE_DIR}")
88

99
# Find dependencies:
10-
set(my_exe_DEPENDENCIES_CONFIGURED fmt)
10+
set(my_exe_DEPENDENCIES_CONFIGURED fmt CACHE STRING "")
1111

1212
foreach(DEPENDENCY ${my_exe_DEPENDENCIES_CONFIGURED})
1313
find_package(${DEPENDENCY} CONFIG REQUIRED)

my_header_lib/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ add_library(my_header_lib INTERFACE)
22
target_link_libraries(my_header_lib INTERFACE project_options project_warnings) # link project_options/warnings
33

44
# Includes
5-
set(my_header_lib_INCLUDE_DIR "./include") # must be relative paths
5+
set(my_header_lib_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "") # must be relative paths
66
target_include_directories(
7-
my_header_lib INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${my_header_lib_INCLUDE_DIR}>"
7+
my_header_lib INTERFACE "$<BUILD_INTERFACE:${my_header_lib_INCLUDE_DIR}>"
88
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
99

1010
# Find dependencies:
11-
set(my_header_lib_DEPENDENCIES_CONFIGURED fmt)
11+
set(my_header_lib_DEPENDENCIES_CONFIGURED fmt CACHE STRING "")
1212

1313
foreach(DEPENDENCY ${my_header_lib_DEPENDENCIES_CONFIGURED})
1414
find_package(${DEPENDENCY} CONFIG REQUIRED)

my_lib/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ add_library(my_lib "./src/my_lib/lib.cpp")
22
target_link_libraries(my_lib PRIVATE project_options project_warnings) # link project_options/warnings
33

44
# Includes
5-
set(my_lib_INCLUDE_DIR "include") # must be relative paths
6-
target_include_directories(my_lib PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${my_lib_INCLUDE_DIR}>"
5+
set(my_lib_INCLUDE_DIR
6+
"${CMAKE_CURRENT_SOURCE_DIR}/include"
7+
CACHE STRING "")
8+
target_include_directories(my_lib PUBLIC "$<BUILD_INTERFACE:${my_lib_INCLUDE_DIR}>"
79
"$<INSTALL_INTERFACE:./${CMAKE_INSTALL_INCLUDEDIR}>")
810

911
# Find dependencies:
10-
set(my_lib_DEPENDENCIES_CONFIGURED fmt)
12+
set(my_lib_DEPENDENCIES_CONFIGURED
13+
fmt
14+
CACHE STRING "")
1115

1216
foreach(DEPENDENCY ${my_lib_DEPENDENCIES_CONFIGURED})
1317
find_package(${DEPENDENCY} CONFIG REQUIRED)

0 commit comments

Comments
 (0)