cmake/link_flag.cmake

26 lines
880 B
CMake
Raw Normal View History

2017-01-17 19:20:12 +11:00
macro(check_link_flag variable flag)
message (STATUS "checking linker flag ${flag}")
set (__check_linker_flag_old "${CMAKE_EXE_LINKER_FLAGS}" INTERNAL)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}")
try_compile (test_check_linker_flag
"${CMAKE_BINARY_DIR}/CMakeTmp"
SOURCES "${CMAKE_SOURCE_DIR}/cmake/test_link_flag.cpp")
if (test_check_linker_flag)
message (STATUS "checking linker flag ${flag} - found")
set (${variable} 1)
else(test_check_linker_flag)
message (STATUS "checking linker flag ${flag} - not found")
set (${variable} 0)
endif(test_check_linker_flag)
endmacro()
macro(append_link_flag flag)
check_link_flag (__test_link_flag_${flag} ${flag})
if (__test_link_flag_${flag})
set (CMAKE_EXE_LINKER_FLAGS "${__append_link_flag_old}")
endif()
endmacro()