-
Notifications
You must be signed in to change notification settings - Fork 4
fix: cmake version #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| cmake_minimum_required(VERSION 3.5) | ||
| file(READ "project.properties" PROJECT_PROPERTIES) | ||
| string(REGEX MATCH "VERSION = ([0-9]*.[0-9]*.[0-9]*)" _ ${PROJECT_PROPERTIES}) | ||
| execute_process( | ||
| COMMAND git describe --tags --abbrev=0 | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
| OUTPUT_VARIABLE GIT_VER | ||
| ) | ||
| string(REGEX MATCH "([0-9]*.[0-9]*.[0-9]*).*" _ ${GIT_VER}) | ||
| set(PROJECT_VERSION ${CMAKE_MATCH_1}) | ||
| if("${PROJECT_VERSION}" STREQUAL "") | ||
| set(PROJECT_VERSION 0.0.0) | ||
| endif() | ||
| project(libosal VERSION ${PROJECT_VERSION}) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 11) | ||
|
|
@@ -93,8 +100,8 @@ else() | |
| endif() | ||
|
|
||
| set(LIBOSAL_STDC_HEADERS 1) | ||
| set(LIBOSAL_PACKAGE_VERSION "${CMAKE_PROJECT_VERSION}") | ||
| set(LIBOSAL_VERSION "${CMAKE_PROJECT_VERSION}") | ||
| set(LIBOSAL_PACKAGE_VERSION "${GIT_VER}") | ||
| set(LIBOSAL_VERSION "${GIT_VER}") | ||
|
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using It's safer to use |
||
| set(LIBOSAL_PACKAGE_URL "${CMAKE_PROJECT_HOMEPAGE_URL}") | ||
| set(LIBOSAL_PACKAGE "${CMAKE_PROJECT_NAME}") | ||
| set(LIBOSAL_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current method of getting the version from
gitis not fully robust.execute_processcall doesn't check if thegitcommand was successful. This can happen ifgitis not installed or if this is not a git repository (e.g., a source archive).([0-9]*.[0-9]*.[0-9]*).*is incorrect. The.matches any character, not a literal dot, and*allows empty version components. It also doesn't handle commonvprefixes in tags.I suggest a more robust implementation that handles
gitcommand failures and uses a more accurate regex. This will also make the fallback to0.0.0more explicit.