Don't treat Visual Studio specially for linker flags.
[metze/wireshark/wip.git] / cmake / modules / CheckCLinkerFlag.cmake
index 4a07a8612e3e5e09b8c177eab386841517c12a9b..f657a9b88483068c510dedbed8f09e26b093cea9 100644 (file)
@@ -32,9 +32,19 @@ MACRO (CHECK_C_LINKER_FLAG _FLAG _RESULT)
    # With 3.2 and later, we could also set policy CMP0056 to NEW and
    # set CMAKE_EXE_LINKER_FLAGS.
    #
-   set(CMAKE_REQUIRED_LIBRARIES "${_FLAG}")
-   message(status "check linker flag - test linker flags: ${CMAKE_REQUIRED_LIBRARIES}")
+   set(save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+   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")
+   endif()
+   set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${_FLAG}")
+   message(status "check linker flag - test linker flags: ${_FLAG}")
    check_c_source_compiles("int main() { return 0;}" ${_RESULT})
-   set(CMAKE_REQUIRED_LIBRARIES "")
+   set(CMAKE_REQUIRED_LIBRARIES "${save_CMAKE_REQUIRED_LIBRARIES}")
 ENDMACRO (CHECK_C_LINKER_FLAG)