Skip to content

Commit 55426c5

Browse files
committed
Support script usage externally for debugging etc.
1 parent 7c55693 commit 55426c5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
#---------------------------------------------------------------------------#
77

88
cmake_minimum_required(VERSION 3.8)
9+
10+
# Determine version number from git metadata
911
include("${CMAKE_CURRENT_LIST_DIR}/cmake/FlibcppVersion.cmake")
1012
flibcpp_find_version(Flibcpp "${CMAKE_CURRENT_LIST_DIR}/cmake/git-version.txt")
13+
message(STATUS "Flibcpp version: ${Flibcpp_VERSION}")
14+
1115
project(Flibcpp VERSION "${Flibcpp_VERSION}" LANGUAGES CXX Fortran)
1216

1317
#---------------------------------------------------------------------------#

cmake/FlibcppVersion.cmake

+17-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ FlibcppVersion
3131
3232
#]=======================================================================]
3333

34+
if (CMAKE_SCRIPT_MODE_FILE)
35+
cmake_minimum_required(VERSION 3.8)
36+
endif()
37+
3438
function(flibcpp_find_version PROJNAME GIT_VERSION_FILE)
3539
# Get a possible Git version generated using git-archive (see the
3640
# .gitattributes file)
@@ -42,7 +46,7 @@ function(flibcpp_find_version PROJNAME GIT_VERSION_FILE)
4246
set(_CACHED_VERSION "${${_CACHE_VAR}}")
4347
if (NOT _CACHED_VERSION)
4448
# Building from a git checkout rather than a distribution
45-
find_package(Git REQUIRED)
49+
find_package(Git QUIET REQUIRED)
4650
execute_process(
4751
COMMAND "${GIT_EXECUTABLE}" "describe" "--tags" "--match" "v*"
4852
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
@@ -101,7 +105,7 @@ function(flibcpp_find_version PROJNAME GIT_VERSION_FILE)
101105
endif()
102106

103107
if (NOT _VERSION_STRING)
104-
message(WARNING "Could not determine version number ${PROJNAME}: "
108+
message(WARNING "Could not determine version number for ${PROJNAME}: "
105109
"perhaps a non-release archive?")
106110
set(_VERSION_STRING "0.0.0")
107111
endif()
@@ -116,6 +120,17 @@ function(flibcpp_find_version PROJNAME GIT_VERSION_FILE)
116120
set(${PROJNAME}_VERSION_STRING "${_FULL_VERSION_STRING}" PARENT_SCOPE)
117121
endfunction()
118122

123+
if (CMAKE_SCRIPT_MODE_FILE)
124+
# This script is being run from the command line. Useful for debugging.
125+
if (NOT DEFINED GIT_VERSION_FILE)
126+
message(FATAL_ERROR "Run this script with "
127+
"cmake -D GIT_VERSION_FILE=git-version.txt -P FlibcppVersion.cmake")
128+
endif()
129+
flibcpp_find_version(local ${GIT_VERSION_FILE})
130+
message(STATUS "${LOCAL_VERSION}")
131+
message(STATUS "${LOCAL_VERSION_STRING}")
132+
endif()
133+
119134
##---------------------------------------------------------------------------##
120135
## end of flibcpp/cmake/FlibcppVersion.cmake
121136
##---------------------------------------------------------------------------##

0 commit comments

Comments
 (0)