Skip to content

Commit 517b5c3

Browse files
committed
Extend check template script to be aware of multiple cmake-init branches
1 parent a0dac20 commit 517b5c3

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ set(META_VERSION_REVISION "${GIT_REV}")
5757
set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}")
5858
set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})")
5959
set(META_CMAKE_INIT_SHA "${GIT_REV}")
60+
set(META_CMAKE_INIT_BRANCH "cmake-3.20")
6061

6162
string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID)
6263
string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID)
@@ -100,7 +101,7 @@ file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}")
100101
#
101102

102103
# Add cmake-init template check cmake targets
103-
add_check_template_target(${META_CMAKE_INIT_SHA})
104+
add_check_template_target(${META_CMAKE_INIT_SHA} ${META_CMAKE_INIT_BRANCH})
104105

105106
# Configure health check tools
106107
enable_cppcheck(ON)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ This module is usable when the following is integrated into the `CMakeLists.txt`
210210

211211
```cmake
212212
# Add cmake-init template check cmake targets
213-
add_check_template_target(<CMAKE_INIT_SHA>)
213+
add_check_template_target(<CMAKE_INIT_SHA> <CMAKE_INIT_BRANCH>)
214214
```
215215

216216
Here, the `<CMAKE_INIT_SHA>` contains the git hash of the used cmake-init template.
@@ -221,9 +221,10 @@ The hash is usually configured using
221221
```cmake
222222
# Meta information about the project
223223
set(META_CMAKE_INIT_SHA "<CMAKE_INIT_SHA>")
224+
set(META_CMAKE_INIT_BRANCH "<CMAKE_INIT_BRANCH>")
224225
225226
# Add cmake-init template check cmake targets
226-
add_check_template_target(<CMAKE_INIT_SHA>)
227+
add_check_template_target(<CMAKE_INIT_SHA> <CMAKE_INIT_BRANCH>)
227228
```
228229

229230
Correctly configures, this module adds a cmake build target named `check-template` that compares the passed `<CMAKE_INIT_SHA>` with the current master commit hash of this repository and provides a link for a diff view.

cmake/CheckTemplate.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
# Get cmake-init latest commit SHA on master
44
#
55

6+
if(NOT APPLIED_CMAKE_INIT_BRANCH)
7+
set(APPLIED_CMAKE_INIT_BRANCH "master")
8+
endif ()
9+
610
file(DOWNLOAD
7-
"https://api.github.com/repos/cginternals/cmake-init/commits/master"
11+
"https://api.github.com/repos/cginternals/cmake-init/commits/${APPLIED_CMAKE_INIT_BRANCH}"
812
"${PROJECT_BINARY_DIR}/cmake-init.github.data"
913
)
1014
file(READ
@@ -45,5 +49,5 @@ endif()
4549
if(${APPLIED_CMAKE_INIT_SHA} STREQUAL ${CMAKE_INIT_SHA})
4650
message(STATUS "cmake-init template is up-to-date (${CMAKE_INIT_SHA})")
4751
else()
48-
message(STATUS "cmake-init template needs an update https://github.com/cginternals/cmake-init/compare/${APPLIED_CMAKE_INIT_SHA}...master")
52+
message(STATUS "cmake-init template needs an update https://github.com/cginternals/cmake-init/compare/${APPLIED_CMAKE_INIT_SHA}...${APPLIED_CMAKE_INIT_BRANCH}")
4953
endif()

cmake/HealthCheck.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ function(enable_clang_tidy status)
8585
endfunction()
8686

8787
# Configure cmake target to check for cmake-init template
88-
function(add_check_template_target current_template_sha)
88+
function(add_check_template_target current_template_sha current_template_branch)
8989
add_custom_target(
9090
check-template
9191
COMMAND ${CMAKE_COMMAND}
9292
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
9393
-DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}
9494
-DAPPLIED_CMAKE_INIT_SHA=${current_template_sha}
95+
-DAPPLIED_CMAKE_INIT_BRANCH=${current_template_branch}
9596
-P ${PROJECT_SOURCE_DIR}/cmake/CheckTemplate.cmake
9697
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
9798
)

0 commit comments

Comments
 (0)