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 .
source share