Having CMake put generated binaries in a specific directory structure with assets

六眼飞鱼酱① 提交于 2021-02-17 15:07:29

问题


My project's directory structure is basically as follows:

root/src

root/assets

root/library

I currently have CMake set up to compile the source, compile the library, and then link them, by calling make from the root directory.

I then have to manually move the executable into the original assets directory to get it to run, since that's where it expects to be (and we want to test with our directory structure in assets as close to what we expect it to be when it's done).

So, is there any way to tell CMake to automatically stick the compiled binary in that directory, as well as copy the assets over? Since we're doing out of source builds, sticking the executable back into the original project source's assets folder seems odd.

In short, two questions: Is there any way to get CMake to copy assets as well as code, and is there any way to have it copy the generated executable to a specific location in the build tree?

Any help would be appreciated --- thank you!


回答1:


Here's a simple example with a structure like yours:

  • root/src/main.cpp (only source file)
  • root/assets (where I want the executable to go)

Here's the cmake file:

PROJECT(HelloCMake)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${HelloCMake_SOURCE_DIR}/assets)
add_executable (HelloCMake src/main.cpp) 

When I build against this using Visual Studio I get the output placed in root/assets/debug. I'd have to dig to figure out how to get rid of the extra configuration folder (debug). Not perfect, but hopefully that gets you on the right track.

Edit...Even better:

INSTALL(TARGETS HelloCMake DESTINATION ${HelloCMake_SOURCE_DIR}/assets)


来源:https://stackoverflow.com/questions/4928341/having-cmake-put-generated-binaries-in-a-specific-directory-structure-with-asset

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