ctkMacroSetupExternalPlugins.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) German Cancer Research Center,
  6. # Division of Medical and Biological Informatics
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. #
  20. ###########################################################################
  21. #! \ingroup CMakeAPI
  22. macro(ctkMacroSetupExternalPlugins )
  23. ctkMacroParseArguments(MY "BUILD_OPTION_PREFIX;BUILD_ALL" "COMPACT_OPTIONS" ${ARGN})
  24. if(NOT MY_DEFAULT_ARGS)
  25. message(FATAL_ERROR "Empty plugin list")
  26. endif()
  27. set(plugin_list ${MY_DEFAULT_ARGS})
  28. if(NOT MY_BUILD_OPTION_PREFIX)
  29. set(MY_BUILD_OPTION_PREFIX "BUILD_")
  30. endif()
  31. if(NOT MY_BUILD_ALL)
  32. set(MY_BUILD_ALL 0)
  33. endif()
  34. # Set up Qt, if not already done
  35. if(NOT QT4_FOUND)
  36. set(minimum_required_qt_version "4.6")
  37. find_package(Qt4 REQUIRED)
  38. if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
  39. message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
  40. endif()
  41. endif()
  42. # Set variable QT_INSTALLED_LIBRARY_DIR that will contains
  43. # Qt shared library
  44. set(QT_INSTALLED_LIBRARY_DIR ${QT_LIBRARY_DIR})
  45. if(WIN32)
  46. get_filename_component(QT_INSTALLED_LIBRARY_DIR ${QT_QMAKE_EXECUTABLE} PATH)
  47. endif()
  48. set(plugin_dirswithoption )
  49. set(plugin_subdirs )
  50. foreach(plugin ${plugin_list})
  51. ctkFunctionExtractOptionNameAndValue(${plugin} plugin_name plugin_value)
  52. if(MY_COMPACT_OPTIONS)
  53. string(REPLACE "/" ";" _tokens ${plugin_name})
  54. list(GET _tokens -1 option_name)
  55. set(option_name ${MY_BUILD_OPTION_PREFIX}${option_name})
  56. else()
  57. set(option_name ${MY_BUILD_OPTION_PREFIX}${plugin_name})
  58. endif()
  59. set(${plugin_name}_option_name ${option_name})
  60. option(${option_name} "Build ${plugin_name} Plugin." ${plugin_value})
  61. if(MY_BUILD_ALL)
  62. set(${option_name} 1)
  63. endif()
  64. list(APPEND plugin_subdirs "${plugin_name}")
  65. if(IS_ABSOLUTE ${plugin_name})
  66. list(APPEND plugin_dirswithoption "${plugin_name}^^${option_name}")
  67. else()
  68. list(APPEND plugin_dirswithoption "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_name}^^${option_name}")
  69. endif()
  70. endforeach()
  71. ctkFunctionGenerateDGraphInput(${CMAKE_CURRENT_BINARY_DIR} "${plugin_dirswithoption}" WITH_EXTERNALS)
  72. ctkMacroValidateBuildOptions("${CMAKE_CURRENT_BINARY_DIR}" "${CTK_DGRAPH_EXECUTABLE}" "${plugin_dirswithoption}")
  73. # Get the gcc version (GCC_VERSION will be empty if the compiler is not gcc).
  74. # This will be used in the ctkMacroBuildPlugin macro to conditionally set compiler flags.
  75. ctkFunctionGetGccversion(${CMAKE_CXX_COMPILER} GCC_VERSION)
  76. foreach(plugin ${plugin_subdirs})
  77. if(${${plugin}_option_name})
  78. if(IS_ABSOLUTE ${plugin})
  79. # get last directory component
  80. get_filename_component(_dirname ${plugin} NAME)
  81. add_subdirectory(${plugin} private_plugins/${_dirname})
  82. else()
  83. add_subdirectory(${plugin})
  84. endif()
  85. endif()
  86. endforeach()
  87. endmacro()