Selaa lähdekoodia

Ensure find_package() is called in CTKConfig.cmake for external projects.

This ensures that external targets pulled in as imported targets
are available when CMake computes transitive link dependencies.

For build trees, supporting variables helping the find_package() call
to find the package are written into the CTKConfig.cmake file. For
relocatable install trees, the CTKConfig.cmake file relies on
CMAKE_PREFIX_PATH (and possibly set variables before CTKConfig.cmake
is included) to find external dependencies.

The CMakeFindDependencyMacro.cmake file was copied to CTK from a
CMake 3.1 source tarball.
Sascha Zelzer 10 vuotta sitten
vanhempi
commit
fc9223928a

+ 110 - 0
CMake/CMakeFindDependencyMacro.cmake

@@ -0,0 +1,110 @@
+#.rst:
+# CMakeFindDependencyMacro
+# -------------------------
+#
+# ::
+#
+#     find_dependency(<dep> [<version> [EXACT]])
+#
+#
+# ``find_dependency()`` wraps a :command:`find_package` call for a package
+# dependency. It is designed to be used in a <package>Config.cmake file, and it
+# forwards the correct parameters for EXACT, QUIET and REQUIRED which were
+# passed to the original :command:`find_package` call.  It also sets an
+# informative diagnostic message if the dependency could not be found.
+#
+
+#=============================================================================
+# Copyright 2013 Stephen Kelly <steveire@gmail.com>
+#
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2014 Kitware, Inc.
+# Copyright 2000-2011 Insight Software Consortium
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+#
+# * Neither the names of Kitware, Inc., the Insight Software Consortium,
+#   nor the names of their contributors may be used to endorse or promote
+#   products derived from this software without specific prior written
+#   permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#=============================================================================
+
+macro(find_dependency dep)
+  if (NOT ${dep}_FOUND)
+    set(cmake_fd_version)
+    if (${ARGC} GREATER 1)
+      if ("${ARGV1}" STREQUAL "")
+        message(FATAL_ERROR "Invalid arguments to find_dependency. VERSION is empty")
+      endif()
+      if ("${ARGV1}" STREQUAL EXACT)
+        message(FATAL_ERROR "Invalid arguments to find_dependency. EXACT may only be specified if a VERSION is specified")
+      endif()
+      set(cmake_fd_version ${ARGV1})
+    endif()
+    set(cmake_fd_exact_arg)
+    if(${ARGC} GREATER 2)
+      if (NOT "${ARGV2}" STREQUAL EXACT)
+        message(FATAL_ERROR "Invalid arguments to find_dependency")
+      endif()
+      set(cmake_fd_exact_arg EXACT)
+    endif()
+    if(${ARGC} GREATER 3)
+      message(FATAL_ERROR "Invalid arguments to find_dependency")
+    endif()
+    set(cmake_fd_quiet_arg)
+    if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
+      set(cmake_fd_quiet_arg QUIET)
+    endif()
+    set(cmake_fd_required_arg)
+    if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
+      set(cmake_fd_required_arg REQUIRED)
+    endif()
+
+    get_property(cmake_fd_alreadyTransitive GLOBAL PROPERTY
+      _CMAKE_${dep}_TRANSITIVE_DEPENDENCY
+    )
+
+    find_package(${dep} ${cmake_fd_version}
+        ${cmake_fd_exact_arg}
+        ${cmake_fd_quiet_arg}
+        ${cmake_fd_required_arg}
+    )
+
+    if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive)
+      set_property(GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY TRUE)
+    endif()
+
+    if (NOT ${dep}_FOUND)
+      set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.")
+      set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
+      return()
+    endif()
+    set(cmake_fd_version)
+    set(cmake_fd_required_arg)
+    set(cmake_fd_quiet_arg)
+    set(cmake_fd_exact_arg)
+  endif()
+endmacro()

+ 13 - 3
CMake/CTKConfig.cmake.in

@@ -8,6 +8,10 @@
 
 @PACKAGE_INIT@
 
+# Help finding external projects which might have been
+# installed with CTK in the same install location
+list(APPEND CMAKE_PREFIX_PATH ${PACKAGE_PREFIX_DIR})
+
 # CMake extension module directory
 set_and_check(CTK_CMAKE_DIR "@PACKAGE_CTK_CMAKE_DIR_CONFIG@")
 set_and_check(CTK_CMAKE_UTILITIES_DIR "@PACKAGE_CTK_CMAKE_UTILITIES_DIR_CONFIG@")
@@ -67,6 +71,12 @@ include("${CTK_CMAKE_DIR}/ctkFunctionGetPluginDependencies.cmake")
 include("${CTK_CMAKE_DIR}/ctkMacroSetupPlugins.cmake")
 include("${CTK_CMAKE_DIR}/ctkMacroGenerateMocs.cmake")
 
+if(CMAKE_VERSION VERSION_LESS 3)
+  include("${CTK_CMAKE_DIR}/CMakeFindDependencyMacro.cmake")
+else()
+  include(CMakeFindDependencyMacro)
+endif()
+
 # List all libraries
 SET(CTK_LIBRARIES @CTK_LIBRARIES@)
 
@@ -76,9 +86,6 @@ SET(CTK_WRAPPED_LIBRARIES_PYTHONQT @CTK_WRAPPED_LIBRARIES_PYTHONQT@)
 # Include CTK Plugin specific variables
 include(${CTK_PLUGIN_USE_FILE})
 
-# CTK external projects variables
-@CTK_SUPERBUILD_EP_VARS_CONFIG@
-
 # Qt configuration
 set(CTK_QT_VERSION "@CTK_QT_VERSION@")
 set(CTK_QT5_COMPONENTS @CTK_QT5_COMPONENTS@)
@@ -112,3 +119,6 @@ set(CTK_INSTALL_QTPLUGIN_DIR "@CTK_INSTALL_QTPLUGIN_DIR@")
 # that build tree (only one will ever be set).
 SET(CTK_CONFIGURATION_TYPES @CTK_CONFIGURATION_TYPES_CONFIG@)
 SET(CTK_BUILD_TYPE @CTK_BUILD_TYPE_CONFIG@)
+
+# CTK external projects variables
+@CTK_SUPERBUILD_EP_VARS_CONFIG@

+ 26 - 8
CMake/LastConfigureStep/CTKGenerateCTKConfig.cmake

@@ -71,14 +71,6 @@ else()
   set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/plugins")
 endif()
 
-# CTK external projects variables
-set(CTK_SUPERBUILD_EP_VARS_CONFIG)
-foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE})
-  set(CTK_SUPERBUILD_EP_VARS_CONFIG
-   "${CTK_SUPERBUILD_EP_VARS_CONFIG}
-set(CTK_${varname} \"${${varname}}\")")
-endforeach()
-
 # CMake extension module directory.
 set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
 set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
@@ -128,6 +120,20 @@ install(EXPORT CTKExports DESTINATION ${CTK_INSTALL_CMAKE_DIR})
 #-----------------------------------------------------------------------------
 # Configure 'CTKConfig.cmake' for a build tree
 
+# CTK external projects variables
+set(CTK_SUPERBUILD_EP_VARS_CONFIG)
+foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE_VARS} ${CTK_EP_LABEL_FIND_PACKAGE})
+  set(CTK_SUPERBUILD_EP_VARS_CONFIG
+   "${CTK_SUPERBUILD_EP_VARS_CONFIG}
+set(${varname} \"${${varname}}\")")
+endforeach()
+foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE})
+  string(REPLACE "_DIR" "" package_name "${varname}")
+  set(CTK_SUPERBUILD_EP_VARS_CONFIG
+   "${CTK_SUPERBUILD_EP_VARS_CONFIG}
+find_dependency(${package_name})")
+endforeach()
+
 set(CTK_CONFIG_DIR_CONFIG ${CTK_SUPERBUILD_BINARY_DIR})
 set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
 set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
@@ -187,6 +193,18 @@ configure_package_config_file(
 #-----------------------------------------------------------------------------
 # Configure 'CTKConfig.cmake' for an install tree
 
+# CTK external projects. We rely on externally set
+# _DIR variables or a proper CMAKE_PREFIX_PATH such
+# that find_dependency/find_package can successfully
+# find the external project. 
+set(CTK_SUPERBUILD_EP_VARS_CONFIG)
+foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE})
+  string(REPLACE "_DIR" "" package_name "${varname}")
+  set(CTK_SUPERBUILD_EP_VARS_CONFIG
+   "${CTK_SUPERBUILD_EP_VARS_CONFIG}
+find_dependency(${package_name})")
+endforeach()
+
 set(CTK_CONFIG_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
 set(CTK_CMAKE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
 set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})

+ 1 - 1
CMakeExternals/KWStyle.cmake

@@ -55,5 +55,5 @@ endif()
 
 mark_as_superbuild(
   VARS KWSTYLE_EXECUTABLE:FILEPATH
-  LABELS "FIND_PACKAGE"
+  LABELS "FIND_PACKAGE_VARS"
   )

+ 6 - 0
CMakeExternals/PythonQt.cmake

@@ -100,11 +100,17 @@ else()
   ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
 endif()
 
+set(PythonQt_DIR ${PYTHONQT_INSTALL_DIR})
+
 mark_as_superbuild(
   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
+  LABELS "FIND_PACKAGE_VARS"
+  )
+mark_as_superbuild(
+  VARS PythonQt_DIR:PATH
   LABELS "FIND_PACKAGE"
   )

+ 5 - 3
CMakeExternals/QtTesting.cmake

@@ -71,8 +71,10 @@ else()
 endif()
 
 mark_as_superbuild(
-  VARS
-    QtTesting_INSTALL_DIR:PATH
-    QtTesting_DIR:PATH
+  VARS QtTesting_INSTALL_DIR:PATH
+  LABELS "FIND_PACKAGE_VARS"
+  )
+mark_as_superbuild(
+  VARS QtTesting_DIR:PATH
   LABELS "FIND_PACKAGE"
   )

+ 1 - 0
CMakeLists.txt

@@ -243,6 +243,7 @@ foreach(file
   Libs/ctkExport.h.in
   CMake/ctkLinkerAsNeededFlagCheck.cmake
   CMake/ctk_compile_python_scripts.cmake.in
+  CMake/CMakeFindDependencyMacro.cmake
   )
   install(FILES ${file} DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development)
 endforeach()

+ 3 - 0
Utilities/CMake/FindPythonQt.cmake

@@ -32,11 +32,14 @@ if(UNIX AND NOT APPLE)
   mark_as_advanced(PYTHONQT_LIBUTIL)
 endif()
 
+# All upper case _FOUND variable is maintained for backwards compatibility.
 set(PYTHONQT_FOUND 0)
+set(PythonQt_FOUND 0)
 if(PYTHONQT_INCLUDE_DIR AND PYTHONQT_LIBRARY)
   # Currently CMake'ified PythonQt only supports building against a python Release build. 
   # This applies independently of CTK build type (Release, Debug, ...)
   add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK)
   set(PYTHONQT_FOUND 1)
+  set(PythonQt_FOUND ${PYTHONQT_FOUND})
   set(PYTHONQT_LIBRARIES ${PYTHONQT_LIBRARY} ${PYTHONQT_LIBUTIL})
 endif()