cmake_modules/compilerchecks.cmake
changeset 9154 a43406054648
parent 9153 354a9803fe91
child 9155 480f483de544
equal deleted inserted replaced
9153:354a9803fe91 9154:a43406054648
     7 #check for noexecstack on ELF, Gentoo security
     7 #check for noexecstack on ELF, Gentoo security
     8 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack")
     8 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack")
     9 check_c_compiler_flag("" HAVE_NOEXECSTACK)
     9 check_c_compiler_flag("" HAVE_NOEXECSTACK)
    10 if(HAVE_NOEXECSTACK)
    10 if(HAVE_NOEXECSTACK)
    11     list(APPEND pascal_flags "-k-z" "-knoexecstack")
    11     list(APPEND pascal_flags "-k-z" "-knoexecstack")
       
    12     list(APPEND haskell_flags "-optl" "-z" "-optl" "noexecstack")
    12     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    13     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    13 endif()
    14 endif()
    14 
    15 
    15 #check for full relro on ELF, Debian security
    16 #check for full relro on ELF, Debian security
    16 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
    17 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
    17 check_c_compiler_flag("" HAVE_RELROFULL)
    18 check_c_compiler_flag("" HAVE_RELROFULL)
    18 if(HAVE_RELROFULL)
    19 if(HAVE_RELROFULL)
    19     list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
    20     list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
       
    21     list(APPEND haskell_flags "-optl" "-z" "-optl" "relro" "-optl" "-z" "-optl" "now")
    20     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    22     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    21 else()
    23 else()
    22     #if full relro is not available, try partial relro
    24     #if full relro is not available, try partial relro
    23     set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
    25     set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
    24     check_c_compiler_flag("" HAVE_RELROPARTIAL)
    26     check_c_compiler_flag("" HAVE_RELROPARTIAL)
    25     if(HAVE_RELROPARTIAL)
    27     if(HAVE_RELROPARTIAL)
    26         list(APPEND pascal_flags "-k-z" "-krelro")
    28         list(APPEND pascal_flags "-k-z" "-krelro")
       
    29         list(APPEND haskell_flags "-optl" "-z" "-optl" "relro")
    27         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    30         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    28     endif()
    31     endif()
    29 endif()
    32 endif()
    30 
    33 
    31 #check for ASLR on Windows Vista or later, requires binutils >= 2.20
    34 #check for ASLR on Windows Vista or later, requires binutils >= 2.20
    32 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
    35 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
    33 check_c_compiler_flag("" HAVE_WINASLR)
    36 check_c_compiler_flag("" HAVE_WINASLR)
    34 if(HAVE_WINASLR)
    37 if(HAVE_WINASLR)
    35     list(APPEND pascal_flags "-k--nxcompat")
    38     list(APPEND pascal_flags "-k--nxcompat")
       
    39     list(APPEND haskell_flags "-optl" "--nxcompat")
    36     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    40     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    37 endif()
    41 endif()
    38 
    42 
    39 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
    43 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
    40 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
    44 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
    41 check_c_compiler_flag("" HAVE_WINDEP)
    45 check_c_compiler_flag("" HAVE_WINDEP)
    42 if(HAVE_WINDEP)
    46 if(HAVE_WINDEP)
    43     list(APPEND pascal_flags "-k--dynamicbase")
    47     list(APPEND pascal_flags "-k--dynamicbase")
       
    48     list(APPEND haskell_flags "-optl" "--dynamicbase")
    44     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    49     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    45 endif()
    50 endif()
    46 
    51 
    47 
    52 
    48 #always unset or these flags will be spread everywhere
    53 #always unset or these flags will be spread everywhere