blob: 94b8dbab829c63b870176f50f73c3dd332d4774d [file] [log] [blame]
Haibo Huangd00577c2020-02-28 16:35:48 -08001CMAKE_PROJECT_NAME
2------------------
3
4The name of the top level project.
5
6This variable holds the name of the project as specified in the top
7level CMakeLists.txt file by a :command:`project` command. In the event that
8the top level CMakeLists.txt contains multiple :command:`project` calls,
9the most recently called one from that top level CMakeLists.txt will determine
10the name that ``CMAKE_PROJECT_NAME`` contains. For example, consider
11the 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
21And ``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
28The most recently seen :command:`project` command from the top level
29CMakeLists.txt would be ``project(Second)``, so this will print::
30
31 CMAKE_PROJECT_NAME = Second
32
33To obtain the name from the most recent call to :command:`project` in
34the current directory scope or above, see the :variable:`PROJECT_NAME`
35variable.