Browse Source

Merge topic 'FortranCInterface-CMP0056'

15e77fbd40 FortranCInterface: Honor CMAKE_EXE_LINKER_FLAGS under CMP0056

Acked-by: Kitware Robot <[email protected]>
Merge-request: !5483
Brad King 5 years ago
parent
commit
fd8eef0341
2 changed files with 18 additions and 0 deletions
  1. 8 0
      Modules/FortranCInterface.cmake
  2. 10 0
      Modules/FortranCInterface/Detect.cmake

+ 8 - 0
Modules/FortranCInterface.cmake

@@ -343,6 +343,13 @@ function(FortranCInterface_VERIFY)
     set(_desc "Verifying Fortran/${lang} Compiler Compatibility")
     message(CHECK_START "${_desc}")
 
+    cmake_policy(GET CMP0056 _FortranCInterface_CMP0056)
+    if(_FortranCInterface_CMP0056 STREQUAL "NEW")
+      set(_FortranCInterface_EXE_LINKER_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}")
+    else()
+      set(_FortranCInterface_EXE_LINKER_FLAGS "")
+    endif()
+
     # Build a sample project which reports symbols.
     set(CMAKE_TRY_COMPILE_CONFIGURATION Release)
     try_compile(FortranCInterface_VERIFY_${lang}_COMPILED
@@ -358,6 +365,7 @@ function(FortranCInterface_VERIFY)
                  "-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}"
                  "-DCMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE}"
                  "-DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE}"
+                 ${_FortranCInterface_EXE_LINKER_FLAGS}
       OUTPUT_VARIABLE _output)
     file(WRITE "${FortranCInterface_BINARY_DIR}/Verify${lang}/output.txt" "${_output}")
 

+ 10 - 0
Modules/FortranCInterface/Detect.cmake

@@ -26,6 +26,14 @@ unset(FortranCInterface_VERIFIED_CXX CACHE)
 
 set(_result)
 
+cmake_policy(GET CMP0056 _FortranCInterface_CMP0056)
+if(_FortranCInterface_CMP0056 STREQUAL "NEW")
+  set(_FortranCInterface_EXE_LINKER_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}")
+else()
+  set(_FortranCInterface_EXE_LINKER_FLAGS "")
+endif()
+unset(_FortranCInterface_CMP0056)
+
 # Build a sample project which reports symbols.
 set(CMAKE_TRY_COMPILE_CONFIGURATION Release)
 try_compile(FortranCInterface_COMPILED
@@ -38,9 +46,11 @@ try_compile(FortranCInterface_COMPILED
     "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
     "-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}"
     "-DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE}"
+    ${_FortranCInterface_EXE_LINKER_FLAGS}
   OUTPUT_VARIABLE FortranCInterface_OUTPUT)
 set(FortranCInterface_COMPILED ${FortranCInterface_COMPILED})
 unset(FortranCInterface_COMPILED CACHE)
+unset(_FortranCInterface_EXE_LINKER_FLAGS)
 
 # Locate the sample project executable.
 set(FortranCInterface_EXE)