浏览代码

Merge topic 'buildsystem-manages-library-dirs'

* buildsystem-manages-library-dirs:
  Remove FIND_PACKAGE(DCMTK) from ctkDICOMDemoSCU
  Review VTK external project definition
  Review OpenIGTLink and ZMQ external project definition
  Review XIP external project definition
  Library dirs can now be managed by the build system
Jean-Christophe Fillion-Robin 14 年之前
父节点
当前提交
9d469e5e80

+ 0 - 9
Applications/ctkDICOMDemoSCU/CMakeLists.txt

@@ -1,15 +1,6 @@
 PROJECT(ctkDICOMDemoSCU)
 
 #
-# 3rd party dependencies
-#
-
-FIND_PACKAGE(DCMTK)
-IF(NOT DCMTK_FOUND)
-  MESSAGE(FATAL_ERROR "error: DCMTK package is required to build ${PROJECT_NAME}")
-ENDIF()
-
-#
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
   

+ 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}_")

+ 7 - 0
CMakeExternals/OpenIGTLink.cmake

@@ -10,6 +10,8 @@ IF(${add_project})
     MESSAGE(FATAL_ERROR "OpenIGTLink_DIR variable is defined but corresponds to non-existing directory")
   ENDIF()
   
+  SET(OpenIGTLink_enabling_variable OpenIGTLink_LIBRARIES)
+  
   SET(proj OpenIGTLink)
   SET(proj_DEPENDENCIES)
   
@@ -32,4 +34,9 @@ IF(${add_project})
   ELSE()
     ctkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}")
   ENDIF()
+  
+  SET(${OpenIGTLink_enabling_variable}_LIBRARY_DIRS OpenIGTLink_LIBRARY_DIRS)
+  SET(${OpenIGTLink_enabling_variable}_INCLUDE_DIRS OpenIGTLink_INCLUDE_DIRS)
+  SET(${OpenIGTLink_enabling_variable}_FIND_PACKAGE_CMD OpenIGTLink)
+  
 ENDIF()

+ 1 - 0
CMakeExternals/VTK.cmake

@@ -62,6 +62,7 @@ IF(${add_project} OR CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
     ctkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}")
   ENDIF()
 
+  SET(${VTK_enabling_variable}_LIBRARY_DIRS VTK_LIBRARY_DIRS)
   SET(${VTK_enabling_variable}_INCLUDE_DIRS VTK_INCLUDE_DIRS)
   SET(${VTK_enabling_variable}_FIND_PACKAGE_CMD VTK)
 ENDIF()

+ 32 - 11
CMakeExternals/XIP.cmake

@@ -4,17 +4,38 @@
 SET (XIP_DEPENDS)
 ctkMacroShouldAddExternalProject(XIP_LIBRARIES add_project)
 IF(${add_project})
+  # Sanity checks
+  IF(DEFINED XIP_DIR AND NOT EXISTS ${XIP_DIR})
+    MESSAGE(FATAL_ERROR "XIP_DIR variable is defined but corresponds to non-existing directory")
+  ENDIF()
+  
+  SET(XIP_enabling_variable XIP_LIBRARIES)
+  
   SET(proj XIP)
-#   MESSAGE(STATUS "Adding project:${proj}")
+  SET(proj_DEPENDENCIES)
+  
   SET(XIP_DEPENDS ${proj})
-  ExternalProject_Add(${proj}
-    SVN_REPOSITORY "https://collab01a.scr.siemens.com/svn/xip/releases/latest"
-    SVN_USERNAME "anonymous"
-    INSTALL_COMMAND ""
-    CMAKE_GENERATOR ${gen}
-    CMAKE_ARGS
-      ${ep_common_args}
-      -DHAS_VTK:BOOL=OFF
-      -DHAS_ITK:BOOL=OFF
-    )
+  
+  IF(NOT DEFINED XIP_DIR)
+    #   MESSAGE(STATUS "Adding project:${proj}")
+    ExternalProject_Add(${proj}
+      SVN_REPOSITORY "https://collab01a.scr.siemens.com/svn/xip/releases/latest"
+      SVN_USERNAME "anonymous"
+      INSTALL_COMMAND ""
+      CMAKE_GENERATOR ${gen}
+      CMAKE_ARGS
+        ${ep_common_args}
+        -DHAS_VTK:BOOL=OFF
+        -DHAS_ITK:BOOL=OFF
+      )
+    SET(XIP_DIR ${ep_build_dir}/${proj})
+    
+  ELSE()
+    ctkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}")
+  ENDIF()
+  
+  SET(${XIP_enabling_variable}_INCLUDE_DIRS XIP_LIBRARY_DIRS)
+  SET(${XIP_enabling_variable}_INCLUDE_DIRS XIP_INCLUDE_DIRS)
+  SET(${XIP_enabling_variable}_FIND_PACKAGE_CMD XIP)
+  
 ENDIF()

+ 1 - 0
CMakeExternals/ZMQ.cmake

@@ -38,6 +38,7 @@ IF(${add_project})
     ctkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}")
   ENDIF()
 
+  SET(${ZMQ_enabling_variable}_INCLUDE_DIRS ZMQ_LIBRARY_DIRS)
   SET(${ZMQ_enabling_variable}_INCLUDE_DIRS ZMQ_INCLUDE_DIRS)
   SET(${ZMQ_enabling_variable}_FIND_PACKAGE_CMD ZMQ)
 ENDIF()

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

+ 0 - 20
Libs/Messaging/Core/CMakeLists.txt

@@ -1,26 +1,6 @@
 PROJECT(CTKMessagingCore)
 
 #
-# 3rd party dependencies
-#
-
-FIND_PACKAGE(ZMQ)
-# TODO In case ZMQ is passed directly using ZMQ_DIR, check expected options
-IF(NOT ZMQ_FOUND)
-  MESSAGE(FATAL_ERROR "error: ZMQ package is required to build ${PROJECT_NAME}")
-ENDIF()
-INCLUDE(${ZMQ_USE_FILE})
-
-
-#FIND_PACKAGE(OpenIGTLink)
-# TODO In case OpenIGTLink is passed directly using OpenIGTLink_DIR, check expected options
-#IF(NOT OpenIGTLink_FOUND)
-#  MESSAGE(FATAL_ERROR "error: OpenIGTLink package is required to build ${PROJECT_NAME}")
-#ENDIF()
-#INCLUDE(${OpenIGTLink_USE_FILE})
-
-
-#
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
 

+ 0 - 10
Libs/Visualization/VTK/Widgets/CMakeLists.txt

@@ -1,16 +1,6 @@
 PROJECT(CTKVisualizationVTKWidgets)
 
 #
-# 3rd party dependencies
-#
-
-FIND_PACKAGE(VTK)
-IF(NOT VTK_FOUND)
-  MESSAGE(FATAL_ERROR "error: VTK package is required to build ${PROJECT_NAME}")
-ENDIF()
-INCLUDE(${VTK_USE_FILE})
-
-#
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
 

+ 0 - 9
Libs/Visualization/XIP/CMakeLists.txt

@@ -1,15 +1,6 @@
 PROJECT(CTKVisualizationXIP)
 
 #
-# 3rd party dependencies
-#
-
-# FIND_PACKAGE(XIP)
-# IF(NOT XIP_FOUND)
-#   MESSAGE(FATAL_ERROR "error: XIP package is required to build ${PROJECT_NAME}")
-# ENDIF()
-
-#
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
 

+ 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.