Przeglądaj źródła

Library dirs can now be managed by the build system

Within an external project, it's now possible to specify the name
of the variable being the directory or list of directories containing
the library of a project.

It means that if a given plugin, lib or app needs to invoke LINK_DIRECTORIES,
 on the directory associated with a given external project,
this will be done automatically.
Jean-Christophe Fillion-Robin 14 lat temu
rodzic
commit
3468ee13f1

+ 55 - 0
CMake/ctkFunctionGetLibraryDirs.cmake

@@ -0,0 +1,55 @@
+###########################################################################
+#
+#  Library: CTK
+#
+#  Copyright (c) German Cancer Research Center,
+#    Division of Medical and Biological Informatics
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+###########################################################################
+
+FUNCTION(ctkFunctionGetLibraryDirs var_library_dirs)
+
+  IF(NOT ARGN)
+    MESSAGE(FATAL_ERROR "No targets given")
+  ENDIF()
+
+  SET(_library_dirs ${${var_library_dirs}})
+  FOREACH(_target ${ARGN})
+
+    # Add the library directories from the external project
+    # The variable ${_target}_DEPENDENCIES is set in the
+    # macro ctkMacroValidateBuildOptions
+
+    SET(ext_deps )
+
+    ctkMacroGetAllNonCTKTargetLibraries("${${_target}_DEPENDENCIES}" ext_deps)
+    
+    FOREACH(dep ${ext_deps})
+
+      IF(${dep}_LIBRARY_DIRS)
+        STRING(REPLACE "^" ";" _ext_library_dirs "${${dep}_LIBRARY_DIRS}")
+        LIST(APPEND _library_dirs ${_ext_library_dirs})
+      ENDIF()
+
+    ENDFOREACH()
+
+  ENDFOREACH()
+
+  IF(_library_dirs)
+    LIST(REMOVE_DUPLICATES _library_dirs)
+  ENDIF()
+  SET(${var_library_dirs} ${_library_dirs} PARENT_SCOPE)
+
+ENDFUNCTION()

+ 8 - 0
CMake/ctkMacroBuildApp.cmake

@@ -66,6 +66,14 @@ MACRO(ctkMacroBuildApp)
   ctkFunctionGetIncludeDirs(my_includes ${proj_name})
 
   INCLUDE_DIRECTORIES(${my_includes})
+  
+  # Add the library directories from the external project
+  ctkFunctionGetLibraryDirs(my_library_dirs ${proj_name})
+  
+  LINK_DIRECTORIES(
+    ${my_library_dirs}
+    )
+  
 
 #   SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
 #   SET(MY_EXPORT_HEADER_PREFIX ${MY_NAME})

+ 7 - 0
CMake/ctkMacroBuildLib.cmake

@@ -64,6 +64,13 @@ MACRO(ctkMacroBuildLib)
   INCLUDE_DIRECTORIES(
     ${my_includes}
     )
+    
+  # Add the library directories from the external project
+  ctkFunctionGetLibraryDirs(my_library_dirs ${lib_name})
+  
+  LINK_DIRECTORIES(
+    ${my_library_dirs}
+    )
 
 
   SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})

+ 7 - 0
CMake/ctkMacroBuildPlugin.cmake

@@ -112,6 +112,13 @@ MACRO(ctkMacroBuildPlugin)
   INCLUDE_DIRECTORIES(
     ${my_includes}
     )
+    
+  # Add the library directories from the external project
+  ctkFunctionGetLibraryDirs(my_library_dirs ${lib_name})
+  
+  LINK_DIRECTORIES(
+    ${my_library_dirs}
+    )
  
   SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
   SET(MY_EXPORT_HEADER_PREFIX "${lib_name}_")

+ 19 - 1
CMakeLists.txt

@@ -168,6 +168,7 @@ INCLUDE(CMake/ctkFunctionGeneratePluginManifest.cmake)
 INCLUDE(CMake/ctkMacroGeneratePluginResourceFile.cmake)
 INCLUDE(CMake/ctkFunctionCheckCompilerFlags.cmake)
 INCLUDE(CMake/ctkFunctionGetIncludeDirs.cmake)
+INCLUDE(CMake/ctkFunctionGetLibraryDirs.cmake)
 INCLUDE(CMake/ctkFunctionGetGccVersion.cmake)
 
 #-----------------------------------------------------------------------------
@@ -549,7 +550,7 @@ IF(CTK_SUPERBUILD)
 ENDIF()
 
 #-----------------------------------------------------------------------------
-# Expand variables containing include directories for external projects
+# Expand variables containing include and library directories for external projects
 # This relies on the variable EXTERNAL_TARGETS set in ctkMacroValidateBuildOptions
 FOREACH(_external_target ${EXTERNAL_TARGETS})
   IF(${_external_target}_FIND_PACKAGE_CMD)
@@ -576,6 +577,23 @@ FOREACH(_external_target ${EXTERNAL_TARGETS})
       #MESSAGE("[${_external_target}] Appended dirs: ${${_external_target}_INCLUDE_DIRS}")
     ENDIF()
   ENDIF()
+  IF(${_external_target}_LIBRARY_DIRS)
+    STRING(REPLACE "^" ";" _library_variable_list "${${_external_target}_LIBRARY_DIRS}")
+    IF(_library_variable_list)
+      #MESSAGE("[${_external_target}] Resolving library variables: ${${_external_target}_LIBRARY_DIRS}")
+      SET(${_external_target}_LIBRARY_DIRS "")
+      FOREACH(_library_variable ${_library_variable_list})
+        #MESSAGE("[${_external_target}] Appending ${${_library_variable}}")
+        IF(${_library_variable})
+          LIST(APPEND ${_external_target}_LIBRARY_DIRS ${${_library_variable}})
+        ELSE()
+          LIST(APPEND ${_external_target}_LIBRARY_DIRS ${_library_variable})
+        ENDIF()
+        #MESSAGE("[${_external_target}] New dirs: ${${_external_target}_LIBRARY_DIRS}")
+      ENDFOREACH()
+      #MESSAGE("[${_external_target}] Appended dirs: ${${_external_target}_LIBRARY_DIRS}")
+    ENDIF()
+  ENDIF()
 ENDFOREACH()
 
 # Since PYTHONQT_USE_VTK library option can be enabled independently of

+ 7 - 0
CTKConfig.cmake.in

@@ -55,6 +55,7 @@ INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGenerateDGraphInput.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGeneratePluginManifest.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroGeneratePluginResourceFile.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetIncludeDirs.cmake")
+INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetLibraryDirs.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionSetupExternalPlugins.cmake")
 
 SET(CTK_EXPORT_HEADER_TEMPLATE "@CTK_EXPORT_HEADER_TEMPLATE@")
@@ -76,9 +77,15 @@ SET(CTK_WRAPPED_LIBRARIES_PYTHONQT @CTK_WRAPPED_LIBRARIES_PYTHONQT@)
 # Library specific include directories
 @CTK_LIBRARY_INCLUDE_DIRS_CONFIG@
 
+# Library specific library directories
+@CTK_LIBRARY_LIBRARY_DIRS_CONFIG@
+
 # Plugin specific include directories
 @CTK_PLUGIN_INCLUDE_DIRS_CONFIG@
 
+# Plugin specific library directories
+@CTK_PLUGIN_LIBRARY_DIRS_CONFIG@
+
 # The CTK include file directories.
 SET(CTK_INCLUDE_DIRS "@CTK_BUILD_DIR@;@CTK_INCLUDE_DIRS_CONFIG@")
  

+ 5 - 2
SuperBuild.cmake

@@ -135,14 +135,17 @@ SET(dependency_args )
 FOREACH(p ${external_projects})
   INCLUDE(CMakeExternals/${p}.cmake)
   IF(${p}_enabling_variable)
-    # Provide the include directories either directly or provide the variable name
+    # Provides the include and library directories either directly or provides the variable name
     # used by the corresponding Find<package>.cmake files. 
     # The top-level CMakeLists.txt file will expand the variable names if not in
-    # superbuild mode. The include dirs are then used in 
+    # superbuild mode. The include and library dirs are then used in 
     # ctkMacroBuildApp, ctkMacroBuildLib, and ctkMacroBuildPlugin
     STRING(REPLACE ";" "^" _include_dirs "${${${p}_enabling_variable}_INCLUDE_DIRS}")
     LIST(APPEND dependency_args 
          -D${${p}_enabling_variable}_INCLUDE_DIRS:STRING=${_include_dirs})
+    STRING(REPLACE ";" "^" _library_dirs "${${${p}_enabling_variable}_LIBRARY_DIRS}")
+    LIST(APPEND dependency_args 
+         -D${${p}_enabling_variable}_LIBRARY_DIRS:STRING=${_library_dirs})
     IF(${${p}_enabling_variable}_FIND_PACKAGE_CMD)
       LIST(APPEND dependency_args
            -D${${p}_enabling_variable}_FIND_PACKAGE_CMD:STRING=${${${p}_enabling_variable}_FIND_PACKAGE_CMD})

+ 10 - 2
Utilities/LastConfigureStep/CTKGenerateCTKConfig.cmake

@@ -76,22 +76,30 @@ ENDFOREACH()
 # as an external library
 EXPORT(TARGETS ${CTK_TARGETS_TO_EXPORT} FILE ${CTK_SUPERBUILD_BINARY_DIR}/CTKExports.cmake)
 
-# Write a set of variables containing plugin specific include directories
+# Write a set of variables containing plugin specific include and library directories
 SET(CTK_PLUGIN_INCLUDE_DIRS_CONFIG)
 FOREACH(plugin ${CTK_PLUGIN_LIBRARIES})
   SET(${plugin}_INCLUDE_DIRS ${${plugin}_SOURCE_DIR} ${${plugin}_BINARY_DIR})
   ctkFunctionGetIncludeDirs(${plugin}_INCLUDE_DIRS ${plugin})
   SET(CTK_PLUGIN_INCLUDE_DIRS_CONFIG "${CTK_PLUGIN_INCLUDE_DIRS_CONFIG}
 SET(${plugin}_INCLUDE_DIRS \"${${plugin}_INCLUDE_DIRS}\")")
+  
+  ctkFunctionGetLibraryDirs(${plugin}_LIBRARY_DIRS ${plugin})
+  SET(CTK_PLUGIN_LIBRARY_DIRS_CONFIG "${CTK_PLUGIN_LIBRARY_DIRS_CONFIG}
+SET(${plugin}_LIBRARY_DIRS \"${${plugin}_LIBRARY_DIRS}\")")
 ENDFOREACH()
 
-# Write a set of variables containing library specific include directories
+# Write a set of variables containing library specific include and library directories
 SET(CTK_LIBRARY_INCLUDE_DIRS_CONFIG)
 FOREACH(lib ${CTK_LIBRARIES})
   SET(${lib}_INCLUDE_DIRS ${${lib}_SOURCE_DIR} ${${lib}_BINARY_DIR})
   ctkFunctionGetIncludeDirs(${lib}_INCLUDE_DIRS ${lib})
   SET(CTK_LIBRARY_INCLUDE_DIRS_CONFIG "${CTK_LIBRARY_INCLUDE_DIRS_CONFIG}
 SET(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")")
+  
+  ctkFunctionGetLibraryDirs(${lib}_LIBRARY_DIRS ${lib})
+  SET(CTK_LIBRARY_LIBRARY_DIRS_CONFIG "${CTK_LIBRARY_LIBRARY_DIRS_CONFIG}
+SET(${lib}_LIBRARY_DIRS \"${${lib}_LIBRARY_DIRS}\")")
 ENDFOREACH()
 
 # Determine the include directories needed.