External Project and debug/release builds with multi-config generators

Hi,

I’m struggling a bit with ExternalProject and multi-config generators (MSVC).
How do I “tell” ExternalProject_Add() whether I need a debug or a release build depending on the currently selected build type ?
The external project has nmake Makefiles.

1 Like

I would think that you would want to use generator expressions to control the build of the external project using nmake.

In addition to a -DCMAKE_BUILD_TYPE:STRING=$<CONFIG>, you’ll likely also want BUILD_DIR something/$<CONFIG> STAMP_DIR/something/$<CONFIG> or the like to avoid rebuilds on every configuration switch. The install tree may also get very confused if the contents of files overlap in ways that are configuration-sensitive (e.g., not changing library names).

1 Like

I would have expected the ExternalProject to follow the same config used to build the main project. Is that not happening for you, or are you trying to force a particular config different to the main build? When the main project is using a multi-config generator, the ExternalProject module explicitly passes the config to use as --config $<CONFIG> on the cmake --build ... command line it constructs.

AFAIK, cmake --config x --build does nothing for single-config generators (as it was baked in at configure time via CMAKE_BUILD_TYPE).