cmake:内置时间中的make_directory [英] cmake: make_directory in built time

查看:175
本文介绍了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?

推荐答案


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

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

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆