2023-02-07 14:15:30 +08:00
|
|
|
# ##############################################################################
|
|
|
|
|
# cmake/nuttx_mkversion.cmake
|
|
|
|
|
#
|
2024-09-09 12:00:35 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
#
|
2023-02-07 14:15:30 +08:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
|
|
|
|
# license agreements. See the NOTICE file distributed with this work for
|
|
|
|
|
# additional information regarding copyright ownership. The ASF licenses this
|
|
|
|
|
# file to you under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
|
# use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
|
# the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
# License for the specific language governing permissions and limitations under
|
|
|
|
|
# the License.
|
|
|
|
|
#
|
|
|
|
|
# ##############################################################################
|
|
|
|
|
|
cmake: Use NUTTX(_DIR/_BIN_DIR) instead CMAKE(_SRC_DIR/_BIN_DIR)
This change fixes NuttX’s CMake support when NuttX is embedded
in another project via add_subdirectory(). CMake’s CMAKE_SOURCE_DIR
and CMAKE_BINARY_DIR refer to the outermost project, causing NuttX
to access its .config, generated files, host tools, and build artifacts
in the parent project’s directories. The fix introduces NUTTX_DIR and
NUTTX_BINARY_DIR, based on CMAKE_CURRENT_SOURCE_DIR and
CMAKE_CURRENT_BINARY_DIR, and consistently uses them for NuttX
self-references while preserving existing standalone builds. It fixes
the Kconfig initialization failure reported in #19697 and allows an
embedded sim:nsh build to configure, build, and boot successfully.
The change affects only the CMake build system (not Make or Kconfig
defaults), requires the corresponding nuttx-apps change, and does not
extend add_subdirectory() support to cross-compiled non-sim boards due
to CMake’s toolchain-file limitation.
Fixes #19697.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Alan Carvalho de Assis <acassis@gmail.com>
2026-08-08 15:52:46 -03:00
|
|
|
set(VERSION_H ${NUTTX_BINARY_DIR}/include/nuttx/version.h)
|
2023-02-07 14:15:30 +08:00
|
|
|
if(EXISTS ${VERSION_H})
|
|
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND git -C ${NUTTX_DIR} describe --match "nuttx-*"
|
|
|
|
|
WORKING_DIRECTORY ${NUTTX_DIR}
|
2023-07-13 16:32:56 +08:00
|
|
|
ERROR_VARIABLE NUTTX_ERROR
|
2023-02-07 14:15:30 +08:00
|
|
|
OUTPUT_VARIABLE NUTTX_VERSION
|
2024-08-21 13:43:28 +02:00
|
|
|
RESULT_VARIABLE VERSION_STATUS
|
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2023-02-07 14:15:30 +08:00
|
|
|
|
|
|
|
|
if(${VERSION_STATUS} AND NOT ${VERSION_STATUS} EQUAL 0)
|
|
|
|
|
set(NUTTX_VERSION "0.0.0")
|
|
|
|
|
else()
|
|
|
|
|
string(REPLACE "-" ";" NUTTX_VERSION ${NUTTX_VERSION})
|
|
|
|
|
list(GET NUTTX_VERSION 1 NUTTX_VERSION)
|
2025-06-18 20:45:51 +08:00
|
|
|
string(STRIP "${NUTTX_VERSION}" NUTTX_VERSION)
|
2023-02-07 14:15:30 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
string(REPLACE "." ";" NUTTX_CHECK_VERSION ${NUTTX_VERSION})
|
|
|
|
|
list(LENGTH NUTTX_CHECK_VERSION NUTTX_VERSION_LENGTH)
|
|
|
|
|
if(${NUTTX_VERSION_LENGTH} LESS 3)
|
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND git -C ${NUTTX_DIR} -c "versionsort.suffix=-" tag --sort=v:refname
|
|
|
|
|
WORKING_DIRECTORY ${NUTTX_DIR}
|
|
|
|
|
OUTPUT_VARIABLE NUTTX_VERSION_LIST
|
|
|
|
|
RESULT_VARIABLE VERSION_STATUS)
|
|
|
|
|
|
|
|
|
|
if(${VERSION_STATUS} EQUAL 0)
|
|
|
|
|
string(REPLACE "\n" ";" NUTTX_VERSION_LIST ${NUTTX_VERSION_LIST})
|
|
|
|
|
foreach(version ${NUTTX_VERSION_LIST})
|
|
|
|
|
string(REGEX MATCH "nuttx-[0-9]+\.[0-9]+\.[0-9]+" NUTTX_CHECK_VERSION
|
|
|
|
|
${version})
|
|
|
|
|
if(NUTTX_CHECK_VERSION)
|
|
|
|
|
string(REPLACE "-" ";" NUTTX_VERSION ${NUTTX_CHECK_VERSION})
|
|
|
|
|
list(GET NUTTX_VERSION 1 NUTTX_VERSION)
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND git -C ${NUTTX_DIR} log --oneline -1
|
|
|
|
|
WORKING_DIRECTORY ${NUTTX_DIR}
|
|
|
|
|
OUTPUT_VARIABLE NUTTX_VERSION_BUILD
|
|
|
|
|
RESULT_VARIABLE VERSION_STATUS)
|
|
|
|
|
|
|
|
|
|
if(${VERSION_STATUS} AND NOT ${VERSION_STATUS} EQUAL 0)
|
|
|
|
|
set(NUTTX_VERSION_BUILD)
|
|
|
|
|
else()
|
|
|
|
|
string(REPLACE " " ";" NUTTX_VERSION_BUILD ${NUTTX_VERSION_BUILD})
|
|
|
|
|
list(GET NUTTX_VERSION_BUILD 0 NUTTX_VERSION_BUILD)
|
|
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND git -C ${NUTTX_DIR} diff-index --name-only HEAD
|
|
|
|
|
WORKING_DIRECTORY ${NUTTX_DIR}
|
|
|
|
|
OUTPUT_VARIABLE NUTTX_VERSION_BUILD_DIRTY)
|
|
|
|
|
|
|
|
|
|
if(NUTTX_VERSION_BUILD_DIRTY)
|
|
|
|
|
set(NUTTX_VERSION_BUILD ${NUTTX_VERSION_BUILD}-dirty)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
file(WRITE ${VERSION_H} "/* version.h -- Autogenerated! Do not edit. */\n\n")
|
|
|
|
|
|
|
|
|
|
file(APPEND ${VERSION_H} "#ifndef __INCLUDE_NUTTX_VERSION_H\n")
|
|
|
|
|
file(APPEND ${VERSION_H} "#define __INCLUDE_NUTTX_VERSION_H\n\n")
|
|
|
|
|
file(APPEND ${VERSION_H} "#define CONFIG_VERSION_STRING \"${NUTTX_VERSION}\"\n")
|
|
|
|
|
|
|
|
|
|
string(REPLACE "." ";" NUTTX_VERSION ${NUTTX_VERSION})
|
|
|
|
|
|
|
|
|
|
list(GET NUTTX_VERSION 0 NUTTX_VERSION_MAJOR)
|
|
|
|
|
list(GET NUTTX_VERSION 1 NUTTX_VERSION_MINOR)
|
|
|
|
|
list(GET NUTTX_VERSION 2 NUTTX_VERSION_PATCH)
|
|
|
|
|
|
|
|
|
|
file(APPEND ${VERSION_H}
|
|
|
|
|
"#define CONFIG_VERSION_MAJOR ${NUTTX_VERSION_MAJOR}\n")
|
|
|
|
|
file(APPEND ${VERSION_H}
|
|
|
|
|
"#define CONFIG_VERSION_MINOR ${NUTTX_VERSION_MINOR}\n")
|
|
|
|
|
file(APPEND ${VERSION_H}
|
|
|
|
|
"#define CONFIG_VERSION_PATCH ${NUTTX_VERSION_PATCH}\n")
|
|
|
|
|
file(APPEND ${VERSION_H}
|
|
|
|
|
"#define CONFIG_VERSION_BUILD \"${NUTTX_VERSION_BUILD}\"\n\n")
|
|
|
|
|
|
|
|
|
|
file(
|
|
|
|
|
APPEND ${VERSION_H}
|
|
|
|
|
"#define CONFIG_VERSION ((CONFIG_VERSION_MAJOR << 16) | \\
|
|
|
|
|
(CONFIG_VERSION_MINOR << 8) | \\
|
|
|
|
|
(CONFIG_VERSION_PATCH))\n")
|
|
|
|
|
|
|
|
|
|
file(APPEND ${VERSION_H} "\n#endif /* __INCLUDE_NUTTX_VERSION_H */\n")
|