相关疑难解决方法(0)

如何获取cmake目标的依赖项列表?

例如,我怎么知道我的可执行目标E是否依赖于我的库目标L?

让我们的图像E取决于L1和L2,但我不知道它们是否依赖于L.

target_link_libraries(E L1 L2)

我想在调用target_link_libraries之前从cmake本身获取列表,这样如果我检测到E依赖于两个不兼容的库,我可以做一些技巧.我玩了一些GetPrerequisites,但是这找到了对磁盘上现有库的依赖性,而不是正在构建的目标库.

谢谢

cmake

21
推荐指数
2
解决办法
1万
查看次数

目标位于子目录中时,替代CMake POST_BUILD命令

通常需要确保CMake构建项目在编译后最终位于某个位置,并且该add_custom_command(..POST_BUILD...)命令是实现该目标的通用设计模式:

add_custom_command(
  TARGET mytarget
  POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:mytarget> ${CMAKE_BINARY_DIR}/final_destination
)
Run Code Online (Sandbox Code Playgroud)

令人遗憾的是,当所讨论的目标位于相对于包含add_custom_command调用的文件的子目录中时,该文件是通过add_subdirectory()命令递归编译的。尝试这样做会导致以下错误消息:

CMake Warning (dev) at CMakeLists.txt:4 (add_custom_command):
  Policy CMP0040 is not set: The target in the TARGET signature of
  add_custom_command() must exist.  Run "cmake --help-policy CMP0040" for
  policy details.  Use the cmake_policy command to set the policy and
  suppress this warning.

  TARGET 'mytarget' was not created in this directory.
This warning is for project developers.  Use -Wno-dev to suppress it.
Run Code Online (Sandbox Code Playgroud)

在许多情况下,有一个简单的解决方法:只需确保该add_custom_command() …

cmake

5
推荐指数
1
解决办法
3006
查看次数

标签 统计

cmake ×2