From db01a1219fac2db85563a8baf388cb50c2136073 Mon Sep 17 00:00:00 2001 From: kohait00 Date: Tue, 24 Oct 2023 23:30:28 +0200 Subject: [PATCH 1/4] This enables project(... VERSION x.y.z.a ...) usage --- tools/cmake/project.cmake | 48 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 290b468f487..379c2d9ad74 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,50 @@ 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(ARGV_EXT "LANGUAGES;C;CXX;ASM") + + set(LANGUAGES_POS -1) + string(FIND "${ARGV}" "LANGUAGES" LANGUAGES_POS) + if (LANGUAGES_POS GREATER 0) + # LANGUAGES definition from top level CMakeFile.txt exists + string(SUBSTRING "${ARGV}" 0 ${LANGUAGES_POS} ARGV_PREFIX) + string(SUBSTRING "${ARGV}" ${LANGUAGES_POS} -1 ARGV_SUB) + # ARGV_SUB is "LANGUAGES X Y Z and the rest", just remove what we specify + + # the C definition is tricky, as it also conflicts with CSharp, CXX etc.. + # so remove the definit option (;C; covers most, ;C at the end covers a special case. + # ;C theoretically could be a DESCRITION or the like too, but unlikly + string(REPLACE ";C;" ";" ARGV_SUB "${ARGV_SUB}") + string(LENGTH "${ARGV_SUB}" _C_LEN) + math(EXPR _C_END_POS "${_C_LEN} - 2" OUTPUT_FORMAT DECIMAL) + string(FIND "${ARGV_SUB}" ";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_SUB "${ARGV_SUB}") + endif() + + # ;CXX is unique enough + string(REPLACE ";CXX" "" ARGV_SUB "${ARGV_SUB}") + + # ;ASM is unique enough + string(REPLACE ";ASM" "" ARGV_SUB "${ARGV_SUB}") + + #last, remove the LANGUAGES keyword, which we specify ourselves, leave ; , might already be gone + string(REPLACE "LANGUAGES;" "" ARGV_SUB "${ARGV_SUB}") + string(REPLACE "LANGUAGES" "" ARGV_SUB "${ARGV_SUB}") + + set(ARGV_PROJECT "${ARGV_PREFIX};${ARGV_EXT};${ARGV_SUB}") + else() + # no LANGUAGES definition from top CMakeFile.txt + set(ARGV_PROJECT "${ARGV};${ARGV_EXT}") + 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 +546,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 CMakeFile 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: From 758152ae23c4b748356ef803ebc8a246ecb93b0d Mon Sep 17 00:00:00 2001 From: Konstantin Hartwich <61991449+kohait00@users.noreply.github.com> Date: Wed, 25 Oct 2023 18:02:21 +0200 Subject: [PATCH 2/4] Update tools/cmake/project.cmake good point, a little more info is always good Co-authored-by: Ivan Grokhotkov --- tools/cmake/project.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 379c2d9ad74..d040dfea4fb 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -451,7 +451,7 @@ macro(project project_name) # LANGUAGES usually to be last topic in ARGV list, so we simply kill all the parts we also specify, # and append the remainder - set(ARGV_EXT "LANGUAGES;C;CXX;ASM") + set(extra_project_args "LANGUAGES;C;CXX;ASM") set(LANGUAGES_POS -1) string(FIND "${ARGV}" "LANGUAGES" LANGUAGES_POS) From 109b71df95c5853e83f59fd37744ca7a07ed26dc Mon Sep 17 00:00:00 2001 From: kohait00 Date: Wed, 25 Oct 2023 21:43:17 +0200 Subject: [PATCH 3/4] fixes on project.cmake based on review findings by @igrr --- tools/cmake/project.cmake | 56 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index d040dfea4fb..ea51cc1cc05 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -453,44 +453,48 @@ macro(project project_name) 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 top level CMakeFile.txt exists - string(SUBSTRING "${ARGV}" 0 ${LANGUAGES_POS} ARGV_PREFIX) - string(SUBSTRING "${ARGV}" ${LANGUAGES_POS} -1 ARGV_SUB) - # ARGV_SUB is "LANGUAGES X Y Z and the rest", just remove what we specify - - # the C definition is tricky, as it also conflicts with CSharp, CXX etc.. - # so remove the definit option (;C; covers most, ;C at the end covers a special case. - # ;C theoretically could be a DESCRITION or the like too, but unlikly - string(REPLACE ";C;" ";" ARGV_SUB "${ARGV_SUB}") - string(LENGTH "${ARGV_SUB}" _C_LEN) - math(EXPR _C_END_POS "${_C_LEN} - 2" OUTPUT_FORMAT DECIMAL) - string(FIND "${ARGV_SUB}" ";C" _C_POS REVERSE) #special case ;C at the end - if( _C_POS GREATER_EQUAL _C_END_POS ) + 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_SUB "${ARGV_SUB}") + string(REPLACE ";C" "" ARGV_languages "${ARGV_languages}") endif() # ;CXX is unique enough - string(REPLACE ";CXX" "" ARGV_SUB "${ARGV_SUB}") + string(REPLACE ";CXX" "" ARGV_languages "${ARGV_languages}") # ;ASM is unique enough - string(REPLACE ";ASM" "" ARGV_SUB "${ARGV_SUB}") + 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_SUB "${ARGV_SUB}") - string(REPLACE "LANGUAGES" "" ARGV_SUB "${ARGV_SUB}") + string(REPLACE "LANGUAGES;" "" ARGV_languages "${ARGV_languages}") + string(REPLACE "LANGUAGES" "" ARGV_languages "${ARGV_languages}") - set(ARGV_PROJECT "${ARGV_PREFIX};${ARGV_EXT};${ARGV_SUB}") + set(ARGV_project "${ARGV_prefix};${extra_project_args};${ARGV_languages}") else() - # no LANGUAGES definition from top CMakeFile.txt - set(ARGV_PROJECT "${ARGV};${ARGV_EXT}") + # no LANGUAGES definition from the project level CMakeList.txt + set(ARGV_project "${ARGV};${extra_project_args}") endif() # The actual call to project() - __project(${ARGV_PROJECT}) + __project(${ARGV_project}) # Generate compile_commands.json (needs to come after project call). set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -546,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 the CMakeFile 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: From 96e2a8a51c7c9613d0699e46e00c4ca160b5eace Mon Sep 17 00:00:00 2001 From: kohait00 Date: Wed, 25 Oct 2023 22:05:31 +0200 Subject: [PATCH 4/4] adding documentation for PROJECT_VERSION in build-system.rst --- docs/en/api-guides/build-system.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index d4aa7ef5889..154528a4e51 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.