3

I am using CMake to build a cross-platform (e.g. Linux/Windows) application which uses also thirdparty libraries as external projects.

I'm aware of the fact that MSVC is a multi-configuration environment, hence CMAKE_BUILD_TYPE is not used, instead it uses the CMAKE_CONFIGURATION_TYPES set to build every possible configuration.

I'm also aware of the fact that instead of providing a configuration at configuration type (e.g. cmake -DCMAKE_BUILD_TYPE ..) I need to provide the configuration at build type (cmake --build . --config Release)

See https://stackoverflow.com/questions/24460486/cmake-build-type-not-being-used-in-cmakelists-txt]

What I completely fail to understand is:

I don't want multi-configuration builds. I want to build either Debug or Release- but only one of them in the generated buildsystem. Can I achieve that with CMake + multi-config generator (like MSVC or Ninja Multi-Config) + ExternalProject projects? If yes, how?

starball
  • 20,030
  • 7
  • 43
  • 238
harsszegi
  • 369
  • 2
  • 15
  • I've to admit I don't understand your question/problem. If you have added the project via [`ExternalProject_Add`](https://cmake.org/cmake/help/latest/module/ExternalProject.html) and you choose e.g. `Debug` in VS IDE as your active configuration, your external project will automatically also build with `Debug`. So you can alternatively use makefile or Ninja generator with MSVC to get single configuration builds. Can you please give mode details what your desired behavior might look like? Calling something from the command line? Restricting something in the IDE? – Florian Jul 02 '17 at 09:32
  • I don't use any VS IDE, only command line compilation. And I don't want to use anything else than cmake (and MSVC obviously) to drive the build. Btw I have created a kind of hack, meaning that I do "cmake --build . --config Debug/Release" and apart from these I build both the Debug and Release variants of the external projects (via giving them CMAKE_BUILD_TYPE manually) so during the compilation of the main application the proper libraries of the given external project is picked up, however I find this extremely hackish – harsszegi Jul 03 '17 at 09:56
  • Can then please give a [mcve] of your CMake code? Especially how you have include the external project? – Florian Jul 03 '17 at 10:14

1 Answers1

0

You should be able to achieve this by just setting CMAKE_CONFIGURATION_TYPES to a single-entry-list on the command line (with the -D argument format) like "-DCMAKE_CONFIGURATION_TYPES=Debug" or "-DCMAKE_CONFIGURATION_TYPES=Release" when you configure the buildsystem, and configuring your calls to ExternalProject_Add of external projects that use CMake to also pass on that value of CMAKE_CONFIGURATION_TYPES to the external project, like:

ExternalProject_Add(
  # ...
  CMAKE_CACHE_ARGS
    "-DCMAKE_CONFIGURATION_TYPES:STRING=${CMAKE_CONFIGURATION_TYPES}"
  # ...
)
starball
  • 20,030
  • 7
  • 43
  • 238