AUTOMOC breaks on configuration-dependent source files
The following project
cmake_minimum_required(VERSION 3.17.0)
project(buggetybug)
set(CMAKE_AUTOMOC YES)
find_package(Qt5 COMPONENTS Core)
add_executable(exe main.cpp
$<$<CONFIG:Debug>:debug_stuff.cpp>
$<$<CONFIG:Release>:release_stuff.cpp>)
configured with
cmake -G"Ninja Multi-Config" -DCMAKE_PREFIX_PATH=~/Qt/5.14/lib/cmake '-DCMAKE_CONFIGURATION_TYPES=Debug;Release'
fails with the very surprising error message
CMake Error in CMakeLists.txt:
Target "exe" has source files which vary by configuration. This is not
supported by the "Ninja Multi-Config" generator.
Config "Debug":
/home/jobor/dev/personal/multicfgbug/main.cpp
/home/jobor/dev/personal/multicfgbug/debug_stuff.cpp
Config "Release":
/home/jobor/dev/personal/multicfgbug/main.cpp
/home/jobor/dev/personal/multicfgbug/release_stuff.cpp
The project builds fine if the line
set(CMAKE_AUTOMOC YES)
is removed / commented out.
This apparently happens, because cmQtAutoGenInitializer::InitScanFiles
calls cmGeneratorTarget::GetConfigCommonSourceFiles()
to gather the target sources, and this function contains a check that yields above error.
Slightly educated guess: Nothing outside of actual generators should call this function, and cmQtAutoGenInitializer must be - somehow - adjusted to gather the source files in some multi-config-compatible way.
I have attached an example project that exhibits the issue: multicfgbug.tar.gz
Edited by Brad King