Skip to content

Commit

Permalink
Add build target to check if cmake-init template is up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibel committed Jan 26, 2017
1 parent cf1705d commit 70a376b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set(META_VERSION_PATCH "0")
set(META_VERSION_REVISION "${GIT_REV}")
set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}")
set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})")
set(META_CMAKE_INIT_SHA "${GIT_SHA1}")

string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID)
string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID)
Expand Down
49 changes: 49 additions & 0 deletions cmake/CheckTemplate.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

#
# Get cmake-init latest commit SHA on master
#

file(DOWNLOAD
"https://api.github.com/repos/cginternals/cmake-init/commits/master"
"${PROJECT_BINARY_DIR}/cmake-init.github.data"
)
file(READ
"${PROJECT_BINARY_DIR}/cmake-init.github.data"
CMAKE_INIT_INFO
)

string(REGEX MATCH
"\"sha\": \"([0-9a-f]+)\","
CMAKE_INIT_SHA
${CMAKE_INIT_INFO})

string(SUBSTRING
${CMAKE_INIT_SHA}
8
40
CMAKE_INIT_SHA
)

#
# Get latest cmake-init commit on this repository
#

# APPLIED_CMAKE_INIT_SHA can be set by parent script
if(NOT APPLIED_CMAKE_INIT_SHA)
# [TODO]: Get from git commit list (see cmake_init/source/scripts/check_template.sh)
set(APPLIED_CMAKE_INIT_SHA "")
endif ()

if("${APPLIED_CMAKE_INIT_SHA}" STREQUAL "")
message(WARNING
"No cmake-init version detected, could not verify up-to-dateness. "
"Set the cmake-init version by defining a META_CMAKE_INIT_SHA for your project."
)
return()
endif()

if(${APPLIED_CMAKE_INIT_SHA} STREQUAL ${CMAKE_INIT_SHA})
message(STATUS "cmake-init template is up-to-date (${CMAKE_INIT_SHA})")
else()
message(STATUS "cmake-init template needs an update https://github.com/cginternals/cmake-init/compare/${APPLIED_CMAKE_INIT_SHA}...master")
endif()
7 changes: 7 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ endif()

# Deploy generated headers
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/${META_PROJECT_NAME} DESTINATION include COMPONENT dev)


#
# Project Health
#

add_subdirectory(scripts)
14 changes: 14 additions & 0 deletions source/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#
# Add project health scripts as cmake targets
#

add_custom_target(
check-template
COMMAND ${CMAKE_COMMAND}
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}
-DAPPLIED_CMAKE_INIT_SHA=${META_CMAKE_INIT_SHA}
-P ${PROJECT_SOURCE_DIR}/cmake/CheckTemplate.cmake
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)

0 comments on commit 70a376b

Please sign in to comment.