如何确保 CMAKE 代码将在子目录之后运行

how to make sure that cmake codes will run after subdirs

本文关键字:子目录 之后 运行 代码 CMAKE 何确保 确保      更新时间:2023-10-16

举一个小例子来说明我的问题:

project(Test)
set(TestLibName mytest)
subdirs(src) # will generate mytest.dll dynamic library
set_property(TARGET ${TestLibName} PROPERTY FOLDER "test")

在这个小脚本中,我想使用 CMakeLists.txt 文件生成动态库 src foler,之后我将在顶部 CMakeLists.txt 中设置库的属性。但是,它似乎不起作用,因为我有以下错误:

set_property cannot find Target "mytest". Perhaps it has been created yet. 

解决此问题的一种解决方案是将set_property放在创建动态库 (src/CMakeLists.txt) 的 CMakeList 中.txt 的 CMakeList 中。如果我坚持把它放在顶级CMakeLists.txt文件中,我该怎么办?谢谢。

不要使用已弃用的命令子目录。当它被add_subdirectory替换时,一切正常