diff options
author | Daniel Black <daniel@linux.ibm.com> | 2020-05-05 11:57:20 +1000 |
---|---|---|
committer | Eugene Kosov <claprix@yandex.ru> | 2020-07-15 09:23:53 +0300 |
commit | 7473e1841c630d86f1873a2a7afacb53955b3f6f (patch) | |
tree | 56988a6cc9ea35b74cd9cda0bc17ad423484c8da /cmake | |
parent | dfdfeecb03edaf5660f5e15337381dda6f83102c (diff) | |
download | mariadb-git-7473e1841c630d86f1873a2a7afacb53955b3f6f.tar.gz |
check_linker_flag: use for linker flags
-Wl,-z,relro,-z,now are linker flags and should
be checked as such.
TODO: perform module, exe shared checks separately
rather than a pure linker check.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/check_linker_flag.cmake | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cmake/check_linker_flag.cmake b/cmake/check_linker_flag.cmake new file mode 100644 index 00000000000..ff4b91e89f6 --- /dev/null +++ b/cmake/check_linker_flag.cmake @@ -0,0 +1,27 @@ +include(CheckCXXSourceCompiles) + +FUNCTION(MY_CHECK_AND_SET_LINKER_FLAG flag_to_set) + # Let's avoid expensive compiler tests on Windows: + IF(WIN32) + RETURN() + ENDIF() + STRING(REGEX REPLACE "[-,= +]" "_" result "HAVE_LINK_FLAG_${flag_to_set}") + SET(SAVE_CMAKE_REQUIRED_LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS}") + STRING(REGEX REPLACE "^-Wno-" "-W" flag_to_check ${flag_to_set}) + SET(CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS} ${flag_to_check}) + CHECK_CXX_SOURCE_COMPILES("int main(void) { return 0; }" ${result}) + SET(CMAKE_REQUIRED_LINK_OPTIONS "${SAVE_CMAKE_REQUIRED_LINK_OPTIONS}") + IF (${result}) + FOREACH(linktype SHARED MODULE EXE) + IF(ARGN) + FOREACH(type ${ARGN}) + SET(CMAKE_${linktype}_LINKER_FLAGS_${type} + "${CMAKE_${linktype}_LINKER_FLAGS_${type}} ${flag_to_set}" PARENT_SCOPE) + ENDFOREACH() + ELSE() + SET(CMAKE_${linktype}_LINKER_FLAGS + "${CMAKE_${linktype}_LINKER_FLAGS} ${flag_to_set}" PARENT_SCOPE) + ENDIF() + ENDFOREACH() + ENDIF() +ENDFUNCTION() |