Wednesday, 6 March 2013

CMake Linker Test Flags

Source: http://www.cmake.org/pipermail/cmake/2011-July/045525.html

If you need to test linker flags, try out this code snippet, and make sure to unset the variable or subsequent tests will fail!
 
include(CheckCCompilerFlag)
set(CMAKE_REQUIRED_FLAGS "-Wl,-z -Wl,noexecstack")
check_c_compiler_flag("" HAVE_NOEXECSTACK) #empty because we are testing a linker flag
if(HAVE_NOEXECSTACK)
    list(APPEND pascal_flags "-k-z" "-knoexecstack")
    if(NOT ${MINIMAL_FLAGS})
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
    endif()
endif()
unset(CMAKE_REQUIRED_FLAGS)




All the projects here are under a Creative Commons 3.0 licence! You can use and distribute them as you like (just quote the author so he knows his work is not useless)!

If you wish to get in touch with me write at projectsymphony@gmail.com