Skip to content

Commit

Permalink
Create CheckLinkerFlag.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
shopglobal committed Jun 10, 2018
1 parent 1dde793 commit 8f2eb25
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions cmake/CheckLinkerFlag.cmake
@@ -0,0 +1,47 @@
include(CheckCCompilerFlag)

macro(CHECK_LINKER_FLAG flag VARIABLE)
if(NOT DEFINED "${VARIABLE}")
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${flag} linker flag")
endif()

set(_cle_source ${CMAKE_SOURCE_DIR}/cmake/CheckLinkerFlag.c)

set(saved_CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
set(CMAKE_C_FLAGS "${flag}")
try_compile(${VARIABLE}
${CMAKE_BINARY_DIR}
${_cle_source}
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${flag}
CMAKE_FLAGS
OUTPUT_VARIABLE OUTPUT)
unset(_cle_source)
set(CMAKE_C_FLAGS ${saved_CMAKE_C_FLAGS})
unset(saved_CMAKE_C_FLAGS)

if ("${OUTPUT}" MATCHES "warning.*ignored")
set(${VARIABLE} 0)
endif()

if(${VARIABLE})
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${flag} linker flag - found")
endif()
set(${VARIABLE} 1 CACHE INTERNAL "Have linker flag ${flag}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the ${flag} linker flag is supported "
"passed with the following output:\n"
"${OUTPUT}\n\n")
else()
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${flag} linker flag - not found")
endif()
set(${VARIABLE} "" CACHE INTERNAL "Have linker flag ${flag}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the ${flag} linker flag is suppored "
"failed with the following output:\n"
"${OUTPUT}\n\n")
endif()
endif()
endmacro()

0 comments on commit 8f2eb25

Please sign in to comment.