cmake: make_directory in built time

大城市里の小女人 提交于 2020-01-25 15:40:09

问题


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?


回答1:


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

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)


来源:https://stackoverflow.com/questions/27094662/cmake-make-directory-in-built-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!