Skip to content

Commit c294a1c

Browse files
committed
Fix version calculation script
1 parent 305a0ae commit c294a1c

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

cmake/calc_version.cmake

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
# Get the version from our sub cmakefile
22
execute_process(
33
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_LIST_DIR}/gitversion.cmake"
4-
ERROR_VARIABLE PROJECT_VERSION
4+
OUTPUT_VARIABLE PROJECT_VERSION
5+
ERROR_VARIABLE PROJECT_VERSION_ERROR
6+
RESULT_VARIABLE PROJECT_VERSION_RESULT
7+
OUTPUT_STRIP_TRAILING_WHITESPACE
58
ERROR_STRIP_TRAILING_WHITESPACE
69
)
710

8-
# Cleanup output
11+
if(NOT PROJECT_VERSION_RESULT EQUAL 0)
12+
if(PROJECT_VERSION_ERROR)
13+
message(FATAL_ERROR "Version calculation failed: ${PROJECT_VERSION_ERROR}")
14+
else()
15+
message(FATAL_ERROR "Version calculation failed with exit code ${PROJECT_VERSION_RESULT}")
16+
endif()
17+
endif()
18+
19+
# Strip CMake's status prefix and surrounding whitespace
20+
string(REGEX REPLACE "^--[ \t]*" "" PROJECT_VERSION "${PROJECT_VERSION}")
921
string(REGEX REPLACE "^[[:space:]]+|[[:space:]]+$" "" PROJECT_VERSION "${PROJECT_VERSION}")
10-
string(REGEX REPLACE "\n$" "" PROJECT_VERSION "${PROJECT_VERSION}")
11-
message("${PROJECT_VERSION}")
22+
23+
if(PROJECT_VERSION STREQUAL "")
24+
message(FATAL_ERROR "Version calculation returned an empty string")
25+
endif()
26+
27+
# Emit plain text so shell captures are clean
28+
execute_process(
29+
COMMAND ${CMAKE_COMMAND} -E echo "${PROJECT_VERSION}"
30+
)
1231

0 commit comments

Comments
 (0)