From 48a09f82ccadf93eb2d60c9efe5da783327a8520 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Fri, 27 Jan 2012 11:14:00 -0500 Subject: [PATCH] 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. --- Modules/CMakeAddFortranSubdirectory.cmake | 4 ++-- Tests/VSGNUFortran/CMakeLists.txt | 19 ++----------------- Tests/VSGNUFortran/subdir/CMakeLists.txt | 15 +++++++++++++++ .../{ => subdir}/fortran/CMakeLists.txt | 0 .../VSGNUFortran/{ => subdir}/fortran/hello.f | 0 .../VSGNUFortran/{ => subdir}/fortran/world.f | 0 6 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 Tests/VSGNUFortran/subdir/CMakeLists.txt rename Tests/VSGNUFortran/{ => subdir}/fortran/CMakeLists.txt (100%) rename Tests/VSGNUFortran/{ => subdir}/fortran/hello.f (100%) rename Tests/VSGNUFortran/{ => subdir}/fortran/world.f (100%) diff --git a/Modules/CMakeAddFortranSubdirectory.cmake b/Modules/CMakeAddFortranSubdirectory.cmake index c846b55a9..5c3e9a206 100644 --- a/Modules/CMakeAddFortranSubdirectory.cmake +++ b/Modules/CMakeAddFortranSubdirectory.cmake @@ -25,7 +25,7 @@ # function is invoked. #============================================================================= -# Copyright 2011 Kitware, Inc. +# Copyright 2011-2012 Kitware, Inc. # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -151,7 +151,7 @@ function(cmake_add_fortran_subdirectory subdir) ) # create imported targets for all libraries foreach(lib ${libraries}) - add_library(${lib} SHARED IMPORTED) + add_library(${lib} SHARED IMPORTED GLOBAL) set_property(TARGET ${lib} APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG) set_target_properties(${lib} PROPERTIES IMPORTED_IMPLIB_NOCONFIG "${library_dir}/lib${lib}.lib" diff --git a/Tests/VSGNUFortran/CMakeLists.txt b/Tests/VSGNUFortran/CMakeLists.txt index 422350a5c..229c3156c 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/subdir/CMakeLists.txt b/Tests/VSGNUFortran/subdir/CMakeLists.txt new file mode 100644 index 000000000..df018b3d9 --- /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/fortran/CMakeLists.txt b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt similarity index 100% rename from Tests/VSGNUFortran/fortran/CMakeLists.txt rename to Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt diff --git a/Tests/VSGNUFortran/fortran/hello.f b/Tests/VSGNUFortran/subdir/fortran/hello.f similarity index 100% rename from Tests/VSGNUFortran/fortran/hello.f rename to Tests/VSGNUFortran/subdir/fortran/hello.f diff --git a/Tests/VSGNUFortran/fortran/world.f b/Tests/VSGNUFortran/subdir/fortran/world.f similarity index 100% rename from Tests/VSGNUFortran/fortran/world.f rename to Tests/VSGNUFortran/subdir/fortran/world.f