Skip to content

Commit 8ff49d7

Browse files
authored
Merge pull request #6 from DavidingPlus/feature-liuzx-install
Add Target Install
2 parents a5903e2 + c0ff960 commit 8ff49d7

File tree

6 files changed

+145
-12
lines changed

6 files changed

+145
-12
lines changed

.github/workflows/build-linux.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
name: Build On Linux
33

44
on:
5+
workflow_dispatch:
56
push:
67
branches:
7-
- master
8+
- master
89

910
jobs:
1011
build:
@@ -26,16 +27,22 @@ jobs:
2627
2728
conan install . --build=missing
2829
29-
cmake --preset cmake-project-release -DWITH_GTEST=ON
30+
cmake --preset cmake-project-release
3031
3132
- name: Build Targets
3233
working-directory: ${{github.workspace}}
3334
run: cmake --build --preset cmake-project-release
3435

35-
- name: Run Unit Test
36+
- name: Install Targets
3637
working-directory: ${{github.workspace}}
3738
run: |
3839
39-
cmake --build --preset cmake-project-release -t tests
40+
cmake --build --preset cmake-project-release -t install
4041
41-
./build/Release/test/gtest-testrun
42+
- name: Upload artifacts
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: install
46+
path: build/Release/install
47+
include-hidden-files: true
48+
if-no-files-found: error

.github/workflows/build-win32.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Template: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
2-
name: Build On Windows
1+
name: Build On Win32
32

43
on:
4+
workflow_dispatch:
55
push:
66
branches:
7-
- master
7+
- master
88

99
jobs:
1010
build:
@@ -26,16 +26,22 @@ jobs:
2626
2727
conan install . --build=missing
2828
29-
cmake --preset cmake-project-default -DWITH_GTEST=ON
29+
cmake --preset cmake-project-default
3030
3131
- name: Build Targets
3232
working-directory: ${{github.workspace}}
3333
run: cmake --build --preset cmake-project-release
3434

35-
- name: Run Unit Test
35+
- name: Install Targets
3636
working-directory: ${{github.workspace}}
3737
run: |
3838
39-
cmake --build --preset cmake-project-release -t tests
39+
cmake --build --preset cmake-project-release -t install
4040
41-
.\build\test\Release\gtest-testrun.exe
41+
- name: Upload artifacts
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: install
45+
path: build/install
46+
include-hidden-files: true
47+
if-no-files-found: error
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Run Unit Test On Linux
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "**"
8+
9+
jobs:
10+
unit-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Conan
17+
run: |
18+
19+
pip install conan==2.6.0
20+
21+
conan profile detect
22+
23+
- name: Configure CMake
24+
working-directory: ${{github.workspace}}
25+
run: |
26+
27+
conan install . --build=missing
28+
29+
cmake --preset cmake-project-release -DWITH_GTEST=ON
30+
31+
- name: Build Targets
32+
working-directory: ${{github.workspace}}
33+
run: cmake --build --preset cmake-project-release
34+
35+
- name: Run Unit Test
36+
working-directory: ${{github.workspace}}
37+
run: |
38+
39+
cmake --build --preset cmake-project-release -t tests
40+
41+
./build/Release/test/gtest-testrun
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Run Unit Test On Windows
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "**"
8+
9+
jobs:
10+
unit-test:
11+
runs-on: windows-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Conan
17+
run: |
18+
19+
pip install conan==2.6.0
20+
21+
conan profile detect
22+
23+
- name: Configure CMake
24+
working-directory: ${{github.workspace}}
25+
run: |
26+
27+
conan install . --build=missing
28+
29+
cmake --preset cmake-project-default -DWITH_GTEST=ON
30+
31+
- name: Build Targets
32+
working-directory: ${{github.workspace}}
33+
run: cmake --build --preset cmake-project-release
34+
35+
- name: Run Unit Test
36+
working-directory: ${{github.workspace}}
37+
run: |
38+
39+
cmake --build --preset cmake-project-release -t tests
40+
41+
.\build\test\Release\gtest-testrun.exe

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ project ("CMake Project"
1616
DESCRIPTION "C/C++ 项目的 CMake 模板。"
1717
)
1818

19+
# write version file
20+
file (WRITE "${PROJECT_BINARY_DIR}/.version" "${PACKAGE_VERSION}")
21+
1922

2023
# configure unit test
2124
option (WITH_GTEST "Enable unit tests by GoogleTest" OFF)
@@ -79,3 +82,27 @@ if (WITH_GTEST)
7982
add_subdirectory (test)
8083

8184
endif ()
85+
86+
87+
# configure install targets
88+
option (INSTALL_IN_PLACE "Set CMAKE_INSTALL_PREFIX inside PROJECT_BINARY_DIR" ON)
89+
90+
if (INSTALL_IN_PLACE)
91+
set (CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/install")
92+
93+
endif ()
94+
95+
message ("-- [CMake Project] Install destination would be: ${CMAKE_INSTALL_PREFIX}")
96+
97+
98+
include (public-headers.cmake)
99+
set_target_properties (cmake-project PROPERTIES PUBLIC_HEADER ${CMAKE_PROJECT_PUBLIC_HEADERS})
100+
101+
install (TARGETS cmake-project
102+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
103+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
104+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
105+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
106+
)
107+
108+
install (FILES ${PROJECT_BINARY_DIR}/.version DESTINATION .)

public-headers.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file defines list of public headers.
2+
# "Public headers" stands for headers exposing to clients.
3+
4+
# First list all headers here
5+
file (GLOB_RECURSE CMAKE_PROJECT_PUBLIC_HEADERS_LIST RELATIVE "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/*.h")
6+
7+
# Concat list items with semicolon to satisfy set_target_properties()
8+
list (JOIN CMAKE_PROJECT_PUBLIC_HEADERS_LIST "\;" CMAKE_PROJECT_PUBLIC_HEADERS)
9+
10+
# Cleanup
11+
unset (CMAKE_PROJECT_PUBLIC_HEADERS_LIST)

0 commit comments

Comments
 (0)