Files
CMake/Help/variable/CMAKE_PROJECT_SPDX_LICENSE.rst
Matthew Woehlke fba540daf6 project: Add SPDX_LICENSE argument
Add an argument to the `project` command to allow specifying a license
for a project as a whole. This is in addition to specifying licenses on
individual targets, and will be used to set the license(s) on exported
packages.

Also, move listing of `COMPAT_VERSION` variables to follow
lexicographical order.
2025-06-20 14:01:25 -04:00

42 lines
1.4 KiB
ReStructuredText

CMAKE_PROJECT_SPDX_LICENSE
--------------------------
.. versionadded:: 4.2
.. note::
Experimental. Gated by ``CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO``.
The license(s) of the top level project.
This variable holds the license expression of the project as specified in the
top level CMakeLists.txt file by a :command:`project` command. In the event
that the top level CMakeLists.txt contains multiple :command:`project` calls,
the most recently called one from that top level CMakeLists.txt will determine
the value that ``CMAKE_PROJECT_SPDX_LICENSE`` contains. For example, consider
the following top level CMakeLists.txt:
.. code-block:: cmake
cmake_minimum_required(VERSION 4.2)
project(First SPDX_LICENSE "BSD-3-Clause")
project(Second SPDX_LICENSE "BSD-3-Clause AND CC-BY-SA-4.0")
add_subdirectory(sub)
project(Third SPDX_LICENSE "BSD-3-Clause AND CC0-1.0")
And ``sub/CMakeLists.txt`` with the following contents:
.. code-block:: cmake
project(SubProj SPDX_LICENSE Apache-2.0)
message("CMAKE_PROJECT_SPDX_LICENSE = ${CMAKE_PROJECT_SPDX_LICENSE}")
The most recently seen :command:`project` command from the top level
CMakeLists.txt would be ``project(Second ...)``, so this will print::
CMAKE_PROJECT_SPDX_LICENSE = BSD-3-Clause AND CC-BY-SA-4.0
To obtain the version from the most recent call to :command:`project` in
the current directory scope or above, see the :variable:`PROJECT_SPDX_LICENSE`
variable.