ctkDashboardDriverScript.cmake 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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_GENERATOR
  36. WITH_MEMCHECK
  37. WITH_COVERAGE
  38. WITH_DOCUMENTATION
  39. CTEST_BUILD_CONFIGURATION
  40. CTEST_TEST_TIMEOUT
  41. CTEST_BUILD_FLAGS
  42. TEST_TO_EXCLUDE_REGEX
  43. CTEST_PROJECT_NAME
  44. CTEST_SOURCE_DIRECTORY
  45. CTEST_BINARY_DIRECTORY
  46. CTEST_BUILD_NAME
  47. SCRIPT_MODE
  48. CTEST_COVERAGE_COMMAND
  49. CTEST_MEMORYCHECK_COMMAND
  50. CTEST_GIT_COMMAND
  51. QT_QMAKE_EXECUTABLE
  52. )
  53. if(WITH_DOCUMENTATION)
  54. list(APPEND expected_variables DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  55. endif()
  56. foreach(var ${expected_variables})
  57. if(NOT DEFINED ${var})
  58. message(FATAL_ERROR "Variable ${var} should be defined in top-level script !")
  59. endif()
  60. endforeach()
  61. # If the dashscript doesn't define a GIT_REPOSITORY variable, let's define it here.
  62. if (NOT DEFINED GIT_REPOSITORY OR GIT_REPOSITORY STREQUAL "")
  63. set(GIT_REPOSITORY http://github.com/commontk/CTK.git)
  64. endif()
  65. # Should binary directory be cleaned?
  66. set(empty_binary_directory FALSE)
  67. # Attempt to build and test also if 'ctest_update' returned an error
  68. set(force_build FALSE)
  69. # Set model options
  70. set(model "")
  71. if (SCRIPT_MODE STREQUAL "experimental")
  72. set(empty_binary_directory FALSE)
  73. set(force_build TRUE)
  74. set(model Experimental)
  75. elseif (SCRIPT_MODE STREQUAL "continuous")
  76. set(empty_binary_directory TRUE)
  77. set(force_build FALSE)
  78. set(model Continuous)
  79. elseif (SCRIPT_MODE STREQUAL "nightly")
  80. set(empty_binary_directory TRUE)
  81. set(force_build TRUE)
  82. set(model Nightly)
  83. else()
  84. message(FATAL_ERROR "Unknown script mode: '${SCRIPT_MODE}'. Script mode should be either 'experimental', 'continuous' or 'nightly'")
  85. endif()
  86. #message("script_mode:${SCRIPT_MODE}")
  87. #message("model:${model}")
  88. #message("empty_binary_directory:${empty_binary_directory}")
  89. #message("force_build:${force_build}")
  90. # For more details, see http://www.kitware.com/blog/home/post/11
  91. set(CTEST_USE_LAUNCHERS 1)
  92. if(NOT "${CTEST_CMAKE_GENERATOR}" MATCHES "Make")
  93. set(CTEST_USE_LAUNCHERS 0)
  94. endif()
  95. set(ENV{CTEST_USE_LAUNCHERS_DEFAULT} ${CTEST_USE_LAUNCHERS})
  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. QT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  117. WITH_COVERAGE:BOOL=${WITH_COVERAGE}
  118. #DOCUMENTATION_TARGET_IN_ALL:BOOL=${WITH_DOCUMENTATION}
  119. DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
  120. ${ADDITIONNAL_CMAKECACHE_OPTION}
  121. ")
  122. endif()
  123. if (res GREATER 0 OR force_build)
  124. ctest_submit(PARTS Update)
  125. message("Configure SuperBuild")
  126. set_property(GLOBAL PROPERTY SubProject SuperBuild)
  127. set_property(GLOBAL PROPERTY Label SuperBuild)
  128. ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
  129. ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}")
  130. ctest_submit(PARTS Configure)
  131. ctest_submit(FILES "${CTEST_BINARY_DIRECTORY}/Project.xml")
  132. # Build top level
  133. message("----------- [ Build SuperBuild ] -----------")
  134. ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}" TARGET "CTK-configure" APPEND)
  135. ctest_submit(PARTS Build)
  136. ctest_test(
  137. BUILD "${CTEST_BINARY_DIRECTORY}"
  138. INCLUDE_LABEL "SuperBuild"
  139. PARALLEL_LEVEL 8
  140. EXCLUDE ${TEST_TO_EXCLUDE_REGEX})
  141. # runs only tests that have a LABELS property matching "${subproject}"
  142. ctest_submit(PARTS Test)
  143. set(ctk_build_dir "${CTEST_BINARY_DIRECTORY}/CTK-build")
  144. # To get CTEST_PROJECT_SUBPROJECTS definition
  145. include("${CTEST_BINARY_DIRECTORY}/CTestConfigSubProject.cmake")
  146. set(kit_suffixes
  147. CppTests
  148. #PythonTests
  149. )
  150. set(kit_widgets_suffixes
  151. Plugins
  152. )
  153. foreach(subproject ${CTEST_PROJECT_SUBPROJECTS})
  154. set_property(GLOBAL PROPERTY SubProject ${subproject})
  155. set_property(GLOBAL PROPERTY Label ${subproject})
  156. message("Build ${subproject}")
  157. # Configure target
  158. ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
  159. ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}")
  160. ctest_submit(PARTS Configure)
  161. # Build target
  162. set(CTEST_BUILD_TARGET "${subproject}")
  163. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  164. ctest_submit(PARTS Build)
  165. # Loop over kit suffixes and try to build the corresponding target
  166. foreach(kit_suffixe ${kit_suffixes})
  167. message("----------- [ Build ${subproject}${kit_suffixe} ] -----------")
  168. set(CTEST_BUILD_TARGET "${subproject}${kit_suffixe}")
  169. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  170. ctest_submit(PARTS Build)
  171. endforeach()
  172. if ("${subproject}" MATCHES "Widgets$")
  173. # Loop over kit suffixes and try to build the corresponding target
  174. foreach(kit_widgets_suffixe ${kit_widgets_suffixes})
  175. message("----------- [ Build ${subproject}${kit_widgets_suffixe} ] -----------")
  176. set(CTEST_BUILD_TARGET "${subproject}${kit_widgets_suffixe}")
  177. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  178. ctest_submit(PARTS Build)
  179. endforeach()
  180. endif()
  181. endforeach()
  182. if (WITH_DOCUMENTATION)
  183. message("----------- [ Build Documentation ] -----------")
  184. # Build Documentation target
  185. set_property(GLOBAL PROPERTY SubProject Documentation)
  186. set_property(GLOBAL PROPERTY Label Documentation)
  187. set(CTEST_BUILD_TARGET "doc")
  188. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  189. ctest_submit(PARTS Build)
  190. endif()
  191. # HACK Unfortunately ctest_coverage ignores the build argument, try to force it...
  192. file(READ ${ctk_build_dir}/CMakeFiles/TargetDirectories.txt ctk_build_coverage_dirs)
  193. file(APPEND "${CTEST_BINARY_DIRECTORY}/CMakeFiles/TargetDirectories.txt" "${ctk_build_coverage_dirs}")
  194. foreach(subproject ${CTEST_PROJECT_SUBPROJECTS})
  195. set_property(GLOBAL PROPERTY SubProject ${subproject})
  196. set_property(GLOBAL PROPERTY Label ${subproject})
  197. message("----------- [ Test ${subproject} ] -----------")
  198. ctest_test(
  199. BUILD "${ctk_build_dir}"
  200. INCLUDE_LABEL "${subproject}"
  201. PARALLEL_LEVEL 8
  202. EXCLUDE ${test_to_exclude_regex})
  203. # runs only tests that have a LABELS property matching "${subproject}"
  204. ctest_submit(PARTS Test)
  205. # Coverage per sub-project (library, application or plugin)
  206. if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
  207. message("----------- [ Coverage ${subproject} ] -----------")
  208. ctest_coverage(BUILD "${ctk_build_dir}" LABELS "${subproject}")
  209. ctest_submit(PARTS Coverage)
  210. endif ()
  211. #if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
  212. # ctest_memcheck(BUILD "${ctk_build_dir}" INCLUDE_LABEL "${subproject}")
  213. # ctest_submit(PARTS MemCheck)
  214. #endif ()
  215. endforeach()
  216. set_property(GLOBAL PROPERTY SubProject SuperBuild)
  217. set_property(GLOBAL PROPERTY Label SuperBuild)
  218. # Global coverage ...
  219. if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
  220. message("----------- [ Global coverage ] -----------")
  221. ctest_coverage(BUILD "${ctk_build_dir}")
  222. ctest_submit(PARTS Coverage)
  223. endif ()
  224. # Global dynamic analysis ...
  225. if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
  226. message("----------- [ Global memcheck ] -----------")
  227. ctest_memcheck(BUILD "${ctk_build_dir}")
  228. ctest_submit(PARTS MemCheck)
  229. endif ()
  230. # Note should be at the end
  231. ctest_submit(PARTS Notes)
  232. endif()
  233. endmacro()
  234. if(SCRIPT_MODE STREQUAL "continuous")
  235. while(${CTEST_ELAPSED_TIME} LESS 46800) # Lasts 13 hours (Assuming it starts at 9am, it will end around 10pm)
  236. set(START_TIME ${CTEST_ELAPSED_TIME})
  237. run_ctest()
  238. # Loop no faster than once every 5 minutes
  239. message("Wait for 5 minutes ...")
  240. ctest_sleep(${START_TIME} 300 ${CTEST_ELAPSED_TIME})
  241. endwhile()
  242. else()
  243. run_ctest()
  244. endif()