Ver código fonte

Merge branch '418-support-use-system-option'

* 418-support-use-system-option:
  COMP: Add support for CTK_USE_SYSTEM_* options
  Automatically reformat list passed to "CTK" inner build.
  Add convenience function "ctk_list_to_string"
Jean-Christophe Fillion-Robin 11 anos atrás
pai
commit
299589f2eb

+ 16 - 0
CMake/Testing/CMakeLists.txt

@@ -0,0 +1,16 @@
+#
+# Helper macro
+#
+macro(add_cmakescript_test testname script)
+  add_test(cmake_${testname} ${CMAKE_COMMAND}
+    -DTEST_${testname}:BOOL=ON
+    -P ${CMAKE_SOURCE_DIR}/CMake/${script}.cmake)
+  set_tests_properties(cmake_${testname} PROPERTIES
+    LABELS CMake
+    PASS_REGULAR_EXPRESSION "SUCCESS")
+endmacro()
+
+#
+# Add 'CMake script' Tests
+#
+add_cmakescript_test(list_to_string_test ctkListToString)

+ 11 - 11
CMake/ctkBlockCheckDependencies.cmake

@@ -30,6 +30,7 @@ ctkMacroGetAllNonProjectTargetLibraries("${ALL_TARGET_LIBRARIES}" NON_CTK_DEPEND
 #-----------------------------------------------------------------------------
 # Enable and setup External project global properties
 #
+
 if(CTK_SUPERBUILD)
   include(ExternalProject)
   include(ctkMacroEmptyExternalProject)
@@ -83,18 +84,17 @@ if(CTK_SUPERBUILD)
   set(CTK_SUPERBUILD_EP_VARS)
 endif()
 
-if(NOT DEFINED CTK_POSSIBLE_DEPENDENCIES)
-  message(FATAL_ERROR "error: CTK_POSSIBLE_DEPENDENCIES variable is not defined !")
+if(NOT DEFINED CTK_DEPENDENCIES)
+  message(FATAL_ERROR "error: CTK_DEPENDENCIES variable is not defined !")
 endif()
-foreach(p ${CTK_POSSIBLE_DEPENDENCIES})
-  if(${p}_FILEPATH)
-    include(${${p}_FILEPATH})
-  else()
-    include(CMakeExternals/${p}.cmake)
-  endif()
-endforeach()
 
-#message("CTK_POSSIBLE_DEPENDENCIES:")
-#foreach(dep ${CTK_POSSIBLE_DEPENDENCIES})
+set(EXTERNAL_PROJECT_DIR ${${CMAKE_PROJECT_NAME}_SOURCE_DIR}/CMakeExternals)
+set(EXTERNAL_PROJECT_FILE_PREFIX "")
+include(ctkMacroCheckExternalProjectDependency)
+
+ctkMacroCheckExternalProjectDependency(CTK)
+
+#message("Updated CTK_DEPENDENCIES:")
+#foreach(dep ${CTK_DEPENDENCIES})
 #  message("  ${dep}")
 #endforeach()

+ 119 - 0
CMake/ctkListToString.cmake

@@ -0,0 +1,119 @@
+###########################################################################
+#
+#  Library:   CTK
+#
+#  Copyright (c) Kitware Inc.
+#
+#  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.txt
+#
+#  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(ctk_list_to_string separator input_list output_string_var)
+  set(_string "")
+  cmake_policy(PUSH)
+  cmake_policy(SET CMP0007 OLD)
+  # Get list length
+  list(LENGTH input_list list_length)
+  # If the list has 0 or 1 element, there is no need to loop over.
+  if(list_length LESS 2)
+    set(_string  "${input_list}")
+  else()
+    math(EXPR last_element_index "${list_length} - 1")
+    foreach(index RANGE ${last_element_index})
+      # Get current item_value
+      list(GET input_list ${index} item_value)
+      # .. and append to output string
+      set(_string  "${_string}${item_value}")
+      # Append separator if current element is NOT the last one.
+      if(NOT index EQUAL last_element_index)
+        set(_string  "${_string}${separator}")
+      endif()
+    endforeach()
+  endif()
+  set(${output_string_var} ${_string} PARENT_SCOPE)
+  cmake_policy(POP)
+endfunction()
+
+
+#
+# cmake -DTEST_ctk_list_to_string_test:BOOL=ON -P ListToString.cmake
+#
+function(ctk_list_to_string_test)
+
+  function(ctk_list_to_string_test_check id current_output expected_output)
+    if(NOT "${current_output}" STREQUAL "${expected_output}")
+      message(FATAL_ERROR "Problem with ctk_list_to_string() - See testcase: ${id}\n"
+                          "current_output:${current_output}\n"
+                          "expected_output:${expected_output}")
+    endif()
+  endfunction()
+
+  set(id 1)
+  set(case${id}_input "")
+  set(case${id}_expected_output "")
+  ctk_list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  set(id 2)
+  set(case${id}_input item1)
+  set(case${id}_expected_output "item1")
+  ctk_list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  set(id 3)
+  set(case${id}_input item1 item2)
+  set(case${id}_expected_output "item1^^item2")
+  ctk_list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  set(id 4)
+  set(case${id}_input item1 item2 item3)
+  set(case${id}_expected_output "item1^^item2^^item3")
+  ctk_list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  set(id 5)
+  set(case${id}_input item1 item2 item3 item4)
+  set(case${id}_expected_output "item1^^item2^^item3^^item4")
+  ctk_list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  set(id 6)
+  set(case${id}_input item1 "" item3 item4)
+  set(case${id}_expected_output "item1^^item3^^item4")
+  ctk_list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  set(id 7)
+  set(case${id}_input item1 ^^item2 item3 item4)
+  set(case${id}_expected_output "item1^^^^item2^^item3^^item4")
+  ctk_list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  set(id 8)
+  set(case${id}_input item1 item2 item3 item4)
+  set(case${id}_expected_output "item1item2item3item4")
+  ctk_list_to_string("" "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  set(id 9)
+  set(case${id}_input item1 item2 item3 item4)
+  set(case${id}_expected_output "item1 item2 item3 item4")
+  ctk_list_to_string(" " "${case${id}_input}" case${id}_current_output)
+  ctk_list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+  message("SUCCESS")
+endfunction()
+if(TEST_ctk_list_to_string_test)
+  ctk_list_to_string_test()
+endif()

+ 180 - 0
CMake/ctkMacroCheckExternalProjectDependency.cmake

@@ -0,0 +1,180 @@
+###########################################################################
+#
+#  Library:   CTK
+#
+#  Copyright (c) Kitware Inc.
+#
+#  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.txt
+#
+#  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.
+#
+###########################################################################
+
+if(NOT EXISTS "${EXTERNAL_PROJECT_DIR}")
+  set(EXTERNAL_PROJECT_DIR ${${CMAKE_PROJECT_NAME}_SOURCE_DIR}/SuperBuild)
+endif()
+
+if(NOT DEFINED EXTERNAL_PROJECT_FILE_PREFIX)
+  set(EXTERNAL_PROJECT_FILE_PREFIX "External_")
+endif()
+
+macro(ctk_include_once)
+  # Make sure this file is included only once
+  get_filename_component(CMAKE_CURRENT_LIST_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME_WE)
+  if(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED)
+    return()
+  endif()
+  set(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED 1)
+endmacro()
+
+macro(_epd_status txt)
+  if(NOT __epd_first_pass)
+    message(STATUS ${txt})
+  endif()
+endmacro()
+
+macro(ctkMacroCheckExternalProjectDependency proj)
+
+  # Set indent variable if needed
+  if(NOT DEFINED __indent)
+    set(__indent "")
+  else()
+    set(__indent "${__indent}  ")
+  endif()
+
+  # Sanity checks
+  if(NOT DEFINED ${proj}_DEPENDENCIES)
+    message(FATAL_ERROR "${__indent}${proj}_DEPENDENCIES variable is NOT defined !")
+  endif()
+
+  # Keep track of the projects
+  list(APPEND __epd_${CMAKE_PROJECT_NAME}_projects ${proj})
+
+  # Is this the first run ? (used to set the <CMAKE_PROJECT_NAME>_USE_SYSTEM_* variables)
+  if(${proj} STREQUAL ${CMAKE_PROJECT_NAME} AND NOT DEFINED __epd_first_pass)
+    message(STATUS "SuperBuild - First pass")
+    set(__epd_first_pass TRUE)
+  endif()
+
+  # Set message strings
+  set(__${proj}_indent ${__indent})
+  set(__${proj}_superbuild_message "SuperBuild - ${__indent}${proj}[OK]")
+  if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+    set(__${proj}_superbuild_message "${__${proj}_superbuild_message} (SYSTEM)")
+  endif()
+
+  # Display dependency of project being processed
+  if("${${proj}_DEPENDENCIES}" STREQUAL "")
+    _epd_status(${__${proj}_superbuild_message})
+  else()
+    set(dependency_str " ")
+    foreach(dep ${${proj}_DEPENDENCIES})
+      if(${EXTERNAL_PROJECT_FILE_PREFIX}${dep}_FILE_INCLUDED)
+        set(dependency_str "${dependency_str}${dep}[INCLUDED], ")
+      else()
+        set(dependency_str "${dependency_str}${dep}, ")
+      endif()
+    endforeach()
+    _epd_status("SuperBuild - ${__indent}${proj} => Requires${dependency_str}")
+  endif()
+
+  foreach(dep ${${proj}_DEPENDENCIES})
+    if(${${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}})
+      set(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${dep} ${${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}})
+    endif()
+    #if(__epd_first_pass)
+    #  message("${CMAKE_PROJECT_NAME}_USE_SYSTEM_${dep} set to [${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}:${${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}}]")
+    #endif()
+  endforeach()
+
+  # Include dependencies
+  foreach(dep ${${proj}_DEPENDENCIES})
+    if(NOT External_${dep}_FILE_INCLUDED)
+      # XXX - Refactor - Add a single variable named 'EXTERNAL_PROJECT_DIRS'
+      if(EXISTS "${EXTERNAL_PROJECT_DIR}/${EXTERNAL_PROJECT_FILE_PREFIX}${dep}.cmake")
+        include(${EXTERNAL_PROJECT_DIR}/${EXTERNAL_PROJECT_FILE_PREFIX}${dep}.cmake)
+      elseif(EXISTS "${${dep}_FILEPATH}")
+        include(${${dep}_FILEPATH})
+      elseif(EXISTS "${EXTERNAL_PROJECT_ADDITIONAL_DIR}/${EXTERNAL_PROJECT_FILE_PREFIX}${dep}.cmake")
+        include(${EXTERNAL_PROJECT_ADDITIONAL_DIR}/${EXTERNAL_PEXCLUDEDROJECT_FILE_PREFIX}${dep}.cmake)
+      else()
+        message(FATAL_ERROR "Can't find ${EXTERNAL_PROJECT_FILE_PREFIX}${dep}.cmake")
+      endif()
+    endif()
+  endforeach()
+
+  # If project being process has dependencies, indicates it has also been added.
+  if(NOT "${${proj}_DEPENDENCIES}" STREQUAL "")
+    _epd_status(${__${proj}_superbuild_message})
+  endif()
+
+  # Update indent variable
+  string(LENGTH "${__indent}" __indent_length)
+  math(EXPR __indent_length "${__indent_length}-2")
+  if(NOT ${__indent_length} LESS 0)
+    string(SUBSTRING "${__indent}" 0 ${__indent_length} __indent)
+  endif()
+
+  if(${proj} STREQUAL ${CMAKE_PROJECT_NAME} AND __epd_first_pass)
+    message(STATUS "SuperBuild - First pass - done")
+    unset(__indent)
+    if(${CMAKE_PROJECT_NAME}_SUPERBUILD)
+      set(__epd_first_pass FALSE)
+    endif()
+
+    unset(${CMAKE_PROJECT_NAME}_DEPENDENCIES) # XXX - Refactor
+
+    foreach(possible_proj ${__epd_${CMAKE_PROJECT_NAME}_projects})
+      if(NOT ${possible_proj} STREQUAL ${CMAKE_PROJECT_NAME})
+
+        unset(${EXTERNAL_PROJECT_FILE_PREFIX}${possible_proj}_FILE_INCLUDED)
+
+        # XXX - Refactor - The following code should be re-organized
+        if(DEFINED ${possible_proj}_enabling_variable)
+          ctkMacroShouldAddExternalproject(${${possible_proj}_enabling_variable} add_project)
+          if(${add_project})
+            list(APPEND ${CMAKE_PROJECT_NAME}_DEPENDENCIES ${possible_proj})
+          else()
+            # XXX HACK
+            if(${possible_proj} STREQUAL "VTK"
+               AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+              list(APPEND ${CMAKE_PROJECT_NAME}_DEPENDENCIES VTK)
+            else()
+              unset(${${possible_proj}_enabling_variable}_INCLUDE_DIRS)
+              unset(${${possible_proj}_enabling_variable}_LIBRARY_DIRS)
+              unset(${${possible_proj}_enabling_variable}_FIND_PACKAGE_CMD)
+              if(${CMAKE_PROJECT_NAME}_SUPERBUILD)
+                message(STATUS "SuperBuild - ${possible_proj}[OPTIONAL]")
+              endif()
+            endif()
+          endif()
+        else()
+          list(APPEND ${CMAKE_PROJECT_NAME}_DEPENDENCIES ${possible_proj})
+        endif()
+        # XXX
+
+      else()
+
+      endif()
+    endforeach()
+
+    list(REMOVE_DUPLICATES ${CMAKE_PROJECT_NAME}_DEPENDENCIES)
+
+    if(${CMAKE_PROJECT_NAME}_SUPERBUILD)
+      ctkMacroCheckExternalProjectDependency(${CMAKE_PROJECT_NAME})
+    endif()
+
+  endif()
+
+  if(__epd_first_pass)
+    return()
+  endif()
+endmacro()

+ 48 - 49
CMakeExternals/CTKData.cmake

@@ -2,57 +2,56 @@
 # CTKData
 #
 
-if(BUILD_TESTING)
-  # Sanity checks
-  if(DEFINED CTKData_DIR AND NOT EXISTS ${CTKData_DIR})
-    message(FATAL_ERROR "CTKData_DIR variable is defined but corresponds to non-existing directory")
-  endif()
+ctk_include_once()
+
+set(CTKData_DEPENDENCIES "")
+
+ctkMacroCheckExternalProjectDependency(CTKData)
+set(proj CTKData)
+
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
 
-  set(proj CTKData)
-  set(proj_DEPENDENCIES)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
-
-  if(CTK_SUPERBUILD)
-
-    if(NOT DEFINED CTKData_DIR)
-
-      set(revision_tag cc07f1ff391b7828459c)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
-      
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/CTKData.git"
-                          GIT_TAG ${revision_tag})
-      endif()
-
-  #    message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        UPDATE_COMMAND ""
-        CONFIGURE_COMMAND ""
-        BUILD_COMMAND ""
-        INSTALL_COMMAND ""
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(CTKData_DIR ${CMAKE_BINARY_DIR}/${proj})
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
-
-    list(APPEND CTK_SUPERBUILD_EP_VARS CTKData_DIR:PATH)
+# Sanity checks
+if(DEFINED CTKData_DIR AND NOT EXISTS ${CTKData_DIR})
+  message(FATAL_ERROR "CTKData_DIR variable is defined but corresponds to non-existing directory")
+endif()
+
+if(NOT DEFINED CTKData_DIR)
 
+  set(revision_tag cc07f1ff391b7828459c)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
   endif()
 
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/CTKData.git"
+                      GIT_TAG ${revision_tag})
+  endif()
+
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    LIST_SEPARATOR ${sep}
+    ${location_args}
+    UPDATE_COMMAND ""
+    CONFIGURE_COMMAND ""
+    BUILD_COMMAND ""
+    INSTALL_COMMAND ""
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(CTKData_DIR ${CMAKE_BINARY_DIR}/${proj})
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS CTKData_DIR:PATH)

+ 84 - 82
CMakeExternals/DCMTK.cmake

@@ -2,99 +2,101 @@
 # DCMTK
 #
 
-ctkMacroShouldAddExternalproject(DCMTK_LIBRARIES add_project)
-if(${add_project})
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED DCMTK_DIR AND NOT EXISTS ${DCMTK_DIR})
-    message(FATAL_ERROR "DCMTK_DIR variable is defined but corresponds to non-existing directory")
-  endif()
+set(DCMTK_enabling_variable DCMTK_LIBRARIES)
+set(${DCMTK_enabling_variable}_INCLUDE_DIRS DCMTK_INCLUDE_DIR)
+set(${DCMTK_enabling_variable}_FIND_PACKAGE_CMD DCMTK)
 
-  set(DCMTK_enabling_variable DCMTK_LIBRARIES)
+set(DCMTK_DEPENDENCIES "")
 
-  set(proj DCMTK)
-  set(proj_DEPENDENCIES)
+ctkMacroCheckExternalProjectDependency(DCMTK)
+set(proj DCMTK)
 
-  list(APPEND CTK_DEPENDENCIES ${proj})
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  unset(DCMTK_DIR CACHE)
+  find_package(DCMTK REQUIRED)
+endif()
 
-  set(${DCMTK_enabling_variable}_INCLUDE_DIRS DCMTK_INCLUDE_DIR)
-  set(${DCMTK_enabling_variable}_FIND_PACKAGE_CMD DCMTK)
+# Sanity checks
+if(DEFINED DCMTK_DIR AND NOT EXISTS ${DCMTK_DIR})
+  message(FATAL_ERROR "DCMTK_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-  if(CTK_SUPERBUILD)
+if(NOT DEFINED DCMTK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  set(revision_tag ae3b946f6e6231)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
+  endif()
 
-    if(NOT DEFINED DCMTK_DIR)
-      set(revision_tag ae3b946f6e6231)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
-      
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://git.dcmtk.org/dcmtk.git"
-                          GIT_TAG ${revision_tag})
-      endif()
-      
-      set(ep_project_include_arg)
-      if(CTEST_USE_LAUNCHERS)
-        set(ep_project_include_arg
-          "-DCMAKE_PROJECT_DCMTK_INCLUDE:FILEPATH=${CMAKE_ROOT}/Modules/CTestUseLaunchers.cmake")
-      endif()
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://git.dcmtk.org/dcmtk.git"
+                      GIT_TAG ${revision_tag})
+  endif()
 
-      #message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        CMAKE_GENERATOR ${gen}
-        UPDATE_COMMAND ""
-        BUILD_COMMAND ""
-        CMAKE_ARGS
-          -DDCMTK_INSTALL_BINDIR:STRING=bin/${CMAKE_CFG_INTDIR}
-          -DDCMTK_INSTALL_LIBDIR:STRING=lib/${CMAKE_CFG_INTDIR}
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          ${ep_project_include_arg}
-          -DBUILD_SHARED_LIBS:BOOL=OFF
-          -DDCMTK_WITH_DOXYGEN:BOOL=OFF
-          -DDCMTK_WITH_ZLIB:BOOL=OFF # see github issue #25
-          -DDCMTK_WITH_OPENSSL:BOOL=OFF # see github issue #25
-          -DDCMTK_WITH_PNG:BOOL=OFF # see github issue #25
-          -DDCMTK_WITH_TIFF:BOOL=OFF  # see github issue #25
-          -DDCMTK_WITH_XML:BOOL=OFF  # see github issue #25
-          -DDCMTK_WITH_ICONV:BOOL=OFF  # see github issue #178
-          -DDCMTK_FORCE_FPIC_ON_UNIX:BOOL=ON
-          -DDCMTK_OVERWRITE_WIN32_COMPILER_FLAGS:BOOL=OFF
-        )
-      set(DCMTK_DIR ${ep_install_dir})
+  set(ep_project_include_arg)
+  if(CTEST_USE_LAUNCHERS)
+    set(ep_project_include_arg
+      "-DCMAKE_PROJECT_DCMTK_INCLUDE:FILEPATH=${CMAKE_ROOT}/Modules/CTestUseLaunchers.cmake")
+  endif()
 
-  # This was used during heavy development on DCMTK itself.
-  # Disabling it for now. (It also leads to to build errors
-  # with the XCode CMake generator on Mac).
-  #
-  #    ExternalProject_Add_Step(${proj} force_rebuild
-  #      COMMENT "Force ${proj} re-build"
-  #      DEPENDERS build    # Steps that depend on this step
-  #      ALWAYS 1
-  #      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${proj}-build
-  #      DEPENDS
-  #        ${proj_DEPENDENCIES}
-  #      )
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    CMAKE_GENERATOR ${gen}
+    UPDATE_COMMAND ""
+    BUILD_COMMAND ""
+    LIST_SEPARATOR ${sep}
+    CMAKE_ARGS
+      -DDCMTK_INSTALL_BINDIR:STRING=bin/${CMAKE_CFG_INTDIR}
+      -DDCMTK_INSTALL_LIBDIR:STRING=lib/${CMAKE_CFG_INTDIR}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      ${ep_project_include_arg}
+      -DBUILD_SHARED_LIBS:BOOL=OFF
+      -DDCMTK_WITH_DOXYGEN:BOOL=OFF
+      -DDCMTK_WITH_ZLIB:BOOL=OFF # see github issue #25
+      -DDCMTK_WITH_OPENSSL:BOOL=OFF # see github issue #25
+      -DDCMTK_WITH_PNG:BOOL=OFF # see github issue #25
+      -DDCMTK_WITH_TIFF:BOOL=OFF  # see github issue #25
+      -DDCMTK_WITH_XML:BOOL=OFF  # see github issue #25
+      -DDCMTK_WITH_ICONV:BOOL=OFF  # see github issue #178
+      -DDCMTK_FORCE_FPIC_ON_UNIX:BOOL=ON
+      -DDCMTK_OVERWRITE_WIN32_COMPILER_FLAGS:BOOL=OFF
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(DCMTK_DIR ${ep_install_dir})
 
-      # Since DCMTK is statically build, there is not need to add its corresponding
-      # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+# This was used during heavy development on DCMTK itself.
+# Disabling it for now. (It also leads to to build errors
+# with the XCode CMake generator on Mac).
+#
+#    ExternalProject_Add_Step(${proj} force_rebuild
+#      COMMENT "Force ${proj} re-build"
+#      DEPENDERS build    # Steps that depend on this step
+#      ALWAYS 1
+#      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${proj}-build
+#      DEPENDS
+#        ${proj_DEPENDENCIES}
+#      )
 
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
+  # Since DCMTK is statically build, there is not need to add its corresponding
+  # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS DCMTK_DIR:PATH)
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
+endif()
 
-  endif()
+list(APPEND CTK_SUPERBUILD_EP_VARS
+  DCMTK_DIR:PATH
+  )
 
-endif()

+ 67 - 69
CMakeExternals/ITK.cmake

@@ -1,87 +1,85 @@
 #
 # ITK
 #
-ctkMacroShouldAddExternalproject(ITK_LIBRARIES add_project)
-if(${add_project})
-  # Sanity checks
-  if(DEFINED ITK_DIR AND NOT EXISTS ${ITK_DIR})
-    message(FATAL_ERROR "ITK_DIR variable is defined but corresponds to non-existing directory")
-  endif()
 
-  set(ITK_enabling_variable ITK_LIBRARIES)
+ctk_include_once()
 
-  set(proj ITK)
-  set(proj_DEPENDENCIES)
+set(ITK_enabling_variable ITK_LIBRARIES)
+set(${ITK_enabling_variable}_LIBRARY_DIRS ITK_LIBRARY_DIRS)
+set(${ITK_enabling_variable}_INCLUDE_DIRS ITK_INCLUDE_DIRS)
+set(${ITK_enabling_variable}_FIND_PACKAGE_CMD ITK)
 
-  list(APPEND CTK_DEPENDENCIES ${proj})
+set(ITK_DEPENDENCIES "")
 
-  set(${ITK_enabling_variable}_LIBRARY_DIRS ITK_LIBRARY_DIRS)
-  set(${ITK_enabling_variable}_INCLUDE_DIRS ITK_INCLUDE_DIRS)
-  set(${ITK_enabling_variable}_FIND_PACKAGE_CMD ITK)
+ctkMacroCheckExternalProjectDependency(ITK)
+set(proj ITK)
 
-  if(CTK_SUPERBUILD)
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  unset(ITK_DIR CACHE)
+  find_package(ITK REQUIRED NO_MODULE)
+endif()
 
-    if(NOT DEFINED ITK_DIR)
+# Sanity checks
+if(DEFINED ITK_DIR AND NOT EXISTS ${ITK_DIR})
+  message(FATAL_ERROR "ITK_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-      set(revision_tag "v3.20.1")
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
-      
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://itk.org/ITK.git"
-                          GIT_TAG ${revision_tag})
-      endif()
-      
-      set(ep_project_include_arg)
-      if(CTEST_USE_LAUNCHERS)
-        set(ep_project_include_arg
-          "-DCMAKE_PROJECT_ITK_INCLUDE:FILEPATH=${CMAKE_ROOT}/Modules/CTestUseLaunchers.cmake")
-      endif()
+if(NOT DEFINED ITK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
 
-  #     message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        UPDATE_COMMAND ""
-        INSTALL_COMMAND ""
-        CMAKE_GENERATOR ${gen}
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          ${ep_project_include_arg}
-          -DBUILD_EXAMPLES:BOOL=OFF
-          -DBUILD_SHARED_LIBS:BOOL=ON
-          -DITK_USE_REVIEW:BOOL=ON
-          -DITK_USE_REVIEW_STATISTICS:BOOL=ON
-          -DITK_USE_OPTIMIZED_REGISTRATION_METHODS:BOOL=ON
-          -DITK_USE_PORTABLE_ROUND:BOOL=ON
-          -DITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY:BOOL=ON
-          -DITK_USE_TRANSFORM_IO_FACTORIES:BOOL=ON
-          -DITK_LEGACY_REMOVE:BOOL=ON
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(ITK_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+  set(revision_tag "v3.20.1")
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
+  endif()
 
-      # Since the link directories associated with ITK is used, it makes sens to
-      # update CTK_EXTERNAL_LIBRARY_DIRS with its associated library output directory
-      list(APPEND CTK_EXTERNAL_LIBRARY_DIRS ${ITK_DIR}/bin)
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://itk.org/ITK.git"
+                      GIT_TAG ${revision_tag})
+  endif()
 
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
+  set(ep_project_include_arg)
+  if(CTEST_USE_LAUNCHERS)
+    set(ep_project_include_arg
+      "-DCMAKE_PROJECT_ITK_INCLUDE:FILEPATH=${CMAKE_ROOT}/Modules/CTestUseLaunchers.cmake")
+  endif()
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS ITK_DIR:PATH)
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    UPDATE_COMMAND ""
+    INSTALL_COMMAND ""
+    CMAKE_GENERATOR ${gen}
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      ${ep_project_include_arg}
+      -DBUILD_EXAMPLES:BOOL=OFF
+      -DBUILD_SHARED_LIBS:BOOL=ON
+      -DITK_USE_REVIEW:BOOL=ON
+      -DITK_USE_REVIEW_STATISTICS:BOOL=ON
+      -DITK_USE_OPTIMIZED_REGISTRATION_METHODS:BOOL=ON
+      -DITK_USE_PORTABLE_ROUND:BOOL=ON
+      -DITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY:BOOL=ON
+      -DITK_USE_TRANSFORM_IO_FACTORIES:BOOL=ON
+      -DITK_LEGACY_REMOVE:BOOL=ON
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(ITK_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
 
-  endif()
+  # Since the link directories associated with ITK is used, it makes sens to
+  # update CTK_EXTERNAL_LIBRARY_DIRS with its associated library output directory
+  list(APPEND CTK_EXTERNAL_LIBRARY_DIRS ${ITK_DIR}/bin)
 
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
 
+list(APPEND CTK_SUPERBUILD_EP_VARS ITK_DIR:PATH)

+ 44 - 42
CMakeExternals/KWStyle.cmake

@@ -2,52 +2,54 @@
 # KWStyle
 #
 
-if(CTK_USE_KWSTYLE)
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED CTK_KWSTYLE_EXECUTABLE AND NOT EXISTS ${CTK_KWSTYLE_EXECUTABLE})
-    message(FATAL_ERROR "CTK_KWSTYLE_EXECUTABLE variable is defined but corresponds to non-existing executable")
+set(KWStyle_DEPENDENCIES "")
+
+ctkMacroCheckExternalProjectDependency(KWStyle)
+set(proj KWStyle)
+
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  unset(KWSTYLE_EXECUTABLE CACHE)
+  find_program(KWSTYLE_EXECUTABLE kwstyle)
+  if(NOT KWSTYLE_EXECUTABLE)
+    message(FATAL_ERROR "Couldn't find 'kwstyle' on the system !")
   endif()
+endif()
 
-  set(proj KWStyle-CVSHEAD)
-  set(proj_DEPENDENCIES)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
-
-  if(CTK_SUPERBUILD)
-
-    if(NOT DEFINED CTK_KWSTYLE_EXECUTABLE)
-    
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      else()
-        set(location_args CVS_REPOSITORY ":pserver:anoncvs:@public.kitware.com:/cvsroot/KWStyle"
-                          CVS_MODULE "KWStyle")
-      endif()
-
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        LIST_SEPARATOR ${sep}
-        ${location_args}
-        CMAKE_GENERATOR ${gen}
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(KWSTYLE_EXECUTABLE ${ep_install_dir}/bin/KWStyle)
-
-      # Since KWStyle is an executable, there is not need to add its corresponding
-      # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
-
-    list(APPEND CTK_SUPERBUILD_EP_VARS KWSTYLE_EXECUTABLE:PATH)
+# Sanity checks
+if(DEFINED KWSTYLE_EXECUTABLE AND NOT EXISTS ${KWSTYLE_EXECUTABLE})
+  message(FATAL_ERROR "KWSTYLE_EXECUTABLE variable is defined but corresponds to non-existing executable")
+endif()
+
+if(NOT DEFINED KWSTYLE_EXECUTABLE)
 
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  else()
+    set(location_args CVS_REPOSITORY ":pserver:anoncvs:@public.kitware.com:/cvsroot/KWStyle"
+                      CVS_MODULE "KWStyle")
   endif()
 
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    CMAKE_GENERATOR ${gen}
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(KWSTYLE_EXECUTABLE ${ep_install_dir}/bin/KWStyle)
+
+  # Since KWStyle is an executable, there is not need to add its corresponding
+  # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS KWSTYLE_EXECUTABLE:PATH)

+ 52 - 56
CMakeExternals/Log4Qt.cmake

@@ -2,70 +2,66 @@
 # Log4Qt
 #
 
-ctkMacroShouldAddExternalproject(Log4Qt_LIBRARIES add_project)
-if(${add_project})
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED Log4Qt_DIR AND NOT EXISTS ${Log4Qt_DIR})
-    message(FATAL_ERROR "Log4Qt_DIR variable is defined but corresponds to non-existing directory")
-  endif()
-
-  set(Log4Qt_enabling_variable Log4Qt_LIBRARIES)
-
-  set(proj Log4Qt)
-  set(proj_DEPENDENCIES)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
-
-  set(${Log4Qt_enabling_variable}_INCLUDE_DIRS Log4Qt_INCLUDE_DIRS)
-  set(${Log4Qt_enabling_variable}_FIND_PACKAGE_CMD Log4Qt)
-
-  if(CTK_SUPERBUILD)
+set(Log4Qt_enabling_variable Log4Qt_LIBRARIES)
+set(${Log4Qt_enabling_variable}_INCLUDE_DIRS Log4Qt_INCLUDE_DIRS)
+set(${Log4Qt_enabling_variable}_FIND_PACKAGE_CMD Log4Qt)
 
-    if(NOT DEFINED Log4Qt_DIR)
+set(Log4Qt_DEPENDENCIES "")
 
-      set(revision_tag 8d3558b0f636cbf8ff83)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
+ctkMacroCheckExternalProjectDependency(Log4Qt)
+set(proj Log4Qt)
 
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/Log4Qt.git"
-                          GIT_TAG ${revision_tag})
-      endif()
-
-  #     message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        CMAKE_GENERATOR ${gen}
-        INSTALL_COMMAND ""
-        UPDATE_COMMAND ""
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(Log4Qt_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
 
-      # Since Log4Qt is statically build, there is not need to add its corresponding
-      # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+# Sanity checks
+if(DEFINED Log4Qt_DIR AND NOT EXISTS ${Log4Qt_DIR})
+  message(FATAL_ERROR "Log4Qt_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
+if(NOT DEFINED Log4Qt_DIR)
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS Log4Qt_DIR:PATH)
+  set(revision_tag 8d3558b0f636cbf8ff83)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
+  endif()
 
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/Log4Qt.git"
+                      GIT_TAG ${revision_tag})
   endif()
 
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    CMAKE_GENERATOR ${gen}
+    INSTALL_COMMAND ""
+    UPDATE_COMMAND ""
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(Log4Qt_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+
+  # Since Log4Qt is statically build, there is not need to add its corresponding
+  # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS Log4Qt_DIR:PATH)

+ 47 - 50
CMakeExternals/OpenIGTLink.cmake

@@ -2,64 +2,61 @@
 # OpenIGTLink
 #
 
-ctkMacroShouldAddExternalproject(OpenIGTLink_LIBRARIES add_project)
-if(${add_project})
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED OpenIGTLink_DIR AND NOT EXISTS ${OpenIGTLink_DIR})
-    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)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
+set(OpenIGTLink_enabling_variable OpenIGTLink_LIBRARIES)
+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)
 
-  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)
+set(OpenIGTLink_DEPENDENCIES "")
 
-  if(CTK_SUPERBUILD)
+ctkMacroCheckExternalProjectDependency(OpenIGTLink)
+set(proj OpenIGTLink)
 
-    if(NOT DEFINED OpenIGTLink_DIR)
-    
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      else()
-        set(location_args SVN_REPOSITORY "http://svn.na-mic.org/NAMICSandBox/trunk/OpenIGTLink")
-      endif()
-      
-      set(ep_project_include_arg)
-      if(CTEST_USE_LAUNCHERS)
-        set(ep_project_include_arg
-          "-DCMAKE_PROJECT_OpenIGTLink_INCLUDE:FILEPATH=${CMAKE_ROOT}/Modules/CTestUseLaunchers.cmake")
-      endif()
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  unset(OpenIGTLink_DIR CACHE)
+  find_package(OpenIGTLink REQUIRED NO_MODULE)
+endif()
 
-    #   message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        INSTALL_COMMAND ""
-        CMAKE_GENERATOR ${gen}
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          ${ep_project_include_arg}
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(OpenIGTLink_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+# Sanity checks
+if(DEFINED OpenIGTLink_DIR AND NOT EXISTS ${OpenIGTLink_DIR})
+  message(FATAL_ERROR "OpenIGTLink_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
+if(NOT DEFINED OpenIGTLink_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS OpenIGTLink_DIR:PATH)
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  else()
+    set(location_args SVN_REPOSITORY "http://svn.na-mic.org/NAMICSandBox/trunk/OpenIGTLink")
+  endif()
 
+  set(ep_project_include_arg)
+  if(CTEST_USE_LAUNCHERS)
+    set(ep_project_include_arg
+      "-DCMAKE_PROJECT_OpenIGTLink_INCLUDE:FILEPATH=${CMAKE_ROOT}/Modules/CTestUseLaunchers.cmake")
   endif()
 
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    INSTALL_COMMAND ""
+    CMAKE_GENERATOR ${gen}
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      ${ep_project_include_arg}
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(OpenIGTLink_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS OpenIGTLink_DIR:PATH)

+ 92 - 96
CMakeExternals/PythonQt.cmake

@@ -2,106 +2,102 @@
 # PythonQt
 #
 
-ctkMacroShouldAddExternalproject(PYTHONQT_LIBRARIES add_project)
-if(${add_project})
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED PYTHONQT_INSTALL_DIR AND NOT EXISTS ${PYTHONQT_INSTALL_DIR})
-    message(FATAL_ERROR "PYTHONQT_INSTALL_DIR variable is defined but corresponds to non-existing directory")
+set(PythonQt_enabling_variable PYTHONQT_LIBRARIES)
+set(${PythonQt_enabling_variable}_INCLUDE_DIRS PYTHONQT_INCLUDE_DIR PYTHON_INCLUDE_DIRS)
+set(${PythonQt_enabling_variable}_FIND_PACKAGE_CMD PythonQt)
+
+set(PythonQt_DEPENDENCIES "")
+
+ctkMacroCheckExternalProjectDependency(PythonQt)
+set(proj PythonQt)
+
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
+
+# Sanity checks
+if(DEFINED PYTHONQT_INSTALL_DIR AND NOT EXISTS ${PYTHONQT_INSTALL_DIR})
+  message(FATAL_ERROR "PYTHONQT_INSTALL_DIR variable is defined but corresponds to non-existing directory")
+endif()
+
+if(NOT DEFINED PYTHONQT_INSTALL_DIR)
+
+  set(ep_PythonQt_args)
+
+  # Should PythonQt use VTK
+  if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+    list(APPEND proj_DEPENDENCIES VTK)
+  endif()
+
+  # Enable Qt libraries PythonQt wrapping if required
+  set(qtlibs core gui network opengl sql svg uitools webkit xml)
+  foreach(qtlib All ${qtlibs})
+    string(TOUPPER ${qtlib} qtlib_uppercase)
+    list(APPEND ep_PythonQt_args -DPythonQt_Wrap_Qt${qtlib}:BOOL=${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QT${qtlib_uppercase}})
+  endforeach()
+
+  # Force wrap option to ON if WRAP_QTALL was set to ON
+  if(${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QTALL})
+    foreach(qtlib ${qtlibs})
+      string(TOUPPER ${qtlib} qtlib_uppercase)
+      set(CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QT${qtlib_uppercase} ON CACHE BOOL "Enable Scripting/Python/Core Library PYTHONQT_WRAP_QT${qtlib_uppercase} option" FORCE)
+    endforeach()
   endif()
 
-  set(PythonQt_enabling_variable PYTHONQT_LIBRARIES)
-
-  set(proj PythonQt)
-  set(proj_DEPENDENCIES)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
-
-  set(${PythonQt_enabling_variable}_INCLUDE_DIRS PYTHONQT_INCLUDE_DIR PYTHON_INCLUDE_DIRS)
-  set(${PythonQt_enabling_variable}_FIND_PACKAGE_CMD PythonQt)
-
-  if(CTK_SUPERBUILD)
-
-    if(NOT DEFINED PYTHONQT_INSTALL_DIR)
-    #   message(STATUS "Adding project:${proj}")
-
-      set(ep_PythonQt_args)
-
-      # Should PythonQt use VTK
-      if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-        list(APPEND proj_DEPENDENCIES VTK)
-      endif()
-
-      # Enable Qt libraries PythonQt wrapping if required
-      set(qtlibs core gui network opengl sql svg uitools webkit xml)
-      foreach(qtlib All ${qtlibs})
-        string(TOUPPER ${qtlib} qtlib_uppercase)
-        list(APPEND ep_PythonQt_args -DPythonQt_Wrap_Qt${qtlib}:BOOL=${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QT${qtlib_uppercase}})
-      endforeach()
-
-      # Force wrap option to ON if WRAP_QTALL was set to ON
-      if(${CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QTALL})
-        foreach(qtlib ${qtlibs})
-          string(TOUPPER ${qtlib} qtlib_uppercase)
-          set(CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QT${qtlib_uppercase} ON CACHE BOOL "Enable Scripting/Python/Core Library PYTHONQT_WRAP_QT${qtlib_uppercase} option" FORCE)
-        endforeach()
-      endif()
-
-      # Python is required
-      find_package(PythonLibs)
-      if(NOT PYTHONLIBS_FOUND)
-        message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
-      endif()
-
-      set(revision_tag e1f1c77d9675c3c5fb1cba19d2a32ace483eda2c)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
-      
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/PythonQt.git"
-                          GIT_TAG ${revision_tag})
-      endif()
-
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        CMAKE_GENERATOR ${gen}
-        UPDATE_COMMAND ""
-        BUILD_COMMAND ""
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
-          -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
-          -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
-          ${ep_PythonQt_args}
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(PYTHONQT_INSTALL_DIR ${ep_install_dir})
-
-      # Since the full path of PythonQt library is used, there is not need to add
-      # its corresponding library output directory to CTK_EXTERNAL_LIBRARY_DIRS
-
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
-
-    list(APPEND CTK_SUPERBUILD_EP_VARS
-      PYTHONQT_INSTALL_DIR:PATH
-      PYTHON_EXECUTABLE:FILEPATH # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined
-      PYTHON_INCLUDE_DIR:PATH # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined
-      PYTHON_LIBRARY:FILEPATH # FindPythonQt expects PYTHON_LIBRARY variable to be defined
-      )
+  # Python is required
+  find_package(PythonLibs)
+  if(NOT PYTHONLIBS_FOUND)
+    message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
+  endif()
 
+  set(revision_tag e1f1c77d9675c3c5fb1cba19d2a32ace483eda2c)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
   endif()
 
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/PythonQt.git"
+                      GIT_TAG ${revision_tag})
+  endif()
+
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    CMAKE_GENERATOR ${gen}
+    UPDATE_COMMAND ""
+    BUILD_COMMAND ""
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+      -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
+      -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
+      ${ep_PythonQt_args}
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(PYTHONQT_INSTALL_DIR ${ep_install_dir})
+
+  # Since the full path of PythonQt library is used, there is not need to add
+  # its corresponding library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS
+  PYTHONQT_INSTALL_DIR:PATH
+  PYTHON_EXECUTABLE:FILEPATH # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined
+  PYTHON_INCLUDE_DIR:PATH # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined
+  PYTHON_LIBRARY:FILEPATH # FindPythonQt expects PYTHON_LIBRARY variable to be defined
+  )

+ 46 - 87
CMakeExternals/PythonQtGenerator.cmake

@@ -2,96 +2,55 @@
 # PythonQtGenerator
 #
 
-if(CTK_WRAP_PYTHONQT_FULL)
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED PYTHONQTGENERATOR_EXECUTABLE AND NOT EXISTS ${PYTHONQTGENERATOR_EXECUTABLE})
-    message(FATAL_ERROR "PYTHONQTGENERATOR_EXECUTABLE variable is defined but corresponds to non-existing executable")
-  endif()
-
-  set(proj PythonQtGenerator)
-  set(proj_DEPENDENCIES)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
-
-  if(CTK_SUPERBUILD)
-
-    if(NOT DEFINED PYTHONQTGENERATOR_EXECUTABLE)
-
-      #
-      # PythonQtGenerator is the tool allowing to generate the PythonQt decorators using
-      # typesystem xml files. If called without any option, it will generate the bindings for Qt.
-      #
-      # See http://www.pyside.org/docs/apiextractor/typesystem.html
-      # See http://doc.trolltech.com/qtjambi-4.5.2_01/com/trolltech/qt/qtjambi-typesystem.html
-      # See http://qt.gitorious.org/qt-labs/qtscriptgenerator
-      #
-
-    #   message(STATUS "Adding project:${proj}")
-
-      #
-      # If directory PythonQt already exists, the corresponding project will
-      # be cloned. Since PythonQt and PythonQtGenerator source code are hosted
-      # on the same repository, we will assume that if the directory PythonQt
-      # exists, the generator code will also be available.
-      #
-      if(EXISTS ${CMAKE_BINARY_DIR}/PythonQt)
-        #message(STATUS "ExternalProject/PythonQtGenerator: PythonQt already added as ExternalProject")
-        ExternalProject_Add(${proj}
-          SOURCE_DIR ${CMAKE_BINARY_DIR}/PythonQt/generator
-          BINARY_DIR ${proj}-build
-          PREFIX ${proj}${ep_suffix}
-          DOWNLOAD_COMMAND ""
-          CMAKE_GENERATOR ${gen}
-          INSTALL_COMMAND ""
-          CMAKE_CACHE_ARGS
-            ${ep_common_cache_args}
-            -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
-          DEPENDS
-            "PythonQt" # To make sure the generator code is checked out, let's depend on PythonQt
-          )
-      else()
-
-        set(revision_tag 2114405a47836b3fb16a3f66fec6a02184f32e71)
-        if(${proj}_REVISION_TAG)
-          set(revision_tag ${${proj}_REVISION_TAG})
-        endif()
-        
-        set(location_args )
-        if(${proj}_URL)
-          set(location_args URL ${${proj}_URL})
-        elseif(${proj}_GIT_REPOSITORY)
-          set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                            GIT_TAG ${revision_tag})
-        else()
-          set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/PythonQt.git"
-                            GIT_TAG ${revision_tag})
-        endif()
-
-        #message(STATUS "ExternalProject/PythonQtGenerator: PythonQt is NOT an ExternalProject")
-        ExternalProject_Add(${proj}
-          SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-          BINARY_DIR ${proj}-build
-          PREFIX ${proj}${ep_suffix}
-          ${location_args}
-          CMAKE_GENERATOR ${gen}
-          UPDATE_COMMAND ""
-          INSTALL_COMMAND ""
-          CMAKE_CACHE_ARGS
-            ${ep_common_cache_args}
-            -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
-          )
-      endif()
-
-      set(PYTHONQTGENERATOR_EXECUTABLE ${CMAKE_BINARY_DIR}/PythonQtGenerator-build/PythonQtGenerator)
-
-      # Since PythonQtGenerator is an executable, there is no need to add its corresponding
-      # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+# Sanity checks
+if(DEFINED PYTHONQTGENERATOR_EXECUTABLE AND NOT EXISTS ${PYTHONQTGENERATOR_EXECUTABLE})
+  message(FATAL_ERROR "PYTHONQTGENERATOR_EXECUTABLE variable is defined but corresponds to non-existing executable")
+endif()
 
-    endif()
+set(PythonQtGenerator_DEPENDENCIES PythonQt)
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS PYTHONQTGENERATOR_EXECUTABLE:FILEPATH)
+ctkMacroCheckExternalProjectDependency(PythonQtGenerator)
+set(proj PythonQtGenerator)
 
-  endif()
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
 
+if(NOT DEFINED PYTHONQTGENERATOR_EXECUTABLE)
+
+  #
+  # PythonQtGenerator is the tool allowing to generate the PythonQt decorators using
+  # typesystem xml files. If called without any option, it will generate the bindings for Qt.
+  #
+  # See http://www.pyside.org/docs/apiextractor/typesystem.html
+  # See http://doc.trolltech.com/qtjambi-4.5.2_01/com/trolltech/qt/qtjambi-typesystem.html
+  # See http://qt.gitorious.org/qt-labs/qtscriptgenerator
+  #
+
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/PythonQt/generator
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    DOWNLOAD_COMMAND ""
+    CMAKE_GENERATOR ${gen}
+    INSTALL_COMMAND ""
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+    DEPENDS
+      ${${proj}_DEPENDENCIES} # To make sure the generator code is checked out, let's depend on PythonQt
+    )
+
+  set(PYTHONQTGENERATOR_EXECUTABLE ${CMAKE_BINARY_DIR}/PythonQtGenerator-build/PythonQtGenerator)
+
+  # Since PythonQtGenerator is an executable, there is no need to add its corresponding
+  # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS PYTHONQTGENERATOR_EXECUTABLE:FILEPATH)

+ 53 - 57
CMakeExternals/QtSOAP.cmake

@@ -2,72 +2,68 @@
 # QtSOAP
 #
 
-ctkMacroShouldAddExternalproject(QtSOAP_LIBRARIES add_project)
-if(${add_project})
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED QtSOAP_DIR AND NOT EXISTS ${QtSOAP_DIR})
-    message(FATAL_ERROR "QtSOAP_DIR variable is defined but corresponds to non-existing directory")
-  endif()
-
-  set(QtSOAP_enabling_variable QtSOAP_LIBRARIES)
-
-  set(proj QtSOAP)
-  set(proj_DEPENDENCIES)
+set(QtSOAP_enabling_variable QtSOAP_LIBRARIES)
+set(${QtSOAP_enabling_variable}_LIBRARY_DIRS QtSOAP_LIBRARY_DIRS)
+set(${QtSOAP_enabling_variable}_INCLUDE_DIRS QtSOAP_INCLUDE_DIRS)
+set(${QtSOAP_enabling_variable}_FIND_PACKAGE_CMD QtSOAP)
 
-  list(APPEND CTK_DEPENDENCIES ${proj})
+set(QtSOAP_DEPENDENCIES "")
 
-  set(${QtSOAP_enabling_variable}_LIBRARY_DIRS QtSOAP_LIBRARY_DIRS)
-  set(${QtSOAP_enabling_variable}_INCLUDE_DIRS QtSOAP_INCLUDE_DIRS)
-  set(${QtSOAP_enabling_variable}_FIND_PACKAGE_CMD QtSOAP)
+ctkMacroCheckExternalProjectDependency(QtSOAP)
+set(proj QtSOAP)
 
-  if(CTK_SUPERBUILD)
-
-    if(NOT DEFINED QtSOAP_DIR)
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
 
-      set(revision_tag 3e49f7a4a1a684779eb66215bad46140d9153731)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
-      
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/QtSOAP.git"
-                          GIT_TAG ${revision_tag})
-      endif()
+# Sanity checks
+if(DEFINED QtSOAP_DIR AND NOT EXISTS ${QtSOAP_DIR})
+  message(FATAL_ERROR "QtSOAP_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-      #     message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        CMAKE_GENERATOR ${gen}
-        UPDATE_COMMAND ""
-        INSTALL_COMMAND ""
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:STRING=${CTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}
-          -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(QtSOAP_DIR "${CMAKE_BINARY_DIR}/${proj}-build")
+if(NOT DEFINED QtSOAP_DIR)
 
-      # Since the QtSOAP dll is created directly in CTK-build/bin, there is not need to add a
-      # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+  set(revision_tag 3e49f7a4a1a684779eb66215bad46140d9153731)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
+  endif()
 
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/QtSOAP.git"
+                      GIT_TAG ${revision_tag})
+  endif()
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS QtSOAP_DIR:PATH)
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    CMAKE_GENERATOR ${gen}
+    UPDATE_COMMAND ""
+    INSTALL_COMMAND ""
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:STRING=${CTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+      -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(QtSOAP_DIR "${CMAKE_BINARY_DIR}/${proj}-build")
 
-  endif()
+  # Since the QtSOAP dll is created directly in CTK-build/bin, there is not need to add a
+  # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
 
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS QtSOAP_DIR:PATH)

+ 63 - 67
CMakeExternals/QtTesting.cmake

@@ -1,83 +1,79 @@
 #
 # QtTesting
 #
-set(QtTesting_DEPENDS)
-if(CTK_USE_QTTESTING)
-
-  # Sanity checks
-  if(DEFINED QtTesting_DIR AND NOT EXISTS ${QtTesting_DIR})
-    message(FATAL_ERROR "QtTesting_DIR variable is defined but corresponds to non-existing directory")
-  endif()
 
-  set(proj QtTesting)
-  set(proj_DEPENDENCIES)
-  
-  list(APPEND CTK_DEPENDENCIES ${proj})
+ctk_include_once()
 
-  set(QtTesting_DEPENDS ${proj})
-  
-  set(${QtTesting_enabling_variable}_INCLUDE_DIRS QtTesting_INCLUDE_DIRS)
-  set(${QtTesting_enabling_variable}_FIND_PACKAGE_CMD QtTesting)
-  
-  if(CTK_SUPERBUILD)
+set(QtTesting_DEPENDS)
 
-    if(NOT DEFINED QtTesting_DIR)
+set(QtTesting_DEPENDENCIES "")
 
-      set(revision_tag 7dbef1003157941e7315220f53cf4e17d78b5e28)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
+ctkMacroCheckExternalProjectDependency(QtTesting)
+set(proj QtTesting)
 
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://paraview.org/QtTesting.git"
-                          GIT_TAG ${revision_tag})
-      endif()
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
 
-      # Set CMake OSX variable to pass down the external project
-      set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS)
-      if(APPLE)
-        list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS
-          -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
-          -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
-          -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
-      endif()
+# Sanity checks
+if(DEFINED QtTesting_DIR AND NOT EXISTS ${QtTesting_DIR})
+  message(FATAL_ERROR "QtTesting_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-      message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        CMAKE_GENERATOR ${gen}
-        UPDATE_COMMAND ""
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          -DBUILD_SHARED_LIBS:BOOL=ON
-          -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(QtTesting_INSTALL_DIR ${ep_install_dir})
-      set(QtTesting_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+if(NOT DEFINED QtTesting_DIR)
 
-      # Since QtTesting is statically build, there is not need to add its corresponding
-      # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+  set(revision_tag 7dbef1003157941e7315220f53cf4e17d78b5e28)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
+  endif()
 
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://paraview.org/QtTesting.git"
+                      GIT_TAG ${revision_tag})
+  endif()
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS
-      QtTesting_INSTALL_DIR:PATH
-      QtTesting_DIR:PATH
-      )
-    
+  # Set CMake OSX variable to pass down the external project
+  set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS)
+  if(APPLE)
+    list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS
+      -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
+      -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
+      -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
   endif()
 
+  message(STATUS "Adding project:${proj}")
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    CMAKE_GENERATOR ${gen}
+    UPDATE_COMMAND ""
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      -DBUILD_SHARED_LIBS:BOOL=ON
+      -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(QtTesting_INSTALL_DIR ${ep_install_dir})
+  set(QtTesting_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+
+  # Since QtTesting is statically build, there is not need to add its corresponding
+  # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS
+  QtTesting_INSTALL_DIR:PATH
+  QtTesting_DIR:PATH
+  )

+ 76 - 79
CMakeExternals/VTK.cmake

@@ -2,96 +2,93 @@
 # VTK
 #
 
-ctkMacroShouldAddExternalproject(VTK_LIBRARIES add_project)
-if(${add_project} OR CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-  # Sanity checks
-  if(DEFINED VTK_DIR AND NOT EXISTS ${VTK_DIR})
-    message(FATAL_ERROR "VTK_DIR variable is defined but corresponds to non-existing directory")
-  endif()
-
-  set(VTK_enabling_variable VTK_LIBRARIES)
-
-  set(proj VTK)
-  set(proj_DEPENDENCIES)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
-
-  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)
+ctk_include_once()
 
-  if(CTK_SUPERBUILD)
+set(VTK_enabling_variable VTK_LIBRARIES)
+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)
 
-    set(additional_vtk_cmakevars )
-    if(MINGW)
-      list(APPEND additional_vtk_cmakevars -DCMAKE_USE_PTHREADS:BOOL=OFF)
-    endif()
+set(VTK_DEPENDENCIES "")
 
-    if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-      list(APPEND additional_vtk_cmakevars
-        -DPYTHON_EXECUTABLE:PATH=${PYTHON_EXECUTABLE}
-        -DPYTHON_LIBRARIES:FILEPATH=${PYTHON_LIBRARIES}
-        -DPYTHON_DEBUG_LIBRARIES:FILEPATH=${PYTHON_DEBUG_LIBRARIES}
-        )
-    endif()
+ctkMacroCheckExternalProjectDependency(VTK)
+set(proj VTK)
 
-    if(NOT DEFINED VTK_DIR)
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  unset(VTK_DIR CACHE)
+  find_package(VTK REQUIRED NO_MODULE)
+endif()
 
-      set(revision_tag v5.10.0)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
-      
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://vtk.org/VTK.git"
-                          GIT_TAG ${revision_tag})
-      endif()
+# Sanity checks
+if(DEFINED VTK_DIR AND NOT EXISTS ${VTK_DIR})
+  message(FATAL_ERROR "VTK_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-  #     message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        UPDATE_COMMAND ""
-        INSTALL_COMMAND ""
-        CMAKE_GENERATOR ${gen}
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          ${additional_vtk_cmakevars}
-          -DVTK_WRAP_TCL:BOOL=OFF
-          -DVTK_USE_TK:BOOL=OFF
-          -DVTK_WRAP_PYTHON:BOOL=${CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK}
-          -DVTK_WRAP_JAVA:BOOL=OFF
-          -DBUILD_SHARED_LIBS:BOOL=ON
-          -DDESIRED_QT_VERSION:STRING=4
-          -DVTK_USE_GUISUPPORT:BOOL=ON
-          -DVTK_USE_QVTK_QTOPENGL:BOOL=ON
-          -DVTK_USE_QT:BOOL=ON
-          -DVTK_LEGACY_REMOVE:BOOL=ON
-          -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(VTK_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+if(NOT DEFINED VTK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
 
-      # Since the link directories associated with VTK is used, it makes sens to
-      # update CTK_EXTERNAL_LIBRARY_DIRS with its associated library output directory
-      list(APPEND CTK_EXTERNAL_LIBRARY_DIRS ${VTK_DIR}/bin)
+  set(revision_tag v5.10.0)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
+  endif()
 
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://vtk.org/VTK.git"
+                      GIT_TAG ${revision_tag})
+  endif()
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS VTK_DIR:PATH)
+  set(additional_vtk_cmakevars )
+  if(MINGW)
+    list(APPEND additional_vtk_cmakevars -DCMAKE_USE_PTHREADS:BOOL=OFF)
+  endif()
 
+  if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+    list(APPEND additional_vtk_cmakevars
+      -DPYTHON_EXECUTABLE:PATH=${PYTHON_EXECUTABLE}
+      -DPYTHON_LIBRARIES:FILEPATH=${PYTHON_LIBRARIES}
+      -DPYTHON_DEBUG_LIBRARIES:FILEPATH=${PYTHON_DEBUG_LIBRARIES}
+      )
   endif()
 
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    UPDATE_COMMAND ""
+    INSTALL_COMMAND ""
+    CMAKE_GENERATOR ${gen}
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      ${additional_vtk_cmakevars}
+      -DVTK_WRAP_TCL:BOOL=OFF
+      -DVTK_USE_TK:BOOL=OFF
+      -DVTK_WRAP_PYTHON:BOOL=${CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK}
+      -DVTK_WRAP_JAVA:BOOL=OFF
+      -DBUILD_SHARED_LIBS:BOOL=ON
+      -DDESIRED_QT_VERSION:STRING=4
+      -DVTK_USE_GUISUPPORT:BOOL=ON
+      -DVTK_USE_QVTK_QTOPENGL:BOOL=ON
+      -DVTK_USE_QT:BOOL=ON
+      -DVTK_LEGACY_REMOVE:BOOL=ON
+      -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(VTK_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+
+  # Since the link directories associated with VTK is used, it makes sens to
+  # update CTK_EXTERNAL_LIBRARY_DIRS with its associated library output directory
+  list(APPEND CTK_EXTERNAL_LIBRARY_DIRS ${VTK_DIR}/bin)
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
 
+list(APPEND CTK_SUPERBUILD_EP_VARS VTK_DIR:PATH)

+ 49 - 49
CMakeExternals/XIP.cmake

@@ -2,57 +2,57 @@
 # XIP
 #
 
-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()
+ctk_include_once()
+
+set(XIP_enabling_variable XIP_LIBRARIES)
+set(${XIP_enabling_variable}_LIBRARY_DIRS XIP_LIBRARY_DIRS)
+set(${XIP_enabling_variable}_INCLUDE_DIRS XIP_INCLUDE_DIRS)
+set(${XIP_enabling_variable}_FIND_PACKAGE_CMD XIP)
+
+set(XIP_DEPENDENCIES "")
+
+ctkMacroCheckExternalProjectDependency(XIP)
+set(proj XIP)
+
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
+
+# 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)
-  set(proj_DEPENDENCIES)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
-
-  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)
-
-  if(CTK_SUPERBUILD)
-
-    if(NOT DEFINED XIP_DIR)
-    
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      else()
-        set(location_args SVN_REPOSITORY "https://collab01a.scr.siemens.com/svn/xip/releases/latest"
-                          SVN_USERNAME "anonymous")
-      endif()
-
-      #   message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        INSTALL_COMMAND ""
-        CMAKE_GENERATOR ${gen}
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          -DHAS_VTK:BOOL=OFF
-          -DHAS_ITK:BOOL=OFF
-        )
-      set(XIP_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
-
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
-
-    list(APPEND CTK_SUPERBUILD_EP_VARS XIP_DIR:PATH)
 
+if(NOT DEFINED XIP_DIR)
+
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  else()
+    set(location_args SVN_REPOSITORY "https://collab01a.scr.siemens.com/svn/xip/releases/latest"
+                      SVN_USERNAME "anonymous")
   endif()
 
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    INSTALL_COMMAND ""
+    CMAKE_GENERATOR ${gen}
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      -DHAS_VTK:BOOL=OFF
+      -DHAS_ITK:BOOL=OFF
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(XIP_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS XIP_DIR:PATH)

+ 52 - 56
CMakeExternals/ZMQ.cmake

@@ -2,70 +2,66 @@
 # ZMQ
 #
 
-ctkMacroShouldAddExternalproject(ZMQ_LIBRARIES add_project)
-if(${add_project})
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED ZMQ_DIR AND NOT EXISTS ${ZMQ_DIR})
-    message(FATAL_ERROR "ZMQ_DIR variable is defined but corresponds to non-existing directory")
-  endif()
-
-  set(ZMQ_enabling_variable ZMQ_LIBRARIES)
-
-  set(proj ZMQ)
-  set(proj_DEPENDENCIES)
-
-  list(APPEND CTK_DEPENDENCIES ${proj})
-
-  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)
+set(ZMQ_enabling_variable ZMQ_LIBRARIES)
+set(${ZMQ_enabling_variable}_LIBRARY_DIRS ZMQ_LIBRARY_DIRS)
+set(${ZMQ_enabling_variable}_INCLUDE_DIRS ZMQ_INCLUDE_DIRS)
+set(${ZMQ_enabling_variable}_FIND_PACKAGE_CMD ZMQ)
 
-  if(CTK_SUPERBUILD)
+set(ZMQ_DEPENDENCIES "")
 
-    if(NOT DEFINED ZMQ_DIR)
+ctkMacroCheckExternalProjectDependency(ZMQ)
+set(proj ZMQ)
 
-      set(revision_tag d2c2f96b49ed3835a47e)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
-      
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://github.com/PatrickCheng/zeromq2.git"
-                          GIT_TAG ${revision_tag})
-      endif()
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
 
-    #   message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        UPDATE_COMMAND ""
-        INSTALL_COMMAND ""
-        CMAKE_GENERATOR ${gen}
-        CMAKE_CACHE_ARGS
-          ${ep_common_cache_args}
-          -DBUILD_SHARED_LIBS:BOOL=ON
-          -DZMQ_BUILD_DEVICES:BOOL=ON
-          -DZMQ_BUILD_PERFORMANCE_TESTS:BOOL=ON
-         DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(ZMQ_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+# Sanity checks
+if(DEFINED ZMQ_DIR AND NOT EXISTS ${ZMQ_DIR})
+  message(FATAL_ERROR "ZMQ_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
+if(NOT DEFINED ZMQ_DIR)
 
-    list(APPEND CTK_SUPERBUILD_EP_VARS ZMQ_DIR:PATH)
+  set(revision_tag d2c2f96b49ed3835a47e)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
+  endif()
 
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://github.com/PatrickCheng/zeromq2.git"
+                      GIT_TAG ${revision_tag})
   endif()
 
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    UPDATE_COMMAND ""
+    INSTALL_COMMAND ""
+    CMAKE_GENERATOR ${gen}
+    LIST_SEPARATOR ${sep}
+    CMAKE_CACHE_ARGS
+      ${ep_common_cache_args}
+      -DBUILD_SHARED_LIBS:BOOL=ON
+      -DZMQ_BUILD_DEVICES:BOOL=ON
+      -DZMQ_BUILD_PERFORMANCE_TESTS:BOOL=ON
+     DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(ZMQ_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
+
+list(APPEND CTK_SUPERBUILD_EP_VARS ZMQ_DIR:PATH)

+ 55 - 59
CMakeExternals/qxmlrpc.cmake

@@ -2,70 +2,66 @@
 # qxmlrpc
 #
 
-ctkMacroShouldAddExternalproject(qxmlrpc_LIBRARY add_project)
-if(${add_project})
+ctk_include_once()
 
-  # Sanity checks
-  if(DEFINED qxmlrpc_DIR AND NOT EXISTS ${qxmlrpc_DIR})
-    message(FATAL_ERROR "qxmlrpc_DIR variable is defined but corresponds to non-existing directory")
-  endif()
-  
-  set(qxmlrpc_enabling_variable qxmlrpc_LIBRARY)
-  
-  set(proj qxmlrpc)
-  set(proj_DEPENDENCIES)
+set(qxmlrpc_enabling_variable qxmlrpc_LIBRARY)
+set(${qxmlrpc_enabling_variable}_LIBRARY_DIRS qxmlrpc_LIBRARY_DIRS)
+set(${qxmlrpc_enabling_variable}_INCLUDE_DIRS qxmlrpc_INCLUDE_DIRS)
+set(${qxmlrpc_enabling_variable}_FIND_PACKAGE_CMD qxmlrpc)
+
+set(qxmlrpc_DEPENDENCIES "")
+
+ctkMacroCheckExternalProjectDependency(qxmlrpc)
+set(proj qxmlrpc)
+
+if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
+  message(FATAL_ERROR "Enabling ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} is not supported !")
+endif()
 
-  list(APPEND CTK_DEPENDENCIES ${proj})
+# Sanity checks
+if(DEFINED qxmlrpc_DIR AND NOT EXISTS ${qxmlrpc_DIR})
+  message(FATAL_ERROR "qxmlrpc_DIR variable is defined but corresponds to non-existing directory")
+endif()
 
-  set(${qxmlrpc_enabling_variable}_LIBRARY_DIRS qxmlrpc_LIBRARY_DIRS)
-  set(${qxmlrpc_enabling_variable}_INCLUDE_DIRS qxmlrpc_INCLUDE_DIRS)
-  set(${qxmlrpc_enabling_variable}_FIND_PACKAGE_CMD qxmlrpc)
-  
-  if(CTK_SUPERBUILD)
+if(NOT DEFINED qxmlrpc_DIR)
 
-    if(NOT DEFINED qxmlrpc_DIR)
-    
-      set(revision_tag 1d46d0e24d68049e726269dd3c6438671cd693ea)
-      if(${proj}_REVISION_TAG)
-        set(revision_tag ${${proj}_REVISION_TAG})
-      endif()
-      
-      set(location_args )
-      if(${proj}_URL)
-        set(location_args URL ${${proj}_URL})
-      elseif(${proj}_GIT_REPOSITORY)
-        set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
-                          GIT_TAG ${revision_tag})
-      else()
-        set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/qxmlrpc.git"
-                          GIT_TAG ${revision_tag})
-      endif()
-      
-      #message(STATUS "Adding project:${proj}")
-      ExternalProject_Add(${proj}
-        SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
-        BINARY_DIR ${proj}-build
-        PREFIX ${proj}${ep_suffix}
-        ${location_args}
-        CMAKE_GENERATOR ${gen}
-        INSTALL_COMMAND ""
-        CMAKE_ARGS
-          ${ep_common_cache_args}
-          -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
-        DEPENDS
-          ${proj_DEPENDENCIES}
-        )
-      set(qxmlrpc_DIR "${CMAKE_BINARY_DIR}/${proj}-build")
-      
-      # Since qxmlrpc is statically build, there is not need to add its corresponding 
-      # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
-    
-    else()
-      ctkMacroEmptyExternalproject(${proj} "${proj_DEPENDENCIES}")
-    endif()
-    
-     list(APPEND CTK_SUPERBUILD_EP_VARS qxmlrpc_DIR:PATH)
+  set(revision_tag 1d46d0e24d68049e726269dd3c6438671cd693ea)
+  if(${proj}_REVISION_TAG)
+    set(revision_tag ${${proj}_REVISION_TAG})
+  endif()
 
+  set(location_args )
+  if(${proj}_URL)
+    set(location_args URL ${${proj}_URL})
+  elseif(${proj}_GIT_REPOSITORY)
+    set(location_args GIT_REPOSITORY ${${proj}_GIT_REPOSITORY}
+                      GIT_TAG ${revision_tag})
+  else()
+    set(location_args GIT_REPOSITORY "${git_protocol}://github.com/commontk/qxmlrpc.git"
+                      GIT_TAG ${revision_tag})
   endif()
+
+  ExternalProject_Add(${proj}
+    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+    BINARY_DIR ${proj}-build
+    PREFIX ${proj}${ep_suffix}
+    ${location_args}
+    CMAKE_GENERATOR ${gen}
+    INSTALL_COMMAND ""
+    LIST_SEPARATOR ${sep}
+    CMAKE_ARGS
+      ${ep_common_cache_args}
+      -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
+    DEPENDS
+      ${${proj}_DEPENDENCIES}
+    )
+  set(qxmlrpc_DIR "${CMAKE_BINARY_DIR}/${proj}-build")
+
+  # Since qxmlrpc is statically build, there is not need to add its corresponding
+  # library output directory to CTK_EXTERNAL_LIBRARY_DIRS
+
+else()
+  ctkMacroEmptyExternalproject(${proj} "${${proj}_DEPENDENCIES}")
 endif()
 
+list(APPEND CTK_SUPERBUILD_EP_VARS qxmlrpc_DIR:PATH)

+ 23 - 8
CMakeLists.txt

@@ -163,6 +163,7 @@ set(CTK_CMAKE_UTILITIES_DIR ${CTK_SOURCE_DIR}/Utilities/CMake)
 # CMake function(s) and macro(s)
 #
 foreach(file
+  CMake/ctkListToString.cmake
   CMake/ctkMacroParseArguments.cmake
   CMake/ctkMacroSetPaths.cmake
   CMake/ctkMacroListFilter.cmake
@@ -838,14 +839,10 @@ ctkFunctionGenerateProjectXml(${CTK_BINARY_DIR} ${PROJECT_NAME} "${target_direct
 #-----------------------------------------------------------------------------
 # CTK dependencies - Projects should be TOPOLOGICALLY ordered
 #-----------------------------------------------------------------------------
-set(CTK_POSSIBLE_DEPENDENCIES
-  CTKData
-  QtTesting
+set(CTK_DEPENDENCIES
   Log4Qt
-  KWStyle
   VTK
   PythonQt
-  PythonQtGenerator # Should be added after PythonQt - See comment in CMakeExternals/PythonQtGenerator.cmake
   DCMTK
   ZMQ
   QtSOAP
@@ -855,6 +852,22 @@ set(CTK_POSSIBLE_DEPENDENCIES
   ITK
   )
 
+if(BUILD_TESTING)
+  list(APPEND CTK_DEPENDENCIES CTKData)
+endif()
+
+if(CTK_USE_KWSTYLE)
+  list(APPEND CTK_DEPENDENCIES KWStyle)
+endif()
+
+if(CTK_USE_QTTESTING)
+  list(APPEND CTK_DEPENDENCIES QtTesting)
+endif()
+
+if(CTK_WRAP_PYTHONQT_FULL)
+  list(APPEND CTK_DEPENDENCIES PythonQtGenerator)
+endif()
+
 #-----------------------------------------------------------------------------
 # Check out the ExternalProjectsContrib repository
 if(CTK_USE_CONTRIBUTED_PLUGINS)
@@ -862,19 +875,18 @@ if(CTK_USE_CONTRIBUTED_PLUGINS)
     ctkFunctionCheckoutRepo(
       NAME ExternalProjectsContrib
       GIT_URL github.com/commontk/ExternalProjectsContrib.git
-      GIT_TAG c15781914f
+      GIT_TAG 4710b4b
       )
   endif()
 
   file(GLOB _contrib_scripts ${ExternalProjectsContrib_DIR}/*.cmake)
   foreach(_contrib_script ${_contrib_scripts})
     get_filename_component(_script_name ${_contrib_script} NAME_WE)
-    list(APPEND CTK_POSSIBLE_DEPENDENCIES ${_script_name})
+    list(APPEND CTK_DEPENDENCIES ${_script_name})
     set(${_script_name}_FILEPATH ${_contrib_script})
   endforeach()
 endif()
 
-set(CTK_DEPENDENCIES) # This variable will contain the list of required CTK dependencies
 include(CMake/ctkBlockCheckDependencies.cmake)
 
 #-----------------------------------------------------------------------------
@@ -886,6 +898,9 @@ if(CTK_SUPERBUILD)
   return()
 endif()
 
+if(BUILD_TESTING)
+  add_subdirectory(CMake/Testing)
+endif()
 
 #-----------------------------------------------------------------------------
 # Expand variables containing include and library directories for external projects

+ 5 - 1
SuperBuild.cmake

@@ -114,7 +114,10 @@ foreach(arg ${CTK_SUPERBUILD_EP_VARS})
   set(target_info_list ${target_info_list})
   list(GET varname_and_vartype 0 _varname)
   list(GET varname_and_vartype 1 _vartype)
-  list(APPEND CTK_SUPERBUILD_EP_ARGS -D${_varname}:${_vartype}=${${_varname}})
+  # Separate list item with <sep>
+  set(ep_arg_as_string "")
+  ctk_list_to_string(${sep} "${${_varname}}" ep_arg_as_string)
+  list(APPEND CTK_SUPERBUILD_EP_ARGS -D${_varname}:${_vartype}=${ep_arg_as_string})
   list(APPEND CTK_SUPERBUILD_EP_VARNAMES ${_varname})
 endforeach()
 string(REPLACE ";" "^" CTK_SUPERBUILD_EP_VARNAMES "${CTK_SUPERBUILD_EP_VARNAMES}")
@@ -140,6 +143,7 @@ set(proj CTK-Configure)
 ExternalProject_Add(${proj}
   DOWNLOAD_COMMAND ""
   CMAKE_GENERATOR ${gen}
+  LIST_SEPARATOR ${sep}
   CMAKE_ARGS
     -DCTK_SUPERBUILD:BOOL=OFF
     -DCTK_SUPERBUILD_BINARY_DIR:PATH=${CTK_BINARY_DIR}