Where is CMAKE_SOURCE_DIR?

2019-02-08 23:43发布

问题:

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?

回答1:

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



标签: cmake