From 707d05e9368f53707b23d565967c996878db27d2 Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Mon, 26 Oct 2009 11:07:27 -0400
Subject: Fix Intel and MinGW Fortran DLL import libraries

We add Intel and MinGW Fortran linker options to create the import
library portion of a DLL.  This allows other binaries to link to a
Fortran DLL.

We also update the Fortran test to use a .def file to specify exports
since there is no __declspec(dllexport) markup syntax in Fortran.
---
 Modules/Platform/Windows-g77.cmake   | 3 ++-
 Modules/Platform/Windows-ifort.cmake | 4 ++--
 Tests/Fortran/CMakeLists.txt         | 2 +-
 Tests/Fortran/world.def              | 2 ++
 4 files changed, 7 insertions(+), 4 deletions(-)
 create mode 100644 Tests/Fortran/world.def

diff --git a/Modules/Platform/Windows-g77.cmake b/Modules/Platform/Windows-g77.cmake
index ad24db6..ed3a073 100644
--- a/Modules/Platform/Windows-g77.cmake
+++ b/Modules/Platform/Windows-g77.cmake
@@ -20,4 +20,5 @@ SET (CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "-O1")
 SET (CMAKE_Fortran_FLAGS_RELEASE_INIT "-O2")
 SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-02 -g")
 
-
+SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY
+  "<CMAKE_Fortran_COMPILER> <CMAKE_SHARED_LIBRARY_Fortran_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>")
diff --git a/Modules/Platform/Windows-ifort.cmake b/Modules/Platform/Windows-ifort.cmake
index 01848a6..c9624b5 100644
--- a/Modules/Platform/Windows-ifort.cmake
+++ b/Modules/Platform/Windows-ifort.cmake
@@ -12,7 +12,7 @@ SET(CMAKE_Fortran_MODDIR_FLAG "-module:")
 SET(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
 
 SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY 
- "link ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE}  /out:<TARGET> /dll  <LINK_FLAGS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
+ "link ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE}  /out:<TARGET> /implib:<TARGET_IMPLIB> /dll  <LINK_FLAGS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
 
 SET(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
 
@@ -26,7 +26,7 @@ SET(CMAKE_Fortran_COMPILE_OBJECT
 SET(CMAKE_COMPILE_RESOURCE "rc <FLAGS> /fo<OBJECT> <SOURCE>")
 
 SET(CMAKE_Fortran_LINK_EXECUTABLE
-  "<CMAKE_Fortran_COMPILER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} <FLAGS> /Fe<TARGET> -link <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
+  "<CMAKE_Fortran_COMPILER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} <FLAGS> /Fe<TARGET> -link /implib:<TARGET_IMPLIB> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
 
 INCLUDE(Platform/Windows-Intel)
 
diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt
index 3e890c8..01c115b 100644
--- a/Tests/Fortran/CMakeLists.txt
+++ b/Tests/Fortran/CMakeLists.txt
@@ -9,7 +9,7 @@ message("CMAKE_Fortran_COMPILER = ${CMAKE_Fortran_COMPILER}")
 message("CMAKE_Fortran_FLAGS = ${CMAKE_Fortran_FLAGS}")
 
 add_library(hello STATIC hello.f)
-add_library(world SHARED world.f)
+add_library(world SHARED world.f world.def)
 add_executable(testf testf.f)
 target_link_libraries(testf hello world)
 
diff --git a/Tests/Fortran/world.def b/Tests/Fortran/world.def
new file mode 100644
index 0000000..ead7710
--- /dev/null
+++ b/Tests/Fortran/world.def
@@ -0,0 +1,2 @@
+EXPORTS
+        WORLD
-- 
cgit v0.12

