]> www.ginac.de Git - cln.git/blob - cmake/modules/AsmNoexecstack.cmake
CLN can be built with CMake
[cln.git] / cmake / modules / AsmNoexecstack.cmake
1 # Check whether the stack can be marked nonexecutable by passing
2 # an option to the C compiler when acting on .s files. 
3
4 # ASM_NOEXECSTACK_FLAG -- compiler option(s) for marking the stack
5 #                         nonexecutable
6
7 # CC='ccache gcc' => "${CMAKE_C_COMPILER_ARG1}" == " gcc"
8 # (notice the leading whitespace). Grrr!
9 string(STRIP "${CMAKE_C_COMPILER_ARG1}" _c_compiler_arg1)
10
11 set(_conftest_c "${CMAKE_BINARY_DIR}/conftest.c")
12 set(_conftest_s "${CMAKE_BINARY_DIR}/conftest.s")
13 set(_conftest_o "${CMAKE_BINARY_DIR}/conftest.o")
14 set(_need_noexecstack)
15 set(_cc_ret)
16
17 file(WRITE ${_conftest_c} "void foo() { }")
18
19 execute_process(
20         COMMAND ${CMAKE_C_COMPILER} ${_c_compiler_arg1} -S ${_conftest_c}
21         RESULT_VARIABLE _cc_ret
22 )
23
24 if ("${_cc_ret}" EQUAL "0")
25         file(STRINGS ${_conftest_s} _need_noexecstack REGEX "\\.note\\.GNU-stack")
26 endif()
27
28 if (_need_noexecstack)
29         execute_process(COMMAND ${CMAKE_C_COMPILER} ${_c_compiler_arg1} -Wa,--noexecstack -c ${_conftest_s}
30                         RESULT_VARIABLE _cc_ret)
31         if ("${_cc_ret}" EQUAL "0")
32                 set(ASM_NOEXECSTACK_FLAG "-Wa,--noexecstack")
33         endif()
34 endif()
35 file(REMOVE ${_conftest_o} ${_conftest_s} ${_conftest_c})
36