diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index d4aa7ef58898..154528a4e514 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -361,6 +361,7 @@ The following are some project/build variables that are available as build prope * If :ref:`CONFIG_APP_PROJECT_VER_FROM_CONFIG` option is set, the value of :ref:`CONFIG_APP_PROJECT_VER` will be used. * Else, if ``PROJECT_VER`` variable is set in project CMakeLists.txt file, its value will be used. * Else, if the ``PROJECT_DIR/version.txt`` exists, its contents will be used as ``PROJECT_VER``. + * Else, if ``PROJECT_VERSION`` contains a version from ``project(... VERSION A.b.p.t ...)`` in project level CMakeLists.txt file, its contents will be used as ``PROJECT_VER``. * Else, if the project is located inside a Git repository, the output of git description will be used. * Otherwise, ``PROJECT_VER`` will be "1". - ``EXTRA_PARTITION_SUBTYPES``: CMake list of extra partition subtypes. Each subtype description is a comma-separated string with ``type_name, subtype_name, numeric_value`` format. Components may add new subtypes by appending them to this list. diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 290b468f4877..ea51cc1cc050 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -74,6 +74,8 @@ function(__project_get_revision var) if(EXISTS "${_project_path}/version.txt") file(STRINGS "${_project_path}/version.txt" PROJECT_VER) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_project_path}/version.txt") + elseif (NOT "${PROJECT_VERSION}" STREQUAL "") + set(PROJECT_VER ${PROJECT_VERSION}) else() git_describe(PROJECT_VER_GIT "${_project_path}") if(PROJECT_VER_GIT) @@ -445,8 +447,54 @@ macro(project project_name) endif() endif() + # handle LANGUAGES duplicates in the definition of project ARGV coming from top CMakeFile.txt + # LANGUAGES usually to be last topic in ARGV list, so we simply kill all the parts we also specify, + # and append the remainder + + set(extra_project_args "LANGUAGES;C;CXX;ASM") + + set(LANGUAGES_pos -1) + string(FIND "${ARGV}" "LANGUAGES" LANGUAGES_pos) + if (LANGUAGES_pos GREATER 0) + # LANGUAGES definition from the project level CMakeLists.txt exists, split ARGV at that position + + string(SUBSTRING "${ARGV}" 0 ${LANGUAGES_pos} ARGV_prefix) + string(SUBSTRING "${ARGV}" ${LANGUAGES_pos} -1 ARGV_languages) + # ARGV_languages contains "LANGUAGES;X;Y;Z now and anything following it" + # just remove the languages we want to default set here via ${extra_project_args} + + # ;C is tricky + # as it also conflicts with CSharp, CXX etc.. + # replace ';C;' with ';' covers most cases, remove ';C' at the end covers a special case. + # unhandled caveat: removeing ';C' could + # also remove from a DESCRITION or any other following part, but unlikely enough + string(REPLACE ";C;" ";" ARGV_languages "${ARGV_languages}") + string(LENGTH "${ARGV_languages}" _ARGV_languages_len) + math(EXPR _C_end_pos "${_ARGV_languages_len} - 2" OUTPUT_FORMAT DECIMAL) + string(FIND "${ARGV_languages}" ";C" _C_pos REVERSE) #special case ;C at the end + if( _C_pos GREATER_EQUAL _C_end_pos ) + # C; present at the end + string(REPLACE ";C" "" ARGV_languages "${ARGV_languages}") + endif() + + # ;CXX is unique enough + string(REPLACE ";CXX" "" ARGV_languages "${ARGV_languages}") + + # ;ASM is unique enough + string(REPLACE ";ASM" "" ARGV_languages "${ARGV_languages}") + + #last, remove the LANGUAGES keyword, which we specify ourselves, leave ; , might already be gone + string(REPLACE "LANGUAGES;" "" ARGV_languages "${ARGV_languages}") + string(REPLACE "LANGUAGES" "" ARGV_languages "${ARGV_languages}") + + set(ARGV_project "${ARGV_prefix};${extra_project_args};${ARGV_languages}") + else() + # no LANGUAGES definition from the project level CMakeList.txt + set(ARGV_project "${ARGV};${extra_project_args}") + endif() + # The actual call to project() - __project(${project_name} C CXX ASM) + __project(${ARGV_project}) # Generate compile_commands.json (needs to come after project call). set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -502,7 +550,7 @@ macro(project project_name) # # PROJECT_NAME is taken from the passed name from project() call # PROJECT_DIR is set to the current directory - # PROJECT_VER is from the version text or git revision of the current repo + # PROJECT_VER is from the version text or the CMakeLists.txt or git revision of the current repo # SDKCONFIG_DEFAULTS environment variable may specify a file name relative to the root of the project. # When building the bootloader, ignore this variable, since: