IMPORTED targets should not fallback to Debug if Release, RelWithDebInfo and MinSizeRel is asked and one is present
Right now the behavior of find_package
is to fallback to an installed Debug
configuration if the exact configuration is not found.
This can cause issues (on windows mainly) where if you have Debug
and Release
installed, you can not build with RelWithDebInfo
or MinSizeRel
configs. (It will find the Debug one, and MSVC doesn't allow to mix debug and non debug runtimes)
This is even more problematic since some projects allow only the Debug
and Release
configurations. (For example OpenCV)
The current workaround I have is to have
set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL MinSizeRel RelWithDebInfo Release Debug)
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo Release MinSizeRel Debug)
set(CMAKE_MAP_IMPORTED_CONFIG_RELEASE Release RelWithDebInfo MinSizeRel Debug)
in my project, or in its config file.
I suggest setting those variables to the right defaults, as this should not break existing codebases (A RelWithDebInfo build relying on Debug builds would be weird)
Edited by Brad King