Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 520
Kozaki Avatar asked Feb 08 '11 00:02

Kozaki


1 Answers

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)
like image 164
Darryl Avatar answered Sep 21 '22 08:09

Darryl