compiler-flag-checks.cmake 1.52 KB
Newer Older
Simon Spannagel's avatar
Simon Spannagel committed
1
2
3
4
5
6
7
8
9
# Check for supported flags and remove unsupported warnings
INCLUDE(CheckCXXCompilerFlag)
FOREACH( FLAG ${COMPILER_FLAGS} )
    STRING(REPLACE "-" "_" FLAG_WORD ${FLAG} )
    STRING(REPLACE "+" "P" FLAG_WORD ${FLAG_WORD} )
    STRING(REPLACE "=" "E" FLAG_WORD ${FLAG_WORD} )

    CHECK_CXX_COMPILER_FLAG( "${FLAG}" CXX_FLAG_WORKS_${FLAG_WORD} )
    IF( ${CXX_FLAG_WORKS_${FLAG_WORD}} )
10
        LIST(APPEND CORRYVRECKAN_CXX_FLAGS ${FLAG})
Simon Spannagel's avatar
Simon Spannagel committed
11
12
13
14
15
16
17
    ELSE()
        MESSAGE ( STATUS "NOT adding ${FLAG} to CXX_FLAGS - unsupported flag" )
    ENDIF()
ENDFOREACH()

# Find threading provider and enable it (NOTE: not used yet)
IF( THREADS_HAVE_PTHREAD_ARG )
18
    LIST(APPEND CORRYVRECKAN_CXX_FLAGS "-pthread")
Simon Spannagel's avatar
Simon Spannagel committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
ELSEIF( CMAKE_THREAD_LIBS_INIT )
    SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
ENDIF()

# Set no undefined symbols flag for the linker if supported
IF((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
    SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
ENDIF()
IF(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
    SET ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
ENDIF()

# Reduce Wstrict-overflow level for some GCC versions due to false positives:
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
34
35
36
    IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
        LIST(APPEND CORRYVRECKAN_CXX_FLAGS "-Wstrict-overflow=2")
    ENDIF()
Simon Spannagel's avatar
Simon Spannagel committed
37
ENDIF()