summaryrefslogtreecommitdiffstats
path: root/Source/Modules/CheckCXXLinkerFlag.cmake
blob: 6cb1ba3ac2947937425b858e697ce4886ae91ef3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

include_guard(GLOBAL)
include(CheckCXXSourceCompiles)
include(CMakeCheckCompilerFlagCommonPatterns)

function(check_cxx_linker_flag _flag _var)
  if(CMAKE_VERSION VERSION_LESS "3.14")
    set(CMAKE_REQUIRED_LIBRARIES "${_flag}")
  else()
    set(CMAKE_REQUIRED_LINK_OPTIONS "${_flag}")
  endif()

  # Normalize locale during test compilation.
  set(_locale_vars LC_ALL LC_MESSAGES LANG)
  foreach(v IN LISTS _locale_vars)
    set(_locale_vars_saved_${v} "$ENV{${v}}")
    set(ENV{${v}} C)
  endforeach()
  check_compiler_flag_common_patterns(_common_patterns)
  check_cxx_source_compiles("int main() { return 0; }" ${_var}
    ${_common_patterns}
    )
  foreach(v IN LISTS _locale_vars)
    set(ENV{${v}} ${_locale_vars_saved_${v}})
  endforeach()
  set(${_var} "${${_var}}" PARENT_SCOPE)
endfunction()