cmake/link_flag.cmake

67 lines
2.1 KiB
CMake
Raw Normal View History

###############################################################################
set(_LINK_FLAG_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})
2022-08-23 13:35:51 +10:00
macro(check_link_flag _variable _flag)
string (MAKE_C_IDENTIFIER ${_flag} _name)
2017-01-17 19:20:12 +11:00
if (NOT DEFINED __check_link_flag_${_name})
message (STATUS "checking linker flag ${_flag}")
2017-01-17 19:20:12 +11:00
set (__check_linker_flag_old "${CMAKE_EXE_LINKER_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_flag}")
try_compile (
__check_link_flag_${_name}
"${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp"
SOURCES
"${_LINK_FLAG_LIST_DIR}/test_link_flag.cpp")
if (__check_link_flag_${_name})
message (STATUS "checking linker flag ${_flag} - found")
else()
message (STATUS "checking linker flag ${_flag} - not found")
endif()
set (CMAKE_EXE_LINKER_FLAGS "${__check_linker_flag_old}")
endif ()
set (${_variable} ${__check_link_flag_${_name}})
2017-01-17 19:20:12 +11:00
endmacro()
##-----------------------------------------------------------------------------
macro(append_link_flag _flag)
check_link_flag (__test_link_flag_${_flag} ${_flag})
if (__test_link_flag_${_flag})
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_flag}")
2017-01-17 19:20:12 +11:00
endif()
endmacro()
2022-08-23 13:35:51 +10:00
##-----------------------------------------------------------------------------
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()