Skip to content

Commit d362e34

Browse files
sharder996ricab
authored andcommitted
[cmake] Fix version derivation on win/mac (#4215)
On Windows and macOS, our version includes a "win" or "mac" suffix in the `<build>` component. In actual releases, that is all that the `<build>` component consists of. This updates that part of the version derivation logic such that the semantic version grammar is respected and WiX accepts our version. We no longer have "+full" in our release tags and we need our suffixes to be properly separated from the rest of the version. In particular, they need to come after a single plus ('+') and must be separated from other parts of the `<build>` component with dots ('.'). See https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions.
1 parent a3a71f2 commit d362e34

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

CMakeLists.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,23 @@ function(determine_version OUTPUT_VARIABLE)
220220
message(FATAL_ERROR "Failed to parse version number: ${GIT_VERSION}")
221221
endif()
222222

223-
if(APPLE OR MSVC)
224-
string(REGEX MATCH "\\+full$" FULL_SUFFIX_MATCH ${NEW_VERSION})
225-
if(NOT FULL_SUFFIX_MATCH)
226-
set(NEW_VERSION ${NEW_VERSION}.full)
223+
# assert that the output of `git describe` does not include "full" any longer (after merger)
224+
string(FIND "${NEW_VERSION}" "full" FULL_POSITION)
225+
if(FULL_POSITION GREATER_EQUAL 0)
226+
message(FATAL_ERROR "Version string should not contain 'full': ${NEW_VERSION}")
227+
endif()
228+
229+
if(APPLE OR WIN32)
230+
set(VERSION_SEPARATOR "+")
231+
string(FIND "${NEW_VERSION}" "+" PLUS_POSITION)
232+
if(PLUS_POSITION GREATER_EQUAL 0)
233+
set(VERSION_SEPARATOR ".")
227234
endif()
235+
228236
if(APPLE)
229-
string(REPLACE "full" "mac" NEW_VERSION ${NEW_VERSION})
237+
string(APPEND NEW_VERSION "${VERSION_SEPARATOR}mac")
230238
else()
231-
string(REPLACE "full" "win" NEW_VERSION ${NEW_VERSION})
239+
string(APPEND NEW_VERSION "${VERSION_SEPARATOR}win")
232240
endif()
233241
endif()
234242

0 commit comments

Comments
 (0)