Difference between CMAKE_PROJECT_NAME and PROJECT_NAME?

What is the difference between CMAKE_PROJECT_NAME and PROJECT_NAME?

From the documentation:

CMAKE_PROJECT_NAME

The name of the current project.

Indicates the name of the current project from the nearest inherited project () command.

PROJECT_NAME

The name of the project given to the project team.

This is the name assigned to the most recent project () command.

I do not understand the difference.

When should you use CMAKE_PROJECT_NAME ? When should I use PROJECT_NAME ?

+6
source share
1 answer

From the documentation I do not get the difference between the two variables.

The difference is that CMAKE_PROJECT_NAME is the name from the last project call from the root CMakeLists.txt, and PROJECT_NAME is from the last project call, regardless of the location of the file containing the command.

The difference is recognized from the following test.

File structure:

 |-CMakeLists.txt \-test2 |-CMakeLists.txt \-test3 \-CMakeLists.txt 

CMakeLists.txt:

 cmake_minimum_required(VERSION 3.0) project(A) message("< ${CMAKE_PROJECT_NAME} / ${PROJECT_NAME}") project(B) message("< ${CMAKE_PROJECT_NAME} / ${PROJECT_NAME}") add_subdirectory(test2) message("< ${CMAKE_PROJECT_NAME} / ${PROJECT_NAME}") project(C) message("< ${CMAKE_PROJECT_NAME} / ${PROJECT_NAME}") 

test2 / CMakeLists.txt:

 project(D) message("<< ${CMAKE_PROJECT_NAME} / ${PROJECT_NAME}") add_subdirectory(test3) project(E) message("<< ${CMAKE_PROJECT_NAME} / ${PROJECT_NAME}") 

test2 / test3 / CMakeLists.txt:

 project(F) message("<<< ${CMAKE_PROJECT_NAME} / ${PROJECT_NAME}") 

Corresponding conclusion:

 < A / A < B / B << B / D <<< B / F << B / E < B / B < C / C 

In subdirectories, always B is the value for CMAKE_PROJECT_NAME .

+6
source

All Articles