Regression when setting CMAKE_CXX_FLAGS_RELEASE before project() since 3.11
Depending on the version of cmake, cmake does not generate compile_commands.json
with the same flags.
With the following CMakeLists.txt
:
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DFOO")
project(foo)
add_executable(foo foo.cpp)
invoking cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release ..
on cmake 3.9 or 3.10 generates compile_commands.json
containing:
[
{
"directory": "/home/foo/build-cmake-3.9.6",
"command": "/usr/bin/c++ -O3 -DNDEBUG -o CMakeFiles/foo.dir/foo.cpp.o -c /home/foo/foo.cpp",
"file": "/home/foo/foo.cpp"
}
]
With cmake >= 3.11, it generates the following file:
[
{
"directory": "/home/foo/build-cmake-3.11.4",
"command": "/usr/bin/c++ -DFOO -o CMakeFiles/foo.dir/foo.cpp.o -c /home/foo/foo.cpp",
"file": "/home/foo/foo.cpp"
}
]
Even though we should not specify CMAKE_CXX_RELEASE_FLAGS
directly, some old codebase do it that way.
Maybe cmake should emit a warning for theses cases?