Haibo Huang | d00577c | 2020-02-28 16:35:48 -0800 | [diff] [blame] | 1 | CMAKE_PROJECT_NAME |
| 2 | ------------------ |
| 3 | |
| 4 | The name of the top level project. |
| 5 | |
| 6 | This variable holds the name of the project as specified in the top |
| 7 | level CMakeLists.txt file by a :command:`project` command. In the event that |
| 8 | the top level CMakeLists.txt contains multiple :command:`project` calls, |
| 9 | the most recently called one from that top level CMakeLists.txt will determine |
| 10 | the name that ``CMAKE_PROJECT_NAME`` contains. For example, consider |
| 11 | the following top level CMakeLists.txt: |
| 12 | |
| 13 | .. code-block:: cmake |
| 14 | |
| 15 | cmake_minimum_required(VERSION 3.0) |
| 16 | project(First) |
| 17 | project(Second) |
| 18 | add_subdirectory(sub) |
| 19 | project(Third) |
| 20 | |
| 21 | And ``sub/CMakeLists.txt`` with the following contents: |
| 22 | |
| 23 | .. code-block:: cmake |
| 24 | |
| 25 | project(SubProj) |
| 26 | message("CMAKE_PROJECT_NAME = ${CMAKE_PROJECT_NAME}") |
| 27 | |
| 28 | The most recently seen :command:`project` command from the top level |
| 29 | CMakeLists.txt would be ``project(Second)``, so this will print:: |
| 30 | |
| 31 | CMAKE_PROJECT_NAME = Second |
| 32 | |
| 33 | To obtain the name from the most recent call to :command:`project` in |
| 34 | the current directory scope or above, see the :variable:`PROJECT_NAME` |
| 35 | variable. |