Having CMake creates the generated binaries in a specific directory structure with assets

The structure of my project is basically as follows:

root / csi

root / assets

root / library

I currently have CMake installed to compile the source, compile the library, and then link it, calling make from the root directory.

Then I need to manually move the executable to the source resource directory so that it starts as it expects it to be (and we want to test our directory structure in assets as close as we expect it to be when it is done).

So, is there a way to tell CMake to automatically paste compiled binaries into this directory, as well as copy assets? As we are doing from source builds, attaching the executable back to the source folder with the project source files seems strange.

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

Any help would be appreciated --- thanks!

+7
source share
1 answer

Here is a simple example with a structure like yours:

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

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 located in the root / assets / debug file. I will need to understand how to get rid of the additional configuration folder (debugging). Not perfect, but I hope you get on the right track.

Edit ... Better yet:

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

All Articles