Incorrect default mapping of CONFIGURATIONs for Visual Studio Generator on Windows
Suppose to have
- a library, e.g., VTK, that you configured so that CMAKE_CONFIGURATION_TYPES are Debug and RelWithDebInfo only
- your application that you configured so that CMAKE_CONFIGURATION_TYPES are Debug and Release only and furthermore this application depends on the library
When you build the application in Release mode, it is linked with the debug version of the library instead of with the release version. The reason for that is that there is no Release CONFIGURATION for the library, so CMake resorts to the first available configuration (and does that even without any warning). This behaviour is wrong. By default, we have 1 debug configuration (Debug) and 3 release configurations (Release, RelWithDebInfo, RelMinSize). Debug and release configurations may never be combined together (this causes a lot of mysterious errors during build or even in runtime).
Indeed, one may easily change the CMAKE_CONFIGURATION_TYPES of the application to RelWithDebInfo, or to update the CMakeList file of the application by adding explicit mapping such as
set_target_properties(${ossLib} PROPERTIES
MAP_IMPORTED_CONFIG_RELEASE RelWithDebInfo
)
to build a working release version of the application but the former is too restrictive and the latter is supposed to be used in non-standard situations while this is not the case.
The correct behaviour should be to map default configurations (Debug, Release, RelWithDebInfo and RelMinSize) so that
- Debug can be mapped to Debug only
- Release can be mapped to Release, RelWithDebInfo or RelMinSize
- RelWithDebInfo can be mapped to RelWithDebInfo, Release, or RelMinSize, whereas there should be probably a warning displayed when mapping to Release or RelMinSize since these two release configurations do not have debug information and this is probably what the user want
- RelMinSize can be mapped to RelMinSize, Release, or RelWithDebInfo, whereas there should be probably a warning displayed when mapping to Release or RelWithDebInfo since the user apparently prefers small sizes of the binaries (for some reason)
If no mapping complying with these rules is possible, an error should be displayed.