From the documentation, I don’t 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, while PROJECT_NAME is from the last project call, regardless from the location of the file containing the command.
The difference is recognizable 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}")
The relevant output is:
< A / A < B / B << B / D <<< B / F << B / E < B / B < C / C
In the sub-directories, always B is the value for CMAKE_PROJECT_NAME.