Are CMAKE_SOURCE_DIR and PROJECT_SOURCE_DIR the same in CMake?and CMAKE_BINARY_DIR?etc

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 recent project() command.

For example, say you have a top-level project called Outer and this contains a subdirectory with its own project called InnerOuter's CMakeLists.txt has:

project(Outer)
add_subdirectory(Inner)

and Inner's:

project(Inner)

Then in both of these CMakeLists files, CMAKE_SOURCE_DIR will refer to Outer's source dir. But while PROJECT_SOURCE_DIR for Outer is also this same dir, this is not the case for InnerInner's PROJECT_SOURCE_DIR is the subdirectory containing its CMakeLists.txt.

This difference applies to all PROJECT_<var> vs CMAKE_<var> variables.


https://cmake.org/cmake/help/v3.5/variable/CMAKE_BINARY_DIR.html

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.

When run in -P script mode, CMake sets the variables CMAKE_BINARY_DIRCMAKE_SOURCE_DIRCMAKE_CURRENT_BINARY_DIRand CMAKE_CURRENT_SOURCE_DIR to the current working directory.


CMAKE_SOURCE_DIR,PROJECT_SOURCE_DIR,_SOURCE_DIR:

这三个变量内容一致,都指的是工程的顶级目录。

CMAKE_CURRENT_BINARY_DIR:外部编译时,指的是target目录,内部编译时,指的是顶级目录

CMAKE_CURRENT_SOURCE_DIR:CMakeList.txt所在的目录

CMAKE_CURRENT_LIST_DIR:CMakeList.txt的完整路径

CMAKE_CURRENT_LIST_LINE:当前所在的行

CMAKE_MODULE_PATH:如果工程复杂,可能需要编写一些cmake模块,这里通过SET指定这个变量

LIBRARY_OUTPUT_DIR,BINARY_OUTPUT_DIR:库和可执行的最终存放目录

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AplusX

踩坑不易,打个赏呗~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值