cmake: How to make a script for copying Data files accompanying my program

前提是你 提交于 2019-12-12 07:53:29

问题


I am trying to automate my build process with cmake. There is currently only one issue:

Where is, in cmake's philosophy (if there is one), the best place to put the copying of data files.

I have a library and a few examples. The examples need the data.

I currently do the following:

I use a custom command in each example's CMakeLists.txt to copy all the Data into the CMAKE_CURRENT_BINARY_DIR in a post-build step. I use this in my debugging workflow, so no install target is executed yet.

This works quite well, but has certain drawbacks:

  1. The copying occurs everytime the project is built. With VS 2005 this sometimes occurs even if it is not newly built. Since the data folders are big, the copying takes time, and it gets a bit annoying.
  2. I am certain that this is a very clumsy way of doing this.

I want to copy those directories to the executable paths, so I don't need hints how to set the debug working directory

The perfect time to copy these directories would be at cmake configuration/generation time, at least I think so. Should I do this, and how would I do this?


回答1:


As recently seen in this question, you can use configure_file to copy files to the build directory:

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input.txt
    ${CMAKE_CURRENT_BINARY_DIR}/output.txt COPYONLY)

That does it once at build time and only when needed.



来源:https://stackoverflow.com/questions/1593881/cmake-how-to-make-a-script-for-copying-data-files-accompanying-my-program

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