diff options
4 files changed, 46 insertions, 3 deletions
| diff --git a/modules/ECMSetupVersion.cmake b/modules/ECMSetupVersion.cmake index f4b2e700..bf9eb7ca 100644 --- a/modules/ECMSetupVersion.cmake +++ b/modules/ECMSetupVersion.cmake @@ -132,9 +132,10 @@ function(ecm_setup_version _version)      if(use_project_version)          set(_version "${PROJECT_VERSION}") -        set(_major "${PROJECT_VERSION_MAJOR}") -        set(_minor "${PROJECT_VERSION_MINOR}") -        set(_patch "${PROJECT_VERSION_PATCH}") +        # drop leading 0 from values to avoid bogus octal values in c/C++ e.g. with 08 or 09 +        string(REGEX REPLACE "^0+" "" _major "${PROJECT_VERSION_MAJOR}") +        string(REGEX REPLACE "^0+" "" _minor "${PROJECT_VERSION_MINOR}") +        string(REGEX REPLACE "^0+" "" _patch "${PROJECT_VERSION_PATCH}")      else()          string(REGEX REPLACE "^0*([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" _major "${_version}")          string(REGEX REPLACE "^[0-9]+\\.0*([0-9]+)\\.[0-9]+.*" "\\1" _minor "${_version}") diff --git a/tests/ECMSetupVersionTest/CMakeLists.txt b/tests/ECMSetupVersionTest/CMakeLists.txt index cfda7c91..242543e1 100644 --- a/tests/ECMSetupVersionTest/CMakeLists.txt +++ b/tests/ECMSetupVersionTest/CMakeLists.txt @@ -35,6 +35,7 @@ if(CMAKE_MAJOR_VERSION GREATER 2)      add_version_test(new_project_header check_header)      add_version_test(new_project_header_abspath check_header)      add_version_test(new_project_header_prefix check_header) +    add_version_test(new_project_header_zero_prefixed_version check_header)      add_version_test(new_project_simple dummy)      add_version_test(new_project_simple_no_version_string_vars dummy)      add_version_test(new_project_simple_prefix dummy) diff --git a/tests/ECMSetupVersionTest/new_project_header_zero_prefixed_version/CMakeLists.txt b/tests/ECMSetupVersionTest/new_project_header_zero_prefixed_version/CMakeLists.txt new file mode 100644 index 00000000..5d16d23b --- /dev/null +++ b/tests/ECMSetupVersionTest/new_project_header_zero_prefixed_version/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.16.0) + +project(new_project_header_zero_prefixed_version VERSION "08.09.07") + +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../modules) +include(ECMSetupVersion) + +ecm_setup_version(PROJECT +    VERSION_HEADER "new_project_header_zero_prefixed_version.h" +) + +include(../version_helpers.cmake) +# NB: name comes from project() command +standard_version_var_checks(new_project_header_zero_prefixed_version "08.09.07") + +add_executable(check_header main.c) +target_include_directories(check_header PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/tests/ECMSetupVersionTest/new_project_header_zero_prefixed_version/main.c b/tests/ECMSetupVersionTest/new_project_header_zero_prefixed_version/main.c new file mode 100644 index 00000000..ec5bdcf0 --- /dev/null +++ b/tests/ECMSetupVersionTest/new_project_header_zero_prefixed_version/main.c @@ -0,0 +1,24 @@ +#include <new_project_header_zero_prefixed_version.h> +#include <string.h> +#include <stdio.h> + +#define intcheck(macro,val) \ +    if (macro != val) { \ +        printf(#macro " was %d instead of %d", macro, val); \ +        return 1; \ +    } +#define strcheck(macro,val) \ +    if (strcmp(macro,val) != 0) { \ +        printf(#macro " was %s instead of %s", macro, val); \ +        return 1; \ +    } + +int main() +{ +    intcheck(new_project_header_zero_prefixed_version_VERSION_MAJOR,8) +    intcheck(new_project_header_zero_prefixed_version_VERSION_MINOR,9) +    intcheck(new_project_header_zero_prefixed_version_VERSION_PATCH,7) +    intcheck(new_project_header_zero_prefixed_version_VERSION,((8 << 16) + (9 << 8) + 7)) +    strcheck(new_project_header_zero_prefixed_version_VERSION_STRING,"08.09.07") +    return 0; +} | 
