本文介绍了cmake:内置时间中的make_directory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在配置期间运行的这段代码:

I have this code that runs during configuration time:

if (NOT EXISTS "${PROJECT_BINARY_DIR}/tmpdir/")
  file (MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/tmpdir/")
  message ("Generating tmpdir directory")
endif ()

如何在构建时间内实现上述代码?

How do I implement the above code but in build time?

推荐答案

这取决于您何时确实需要这个目录。例如,如果在编译可执行文件 foo 之前需要它,则可以使用和:

It depends on when you exactly need this directory. For instance if you need it before executable foo compiled, you can use add_custom_target and add_dependencies:

add_custom_target(
    make_temp
    "${CMAKE_COMMAND}" -E make_directory "${PROJECT_BINARY_DIR}/tmpdir"
    COMMENT "Create 'tmpdir'"
)

add_executable(foo ...)
add_dependencies(foo make_temp)

这篇关于cmake:内置时间中的make_directory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 03:48