Improve warnings for MSVC_RUNTIME_LIBRARY (or unsupported properties in general)
In my scenario I had the following:
# FetchContent was introduced in 3.14.5 cmake_minimum_required(VERSION 3.14.5) project(foo) add_executable(foo main.cpp) set_target_properties(foo PROPERTIES # Use static runtime (/MT) MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
To my surprise this didn't work so I re-read the documentation page and found that this only works on 3.15 or higher and that it will be ignored if the policy is not set to
NEW. Switching to
cmake_minimum_required(VERSION 3.15) fixed everything, but I think there is room for improvement here.
I was using CMake 3.18 and it 'knows' about the
MSVC_RUNTIME_LIBRARY target property, but did not warn me that the property is ignored because the policy is set to
OLD. My suggestion would be to warn (I would prefer a hard error, but that's likely impossible) that a user is using a feature that is not supported according to their
cmake_minimum_required, but is actually supported by a newer CMake version.
If that is not possible it might be worthwhile to update the documentation to say for example:
New in version 3.15. Use
cmake_minimum_required(VERSION 3.15)or later to enable this feature.
Let me know what you think. This is the first concrete instance I have reported, but I have had similar experience when setting the
FOLDER property without calling
set_property(GLOBAL PROPERTY USE_FOLDERS ON)) first. I know that technically this is user error, but I can see how things like this might contribute to the sentiment that CMake is too complicated and difficult to learn.