CMake中的CMAKE_SOURCE_DIR和PROJECT_SOURCE_DIR是否相同? [英] Are CMAKE_SOURCE_DIR and PROJECT_SOURCE_DIR the same in CMake?

查看:1119
本文介绍了CMake中的CMAKE_SOURCE_DIR和PROJECT_SOURCE_DIR是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此页面包含变量的完整摘要CMake已经为我们定义了。我觉得有些变量是相同的。以 CMAKE_SOURCE_DIR PROJECT_SOURCE_DIR 为例。它们是相同的,是指定义顶级CMakeLists.txt的文件夹。所以我的问题是:它们之间是否存在细微差别?谢谢。

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.

推荐答案

这些变量之间的区别是 CMAKE_SOURCE_DIR 确实可以请参考定义了顶级CMakeLists.txt的文件夹。但是, PROJECT_SOURCE_DIR 指的是CMakeLists.txt的文件夹,其中包含最新的 project()命令。

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.

例如,说您有一个名为 Outer 的顶级项目,它包含一个子目录,该子目录带有自己的名为 Inner 的项目。 外部的CMakeLists.txt具有:

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

project(Outer)
add_subdirectory(Inner)

内部's:

project(Inner)

然后在这两个CMakeLists文件中, CMAKE_SOURCE_DIR 将引用外部的源目录。但是,虽然 PROJECT_SOURCE_DIR 对于外部也是相同的目录,但对于 Inner不是这种情况 Inner PROJECT_SOURCE_DIR 是包含其CMakeLists.txt的子目录。

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 Inner. Inner's PROJECT_SOURCE_DIR is the subdirectory containing its CMakeLists.txt.

此差异适用于所有 PROJECT_< var> CMAKE_< var> 变量。

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

这篇关于CMake中的CMAKE_SOURCE_DIR和PROJECT_SOURCE_DIR是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆