瀏覽代碼

CMakeAddFortranSubdirectory: Allow full paths to directories

Fix the implementation to allow full paths with spaces.  Change the
interpretation of relative paths to be with respect to the current binary
directory.  This matches the convention used in ExternalProject.  Test
both full and relative paths in the VSGNUFortran test.
Brad King 14 年之前
父節點
當前提交
e4ae038f5d

+ 13 - 6
Modules/CMakeAddFortranSubdirectory.cmake

@@ -13,14 +13,17 @@
 # cmake_add_fortran_subdirectory(
 # cmake_add_fortran_subdirectory(
 #   <subdir>                 # name of subdirectory
 #   <subdir>                 # name of subdirectory
 #    PROJECT <project_name>  # project name in sbudir toplevel CMakeLists.txt
 #    PROJECT <project_name>  # project name in sbudir toplevel CMakeLists.txt
-#  ARCHIVE_DIR <dir>         # .lib location relative to root binary tree (lib)
-#  RUNTIME_DIR <dir>         # .dll location relative to root binary tree (bin)
+#  ARCHIVE_DIR <dir>         # dir where project places .lib files
+#  RUNTIME_DIR <dir>         # dir where project places .dll files
 #  LIBRARIES lib2 lib2    # names of libraries created and exported
 #  LIBRARIES lib2 lib2    # names of libraries created and exported
 #  LINK_LIBRARIES            # link interface libraries for LIBRARIES
 #  LINK_LIBRARIES            # link interface libraries for LIBRARIES
 #   LINK_LIBS <lib1>  <dep1> <dep2> ... <depN>
 #   LINK_LIBS <lib1>  <dep1> <dep2> ... <depN>
 #   LINK_LIBS <lib2> <dep1> <dep2> ... <depN>
 #   LINK_LIBS <lib2> <dep1> <dep2> ... <depN>
 #  CMAKE_COMMAND_LINE        # extra command line flags to pass to cmake
 #  CMAKE_COMMAND_LINE        # extra command line flags to pass to cmake
 #   )
 #   )
+# Relative paths in ARCHIVE_DIR and RUNTIME_DIR are interpreted with respect
+# to the build directory corresponding to the source directory in which the
+# function is invoked.
 #
 #
 
 
 #=============================================================================
 #=============================================================================
@@ -102,6 +105,12 @@ function(cmake_add_fortran_subdirectory subdir)
   set(libraries ${ARGS_LIBRARIES})
   set(libraries ${ARGS_LIBRARIES})
   # use the same directory that add_subdirectory would have used
   # use the same directory that add_subdirectory would have used
   set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${subdir}")
   set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${subdir}")
+  foreach(dir_var library_dir binary_dir)
+    if(NOT IS_ABSOLUTE "${${dir_var}}")
+      get_filename_component(${dir_var}
+        "${CMAKE_CURRENT_BINARY_DIR}/${${dir_var}}" ABSOLUTE)
+    endif()
+  endforeach()
   # create build and configure wrapper scripts
   # create build and configure wrapper scripts
   _setup_mingw_config_and_build(${source_dir})
   _setup_mingw_config_and_build(${source_dir})
   # create the external project
   # create the external project
@@ -128,10 +137,8 @@ function(cmake_add_fortran_subdirectory subdir)
     add_library(${lib} SHARED IMPORTED)
     add_library(${lib} SHARED IMPORTED)
     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
-      "${build_dir}/${library_dir}/lib${lib}.lib"
-      IMPORTED_LOCATION_NOCONFIG
-      "${build_dir}/${binary_dir}/lib${lib}.dll"
+      IMPORTED_IMPLIB_NOCONFIG   "${library_dir}/lib${lib}.lib"
+      IMPORTED_LOCATION_NOCONFIG "${binary_dir}/lib${lib}.dll"
       )
       )
     add_dependencies(${lib} ${project_name}_build)
     add_dependencies(${lib} ${project_name}_build)
   endforeach()
   endforeach()

+ 2 - 1
Modules/CMakeAddFortranSubdirectory/config_mingw.cmake.in

@@ -1,8 +1,9 @@
 set(ENV{PATH} "@MINGW_PATH@\;$ENV{PATH}")
 set(ENV{PATH} "@MINGW_PATH@\;$ENV{PATH}")
+set(CMAKE_COMMAND_LINE "@ARGS_CMAKE_COMMAND_LINE@")
 execute_process(
 execute_process(
   COMMAND "@CMAKE_COMMAND@" "-GMinGW Makefiles"
   COMMAND "@CMAKE_COMMAND@" "-GMinGW Makefiles"
   -DCMAKE_Fortran_COMPILER:PATH=@MINGW_GFORTRAN@
   -DCMAKE_Fortran_COMPILER:PATH=@MINGW_GFORTRAN@
   -DBUILD_SHARED_LIBS=ON
   -DBUILD_SHARED_LIBS=ON
   -DCMAKE_GNUtoMS=ON
   -DCMAKE_GNUtoMS=ON
-  @ARGS_CMAKE_COMMAND_LINE@
+  ${CMAKE_COMMAND_LINE}
   "@source_dir@")
   "@source_dir@")

+ 12 - 10
Tests/VSGNUFortran/CMakeLists.txt

@@ -1,5 +1,10 @@
 cmake_minimum_required(VERSION 2.8)
 cmake_minimum_required(VERSION 2.8)
 project(VSGNUFortran)
 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
 # force the executable to be put out of Debug/Release dir
 # because gmake build of fortran will not be in a config
 # because gmake build of fortran will not be in a config
 # directory, and for easier testing we want the exe and .dll
 # directory, and for easier testing we want the exe and .dll
@@ -7,14 +12,9 @@ project(VSGNUFortran)
 if(CMAKE_CONFIGURATION_TYPES)
 if(CMAKE_CONFIGURATION_TYPES)
   foreach(config ${CMAKE_CONFIGURATION_TYPES})
   foreach(config ${CMAKE_CONFIGURATION_TYPES})
     string(TOUPPER "${config}" config)
     string(TOUPPER "${config}" config)
-    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config}
-      "${PROJECT_BINARY_DIR}/bin")
     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config}
     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config}
-      "${PROJECT_BINARY_DIR}/bin")
+      ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
   endforeach()
   endforeach()
-else()
-  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
-  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
 endif()
 endif()
 
 
 include(CMakeAddFortranSubdirectory)
 include(CMakeAddFortranSubdirectory)
@@ -22,11 +22,13 @@ include(CMakeAddFortranSubdirectory)
 # the subdir is fortran, the project is FortranHello
 # the subdir is fortran, the project is FortranHello
 cmake_add_fortran_subdirectory(fortran
 cmake_add_fortran_subdirectory(fortran
   PROJECT FortranHello  # project name in toplevel CMakeLists.txt
   PROJECT FortranHello  # project name in toplevel CMakeLists.txt
-  ARCHIVE_DIR ../bin # .lib location relative to root binary tree
-  RUNTIME_DIR ../bin # .dll location relative to root binary tree
+  ARCHIVE_DIR ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
+  RUNTIME_DIR bin # ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
   LIBRARIES hello world # target libraries created
   LIBRARIES hello world # target libraries created
-  CMAKE_COMMAND_LINE -DEXECUTABLE_OUTPUT_PATH=../bin
-                     -DLIBRARY_OUTPUT_PATH=../bin
+  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_LIBRARIES  # link interface libraries
    LINK_LIBS hello world  # hello needs world to link
    LINK_LIBS hello world  # hello needs world to link
    )
    )