File tree Expand file tree Collapse file tree 6 files changed +145
-12
lines changed Expand file tree Collapse file tree 6 files changed +145
-12
lines changed Original file line number Diff line number Diff line change 22name : Build On Linux
33
44on :
5+ workflow_dispatch :
56 push :
67 branches :
7- - master
8+ - master
89
910jobs :
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
Original file line number Diff line number Diff line change 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
43on :
4+ workflow_dispatch :
55 push :
66 branches :
7- - master
7+ - master
88
99jobs :
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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
2124option (WITH_GTEST "Enable unit tests by GoogleTest" OFF )
@@ -79,3 +82,27 @@ if (WITH_GTEST)
7982 add_subdirectory (test )
8083
8184endif ()
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 .)
Original file line number Diff line number Diff line change 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)
You can’t perform that action at this time.
0 commit comments