Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I suppress Xcode from generating a folder named after the build configuration in cmake?

Tags:

xcode

cmake

I have a cmake configuration that works great for my project on Windows and Linux. We're tinkering with MacOS right now and we're at the point where Xcode spits out the libraries built one directory off from what we define. Instead of it being dropped in ~/bin it is dropped in ~/bin/Debug, for example. As best I can tell Xcode is taking upon itself to add this folder to the path and I don't want that.

How can I disable Xcode from doing this from within my cmake configuration?

like image 958
Mako_Energy Avatar asked Mar 23 '23 16:03

Mako_Energy


1 Answers

You'll need to specify the target properties ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>, LIBRARY_OUTPUT_DIRECTORY_<CONFIG>, and/or RUNTIME_OUTPUT_DIRECTORY_<CONFIG> for each config type and each target you want to affect.

To affect all targets, you can set variables named as these with CMAKE_ prepended. Any relevant target added after these have been set will be affected.

So, for example you could either do:

add_library(MyLib ${Sources})
set_target_properties(MyLib PROPERTIES
                      ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}
                      ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})

or you could do:

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
add_library(MyLib ${Sources})

Having said that, I normally find it's best to let multi-configuration generators like XCode and MSVC just add the config-specific directories. Unless you plan to also change the default names of exes and libs, these multi-config IDEs will overwrite one config's outputs with another's. So, it's hard to tell whether you're looking at a Debug or Release exe for example.

For single-config generators, I think it's common to have separate build trees per configuration to keep the distinction clear.

Basically, I wouldn't fight against the generator. CMake automates so much of the build process that I never find this slight difference between generators to be a problem. You rarely have to consider whether the output path contains a config dir or not.

like image 187
Fraser Avatar answered Apr 03 '23 20:04

Fraser