ctkDashboardDriverScript.cmake 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) Kitware Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0.txt
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. ###########################################################################
  20. #
  21. # Included from a dashboard script, this cmake file will drive the configure and build
  22. # steps of the different CTK sub-project (library, application or plugins)
  23. #
  24. # ctkDashboardDriverScript.cmake is automatically downloaded by the dashboard script
  25. # from the url http://commontk.org/ctkDashboardDriverScript.cmake
  26. # \note Any change to the file should also be backported on http://commontk.org/
  27. #
  28. #-----------------------------------------------------------------------------
  29. # The following variable are expected to be define in the top-level script:
  30. set(expected_variables
  31. ADDITIONNAL_CMAKECACHE_OPTION
  32. CTEST_NOTES_FILES
  33. CTEST_SITE
  34. CTEST_DASHBOARD_ROOT
  35. CTEST_CMAKE_COMMAND
  36. CTEST_CMAKE_GENERATOR
  37. WITH_MEMCHECK
  38. WITH_COVERAGE
  39. WITH_DOCUMENTATION
  40. CTEST_BUILD_CONFIGURATION
  41. CTEST_TEST_TIMEOUT
  42. CTEST_BUILD_FLAGS
  43. TEST_TO_EXCLUDE_REGEX
  44. CTEST_PROJECT_NAME
  45. CTEST_SOURCE_DIRECTORY
  46. CTEST_BINARY_DIRECTORY
  47. CTEST_BUILD_NAME
  48. SCRIPT_MODE
  49. CTEST_COVERAGE_COMMAND
  50. CTEST_MEMORYCHECK_COMMAND
  51. CTEST_GIT_COMMAND
  52. QT_QMAKE_EXECUTABLE
  53. )
  54. if(WITH_DOCUMENTATION)
  55. list(APPEND expected_variables DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  56. endif()
  57. foreach(var ${expected_variables})
  58. if(NOT DEFINED ${var})
  59. message(FATAL_ERROR "Variable ${var} should be defined in top-level script !")
  60. endif()
  61. endforeach()
  62. # If the dashscript doesn't define a GIT_REPOSITORY variable, let's define it here.
  63. if (NOT DEFINED GIT_REPOSITORY OR GIT_REPOSITORY STREQUAL "")
  64. set(GIT_REPOSITORY http://github.com/commontk/CTK.git)
  65. endif()
  66. # Should binary directory be cleaned?
  67. set(empty_binary_directory FALSE)
  68. # Attempt to build and test also if 'ctest_update' returned an error
  69. set(force_build FALSE)
  70. # Set model options
  71. set(model "")
  72. if (SCRIPT_MODE STREQUAL "experimental")
  73. set(empty_binary_directory FALSE)
  74. set(force_build TRUE)
  75. set(model Experimental)
  76. elseif (SCRIPT_MODE STREQUAL "continuous")
  77. set(empty_binary_directory TRUE)
  78. set(force_build FALSE)
  79. set(model Continuous)
  80. elseif (SCRIPT_MODE STREQUAL "nightly")
  81. set(empty_binary_directory TRUE)
  82. set(force_build TRUE)
  83. set(model Nightly)
  84. else()
  85. message(FATAL_ERROR "Unknown script mode: '${SCRIPT_MODE}'. Script mode should be either 'experimental', 'continuous' or 'nightly'")
  86. endif()
  87. #message("script_mode:${SCRIPT_MODE}")
  88. #message("model:${model}")
  89. #message("empty_binary_directory:${empty_binary_directory}")
  90. #message("force_build:${force_build}")
  91. # For more details, see http://www.kitware.com/blog/home/post/11
  92. set(CTEST_USE_LAUNCHERS 0)
  93. #if (NOT ${CTEST_CMAKE_GENERATOR} MATCHES "Visual Studio")
  94. # set(CTEST_USE_LAUNCHERS 1)
  95. #endif()
  96. if(empty_binary_directory)
  97. message("Directory ${CTEST_BINARY_DIRECTORY} cleaned !")
  98. ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
  99. endif()
  100. if(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}")
  101. set(CTEST_CHECKOUT_COMMAND "${CTEST_GIT_COMMAND} clone ${GIT_REPOSITORY} ${CTEST_SOURCE_DIRECTORY}")
  102. endif()
  103. set(CTEST_UPDATE_COMMAND "${CTEST_GIT_COMMAND}")
  104. #
  105. # run_ctest macro
  106. #
  107. MACRO(run_ctest)
  108. ctest_start(${model})
  109. ctest_update(SOURCE "${CTEST_SOURCE_DIRECTORY}" RETURN_VALUE res)
  110. # force a build if this is the first run and the build dir is empty
  111. if(NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
  112. message("First time build - Initialize CMakeCache.txt")
  113. set(res 1)
  114. # Write initial cache.
  115. file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "
  116. CTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS}
  117. QT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  118. SUPERBUILD_EXCLUDE_CTKBUILD_TARGET:BOOL=TRUE
  119. WITH_COVERAGE:BOOL=${WITH_COVERAGE}
  120. #DOCUMENTATION_TARGET_IN_ALL:BOOL=${WITH_DOCUMENTATION}
  121. DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
  122. ${ADDITIONNAL_CMAKECACHE_OPTION}
  123. ")
  124. endif()
  125. if (res GREATER 0 OR force_build)
  126. ctest_submit(PARTS Update)
  127. message("Configure SuperBuild")
  128. set_property(GLOBAL PROPERTY SubProject SuperBuild)
  129. set_property(GLOBAL PROPERTY Label SuperBuild)
  130. ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
  131. ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}")
  132. ctest_submit(PARTS Configure)
  133. ctest_submit(FILES "${CTEST_BINARY_DIRECTORY}/Project.xml")
  134. # Build top level
  135. message("----------- [ Build SuperBuild ] -----------")
  136. ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}" APPEND)
  137. ctest_submit(PARTS Build)
  138. ctest_test(
  139. BUILD "${CTEST_BINARY_DIRECTORY}"
  140. INCLUDE_LABEL "SuperBuild"
  141. PARALLEL_LEVEL 8
  142. EXCLUDE ${TEST_TO_EXCLUDE_REGEX})
  143. # runs only tests that have a LABELS property matching "${subproject}"
  144. ctest_submit(PARTS Test)
  145. set(ctk_build_dir "${CTEST_BINARY_DIRECTORY}/CTK-build")
  146. # To get CTEST_PROJECT_SUBPROJECTS definition
  147. include("${CTEST_BINARY_DIRECTORY}/CTestConfigSubProject.cmake")
  148. set(kit_suffixes
  149. CppTests
  150. #PythonTests
  151. )
  152. set(kit_widgets_suffixes
  153. Plugins
  154. )
  155. foreach(subproject ${CTEST_PROJECT_SUBPROJECTS})
  156. set_property(GLOBAL PROPERTY SubProject ${subproject})
  157. set_property(GLOBAL PROPERTY Label ${subproject})
  158. message("Build ${subproject}")
  159. # Configure target
  160. ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
  161. ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}")
  162. ctest_submit(PARTS Configure)
  163. # Build target
  164. set(CTEST_BUILD_TARGET "${subproject}")
  165. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  166. ctest_submit(PARTS Build)
  167. # Loop over kit suffixes and try to build the corresponding target
  168. foreach(kit_suffixe ${kit_suffixes})
  169. message("----------- [ Build ${subproject}${kit_suffixe} ] -----------")
  170. set(CTEST_BUILD_TARGET "${subproject}${kit_suffixe}")
  171. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  172. ctest_submit(PARTS Build)
  173. endforeach()
  174. if ("${subproject}" MATCHES "Widgets$")
  175. # Loop over kit suffixes and try to build the corresponding target
  176. foreach(kit_widgets_suffixe ${kit_widgets_suffixes})
  177. message("----------- [ Build ${subproject}${kit_widgets_suffixe} ] -----------")
  178. set(CTEST_BUILD_TARGET "${subproject}${kit_widgets_suffixe}")
  179. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  180. ctest_submit(PARTS Build)
  181. endforeach()
  182. endif()
  183. endforeach()
  184. if (WITH_DOCUMENTATION)
  185. message("----------- [ Build Documentation ] -----------")
  186. # Build Documentation target
  187. set_property(GLOBAL PROPERTY SubProject Documentation)
  188. set_property(GLOBAL PROPERTY Label Documentation)
  189. set(CTEST_BUILD_TARGET "doc")
  190. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  191. ctest_submit(PARTS Build)
  192. endif()
  193. # HACK Unfortunately ctest_coverage ignores the build argument, try to force it...
  194. file(READ ${ctk_build_dir}/CMakeFiles/TargetDirectories.txt ctk_build_coverage_dirs)
  195. file(APPEND "${CTEST_BINARY_DIRECTORY}/CMakeFiles/TargetDirectories.txt" "${ctk_build_coverage_dirs}")
  196. foreach(subproject ${CTEST_PROJECT_SUBPROJECTS})
  197. set_property(GLOBAL PROPERTY SubProject ${subproject})
  198. set_property(GLOBAL PROPERTY Label ${subproject})
  199. message("----------- [ Test ${subproject} ] -----------")
  200. ctest_test(
  201. BUILD "${ctk_build_dir}"
  202. INCLUDE_LABEL "${subproject}"
  203. PARALLEL_LEVEL 8
  204. EXCLUDE ${test_to_exclude_regex})
  205. # runs only tests that have a LABELS property matching "${subproject}"
  206. ctest_submit(PARTS Test)
  207. # Coverage per sub-project (library, application or plugin)
  208. if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
  209. message("----------- [ Coverage ${subproject} ] -----------")
  210. ctest_coverage(BUILD "${ctk_build_dir}" LABELS "${subproject}")
  211. ctest_submit(PARTS Coverage)
  212. endif ()
  213. #if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
  214. # ctest_memcheck(BUILD "${ctk_build_dir}" INCLUDE_LABEL "${subproject}")
  215. # ctest_submit(PARTS MemCheck)
  216. #endif ()
  217. endforeach()
  218. set_property(GLOBAL PROPERTY SubProject SuperBuild)
  219. set_property(GLOBAL PROPERTY Label SuperBuild)
  220. # Global coverage ...
  221. if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
  222. message("----------- [ Global coverage ] -----------")
  223. ctest_coverage(BUILD "${ctk_build_dir}")
  224. ctest_submit(PARTS Coverage)
  225. endif ()
  226. # Global dynamic analysis ...
  227. if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
  228. message("----------- [ Global memcheck ] -----------")
  229. ctest_memcheck(BUILD "${ctk_build_dir}")
  230. ctest_submit(PARTS MemCheck)
  231. endif ()
  232. # Note should be at the end
  233. ctest_submit(PARTS Notes)
  234. endif()
  235. endmacro()
  236. if(SCRIPT_MODE STREQUAL "continuous")
  237. while(${CTEST_ELAPSED_TIME} LESS 68400)
  238. set(START_TIME ${CTEST_ELAPSED_TIME})
  239. run_ctest()
  240. # Loop no faster than once every 5 minutes
  241. message("Wait for 5 minutes ...")
  242. ctest_sleep(${START_TIME} 300 ${CTEST_ELAPSED_TIME})
  243. endwhile()
  244. else()
  245. run_ctest()
  246. endif()