Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This enables project(... VERSION x.y.z.a ...) and DESCRIPTION etc.. usage (IDFGH-11310) #12461

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/api-guides/build-system.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
52 changes: 50 additions & 2 deletions tools/cmake/project.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
kohait00 marked this conversation as resolved.
Show resolved Hide resolved
else()
git_describe(PROJECT_VER_GIT "${_project_path}")
if(PROJECT_VER_GIT)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down