cmake_modules/compilerchecks.cmake
author koda
Sat, 08 Jun 2013 01:52:32 +0200
changeset 9152 c884e40dca9e
child 9153 354a9803fe91
permissions -rw-r--r--
move compiler checks in a separate cmake module
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9152
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     1
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     2
#TESTING TIME
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     3
include(CheckCCompilerFlag)
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     4
#when you need to check for a linker flag, just leave the argument of "check_c_compiler_flag" empty
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     5
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     6
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     7
#check for noexecstack on ELF, Gentoo security
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     8
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
     9
check_c_compiler_flag("" HAVE_NOEXECSTACK)
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    10
if(HAVE_NOEXECSTACK)
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    11
    list(APPEND pascal_flags "-k-z" "-knoexecstack")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    12
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    13
endif()
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    14
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    15
#check for ASLR on Windows Vista or later, requires binutils >= 2.20
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    16
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    17
check_c_compiler_flag("" HAVE_WINASLR)
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    18
if(HAVE_WINASLR)
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    19
    list(APPEND pascal_flags "-k--nxcompat")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    20
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    21
endif()
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    22
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    23
#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    24
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    25
check_c_compiler_flag("" HAVE_WINDEP)
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    26
if(HAVE_WINDEP)
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    27
    list(APPEND pascal_flags "-k--dynamicbase")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    28
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    29
endif()
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    30
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    31
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    32
#always unset or these flags will be spread everywhere
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    33
unset(CMAKE_REQUIRED_FLAGS)
c884e40dca9e move compiler checks in a separate cmake module
koda
parents:
diff changeset
    34