Is this variable always set to the directory containing the CMakeLists.txt
file that I run cmake
on?
For example, if I wish to run cmake
on a CMakeLists.txt
file that exists in the directory above my current directory, I would go: cmake ..
.
In this case, what is my CMAKE_SOURCE_DIR set to?
The path to the top level of the source tree. This is the full path to the top level of the current CMake source tree. For an in-source build, this would be the same as CMAKE_BINARY_DIR .
The path to the top level of the build tree. This is the full path to the top level of the current CMake build tree. For an in-source build, this would be the same as CMAKE_SOURCE_DIR .
This is the source directory of the last call to the project() command made in the current directory scope or one of its parents. Note, it is not affected by calls to project() made within a child directory scope (i.e. from within a call to add_subdirectory() from the current scope).
CMAKE_CURRENT_SOURCE_DIR. The path to the source directory currently being processed. This is the full path to the source directory that is currently being processed by cmake.
Assuming that you have 2 folders src
and build
where src
contains your projects and build
is the empty folder that you just created so you can deploy your out-of-tree build in it: CMAKE_SOURCE_DIR
is the path to src
where CMAKE_BINARY_DIR
points to build
.
Note that if you are doing an in-tree build, the 2 cache entries get the same value.
link: CMake Useful Variables .
EDIT
for further clarifications
<some location>/src/CMakeLists.txt ( so *src* is the root of your project )
<some location>/build
if you do something like
cd <some location>/build
cmake <some location>/src
you are making an out-of-tree build where CMAKE_SOURCE_DIR
and CMAKE_BINARY_DIR
get different values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With