cmake_modules/compilerchecks.cmake
changeset 9207 16373565692a
parent 9206 4788b24fee05
child 9211 6235925d0fa1
equal deleted inserted replaced
9206:4788b24fee05 9207:16373565692a
    30 #check for noexecstack on ELF, Gentoo security
    30 #check for noexecstack on ELF, Gentoo security
    31 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack")
    31 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack")
    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" "-z" "-optl" "noexecstack")
    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 endif()
    37 endif()
    38 
    38 
    39 #check for full relro on ELF, Debian security
    39 #check for full relro on ELF, Debian security
    40 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
    40 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
    41 check_c_compiler_flag("" HAVE_RELROFULL)
    41 check_c_compiler_flag("" HAVE_RELROFULL)
    42 if(HAVE_RELROFULL)
    42 if(HAVE_RELROFULL)
    43     list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
    43     list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
    44     list(APPEND haskell_flags "-optl" "-z" "-optl" "relro" "-optl" "-z" "-optl" "now")
    44     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    45     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    45     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    46 else()
    46 else()
    47     #if full relro is not available, try partial relro
    47     #if full relro is not available, try partial relro
    48     set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
    48     set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
    49     check_c_compiler_flag("" HAVE_RELROPARTIAL)
    49     check_c_compiler_flag("" HAVE_RELROPARTIAL)
    50     if(HAVE_RELROPARTIAL)
    50     if(HAVE_RELROPARTIAL)
    51         list(APPEND pascal_flags "-k-z" "-krelro")
    51         list(APPEND pascal_flags "-k-z" "-krelro")
    52         list(APPEND haskell_flags "-optl" "-z" "-optl" "relro")
    52         list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    53         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    53         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    54     endif()
    54     endif()
    55 endif()
    55 endif()
    56 
    56 
    57 #check for ASLR on Windows Vista or later, requires binutils >= 2.20
    57 #check for ASLR on Windows Vista or later, requires binutils >= 2.20
    58 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
    58 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
    59 check_c_compiler_flag("" HAVE_WINASLR)
    59 check_c_compiler_flag("" HAVE_WINASLR)
    60 if(HAVE_WINASLR)
    60 if(HAVE_WINASLR)
    61     list(APPEND pascal_flags "-k--nxcompat")
    61     list(APPEND pascal_flags "-k--nxcompat")
    62     list(APPEND haskell_flags "-optl" "--nxcompat")
    62     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    63     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    63     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    64 endif()
    64 endif()
    65 
    65 
    66 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
    66 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
    67 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
    67 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
    68 check_c_compiler_flag("" HAVE_WINDEP)
    68 check_c_compiler_flag("" HAVE_WINDEP)
    69 if(HAVE_WINDEP)
    69 if(HAVE_WINDEP)
    70     list(APPEND pascal_flags "-k--dynamicbase")
    70     list(APPEND pascal_flags "-k--dynamicbase")
    71     list(APPEND haskell_flags "-optl" "--dynamicbase")
    71     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    72     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    72     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    73 endif()
    73 endif()
    74 
    74 
    75 #this is actually an optimisation
    75 #this is actually an optimisation
    76 set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed")
    76 set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed")
    77 check_c_compiler_flag("" HAVE_ASNEEDED)
    77 check_c_compiler_flag("" HAVE_ASNEEDED)
    78 if(HAVE_ASNEEDED)
    78 if(HAVE_ASNEEDED)
    79     list(APPEND pascal_flags "-k--as-needed")
    79     list(APPEND pascal_flags "-k--as-needed")
    80     list(APPEND haskell_flags "-optl" "--as-needed")
    80     list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
    81     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    81     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    82 endif()
    82 endif()
    83 
    83 
    84 #always unset or these flags will be spread everywhere
    84 #always unset or these flags will be spread everywhere
    85 unset(CMAKE_REQUIRED_FLAGS)
    85 unset(CMAKE_REQUIRED_FLAGS)