Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
给定一个CMakeLists文件,有没有办法知道哪个父CMakeLists';称为';信息技术_Cmake - Fatal编程技术网

给定一个CMakeLists文件,有没有办法知道哪个父CMakeLists';称为';信息技术

给定一个CMakeLists文件,有没有办法知道哪个父CMakeLists';称为';信息技术,cmake,Cmake,给定一个大的cmake项目,让B成为CMakeLists.txt,位于其中的某个目录中。是否有任何方法可以从B中打印(message(…))哪个父CMakeLists.txt文件添加了子目录(B)或等效文件 注意:让我们假设没有cmake文件确实是add_子目录(B),而是add_子目录(${X}),它是X子目录B的路径,通过cmake树确定。否则,只需使用grep属性包含父源目录即可确定: get_directory_property(parent_dir PARENT_DIRECTORY)

给定一个大的
cmake
项目,让
B
成为
CMakeLists.txt
,位于其中的某个目录中。是否有任何方法可以从
B
中打印(
message(…)
哪个父
CMakeLists.txt
文件添加了子目录(B)
或等效文件

注意:让我们假设没有
cmake
文件确实是
add_子目录(B)
,而是
add_子目录(${X})
,它是
X
子目录
B
的路径,通过
cmake
树确定。否则,只需使用
grep

属性包含父源目录即可确定:

get_directory_property(parent_dir PARENT_DIRECTORY)
if (parent_dir)
    message(STATUS "I am called with 'add_subdirectory' from script ${parent_dir}/CMakeLists.txt")
else ()
    message(STATUS "I am top-level CMakeLists.txt script)
endif()
另请参见属性包含父源目录:

get_directory_property(parent_dir PARENT_DIRECTORY)
if (parent_dir)
    message(STATUS "I am called with 'add_subdirectory' from script ${parent_dir}/CMakeLists.txt")
else ()
    message(STATUS "I am top-level CMakeLists.txt script)
endif()

另请参见

如果子CMake文件是通过
include()
find\u package()
添加的,则
父目录
属性也将返回空字符串。因此,对于这些情况,您可以改为使用来获取父CMakeLists.txt文件的完整路径。是的,
parent\u目录
仅用于通过
add\u subdirectory()
包含。而
CMAKE_PARENT_LIST_文件
仅通过
include()
find_package()
用于包含。如果通过
include()
find_package()
添加子CMAKE文件,则
PARENT_目录
属性也将返回空字符串。因此,对于这些情况,您可以改为使用来获取父CMakeLists.txt文件的完整路径。是的,
parent\u目录
仅用于通过
add\u subdirectory()
包含。和
CMAKE\u PARENT\u LIST\u文件
仅适用于通过
include()
find\u package()
包含的内容。