SuperBuild.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. SET(cmake_version_required "2.8")
  2. SET(cmake_version_required_dash "2-8")
  3. CMAKE_MINIMUM_REQUIRED(VERSION ${cmake_version_required})
  4. #
  5. # CTK_KWSTYLE_EXECUTABLE
  6. # DCMTK_DIR
  7. # QT_QMAKE_EXECUTABLE
  8. #
  9. #-----------------------------------------------------------------------------
  10. # Enable and setup External project global properties
  11. #
  12. INCLUDE(ExternalProject)
  13. SET(ep_base "${CMAKE_BINARY_DIR}/CMakeExternals")
  14. SET_PROPERTY(DIRECTORY PROPERTY EP_BASE ${ep_base})
  15. SET(ep_install_dir ${ep_base}/Install)
  16. SET(ep_build_dir ${ep_base}/Build)
  17. SET(ep_source_dir ${ep_base}/Source)
  18. #SET(ep_parallelism_level)
  19. SET(ep_build_shared_libs ON)
  20. SET(ep_build_testing OFF)
  21. SET(ep_common_args
  22. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  23. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  24. -DBUILD_TESTING:BOOL=${ep_build_testing}
  25. )
  26. # Compute -G arg for configuring external projects with the same CMake generator:
  27. IF(CMAKE_EXTRA_GENERATOR)
  28. SET(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  29. ELSE()
  30. SET(gen "${CMAKE_GENERATOR}")
  31. ENDIF()
  32. # Use this value where semi-colons are needed in ep_add args:
  33. set(sep "^^")
  34. # Find the git executable, used for custom git commands for external projects
  35. # (e.g. for QtMobility)
  36. find_program(Git_EXECUTABLE git DOC "git command line client")
  37. mark_as_advanced(Git_EXECUTABLE)
  38. if(NOT Git_EXECUTABLE)
  39. message(SEND_ERROR "Set Git_EXECUTABLE to the path of your git executable")
  40. endif()
  41. #-----------------------------------------------------------------------------
  42. # Update CMake module path
  43. #
  44. SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
  45. #-----------------------------------------------------------------------------
  46. # Collect CTK library target dependencies
  47. #
  48. ctkMacroCollectAllTargetLibraries("${CTK_LIBS}" "Libs" ALL_TARGET_LIBRARIES)
  49. ctkMacroCollectAllTargetLibraries("${CTK_PLUGINS}" "Plugins" ALL_TARGET_LIBRARIES)
  50. ctkMacroCollectAllTargetLibraries("${CTK_APPLICATIONS}" "Applications" ALL_TARGET_LIBRARIES)
  51. #MESSAGE(STATUS ALL_TARGET_LIBRARIES:${ALL_TARGET_LIBRARIES})
  52. #-----------------------------------------------------------------------------
  53. # Initialize NON_CTK_DEPENDENCIES variable
  54. #
  55. # Using the variable ALL_TARGET_LIBRARIES initialized above with the help
  56. # of the macro ctkMacroCollectAllTargetLibraries, let's get the list of all Non-CTK dependencies.
  57. # NON_CTK_DEPENDENCIES is expected by the macro ctkMacroShouldAddExternalProject
  58. ctkMacroGetAllNonCTKTargetLibraries("${ALL_TARGET_LIBRARIES}" NON_CTK_DEPENDENCIES)
  59. #MESSAGE(STATUS NON_CTK_DEPENDENCIES:${NON_CTK_DEPENDENCIES})
  60. #-----------------------------------------------------------------------------
  61. # Qt is expected to be setup by CTK/CMakeLists.txt just before it includes the SuperBuild script
  62. #
  63. #-----------------------------------------------------------------------------
  64. # KWStyle
  65. #
  66. SET(kwstyle_DEPENDS)
  67. IF(CTK_USE_KWSTYLE)
  68. IF(NOT DEFINED CTK_KWSTYLE_EXECUTABLE)
  69. SET(proj KWStyle-CVSHEAD)
  70. SET(kwstyle_DEPENDS ${proj})
  71. ExternalProject_Add(${proj}
  72. LIST_SEPARATOR ${sep}
  73. CVS_REPOSITORY ":pserver:anoncvs:@public.kitware.com:/cvsroot/KWStyle"
  74. CVS_MODULE "KWStyle"
  75. CMAKE_GENERATOR ${gen}
  76. CMAKE_ARGS
  77. ${ep_common_args}
  78. )
  79. SET(CTK_KWSTYLE_EXECUTABLE ${ep_install_dir}/bin/KWStyle)
  80. ENDIF()
  81. ENDIF()
  82. #-----------------------------------------------------------------------------
  83. # PythonQt
  84. #
  85. SET(PythonQt_DEPENDS)
  86. ctkMacroShouldAddExternalProject(PYTHONQT_LIBRARIES add_project)
  87. IF(${add_project})
  88. # SET(proj PythonQt)
  89. # SET(PythonQt_DEPENDS ${proj})
  90. # ExternalProject_Add(${proj}
  91. # SVN_REPOSITORY "https://pythonqt.svn.sourceforge.net/svnroot/pythonqt/trunk"
  92. # CMAKE_GENERATOR ${gen}
  93. # PATCH_COMMAND ${CMAKE_COMMAND} -P ${pythonqt_patch_script}
  94. # BUILD_COMMAND ""
  95. # CMAKE_ARGS
  96. # ${ep_common_args}
  97. # -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  98. # #${vtk_PYTHON_ARGS}
  99. # INSTALL_COMMAND "")
  100. ENDIF()
  101. #-----------------------------------------------------------------------------
  102. # Utilities/DCMTK
  103. #
  104. SET(DCMTK_DEPENDS)
  105. ctkMacroShouldAddExternalProject(DCMTK_LIBRARIES add_project)
  106. IF(${add_project})
  107. IF(NOT DEFINED DCMTK_DIR)
  108. SET(proj DCMTK)
  109. # MESSAGE(STATUS "Adding project:${proj}")
  110. SET(DCMTK_DEPENDS ${proj})
  111. ExternalProject_Add(${proj}
  112. DOWNLOAD_COMMAND ""
  113. CMAKE_GENERATOR ${gen}
  114. SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/${proj}
  115. CMAKE_ARGS
  116. ${ep_common_args}
  117. -DDCMTK_BUILD_APPS:BOOL=ON # Build also dmctk tools (movescu, storescp, ...)
  118. )
  119. SET(DCMTK_DIR ${ep_install_dir})
  120. ENDIF()
  121. ENDIF()
  122. #-----------------------------------------------------------------------------
  123. # Utilities/ZMQ
  124. #
  125. SET(ZMQ_DEPENDS)
  126. ctkMacroShouldAddExternalProject(ZMQ_LIBRARIES add_project)
  127. IF(${add_project})
  128. SET(proj ZMQ)
  129. # MESSAGE(STATUS "Adding project:${proj}")
  130. SET(ZMQ_DEPENDS ${proj})
  131. ExternalProject_Add(${proj}
  132. DOWNLOAD_COMMAND ""
  133. INSTALL_COMMAND ""
  134. CMAKE_GENERATOR ${gen}
  135. SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/ZMQ
  136. CMAKE_ARGS
  137. ${ep_common_args}
  138. )
  139. ENDIF()
  140. #-----------------------------------------------------------------------------
  141. # QtMobility
  142. #
  143. SET(QtMobility_DEPENDS)
  144. ctkMacroShouldAddExternalProject(QTMOBILITY_QTSERVICEFW_LIBRARIES add_project)
  145. IF(${add_project})
  146. SET(proj QtMobility)
  147. # MESSAGE(STATUS "Adding project:${proj}")
  148. SET(QtMobility_DEPENDS ${proj})
  149. # Configure patch script
  150. SET(qtmobility_src_dir ${ep_source_dir}/${proj})
  151. SET(qtmobility_patch_dir ${CTK_SOURCE_DIR}/Utilities/QtMobility/)
  152. SET(qtmobility_configured_patch_dir ${CTK_BINARY_DIR}/Utilities/QtMobility/)
  153. SET(qtmobility_patchscript
  154. ${CTK_BINARY_DIR}/Utilities/QtMobility/QtMobilityGitBranch1.0-patch.cmake)
  155. CONFIGURE_FILE(
  156. ${CTK_SOURCE_DIR}/Utilities/QtMobility/QtMobilityGitBranch1.0-patch.cmake.in
  157. ${qtmobility_patchscript} @ONLY)
  158. # Define configure options
  159. SET(qtmobility_modules "serviceframework")
  160. SET(qtmobility_build_type "release")
  161. IF(UNIX)
  162. IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
  163. SET(qtmobility_build_type "debug")
  164. ENDIF()
  165. ELSEIF(NOT ${CMAKE_CFG_INTDIR} STREQUAL "Release")
  166. SET(qtmobility_build_type "debug")
  167. ENDIf()
  168. SET(qtmobility_make_cmd)
  169. IF(UNIX OR MINGW)
  170. SET(qtmobility_make_cmd make)
  171. ELSEIF(WIN32)
  172. SET(qtmobility_make_cmd nmake)
  173. ENDIF()
  174. ExternalProject_Add(${proj}
  175. GIT_REPOSITORY git://gitorious.org/qt-mobility/qt-mobility.git
  176. # the patch command is also used to checkout the 1.0 branch
  177. PATCH_COMMAND ${CMAKE_COMMAND} -P ${qtmobility_patchscript}
  178. CONFIGURE_COMMAND <SOURCE_DIR>/configure -${qtmobility_build_type} -libdir ${CMAKE_BINARY_DIR}/CTK-build/bin -no-docs -modules ${qtmobility_modules}
  179. BUILD_COMMAND ${qtmobility_make_cmd}
  180. INSTALL_COMMAND ${qtmobility_make_cmd} install
  181. BUILD_IN_SOURCE 1
  182. )
  183. ENDIF()
  184. #-----------------------------------------------------------------------------
  185. # Utilities/OpenIGTLink
  186. #
  187. SET (OpenIGTLink_DEPENDS)
  188. ctkMacroShouldAddExternalProject(OpenIGTLink_LIBRARIES add_project)
  189. IF(${add_project})
  190. IF(NOT DEFINED OpenIGTLink_DIR)
  191. SET(proj OpenIGTLink)
  192. # MESSAGE(STATUS "Adding project:${proj}")
  193. SET(OpenIGTLink_DEPENDS ${proj})
  194. ExternalProject_Add(${proj}
  195. SVN_REPOSITORY "http://svn.na-mic.org/NAMICSandBox/trunk/OpenIGTLink"
  196. INSTALL_COMMAND ""
  197. CMAKE_GENERATOR ${gen}
  198. CMAKE_ARGS
  199. ${ep_common_args}
  200. )
  201. SET(OpenIGTLink_DIR ${ep_build_dir}/${proj})
  202. ENDIF()
  203. ENDIF()
  204. #-----------------------------------------------------------------------------
  205. # XIP
  206. #
  207. SET (XIP_DEPENDS)
  208. ctkMacroShouldAddExternalProject(XIP_LIBRARIES add_project)
  209. IF(${add_project})
  210. SET(proj XIP)
  211. # MESSAGE(STATUS "Adding project:${proj}")
  212. SET(XIP_DEPENDS ${proj})
  213. ExternalProject_Add(${proj}
  214. SVN_REPOSITORY "https://collab01a.scr.siemens.com/svn/xip/releases/latest"
  215. SVN_USERNAME "anonymous"
  216. INSTALL_COMMAND ""
  217. CMAKE_GENERATOR ${gen}
  218. CMAKE_ARGS
  219. ${ep_common_args}
  220. )
  221. ENDIF()
  222. #-----------------------------------------------------------------------------
  223. # CTK Utilities
  224. #
  225. set(proj CTK-Utilities)
  226. ExternalProject_Add(${proj}
  227. DOWNLOAD_COMMAND ""
  228. CONFIGURE_COMMAND ""
  229. BUILD_COMMAND ""
  230. INSTALL_COMMAND ""
  231. DEPENDS
  232. # Mandatory dependencies
  233. ${QtMobility_DEPENDS}
  234. # Optionnal dependencies
  235. ${kwstyle_DEPENDS}
  236. ${DCMTK_DEPENDS}
  237. ${PythonQt_DEPENDS}
  238. ${ZMQ_DEPENDS}
  239. ${OpenIGTLink_DEPENDS}
  240. ${XIP_DEPENDS}
  241. )
  242. #-----------------------------------------------------------------------------
  243. # Generate cmake variable name corresponding to Libs, Plugins and Applications
  244. #
  245. SET(ctk_libs_bool_vars)
  246. FOREACH(lib ${ctk_libs})
  247. LIST(APPEND ctk_libs_bool_vars CTK_LIB_${lib})
  248. ENDFOREACH()
  249. SET(ctk_plugins_bool_vars)
  250. FOREACH(plugin ${ctk_plugins})
  251. LIST(APPEND ctk_plugins_bool_vars CTK_PLUGIN_${plugin})
  252. ENDFOREACH()
  253. SET(ctk_applications_bool_vars)
  254. FOREACH(app ${ctk_applications})
  255. LIST(APPEND ctk_applications_bool_vars CTK_APP_${app})
  256. ENDFOREACH()
  257. #-----------------------------------------------------------------------------
  258. # Convenient macro allowing to define superbuild arg
  259. #
  260. MACRO(ctk_set_superbuild_boolean_arg ctk_cmake_var)
  261. SET(superbuild_${ctk_cmake_var} ON)
  262. IF(DEFINED ${ctk_cmake_var} AND NOT ${ctk_cmake_var})
  263. SET(superbuild_${ctk_cmake_var} OFF)
  264. ENDIF()
  265. ENDMACRO()
  266. #-----------------------------------------------------------------------------
  267. # Set superbuild boolean args
  268. #
  269. SET(ctk_cmake_boolean_args
  270. BUILD_TESTING
  271. CTK_USE_KWSTYLE
  272. ${ctk_libs_bool_vars}
  273. ${ctk_plugins_bool_vars}
  274. ${ctk_applications_bool_vars}
  275. )
  276. SET(ctk_superbuild_boolean_args)
  277. FOREACH(ctk_cmake_arg ${ctk_cmake_boolean_args})
  278. ctk_set_superbuild_boolean_arg(${ctk_cmake_arg})
  279. LIST(APPEND ctk_superbuild_boolean_args -D${ctk_cmake_arg}:BOOL=${superbuild_${ctk_cmake_arg}})
  280. ENDFOREACH()
  281. #-----------------------------------------------------------------------------
  282. # CTK Configure
  283. #
  284. SET(proj CTK-Configure)
  285. ExternalProject_Add(${proj}
  286. DOWNLOAD_COMMAND ""
  287. CMAKE_GENERATOR ${gen}
  288. CMAKE_ARGS
  289. ${ctk_superbuild_boolean_args}
  290. -DCTK_SUPERBUILD:BOOL=OFF
  291. -DWITH_COVERAGE:BOOL=${WITH_COVERAGE}
  292. -DCTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS}
  293. -DCTK_SUPERBUILD_BINARY_DIR:PATH=${CTK_BINARY_DIR}
  294. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  295. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  296. -DCTK_CXX_FLAGS:STRING=${CTK_CXX_FLAGS}
  297. -DCTK_C_FLAGS:STRING=${CTK_C_FLAGS}
  298. -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  299. -DCTK_KWSTYLE_EXECUTABLE:FILEPATH=${CTK_KWSTYLE_EXECUTABLE}
  300. -DDCMTK_DIR:PATH=${DCMTK_DIR} # FindDCMTK expects DCMTK_DIR
  301. SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
  302. BINARY_DIR ${CMAKE_BINARY_DIR}/CTK-build
  303. BUILD_COMMAND ""
  304. INSTALL_COMMAND ""
  305. DEPENDS
  306. "CTK-Utilities"
  307. )
  308. #-----------------------------------------------------------------------------
  309. # CTK
  310. #
  311. #MESSAGE(STATUS SUPERBUILD_EXCLUDE_CTKBUILD_TARGET:${SUPERBUILD_EXCLUDE_CTKBUILD_TARGET})
  312. IF(NOT DEFINED SUPERBUILD_EXCLUDE_CTKBUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_CTKBUILD_TARGET)
  313. SET(proj CTK-build)
  314. ExternalProject_Add(${proj}
  315. DOWNLOAD_COMMAND ""
  316. CMAKE_GENERATOR ${gen}
  317. SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
  318. BINARY_DIR CTK-build
  319. INSTALL_COMMAND ""
  320. DEPENDS
  321. "CTK-Configure"
  322. )
  323. ENDIF()
  324. #-----------------------------------------------------------------------------
  325. # Custom target allowing to drive the build of CTK project itself
  326. #
  327. ADD_CUSTOM_TARGET(CTK
  328. COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/CTK-build
  329. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CTK-build
  330. )