From 3b9eb09ba5d870e0d14f57c5f980ae4a71c1f327 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 23 Aug 2022 13:35:51 +1000 Subject: [PATCH] link_flag: add multiple flag search --- link_flag.cmake | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/link_flag.cmake b/link_flag.cmake index 474f732..ccb2302 100644 --- a/link_flag.cmake +++ b/link_flag.cmake @@ -1,6 +1,7 @@ ############################################################################### set(_LINK_FLAG_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}) + macro(check_link_flag _variable _flag) string (MAKE_C_IDENTIFIER ${_flag} _name) @@ -36,3 +37,31 @@ macro(append_link_flag _flag) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_flag}") endif() endmacro() + + +##----------------------------------------------------------------------------- +macro(append_first_link_flag) + message(CHECK_START "First LDFLAG ${ARGV}") + + foreach(__append_first_link_flag__flag ${ARGV}) + set(__append_first_link_flag__test 0) + + check_link_flag( + __append_first_link_flag__test + ${__append_first_link_flag__flag} + ) + + if (${append_first_link_flag__test}) + set (CMAKE_EXE_LINKER_FLAGS + "${CMAKE_EXE_LINKER_FLAGS} ${__append_first_link_flag__flag}" + ) + + message(CHECK_PASS "Found ${__append_first_link_flag__flag}") + break() + endif() + endforeach() + + if (NOT ${_append_first_link_flag__test}) + message(CHECK_FAIL "No valid flags") + endif () +endmacro() \ No newline at end of file