PROJECT_SOURCE_DIR
为包含PROJECT()
的最近一个CMakeLists.txt
文件所在的文件夹。
如以下文件结构:
test
|
+-----build
|
+-----include
|
+-----lib
|
+-----src
|
+main.cpp
|
+CMakeLists.txt
|
+-----CMakeLists.txt
test/CMakeLists.txt
文件内容为
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(test) ADD_SUBDIRECTORY(src)
test/src/CMakeLists.txt
文件内容为
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) #PROJECT(main)
在build
中执行cmake ..
(两个小数点别丢了)则PROJECT_SOURCE_DIR
的值为(parent_path)/test
,
取消#PROJECT(main)
的注释,PROJECT_SOURCE_DIR
的值为(parent_path)/test/src
.