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