cmake_minimum_required required version impact generated files
I'm experiencing a strange behaviour where changing cmake_minimum_required
affects files generated by CMake
targetting Visual Studio 2019. According to the doc of cmake_minimum_required
:
If the running version of CMake is lower than the required version it will stop processing the project and report an error
So it's just supposed to interrupt project generation.
But, if I create:
main.cpp:
int main()
{
#ifndef _DEBUG
#error "DEBUG flag not set"
#endif
return 0;
}
and CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.12)
project(hello_world)
set( CMAKE_CONFIGURATION_TYPES "Debug;Release;MyDebug" CACHE INTERNAL "" FORCE )
set( CMAKE_CXX_FLAGS_MYDEBUG "${CMAKE_CXX_FLAGS_DEBUG}" )
set( CMAKE_C_FLAGS_MYDEBUG "${CMAKE_C_FLAGS_DEBUG}" )
set( CMAKE_EXE_LINKER_FLAGS_MYDEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" )
set( CMAKE_SHARED_LINKER_FLAGS_MYDEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" )
set_property( GLOBAL PROPERTY DEBUG_CONFIGURATIONS "Debug;MyDebug" )
add_executable(app main.cpp)
If I generate this project with CMake 3.24.1 for Visual Studio 2019, then it builds correctly using MyDebug
config as _DEBUG
compilation flag is correctly set.
However, if I change cmake_minimum_required(VERSION 2.8.12)
to cmake_minimum_required(VERSION 3.24.1)
, then it fails to build, reporting DEBUG flag not set
, meaning _DEBUG
compilation flag is not set anymore.
When I check vcproj
file, I see that for MyDebug
, <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
is changed to <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
.
Is this a CMake
bug or am I doing something wrong?