Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is CMAKE_SOURCE_DIR?

Tags:

cmake

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?

like image 978
patchwork Avatar asked May 12 '14 11:05

patchwork


People also ask

What is the Cmake_source_dir?

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 .

What is 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 .

What is Project_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).

What is Cmake_current_source_dir?

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.


1 Answers

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

like image 199
user2485710 Avatar answered Oct 11 '22 09:10

user2485710