summaryrefslogtreecommitdiff
path: root/Tests/VSGNUFortran
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/VSGNUFortran')
-rw-r--r--Tests/VSGNUFortran/CMakeLists.txt26
-rw-r--r--Tests/VSGNUFortran/c_code/CMakeLists.txt2
-rw-r--r--Tests/VSGNUFortran/c_code/main.c7
-rw-r--r--Tests/VSGNUFortran/runtest.cmake.in23
-rw-r--r--Tests/VSGNUFortran/subdir/CMakeLists.txt16
-rw-r--r--Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt46
-rw-r--r--Tests/VSGNUFortran/subdir/fortran/hello.f7
-rw-r--r--Tests/VSGNUFortran/subdir/fortran/world.f6
8 files changed, 133 insertions, 0 deletions
diff --git a/Tests/VSGNUFortran/CMakeLists.txt b/Tests/VSGNUFortran/CMakeLists.txt
new file mode 100644
index 000000000..229c3156c
--- /dev/null
+++ b/Tests/VSGNUFortran/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.8)
+project(VSGNUFortran)
+
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
+
+# force the executable to be put out of Debug/Release dir
+# because gmake build of fortran will not be in a config
+# directory, and for easier testing we want the exe and .dll
+# to be in the same directory.
+if(CMAKE_CONFIGURATION_TYPES)
+ foreach(config ${CMAKE_CONFIGURATION_TYPES})
+ string(TOUPPER "${config}" config)
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config}
+ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
+ endforeach()
+endif()
+
+add_subdirectory(subdir)
+include_directories(${VSGNUFortran_BINARY_DIR}/subdir/fortran)
+add_subdirectory(c_code)
+# use a cmake script to run the executable so that PATH
+# can be set with the MinGW/bin in it, and the fortran
+# runtime libraries can be found.
+configure_file(runtest.cmake.in runtest.cmake @ONLY)
diff --git a/Tests/VSGNUFortran/c_code/CMakeLists.txt b/Tests/VSGNUFortran/c_code/CMakeLists.txt
new file mode 100644
index 000000000..27d22fd35
--- /dev/null
+++ b/Tests/VSGNUFortran/c_code/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(c_using_fortran main.c)
+target_link_libraries(c_using_fortran hello)
diff --git a/Tests/VSGNUFortran/c_code/main.c b/Tests/VSGNUFortran/c_code/main.c
new file mode 100644
index 000000000..9157cc5f3
--- /dev/null
+++ b/Tests/VSGNUFortran/c_code/main.c
@@ -0,0 +1,7 @@
+#include <HelloWorldFCMangle.h> /* created by FortranCInterface */
+extern void FC_hello(void);
+int main()
+{
+ FC_hello();
+ return 0;
+}
diff --git a/Tests/VSGNUFortran/runtest.cmake.in b/Tests/VSGNUFortran/runtest.cmake.in
new file mode 100644
index 000000000..987207bc4
--- /dev/null
+++ b/Tests/VSGNUFortran/runtest.cmake.in
@@ -0,0 +1,23 @@
+get_filename_component(MINGW_PATH "@MINGW_GFORTRAN@" PATH)
+if(NOT EXISTS "${MINGW_PATH}")
+ set(test_exe
+ "@VSGNUFortran_BINARY_DIR@/bin/c_using_fortran@CMAKE_EXECUTABLE_SUFFIX@")
+ message("run: ${test_exe}")
+ execute_process(COMMAND "${test_exe}"
+ RESULT_VARIABLE res)
+ if(NOT "${res}" EQUAL 0)
+ message(FATAL_ERROR "${test_exe} returned a non 0 value")
+ endif()
+ return()
+endif()
+file(TO_NATIVE_PATH "${MINGW_PATH}" MINGW_PATH)
+string(REPLACE "\\" "\\\\" MINGW_PATH "${MINGW_PATH}")
+message("${MINGW_PATH}")
+set(test_exe "@VSGNUFortran_BINARY_DIR@/bin/c_using_fortran.exe")
+set(ENV{PATH} "${MINGW_PATH}";$ENV{PATH})
+message("run ${test_exe}")
+execute_process(COMMAND "${test_exe}"
+ RESULT_VARIABLE res)
+if(NOT "${res}" EQUAL 0)
+ message(FATAL_ERROR "${test_exe} returned a non 0 value")
+endif()
diff --git a/Tests/VSGNUFortran/subdir/CMakeLists.txt b/Tests/VSGNUFortran/subdir/CMakeLists.txt
new file mode 100644
index 000000000..0b9919953
--- /dev/null
+++ b/Tests/VSGNUFortran/subdir/CMakeLists.txt
@@ -0,0 +1,16 @@
+include(CMakeAddFortranSubdirectory)
+# add the fortran subdirectory as a fortran project
+# the subdir is fortran, the project is FortranHello
+cmake_add_fortran_subdirectory(fortran
+ PROJECT FortranHello # project name in toplevel CMakeLists.txt
+ ARCHIVE_DIR ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
+ RUNTIME_DIR bin # ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+ LIBRARIES hello world # target libraries created
+ CMAKE_COMMAND_LINE
+ -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+ -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
+ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
+ LINK_LIBRARIES # link interface libraries
+ LINK_LIBS hello world # hello needs world to link
+ NO_EXTERNAL_INSTALL
+ )
diff --git a/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt
new file mode 100644
index 000000000..3ee1855c3
--- /dev/null
+++ b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt
@@ -0,0 +1,46 @@
+cmake_minimum_required(VERSION 2.8)
+project(FortranHello Fortran C)
+
+# add a function to test for -lsunquad on sunpro sun systems.
+function(test_sunquad result)
+ set( TEST_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/sunq")
+ file(WRITE "${TEST_DIR}/testsunq.f" "
+ PROGRAM TEST
+ END
+ ")
+ file(WRITE ${TEST_DIR}/CMakeLists.txt "
+project(sunq Fortran)
+add_library(sunq SHARED testsunq.f)
+target_link_libraries(sunq sunquad)
+")
+ message(STATUS "looking for -lsunquad")
+ try_compile(RESULT "${TEST_DIR}" "${TEST_DIR}" sunq OUTPUT_VARIABLE OUT)
+ if("${RESULT}")
+ message(STATUS "-lsunquad found")
+ else()
+ message(STATUS "-lsunquad not found")
+ endif()
+ message(STATUS
+ "looking for sunquad:\nRESULT=[${RESULT}]\nOUTPUT=[\n${OUT}\n]")
+ set(${result} "${RESULT}" PARENT_SCOPE)
+endfunction()
+
+# check for the fortran c interface mangling
+include(FortranCInterface)
+FortranCInterface_HEADER(HelloWorldFCMangle.h
+ MACRO_NAMESPACE "FC_"
+ SYMBOL_NAMESPACE "FC_"
+ SYMBOLS hello world)
+add_library(hello SHARED hello.f)
+add_library(world SHARED world.f)
+target_link_libraries(hello world)
+if(CMAKE_Fortran_COMPILER_ID MATCHES SunPro)
+ target_link_libraries(hello fsu)
+ if(CMAKE_Fortran_PLATFORM_ID MATCHES SunOS)
+ target_link_libraries(hello sunmath m)
+ test_sunquad(CMAKE_HAS_SUNQUAD)
+ if(CMAKE_HAS_SUNQUAD)
+ target_link_libraries(hello sunquad)
+ endif()
+ endif()
+endif()
diff --git a/Tests/VSGNUFortran/subdir/fortran/hello.f b/Tests/VSGNUFortran/subdir/fortran/hello.f
new file mode 100644
index 000000000..e52119add
--- /dev/null
+++ b/Tests/VSGNUFortran/subdir/fortran/hello.f
@@ -0,0 +1,7 @@
+!DEC$ ATTRIBUTES DLLEXPORT :: HELLO
+ SUBROUTINE HELLO
+
+ PRINT *, 'Hello'
+ CALL WORLD
+
+ END
diff --git a/Tests/VSGNUFortran/subdir/fortran/world.f b/Tests/VSGNUFortran/subdir/fortran/world.f
new file mode 100644
index 000000000..0598eeea6
--- /dev/null
+++ b/Tests/VSGNUFortran/subdir/fortran/world.f
@@ -0,0 +1,6 @@
+!DEC$ ATTRIBUTES DLLEXPORT :: WORLD
+ SUBROUTINE WORLD
+
+ PRINT *, 'World!'
+
+ END