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.
This commit is contained in:
Bill Hoffman 2012-01-27 11:14:00 -05:00 committed by Brad King
parent 067c1f44a8
commit 48a09f82cc
6 changed files with 19 additions and 19 deletions

View File

@ -25,7 +25,7 @@
# function is invoked. # function is invoked.
#============================================================================= #=============================================================================
# Copyright 2011 Kitware, Inc. # Copyright 2011-2012 Kitware, Inc.
# #
# Distributed under the OSI-approved BSD License (the "License"); # Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details. # see accompanying file Copyright.txt for details.
@ -151,7 +151,7 @@ function(cmake_add_fortran_subdirectory subdir)
) )
# create imported targets for all libraries # create imported targets for all libraries
foreach(lib ${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_property(TARGET ${lib} APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
set_target_properties(${lib} PROPERTIES set_target_properties(${lib} PROPERTIES
IMPORTED_IMPLIB_NOCONFIG "${library_dir}/lib${lib}.lib" IMPORTED_IMPLIB_NOCONFIG "${library_dir}/lib${lib}.lib"

View File

@ -17,23 +17,8 @@ if(CMAKE_CONFIGURATION_TYPES)
endforeach() endforeach()
endif() endif()
include(CMakeAddFortranSubdirectory) add_subdirectory(subdir)
# add the fortran subdirectory as a fortran project include_directories(${VSGNUFortran_BINARY_DIR}/subdir/fortran)
# 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(c_code) add_subdirectory(c_code)
# use a cmake script to run the executable so that PATH # use a cmake script to run the executable so that PATH
# can be set with the MinGW/bin in it, and the fortran # can be set with the MinGW/bin in it, and the fortran

View File

@ -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
)