CMake获取源文件属性命令get_source_file_pr

2023-09-15  本文已影响0人  Domibaba

可以使用get_source_file_property命令获取指定源文件的属性,源文件属性默认是从当前目录属性中获取。

命令格式

get_source_file_property(<variable> <file>
[DIRECTORY <dir> | TARGET_DIRECTORY <target>]
<property>)

简单示例

下面展示获取源文件LOCATION属性的示例,该属性表示源文件的全路径。更多的源文件属性请参考这里

假设接下来的目录结构为:

get_source_file_property/
├── CMakeLists.txt
├── main.cpp
└── test
    ├── CMakeLists.txt
    └── test.cpp

其中get_source_file_property/test/test.cpp提供了一个test_print()接口,并被编译成test库,供get_source_file_property/main.cpp调用。

get_source_file_property/test/test.cpp文件内容:

#include <iostream>

void test_print()
{
    std::cout << "In test: say hello!" << std::endl;
}

get_source_file_property/main.cpp文件内容:

extern void test_print();

int main(int argc, char** argv)
{
    test_print();
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读