cmake_modules/compilerchecks.cmake
changeset 9217 992b7ef2eba3
parent 9211 6235925d0fa1
child 9219 0a4b6bb69f99
equal deleted inserted replaced
9216:29372f16ddce 9217:992b7ef2eba3
    13 check_c_compiler_flag("-fstack-protector-all -fstack-protector" HAVE_STACKPROTECTOR)
    13 check_c_compiler_flag("-fstack-protector-all -fstack-protector" HAVE_STACKPROTECTOR)
    14 if(HAVE_STACKPROTECTOR)
    14 if(HAVE_STACKPROTECTOR)
    15     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all -fstack-protector")
    15     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all -fstack-protector")
    16     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -fstack-protector")
    16     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -fstack-protector")
    17     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fstack-protector-all -fstack-protector")
    17     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fstack-protector-all -fstack-protector")
    18     set(CMAKE_SHARED_LIBRARY_C_FLAGS  "${CMAKE_SHARED_LIBRARY_C_FLAGS} -fstack-protector-all -fstack-protector")
    18     set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -fstack-protector-all -fstack-protector")
    19     set(CMAKE_SHARED_LIBRARY_CXX_FLAGS  "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -fstack-protector-all -fstack-protector")
    19     set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -fstack-protector-all -fstack-protector")
    20 endif()
    20 endif()
    21 
    21 
    22 #symbol visibility, not supported on Windows (so we error out to avoid spam)
    22 #symbol visibility, not supported on Windows (so we error out to avoid spam)
    23 check_c_compiler_flag("-fvisibility=hidden -Werror" HAVE_VISIBILITY)
    23 check_c_compiler_flag("-fvisibility=hidden -Werror" HAVE_VISIBILITY)
    24 if(HAVE_VISIBILITY)
    24 if(HAVE_VISIBILITY)
    32 check_c_compiler_flag("" HAVE_NOEXECSTACK)
    32 check_c_compiler_flag("" HAVE_NOEXECSTACK)
    33 if(HAVE_NOEXECSTACK)
    33 if(HAVE_NOEXECSTACK)
    34     list(APPEND pascal_flags "-k-z" "-knoexecstack")
    34     list(APPEND pascal_flags "-k-z" "-knoexecstack")
    35     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    35     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    36     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    36     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    37     set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    38     set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    37 endif()
    39 endif()
    38 
    40 
    39 #check for full relro on ELF, Debian security
    41 #check for full relro on ELF, Debian security
    40 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
    42 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
    41 check_c_compiler_flag("" HAVE_RELROFULL)
    43 check_c_compiler_flag("" HAVE_RELROFULL)
    42 if(HAVE_RELROFULL)
    44 if(HAVE_RELROFULL)
    43     list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
    45     list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
    44     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    46     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    45     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    47     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    48     set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    49     set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    46 else()
    50 else()
    47     #if full relro is not available, try partial relro
    51     #if full relro is not available, try partial relro
    48     set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
    52     set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
    49     check_c_compiler_flag("" HAVE_RELROPARTIAL)
    53     check_c_compiler_flag("" HAVE_RELROPARTIAL)
    50     if(HAVE_RELROPARTIAL)
    54     if(HAVE_RELROPARTIAL)
    51         list(APPEND pascal_flags "-k-z" "-krelro")
    55         list(APPEND pascal_flags "-k-z" "-krelro")
    52         list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    56         list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    53         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    57         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    58         set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    59         set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    54     endif()
    60     endif()
    55 endif()
    61 endif()
    56 
    62 
    57 #check for ASLR on Windows Vista or later, requires binutils >= 2.20
    63 #check for ASLR on Windows Vista or later, requires binutils >= 2.20
    58 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
    64 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
    59 check_c_compiler_flag("" HAVE_WINASLR)
    65 check_c_compiler_flag("" HAVE_WINASLR)
    60 if(HAVE_WINASLR)
    66 if(HAVE_WINASLR)
    61     list(APPEND pascal_flags "-k--nxcompat")
    67     list(APPEND pascal_flags "-k--nxcompat")
    62     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    68     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    63     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    69     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    70     set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    71     set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    64 endif()
    72 endif()
    65 
    73 
    66 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
    74 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
    67 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
    75 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
    68 check_c_compiler_flag("" HAVE_WINDEP)
    76 check_c_compiler_flag("" HAVE_WINDEP)
    69 if(HAVE_WINDEP)
    77 if(HAVE_WINDEP)
    70     list(APPEND pascal_flags "-k--dynamicbase")
    78     list(APPEND pascal_flags "-k--dynamicbase")
    71     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    79     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    72     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    80     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    81     set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    82     set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    73 endif()
    83 endif()
    74 
    84 
    75 #this is actually an optimisation
    85 #this is actually an optimisation
    76 set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed")
    86 set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed")
    77 check_c_compiler_flag("" HAVE_ASNEEDED)
    87 check_c_compiler_flag("" HAVE_ASNEEDED)
    78 if(HAVE_ASNEEDED)
    88 if(HAVE_ASNEEDED)
    79     list(APPEND pascal_flags "-k--as-needed")
    89     list(APPEND pascal_flags "-k--as-needed")
    80     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    90     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    81     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    91     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    92     set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
       
    93     set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    82 endif()
    94 endif()
    83 
    95 
    84 #always unset or these flags will be spread everywhere
    96 #always unset or these flags will be spread everywhere
    85 unset(CMAKE_REQUIRED_FLAGS)
    97 unset(CMAKE_REQUIRED_FLAGS)
    86 
    98