Skip to content

Commit ae4ac1d

Browse files
committed
Update cmake-format config file
Format all cmake files. Update CPM.cmake version. Use FILE_SET HEADER to verify and install the header files. Prevent build problems caused by CPM_USE_LOCAL_PACKAGES Prevent problems with doctest if local found
1 parent 8aff5ff commit ae4ac1d

File tree

6 files changed

+52
-28
lines changed

6 files changed

+52
-28
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ endif()
2323

2424
include(cmake/CPM.cmake)
2525

26-
# PackageProject.cmake will be used to make our target installable XXX
27-
# CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.13.0")
26+
# PackageProject.cmake will be used to make our target installable
2827
include(cmake/PackageProject.cmake)
28+
# XXX # CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.13.0")
2929

3030
# XXX set(CMAKE_SKIP_INSTALL_RULES YES)
3131

@@ -88,6 +88,8 @@ endif()
8888
# ---- Create an installable target ----
8989
# this allows users to install and find the library via `find_package()`.
9090

91+
include(cmake/AddUninstallTarget.cmake)
92+
9193
packageProject(
9294
NAME ${PROJECT_NAME}
9395
VERSION ${PROJECT_VERSION}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This template is the result of learnings from many previous projects and should
4444
Eventually, you can remove any unused files, such as the standalone directory or irrelevant github workflows for your project.
4545
Feel free to replace the License with one suited for your project.
4646

47-
To cleanly separate the library and subproject code, the outer `CMakeList.txt` only defines the library itself while the tests and other subprojects are self-contained in their own directories.
47+
To cleanly separate the library and subproject code, the outer `CMakeList.txt` only defines the library itself while the tests and other subprojects are self-contained in their own directories.
4848
During development it is usually convenient to [build all subprojects at once](#build-everything-at-once).
4949

5050
### Build and run the standalone target
@@ -66,7 +66,7 @@ cmake -S test -B build/test
6666
cmake --build build/test
6767
CTEST_OUTPUT_ON_FAILURE=1 cmake --build build/test --target test
6868

69-
# or simply call the executable:
69+
# or simply call the executable:
7070
./build/test/GreeterTests
7171
```
7272

@@ -91,7 +91,7 @@ See [Format.cmake](https://github.com/TheLartians/Format.cmake) for details.
9191
These dependencies can be easily installed using pip.
9292

9393
```bash
94-
pip install clang-format==14.0.6 cmake_format==0.6.11 pyyaml
94+
pip install cmake clang-format cmake_format==0.6.11 pyyaml
9595
```
9696

9797
### Build the documentation

cmake/AddUninstallTarget.cmake

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT)
2-
# SPDX-FileCopyrightText: 2008-2013 Kitware Inc.
3-
# SPDX-License-Identifier: BSD-3-Clause
1+
# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT) SPDX-FileCopyrightText:
2+
# 2008-2013 Kitware Inc. SPDX-License-Identifier: BSD-3-Clause
43

54
#[=======================================================================[.rst:
65
AddUninstallTarget
@@ -27,14 +26,13 @@ your project using ``add_subdirectory`` (for example when using it with
2726
If the ``uninstall`` target already exists, the module does nothing.
2827
#]=======================================================================]
2928

30-
3129
# AddUninstallTarget works only when included in the main CMakeLists.txt
3230
if(NOT "${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
3331
return()
3432
endif()
3533

36-
# The name of the target is uppercase in MSVC and Xcode (for coherence with the
37-
# other standard targets)
34+
# The name of the target is uppercase in MSVC and Xcode (for coherence with the other standard
35+
# targets)
3836
if("${CMAKE_GENERATOR}" MATCHES "^(Visual Studio|Xcode)")
3937
set(_uninstall "UNINSTALL")
4038
else()
@@ -46,11 +44,11 @@ if(TARGET ${_uninstall})
4644
return()
4745
endif()
4846

49-
5047
set(_filename cmake_uninstall.cmake)
5148

52-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_filename}"
53-
"if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\")
49+
file(
50+
WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_filename}"
51+
"if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\")
5452
message(WARNING \"Cannot find install manifest: \\\"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\\\"\")
5553
return()
5654
endif()
@@ -73,20 +71,31 @@ foreach(file \${files})
7371
message(STATUS \"Not-found: \$ENV{DESTDIR}\${file}\")
7472
endif()
7573
endforeach(file)
76-
")
74+
"
75+
)
7776

7877
set(_desc "Uninstall the project...")
7978
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
80-
set(_comment COMMAND \$\(CMAKE_COMMAND\) -E cmake_echo_color --switch=$\(COLOR\) --cyan "${_desc}")
79+
set(_comment
80+
COMMAND
81+
\$\(CMAKE_COMMAND\)
82+
-E
83+
cmake_echo_color
84+
--switch=$\(COLOR\)
85+
--cyan
86+
"${_desc}"
87+
)
8188
else()
8289
set(_comment COMMENT "${_desc}")
8390
endif()
84-
add_custom_target(${_uninstall}
85-
${_comment}
86-
COMMAND ${CMAKE_COMMAND} -P ${_filename}
87-
USES_TERMINAL
88-
BYPRODUCTS uninstall_byproduct
89-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
91+
add_custom_target(
92+
${_uninstall}
93+
${_comment}
94+
COMMAND ${CMAKE_COMMAND} -P ${_filename}
95+
USES_TERMINAL
96+
BYPRODUCTS uninstall_byproduct
97+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
98+
)
9099
set_property(SOURCE uninstall_byproduct PROPERTY SYMBOLIC 1)
91100

92101
set_property(TARGET ${_uninstall} PROPERTY FOLDER "CMakePredefinedTargets")

cmake/CPM.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#
33
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
44

5-
set(CPM_DOWNLOAD_VERSION 0.40.6)
6-
set(CPM_HASH_SUM "3440292907e35353bf0761049d3680e9ed0031443c8ebeb9cbb6a421c4550ec1")
5+
set(CPM_DOWNLOAD_VERSION 0.40.7)
6+
set(CPM_HASH_SUM "c0fc82149e00c43a21febe7b2ca57b2ffea2b8e88ab867022c21d6b81937eb50")
77

88
if(CPM_SOURCE_CACHE)
99
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")

standalone/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ CPMAddPackage(
1616
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES"
1717
)
1818

19-
CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
19+
CPMAddPackage(
20+
NAME Greeter
21+
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..
22+
FORCE ON
23+
)
2024

2125
# ---- Create standalone executable ----
2226

test/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ CPMAddPackage("gh:TheLartians/Format.cmake@1.8.3")
2121
if(TEST_INSTALLED_VERSION)
2222
find_package(Greeter REQUIRED)
2323
else()
24-
CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
24+
CPMAddPackage(
25+
NAME Greeter
26+
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..
27+
FORCE ON
28+
)
2529
endif()
2630

2731
# ---- Create binary ----
@@ -49,8 +53,13 @@ enable_testing()
4953
# testing frameworks add the tests target instead: add_test(NAME ${PROJECT_NAME} COMMAND
5054
# ${PROJECT_NAME})
5155

52-
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
53-
doctest_discover_tests(${PROJECT_NAME})
56+
# prevent problems if CPM_USE_LOCAL_PACKAGES is set:
57+
if(EXISTS ${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
58+
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
59+
doctest_discover_tests(${PROJECT_NAME})
60+
else()
61+
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
62+
endif
5463

5564
# ---- code coverage ----
5665

0 commit comments

Comments
 (0)