cmake/link_flag.cmake

39 lines
1.1 KiB
CMake
Raw Normal View History

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
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/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 ()
if (__check_link_flag_${_name})
set (${variable} 1)
else()
set (${variable} 0)
endif()
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()