Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CMAKE how to stop the "Debug" and "Release" subdirectories

I have specified my binary output directory with:

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

Unfortunately, Visual Studio adds Debug and Release directories.

I do not want these.

The documentation for CMAKE says:

Multi-configuration generators (VS, Xcode) append a per-configuration subdirectory to the specified directory unless a generator expression is used.

But I am not sure exactly what that means.

How can I get Visual Studio to not add those directories?

like image 615
Startec Avatar asked Nov 08 '17 09:11

Startec


1 Answers

To directly answer your question: use a generator expression, as the documentation suggests. Here's an example:

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}/bin>)

$<1:xxx> is a genex which expands to xxx, so that means the final value will be what you want it to be.

However, be aware that this means that when building, binaries from the currently built configuration will overwrite those from the previous build, even if that was a different configuration. Are you sure you want that?


As a side note, that path you've specified is relative to the source directory. That sounds really unusual too, and could easily lead to problems. For example, if you generate multiple buildsystems from the same source (into different binary directories), the .exe files from them all will be stored in the same location, the last one built overwriting any previous ones. That sounds like a solid can of worms and a future maintenance nightmare.

While I do not know the details of your setup, I urge you to reconsider storing build artefacts in the source tree.

like image 152
Angew is no longer proud of SO Avatar answered Nov 02 '22 05:11

Angew is no longer proud of SO