I use cmake 3.22. I try to get root directory of the my project in the install[CODE] section in the my top level CMakeLists.txt file:
cmake_minimum_required(VERSION 3.22)
...
project(myProject CXX)
...
install(CODE [[
message(STATUS "PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
message(STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
message(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
]])
I get the following outputs during installation ${PROJECT_SOURCE_DIR}:
-- PROJECT_SOURCE_DIR:
-- CMAKE_BINARY_DIR: /project_root/build/config_type_dir
-- CMAKE_SOURCE_DIR: /project_root/build/config_type_dir
But I need to get my /project_root path.
Doc says about ${PROJECT_SOURCE_DIR} variable:
This is the source directory of the last call to the project() command made in the current directory scope or one of its parents.
https://cmake.org/cmake/help/latest/variable/PROJECT_SOURCE_DIR.html
Is it a bug? Or I do something wrong?