Moving to 2.6.0 from 2.3.0 problem with VERSION

Hi,

I am moving to version 2.6.0 of the SDK and toolchain.  I am developing on windows 11 pro.  Our cMakeLists.txt file creates a version file in our conf directory version.conf.  I am trying to change it to use the APP_ROOT/VERSION file.  I have taken out all of the previous code that created that version file and now having it create the VERSION file per docs Here.  

Here is my CMakeLists.txt

#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
cmake_minimum_required(VERSION 3.20.0)

set(version_major 0)
set(version_minor 0)
set(version_patch 0)
set(version_commit 0)


# Determine the build type
if (NOT BUILD_TYPE)
  set(BUILD_TYPE debug)
elseif(BUILD_TYPE STREQUAL "release")
  add_compile_definitions( BUILD_TYPE_RELEASE )
else()
  message( FATAL_ERROR "Unknown build type: ${BUILD_TYPE}" )
endif()

# Print out build type
message(STATUS "Build type: ${BUILD_TYPE}")

# Get the version from Git
find_package(Git QUIET)
if(GIT_FOUND)
  execute_process(
    COMMAND git describe --tags --long
    WORKING_DIRECTORY                ${CMAKE_CURRENT_SOURCE_DIR}
    OUTPUT_VARIABLE                  version
    OUTPUT_STRIP_TRAILING_WHITESPACE
    ERROR_STRIP_TRAILING_WHITESPACE
    ERROR_VARIABLE                   stderr
    RESULT_VARIABLE                  return_code
  )
  if(return_code)
    message(STATUS "git describe failed: ${stderr}; ${KERNEL_VERSION_STRING} will be used instead")
  elseif(CMAKE_VERBOSE_MAKEFILE)
    message(STATUS "git describe stderr: ${stderr}")
  endif()
endif()

if(version)
  string(REGEX REPLACE "^([0-9]+).*$" "\\1" version_major ${version})
  string(REGEX REPLACE "^[0-9]+\.([0-9]+).*$" "\\1" version_minor "${version}")
  string(REGEX REPLACE "^[0-9]+\.[0-9]+\.([0-9]+).*$" "\\1" version_patch "${version}")
  string(REGEX REPLACE "^[0-9]+\.[0-9]+\.[0-9]+-([0-9]+)-.*$" "\\1" version_commit "${version}")
  string(REGEX REPLACE "^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-(.*)$" "\\1" version_hash "${version}")

  
  # VERSION file
  file(WRITE VERSION "VERSION_MAJOR=${version_major}\n")
  file(APPEND VERSION "VERSION_MINOR=${version_minor}\n")
  file(APPEND VERSION "PATCHLEVEL=${version_patch}\n")
  file(APPEND VERSION "VERSION_TWEAK=${version_commit}\n")
  message(STATUS "Version: ${version_major}.${version_minor}.${version_patch}-${version_commit}-${version_hash}")
else()
   # VERSION file
   file(WRITE VERSION "VERSION_MAJOR=${version_major}\n")
   file(APPEND VERSION "VERSION_MINOR=${version_minor}\n")
   file(APPEND VERSION "PATCHLEVEL=${version_patch}\n")
   file(APPEND VERSION "VERSION_TWEAK=${version_commit}\n")

  message(STATUS "Version: ${version_major}.${version_minor}.${version_patch}-${version_commit}-${version_hash}")

endif()

# Define configuration files.
list(APPEND CONF_FILE
  ${CMAKE_CURRENT_SOURCE_DIR}/conf/prj.conf
  ${CMAKE_CURRENT_SOURCE_DIR}/conf/prj-${BUILD_TYPE}.conf
  ${CMAKE_CURRENT_SOURCE_DIR}/VERSION
)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(xxxxxx_xxxxxxxxxx2)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

Here is what is created in the application root for VERSION:

VERSION_MAJOR=2
VERSION_MINOR=0
PATCHLEVEL=0
VERSION_TWEAK=1

I am getting the following errors and cant seem to figure out why:

-- west build: generating a build system
-- Build type: debug
-- Version: 2.0.0-1-gd81431d
-- Application: xxxxxxxxxx
-- CMake version: 3.21.0

NOTE: After more testing these errors seemed to go away after i put spaces after the = in my version file.
CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/version.cmake:76 (math):
math cannot parse the expression: "( << 16) + ( << 8) + ()": syntax error,
unexpected exp_SHIFTLEFT (4).
Call Stack (most recent call first):
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfigVersion.cmake:59 (include)
CMakeLists.txt:96 (find_package)


CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/version.cmake:77 (math):
math cannot parse the expression: "( << 24) + ( << 16) + ( << 8) + ()":
syntax error, unexpected exp_SHIFTLEFT (4).
Call Stack (most recent call first):
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfigVersion.cmake:59 (include)
CMakeLists.txt:96 (find_package)


Loading Zephyr default modules (Zephyr base (cached)).
-- Cache files will be written to: C:/ncs/v2.6.0/zephyr/.cache
-- Zephyr version: 3.5.99 (C:/ncs/v2.6.0/zephyr)
CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/version.cmake:76 (math):
math cannot parse the expression: "( << 16) + ( << 8) + ()": syntax error,
unexpected exp_SHIFTLEFT (4).
Call Stack (most recent call first):
C:/ncs/v2.6.0/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
CMakeLists.txt:96 (find_package)


CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/version.cmake:77 (math):
math cannot parse the expression: "( << 24) + ( << 16) + ( << 8) + ()":
syntax error, unexpected exp_SHIFTLEFT (4).
Call Stack (most recent call first):
C:/ncs/v2.6.0/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
CMakeLists.txt:96 (find_package)

NOTE: Even though the abobe went away the following still exist and the compile stops with:


error: Aborting due to Kconfig warnings

CMake Error at C:/ncs/v2.6.0/zephyr/cmake/modules/kconfig.cmake:358 (message):
command failed with return code: 1
Call Stack (most recent call first):
C:/ncs/v2.6.0/nrf/cmake/modules/kconfig.cmake:29 (include)
C:/ncs/v2.6.0/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
C:/ncs/v2.6.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
CMakeLists.txt:96 (find_package)

xxxxxxxxxxxx/VERSION:1: warning: ignoring malformed line 'VERSION_MAJOR = 2'

xxxxxxxxxxxx/VERSION:2: warning: ignoring malformed line 'VERSION_MINOR = 0'

xxxxxxxxxxxx/VERSION:3: warning: ignoring malformed line 'PATCHLEVEL = 0'

xxxxxxxxxxxx/VERSION:4: warning: ignoring malformed line 'VERSION_TWEAK = 1'

error: Aborting due to Kconfig warnings

The errors seem to suggest that the temporary convenience variables in version.cmake are not being created but i have no way to figure out why.  Additionally the error on line 77 on the version.cmake looks to be setting kernel version not project version, that happens later in the file.

What am I doing wrong here?

Brian

Related