From 48a09f82ccadf93eb2d60c9efe5da783327a8520 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Fri, 27 Jan 2012 11:14:00 -0500 Subject: CMakeAddFortranSubdirectory: Make IMPORTED targets GLOBAL cmake_add_fortran_directory uses imported targets when using the mingw fortran compiler. This change makes those targets global in scope so they act just like the real targets that exist when a fortran compiler exists and regular add_subdirectory is used. --- Tests/VSGNUFortran/CMakeLists.txt | 19 ++-------- Tests/VSGNUFortran/fortran/CMakeLists.txt | 46 ------------------------ Tests/VSGNUFortran/fortran/hello.f | 7 ---- Tests/VSGNUFortran/fortran/world.f | 6 ---- Tests/VSGNUFortran/subdir/CMakeLists.txt | 15 ++++++++ Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt | 46 ++++++++++++++++++++++++ Tests/VSGNUFortran/subdir/fortran/hello.f | 7 ++++ Tests/VSGNUFortran/subdir/fortran/world.f | 6 ++++ 8 files changed, 76 insertions(+), 76 deletions(-) delete mode 100644 Tests/VSGNUFortran/fortran/CMakeLists.txt delete mode 100644 Tests/VSGNUFortran/fortran/hello.f delete mode 100644 Tests/VSGNUFortran/fortran/world.f create mode 100644 Tests/VSGNUFortran/subdir/CMakeLists.txt create mode 100644 Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt create mode 100644 Tests/VSGNUFortran/subdir/fortran/hello.f create mode 100644 Tests/VSGNUFortran/subdir/fortran/world.f (limited to 'Tests/VSGNUFortran') diff --git a/Tests/VSGNUFortran/CMakeLists.txt b/Tests/VSGNUFortran/CMakeLists.txt index 422350a5c5..229c3156c1 100644 --- a/Tests/VSGNUFortran/CMakeLists.txt +++ b/Tests/VSGNUFortran/CMakeLists.txt @@ -17,23 +17,8 @@ if(CMAKE_CONFIGURATION_TYPES) endforeach() endif() -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 - ) - -include_directories(${VSGNUFortran_BINARY_DIR}/fortran) +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 diff --git a/Tests/VSGNUFortran/fortran/CMakeLists.txt b/Tests/VSGNUFortran/fortran/CMakeLists.txt deleted file mode 100644 index 3ee1855c33..0000000000 --- a/Tests/VSGNUFortran/fortran/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -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/fortran/hello.f b/Tests/VSGNUFortran/fortran/hello.f deleted file mode 100644 index e52119add9..0000000000 --- a/Tests/VSGNUFortran/fortran/hello.f +++ /dev/null @@ -1,7 +0,0 @@ -!DEC$ ATTRIBUTES DLLEXPORT :: HELLO - SUBROUTINE HELLO - - PRINT *, 'Hello' - CALL WORLD - - END diff --git a/Tests/VSGNUFortran/fortran/world.f b/Tests/VSGNUFortran/fortran/world.f deleted file mode 100644 index 0598eeea66..0000000000 --- a/Tests/VSGNUFortran/fortran/world.f +++ /dev/null @@ -1,6 +0,0 @@ -!DEC$ ATTRIBUTES DLLEXPORT :: WORLD - SUBROUTINE WORLD - - PRINT *, 'World!' - - END diff --git a/Tests/VSGNUFortran/subdir/CMakeLists.txt b/Tests/VSGNUFortran/subdir/CMakeLists.txt new file mode 100644 index 0000000000..df018b3d92 --- /dev/null +++ b/Tests/VSGNUFortran/subdir/CMakeLists.txt @@ -0,0 +1,15 @@ +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 + ) diff --git a/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt new file mode 100644 index 0000000000..3ee1855c33 --- /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 0000000000..e52119add9 --- /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 0000000000..0598eeea66 --- /dev/null +++ b/Tests/VSGNUFortran/subdir/fortran/world.f @@ -0,0 +1,6 @@ +!DEC$ ATTRIBUTES DLLEXPORT :: WORLD + SUBROUTINE WORLD + + PRINT *, 'World!' + + END -- cgit v1.2.1