给定一个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()
包含的内容。