Provide a way to exclude targets per configuration from the "all" target when using Ninja Multi-Config cross config mode
Sample project:
cmake_minimum_required(VERSION 3.17.0)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "")
if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config")
set(CMAKE_DEFAULT_BUILD_TYPE "Release" CACHE STRING "")
set(CMAKE_CROSS_CONFIGS "all" CACHE STRING "")
set(CMAKE_DEFAULT_CONFIGS "all" CACHE STRING "")
endif()
project(multi_ninja_cross_config_exclude_from_all LANGUAGES CXX)
set(source_path "${CMAKE_CURRENT_BINARY_DIR}/source.cpp")
file(WRITE "${source_path}" "void foo() {}")
add_library(Core SHARED "${source_path}")
# set_target_properties(Core PROPERTIES EXCLUDE_FROM_ALL TRUE) <--- How to do this per-config?
# A possible API could be
# set_target_properties(Core PROPERTIES EXCLUDE_FROM_ALL_DEBUG TRUE)
# aka
# set_target_properties(Core PROPERTIES EXCLUDE_FROM_ALL_<CONFIG> TRUE)
Configuring with cmake .. -G"Ninja Multi-Config"
and running ninja -v
will build the Core
target for both Debug
and Release
.
There is currently no way to exclude the Core
target from the ninja all
target per configuration.
While the sample project is short in order to demonstrate the issue, the motivating use case is building Qt with NMC.
Currently if someone tries to build a "Release;Debug"
build of Qt with NMC on Windows, it will build both the Qt libraries and the Qt tools (like moc
and qdoc
) in both configurations.
Now qdoc
uses libclang
/ LLVM
.
The clang
CMake Config package file by default contains only Release
libraries.
CMake will thus try to link the Release
libraries into the Debug
qdoc, which will fail with compiler / linker errors due to mixing the Release
and Debug
MSVC runtime libraries.
If the project could exclude the tool targets from the all
target per configuration, it would be possible to build the libraries in both configurations, while tools only in the Release
configuration, and thus avoid the issue above.