In CMake, flags for the C ++ compiler can undergo various influences: setting CMAKE_CXX_FLAGS manually, using add_definitions() , forcing a specific C ++ standard, etc.
To compile the target in the same project with different rules (a precompiled header, in my case), I need to play the exact command that is used to compile the files added by the add_executable() command in this directory.
Reading CMAKE_CXX_FLAGS returns only the value set explicitly in it, CMAKE_CXX_FLAGS_DEBUG , and siblings list only the default Debug / Release parameters. There are special functions for extracting flags from add_definitions() and add_compiler_options() , but no one seems to be able to return the final command line.
How can I get all the flags passed to the compiler in a CMake variable?
source share