Commit f0f0df61 authored by jcfr's avatar jcfr

COMP: Move most of find_package calls into each Slicer sub-project.

To help address issue #3741 [1], call to find_package associated to CTK,
DCMTK, ITK and SlicerExecutionModel have been moved in every Slicer
sub project, library or module expecting it.

This allows to reduce both the number of include directories and
the number of libraries passed to the compiler.

Moving forward, every Slicer sub project, library or module will be
responsible to call find_package (optionally specifying a list of
components) and (if it applies) include the associated "use file".

Note that call to find_package(VTK) is still done at the top-level, before
moving the call to the expected sub-directories, the CTKConfig.cmake
will have to be updated to call find_package(VTK) specifying the required
components where it is needed.

[1] http://na-mic.org/Mantis/view.php?id=3741

git-svn-id: http://svn.slicer.org/Slicer4/trunk@23413 3bd1e089-480b-0410-8dfb-8563597acbee
parent 2dc292f2
project(SlicerBaseCLI)
# --------------------------------------------------------------------------
# Third party library
# Dependencies
# --------------------------------------------------------------------------
#
# ModuleDescriptionParser
#
find_package(SlicerExecutionModel REQUIRED ModuleDescriptionParser)
#
# ITK - Import ITK targets required by ModuleDescriptionParser
#
set(${PROJECT_NAME}_ITK_COMPONENTS
${ModuleDescriptionParser_ITK_COMPONENTS}
)
find_package(ITK 4.5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
# --------------------------------------------------------------------------
# Include dirs
# --------------------------------------------------------------------------
......@@ -73,7 +86,7 @@ endif()
set(SlicerBaseCLI_SRCS
)
set(SlicerBaseCLI_LIBS
ModuleDescriptionParser
ModuleDescriptionParser ${ITK_LIBRARIES}
)
#find_package(VTK)
......
project(SlicerBaseLogic)
# --------------------------------------------------------------------------
# Third party library
# Dependencies
# --------------------------------------------------------------------------
#
# ModuleDescriptionParser
#
if(Slicer_BUILD_CLI_SUPPORT)
find_package(SlicerExecutionModel REQUIRED ModuleDescriptionParser)
endif()
#
# VTK
#
if(Slicer_USE_PYTHONQT AND NOT VTK_WRAP_PYTHON)
message(FATAL_ERROR "Since Slicer_USE_PYTHONQT is ON, VTK_WRAP_PYTHON is expected to be ON. "
"Re-configure VTK with python wrapping.")
endif()
#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
ITKCommon
ITKIOTransformBase
ITKTransform
)
if(Slicer_BUILD_CLI_SUPPORT)
list(APPEND ${PROJECT_NAME}_ITK_COMPONENTS ${ModuleDescriptionParser_ITK_COMPONENTS})
endif()
find_package(ITK 4.5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
list(APPEND ITK_LIBRARIES ITKFactoryRegistration)
list(APPEND ITK_INCLUDE_DIRS
${ITKFactoryRegistration_INCLUDE_DIRS}
)
include(${ITK_USE_FILE})
#
# LibArchive
#
......@@ -125,15 +156,19 @@ set(srcs ${SlicerBaseLogic_SRCS})
add_library(${lib_name} ${srcs})
set(VTK_LIBRARIES
#vtkCommon # Provided by MRMLLogic
#vtkFiltering # Provided by MRMLLogic
#vtkGraphics # Provided by MRMLLogic
#vtkHybrid # Provided by MRMLLogic
#vtkIO # Provided by MRMLLogic
"" # Since no direct dependency to VTK libraries are required, let's explicitly set
# the variable to an empty string to avoid complaints from vtkMacroKitPythonWraps.cmake.
)
if(${VTK_VERSION_MAJOR} GREATER 5)
# Minimum set of libraries already specified using components
else()
set(VTK_LIBRARIES
#vtkCommon # Provided by MRMLLogic
#vtkFiltering # Provided by MRMLLogic
#vtkGraphics # Provided by MRMLLogic
#vtkHybrid # Provided by MRMLLogic
#vtkIO # Provided by MRMLLogic
"" # Since no direct dependency to VTK libraries are required, let's explicitly set
# the variable to an empty string to avoid complaints from vtkMacroKitPythonWraps.cmake.
)
endif()
set(libs
MRMLLogic
......@@ -193,6 +228,8 @@ install(TARGETS ${lib_name}
# Python Wrapping
# --------------------------------------------------------------------------
if(VTK_WRAP_PYTHON)
include(vtkMacroKitPythonWrap)
vtkMacroKitPythonWrap(
KIT_NAME ${lib_name}
KIT_SRCS ${SlicerBaseLogic_SRCS}
......
......@@ -33,6 +33,7 @@ set(KIT_UI_SRCS
# Additional Target libraries (QT libs already included)
set(KIT_target_libraries
# ${QT_LIBRARIES} # Not needed: All dependencies are transitively satisfied by other targets
qSlicerModulesCore
)
......
project(qSlicerBaseQTCLI)
#
# Third party library
# Dependencies
#
# Required to define ModuleDescriptionParser_INCLUDE_DIRS
#
# ModuleDescriptionParser
#
find_package(SlicerExecutionModel REQUIRED ModuleDescriptionParser)
#
# ITK - Import ITK targets required by ModuleDescriptionParser
#
set(${PROJECT_NAME}_ITK_COMPONENTS
${ModuleDescriptionParser_ITK_COMPONENTS}
)
find_package(ITK 4.5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
#
# VTK
#
if(Slicer_USE_PYTHONQT AND NOT VTK_WRAP_PYTHON)
message(FATAL_ERROR "Since Slicer_USE_PYTHONQT is ON, VTK_WRAP_PYTHON is expected to be ON. "
"Re-configure VTK with python wrapping.")
endif()
#
# See CMake/SlicerMacroBuildBaseQtLibrary.cmake for details
#
......@@ -70,9 +88,10 @@ set(KIT_resources
# Additional Target libraries (QT libs already included)
set(KIT_target_libraries
# ${QT_LIBRARIES} # Not needed: All dependencies are transitively satisfied by other targets
qSlicerBaseQTCore
qSlicerBaseQTGUI
ModuleDescriptionParser
ModuleDescriptionParser ${ITK_LIBRARIES}
MRMLCLI
)
......@@ -105,6 +124,8 @@ add_subdirectory(DesignerPlugins)
# Python Wrapping
# --------------------------------------------------------------------------
if(VTK_WRAP_PYTHON)
include(vtkMacroKitPythonWrap)
vtkMacroKitPythonWrap(
KIT_NAME ${PROJECT_NAME}
KIT_SRCS ${KIT_VTK_SRCS}
......
#-----------------------------------------------------------------------------
set(KIT ${PROJECT_NAME})
#-----------------------------------------------------------------------------
#
# SlicerExecutionModel
#
find_package(SlicerExecutionModel REQUIRED)
include(${SlicerExecutionModel_USE_FILE})
#-----------------------------------------------------------------------------
SEMMacroBuildCLI(
NAME CLIModule4Test
LOGO_HEADER ${Slicer_SOURCE_DIR}/Resources/ITKLogo.h
NO_INSTALL
)
#-----------------------------------------------------------------------------
set(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "DEBUG_LEAKS_ENABLE_EXIT_ERROR();" )
create_test_sourcelist(Tests ${KIT}CxxTests.cxx
qSlicerCLIExecutableModuleFactoryTest1.cxx
......
......@@ -4,13 +4,33 @@ project(qSlicerBaseQTCore)
# Dependencies
#
#
# DCMTK
#
if(Slicer_BUILD_DICOM_SUPPORT)
find_package(DCMTK REQUIRED)
endif()
#
# ModuleDescriptionParser - Required to define ModuleDescriptionParser_INCLUDE_DIRS
#
if(Slicer_BUILD_CLI_SUPPORT)
find_package(SlicerExecutionModel REQUIRED ModuleDescriptionParser)
#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
# Import ITK targets required by ModuleDescriptionParser
${ModuleDescriptionParser_ITK_COMPONENTS}
# Import ITK targets required by CTKImageProcessingITKCore
ITKCommon
)
find_package(ITK 4.5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
include(${ITK_USE_FILE})
endif()
#
# qRestAPI
#
......@@ -141,10 +161,12 @@ set(KIT_target_libraries
CTKCore
CTKImageProcessingITKCore
CTKVisualizationVTKCore
${ITK_LIBRARIES}
)
if(Slicer_BUILD_DICOM_SUPPORT)
list(APPEND KIT_target_libraries
${DCMTK_LIBRARIES}
CTKDICOMCore
)
endif()
......@@ -157,6 +179,7 @@ endif()
if(Slicer_BUILD_CLI_SUPPORT)
list(APPEND KIT_target_libraries
${ITK_LIBRARIES}
ModuleDescriptionParser
)
endif()
......
......@@ -327,12 +327,18 @@ SlicerMacroBuildBaseQtLibrary(
#-----------------------------------------------------------------------------
# Slicer icon engine
#-----------------------------------------------------------------------------
#
# CTK
#
set(CTK_LIBRARIES CTKWidgets)
ctkMacroBuildQtIconEnginesPlugin(
NAME qSlicerIconEnginePlugin
EXPORT_DIRECTIVE "Q_SLICER_BASE_QTGUI_ICON_ENGINE_EXPORT"
SRCS qSlicerIconEnginePlugin.cxx qSlicerIconEnginePlugin.h
MOC_SRCS qSlicerIconEnginePlugin.h
TARGET_LIBRARIES ${QT_LIBRARIES} ${CTK_LIBRARIES} ${VTK_LIBRARIES}
TARGET_LIBRARIES ${QT_LIBRARIES} ${CTK_LIBRARIES}
)
# Qt Plugins
......
......@@ -210,8 +210,6 @@ macro(SlicerMacroBuildBaseQtLibrary)
endif()
target_link_libraries(${lib_name}
${QT_LIBRARIES}
${CTK_EXTERNAL_LIBRARIES}
${SLICERQTBASELIB_TARGET_LIBRARIES}
)
......
......@@ -41,6 +41,11 @@ macro(SlicerMacroPythonWrapModuleVTKLibrary)
${ARGN}
)
if(Slicer_USE_PYTHONQT AND NOT VTK_WRAP_PYTHON)
message(FATAL_ERROR "Since Slicer_USE_PYTHONQT is ON, VTK_WRAP_PYTHON is expected to be ON. "
"Re-configure VTK with python wrapping.")
endif()
# --------------------------------------------------------------------------
# Sanity checks
# --------------------------------------------------------------------------
......@@ -90,7 +95,7 @@ macro(SlicerMacroPythonWrapModuleVTKLibrary)
vtksys
vtktiff
)
if (NOT WIN32)
if(NOT WIN32)
list(APPEND VTK_NO_PYTHON_WRAP_LIBRARIES
vtkRenderingFreeTypeFontConfig)
endif()
......
......@@ -89,7 +89,7 @@ macro(vtkMacroKitPythonWrap)
vtkGUISupportQtSQL
vtkGUISupportQtOpenGL
)
if (NOT WIN32)
if(NOT WIN32)
list(APPEND VTK_NO_PYTHON_WRAP_LIBRARIES
vtkRenderingFreeTypeFontConfig)
endif()
......
......@@ -484,86 +484,6 @@ if(Slicer_BUILD_CLI_SUPPORT)
set(Slicer_INSTALL_CLIMODULES_SHARE_DIR "${Slicer_INSTALL_ROOT}${Slicer_CLIMODULES_SHARE_DIR}")
endif()
#-----------------------------------------------------------------------------
# ITKv4 - Slicer_ITK_COMPONENTS
#-----------------------------------------------------------------------------
set(ITK_IO_MODULES_USED
ITKIOJPEG
ITKIOGDCM
ITKIOBMP
ITKIOLSM
ITKIOPNG
ITKIOTIFF
ITKIOVTK
ITKIOStimulate
ITKIOBioRad
ITKIOMeta
ITKIONIFTI
ITKIONRRD
ITKIOGIPL
)
if(Slicer_BUILD_DICOM_SUPPORT)
list(APPEND ITK_IO_MODULES_USED ITKIODCMTK)
endif()
set(Slicer_ITK_COMPONENTS
ITKAnisotropicSmoothing
ITKAntiAlias
ITKBiasCorrection
ITKBinaryMathematicalMorphology
ITKCommon
ITKConnectedComponents
ITKCurvatureFlow
ITKDeprecated
ITKDiffusionTensorImage
ITKDisplacementField
ITKDistanceMap
ITKFastMarching
ITKHDF5
ITKIOImageBase
ITKIOSpatialObjects
ITKIOStimulate
ITKIOTransformBase
ITKImageAdaptors
ITKImageCompare
ITKImageCompose
ITKImageFeature
ITKImageFilterBase
ITKImageFunction
ITKImageFusion
ITKImageGradient
ITKImageGrid
ITKImageIntensity
ITKImageSources
ITKImageStatistics
ITKLabelVoting
ITKLevelSets
ITKMathematicalMorphology
ITKMesh
ITKOptimizers
ITKPDEDeformableRegistration
ITKPath
ITKQuadEdgeMesh
ITKQuadEdgeMeshFiltering
ITKRegionGrowing
ITKRegistrationCommon
ITKReview
ITKSmoothing
ITKSpatialObjects
ITKStatistics
ITKTestKernel
ITKThresholding
ITKTransform
ITKV3Compatibility
ITKVTK
# ITKVtkGlue
ITKZLIB
${ITK_IO_MODULES_USED}
)
if(Slicer_BUILD_BRAINSTOOLS)
list(APPEND Slicer_ITK_COMPONENTS ITKOptimizersv4)
endif()
#-----------------------------------------------------------------------------
# VTKv6 - Slicer_VTK_COMPONENTS
#-----------------------------------------------------------------------------
......@@ -676,13 +596,8 @@ foreach(dep QT ${Slicer_DEPENDENCIES})
endforeach()
#-----------------------------------------------------------------------------
# CMake Function(s) and Macro(s)
#-----------------------------------------------------------------------------
if(Slicer_BUILD_CLI_SUPPORT)
include(SlicerMacroBuildCLI)
endif()
# Clear SlicerTargets.cmake
#-----------------------------------------------------------------------------
file(WRITE "${Slicer_BINARY_DIR}/SlicerTargets.cmake" "")
#-----------------------------------------------------------------------------
......@@ -761,16 +676,15 @@ if(BUILD_TESTING)
endif()
#-----------------------------------------------------------------------------
# ITK
# NOTE: How to include dependent packages ?
#-----------------------------------------------------------------------------
find_package(ITK 4.5 COMPONENTS ${Slicer_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
list(APPEND ITK_LIBRARIES ITKFactoryRegistration)
list(APPEND ITK_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/Libs/ITKFactoryRegistration
${CMAKE_CURRENT_BINARY_DIR}/Libs/ITKFactoryRegistration
)
include(${ITK_USE_FILE})
# Every Slicer sub project, library or module is responsible
# to call find_package (optionally specifying a list of components)
# and (if it applies) include the associated "use file".
#
# This means that moving forward most of the find_package calls listed below
# will be removed.
#-----------------------------------------------------------------------------
# VTK
......@@ -813,7 +727,6 @@ endif()
# Update CMake module path
#-----------------------------------------------------------------------------
set(CMAKE_MODULE_PATH
${VTK_CMAKE_DIR}
${CTK_CMAKE_DIR}
${CMAKE_MODULE_PATH}
${CTK_CMAKE_UTILITIES_DIR})
......@@ -845,13 +758,6 @@ endif()
# PythonQt
#-----------------------------------------------------------------------------
if(Slicer_USE_PYTHONQT)
if(NOT VTK_WRAP_PYTHON)
message(FATAL_ERROR "Since Slicer_USE_PYTHONQT is ON, VTK_WRAP_PYTHON is expected to be ON. "
"Re-configure VTK with python wrapping.")
endif()
include(vtkMacroKitPythonWrap)
set(PYTHONQT_INSTALL_DIR ${CTK_PYTHONQT_INSTALL_DIR})
# Find PythonQt package so that PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is defined
# See https://github.com/commontk/PythonQt/issues/7
......
......@@ -2,6 +2,25 @@
#-----------------------------------------------------------------------------
set(MODULE_NAME CLIModuleTemplate)
#-----------------------------------------------------------------------------
#
# SlicerExecutionModel
#
find_package(SlicerExecutionModel REQUIRED)
include(${SlicerExecutionModel_USE_FILE})
#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
ITKIOImageBase
ITKSmoothing
)
find_package(ITK 4.5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
include(${ITK_USE_FILE})
#-----------------------------------------------------------------------------
set(MODULE_INCLUDE_DIRECTORIES
)
......
......@@ -8,7 +8,7 @@ set(CLP ${MODULE_NAME})
#-----------------------------------------------------------------------------
add_executable(${CLP}Test ${CLP}Test.cxx)
target_link_libraries(${CLP}Test ${CLP}Lib)
target_link_libraries(${CLP}Test ${CLP}Lib ${SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES})
set_target_properties(${CLP}Test PROPERTIES LABELS ${CLP})
#-----------------------------------------------------------------------------
......
......@@ -2,6 +2,25 @@
#-----------------------------------------------------------------------------
set(MODULE_NAME SuperCLIModuleTemplate)
#-----------------------------------------------------------------------------
#
# SlicerExecutionModel
#
find_package(SlicerExecutionModel REQUIRED)
include(${SlicerExecutionModel_USE_FILE})
#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
ITKIOImageBase
ITKSmoothing
)
find_package(ITK 4.5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
include(${ITK_USE_FILE})
#-----------------------------------------------------------------------------
set(MODULE_INCLUDE_DIRECTORIES
)
......
......@@ -8,7 +8,7 @@ set(CLP ${MODULE_NAME})
#-----------------------------------------------------------------------------
add_executable(${CLP}Test ${CLP}Test.cxx)
target_link_libraries(${CLP}Test ${CLP}Lib)
target_link_libraries(${CLP}Test ${CLP}Lib ${SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES})
set_target_properties(${CLP}Test PROPERTIES LABELS ${CLP})
#-----------------------------------------------------------------------------
......
......@@ -11,15 +11,28 @@ if(POLICY CMP0017)
cmake_policy(SET CMP0017 OLD)
endif()
# --------------------------------------------------------------------------
# Options
# --------------------------------------------------------------------------
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build with shared libraries." ON)
endif()
# --------------------------------------------------------------------------
# Dependencies
# --------------------------------------------------------------------------
#
# VTK
#
#find_package(VTK REQUIRED)
#include(${VTK_USE_FILE})
#
# ZLIB
#
find_package(ZLIB REQUIRED)
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build with shared libraries." ON)
endif()
# --------------------------------------------------------------------------
# Include dirs
# --------------------------------------------------------------------------
......@@ -80,13 +93,7 @@ set(srcs ${FreeSurfer_SRCS})
add_library(${lib_name} ${srcs})
if(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
vtkCommonCore
vtkCommonDataModel
vtkCommonExecutionModel
vtkCommonMath
vtkIOLegacy
)
# Minimum set of libraries already specified using components
else()
set(VTK_LIBRARIES
vtkCommon
......
......@@ -2,9 +2,39 @@ project(ITKFactoryRegistration)
cmake_minimum_required(VERSION 2.8.4)
list(REMOVE_ITEM ITK_LIBRARIES ITKFactoryRegistration)
# --------------------------------------------------------------------------
# Dependencies
# --------------------------------------------------------------------------
#
# ITK
#
set(ITK_IO_MODULES_USED
ITKIOJPEG
ITKIOGDCM
ITKIOBMP
ITKIOLSM
ITKIOPNG
ITKIOTIFF
ITKIOVTK
ITKIOStimulate
ITKIOBioRad
ITKIOMeta
ITKIONIFTI
ITKIONRRD
ITKIOGIPL
ITKIOTransformInsightLegacy
)
if(Slicer_BUILD_DICOM_SUPPORT)
list(APPEND ITK_IO_MODULES_USED ITKIODCMTK)
endif()
find_package(ITK REQUIRED)
set(${PROJECT_NAME}_ITK_COMPONENTS
ITKIOImageBase
ITKIOTransformBase
${ITK_IO_MODULES_USED}
)
find_package(ITK 4.5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
# This is the Slicer library in charge of registering the default ITK factories.
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 0)
......
......@@ -11,21 +11,31 @@ if(POLICY CMP0017)
cmake_policy(SET CMP0017 OLD)
endif()
set(${CMAKE_PROJECT_NAME}_ITK_COMPONENTS
# --------------------------------------------------------------------------
# Options
# --------------------------------------------------------------------------
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build with shared libraries." ON)
endif()
# --------------------------------------------------------------------------
# Dependencies
# --------------------------------------------------------------------------
#
# ITK
#
set(${PROJECT_NAME}_ITK_COMPONENTS
ITKCommon
ITKIOImageBase
ITKZLIB
)
find_package(ITK 4.5 COMPONENTS ${${CMAKE_PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
find_package(ITK 4.5 COMPONENTS ${${PROJECT_NAME}_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
list(APPEND ITK_LIBRARIES ITKFactoryRegistration)
list(APPEND ITK_INCLUDE_DIRS ${ITKFactoryRegistration_INCLUDE_DIRS})
include(${ITK_USE_FILE})
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build with shared libraries." ON)
endif()
# --------------------------------------------------------------------------
# Include dirs
# --------------------------------------------------------------------------
......
......@@ -11,15 +11,38 @@ if(POLICY CMP0017)
cmake_policy(SET CMP0017 OLD)
endif()
# --------------------------------------------------------------------------
# Options
# --------------------------------------------------------------------------
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build with shared libraries." ON)
endif()
# --------------------------------------------------------------------------
# Third party library
# Dependencies
# --------------------------------------------------------------------------
#
# ModuleDescriptionParser
#
find_package(SlicerExecutionModel REQUIRED ModuleDescriptionParser)