[CMake] MinGW flags

Daniel S. Reichenbach daniel at kogitoapp.com
Mon Dec 15 11:47:29 EST 2014


Hi,

> Is it possible to set a compiler flags only if compiler is MinGW (that
> means these flags wouldn't be set on MSVC).
to target specific compilers you can make use of CMAKE_CXX_COMPILER_ID.

In my projects I usually include compiler specific settings like this:

foreach(_base
    ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}
    ${CMAKE_CXX_COMPILER_ID})
    set(_file ${CMAKE_SOURCE_DIR}/cmake/compilers/${_base}.cmake)
    if(EXISTS ${_file})
        include(${_file})
        break()
    endif()
endforeach()

… and in ${CMAKE_SOURCE_DIR}/cmake/compilers/ I keep the target compiler
specific settings in Clang.cmake, GNU.cmake, MSVC.cmake and MinGW.cmake.

For normal use cases this works fine.

With kind regards,
Daniel




More information about the CMake mailing list