This page contains a good summary of variables CMake already defines for us. I feel that some variables are the same. Take the example of CMAKE_SOURCE_DIR
and PROJECT_SOURCE_DIR
for example. They are the same, referring to the folder where the top level CMakeLists.txt is defined. So my question is: are there subtle difference between them? Thanks.
相关问题
- Avoid cmake to add the flags -search_paths_first a
- CMakeList file to generate LLVM bitcode file from
- How to fix NDK build error for HelloCardboard samp
- Linking against GLEW with CMake
- Linking libavcodec in Cmake, find_library won'
相关文章
- Target requires the language dialect “CXX17” (with
- How do I tell cmake not to create a console window
- Do something for all targets
- CMake: Replace compile flags of an INTERFACE targe
- Generate Web Assembly from CMake Project with a Sp
- Integrate ITK (Insight Toolkit) into own project
- Is there a way to disallow “experimental” C++17 in
- CMake properties and expanding generator expressio
Following Fraser's excellent answer.
CMAKE_CURRENT_SOURCE_DIR is
the build directory being processed
.Let's say you have a directory called
Inner1
containing a CMakeLists.txt file without callingproject
inside of it. ThenPROJECT_SOURCE_DIR
is not set withInner1
's dir path, but theCMAKE_CURRENT_SOURCE_DIR
is set when being processed.You may also find CMAKE_CURRENT_LIST_DIR interesting and the definition of listfile useful.
There is a difference between these variables.
CMAKE_SOURCE_DIR
does indeed refer to the folder where the top-level CMakeLists.txt is defined. However,PROJECT_SOURCE_DIR
refers to the folder of the CMakeLists.txt containing the most recentproject()
command.For example, say you have a top-level project called
Outer
and this contains a subdirectory with its own project calledInner
.Outer
's CMakeLists.txt has:and
Inner
's:Then in both of these CMakeLists files,
CMAKE_SOURCE_DIR
will refer toOuter
's source dir. But whilePROJECT_SOURCE_DIR
forOuter
is also this same dir, this is not the case forInner
.Inner
'sPROJECT_SOURCE_DIR
is the subdirectory containing its CMakeLists.txt.This difference applies to all
PROJECT_<var>
vsCMAKE_<var>
variables.