summaryrefslogtreecommitdiffstats
path: root/cmake/modules/CheckCLinkerFlag.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
commite4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch)
tree68cb5ef9081156392f1dd62a00c6ccc1451b93df /cmake/modules/CheckCLinkerFlag.cmake
parentInitial commit. (diff)
downloadwireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz
wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cmake/modules/CheckCLinkerFlag.cmake')
-rw-r--r--cmake/modules/CheckCLinkerFlag.cmake57
1 files changed, 57 insertions, 0 deletions
diff --git a/cmake/modules/CheckCLinkerFlag.cmake b/cmake/modules/CheckCLinkerFlag.cmake
new file mode 100644
index 0000000..f21d573
--- /dev/null
+++ b/cmake/modules/CheckCLinkerFlag.cmake
@@ -0,0 +1,57 @@
+# - Check whether the C linker supports a given flag.
+# CHECK_C_LINKER_FLAG(FLAG VARIABLE)
+#
+# FLAG - the compiler flag
+# VARIABLE - variable to store the result
+#
+# This actually calls the check_c_source_compiles macro.
+# See help for CheckCSourceCompiles for a listing of variables
+# that can modify the build.
+
+# Copyright (c) 2010, Joerg Mayer (see AUTHORS file)
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+
+INCLUDE(CheckCSourceRuns)
+
+MACRO (CHECK_C_LINKER_FLAG _FLAG _RESULT)
+ #
+ # This is ugly.
+ #
+ # See CMake bug 0015934:
+ #
+ # https://cmake.org/Bug/view.php?id=15934
+ #
+ # So we add the flags to CMAKE_REQUIRED_LIBRARIES, to sneak it into
+ # the linker flags.
+ #
+ # This may or may not work with versions earlier than 2.8.11, although
+ # 2.8.10's Xcode generator doesn't appear to work at all - it fails
+ # with an internal CMake error.
+ #
+ # With 3.2 and later, we could also set policy CMP0056 to NEW and
+ # set CMAKE_EXE_LINKER_FLAGS.
+ #
+ set(save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+ set(CMAKE_REQUIRED_LIBRARIES "${_FLAG}")
+ if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
+ #
+ # This means the linker is presumably the Microsoft linker;
+ # we need to pass /WX in order to have the linker fail,
+ # rather than just complaining and driving on, if it's
+ # passed a flag it doesn't handle.
+ #
+ set(CMAKE_REQUIRED_LIBRARIES "/WX ${CMAKE_REQUIRED_LIBRARIES}")
+ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
+ #
+ # We'll be running the linker through the compiler driver, so
+ # we may need to pass -Werror=unused-command-line-argument to have it
+ # fail, rather than just complaining and driving on, if it's
+ # passed a flag it doesn't handle.
+ set(CMAKE_REQUIRED_LIBRARIES
+ "-Werror=unused-command-line-argument ${CMAKE_REQUIRED_LIBRARIES}")
+ endif()
+ check_c_source_compiles("int main(void) { return 0;}" ${_RESULT})
+ set(CMAKE_REQUIRED_LIBRARIES "${save_CMAKE_REQUIRED_LIBRARIES}")
+ENDMACRO (CHECK_C_LINKER_FLAG)
+