ctkDashboardDriverScript.cmake 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) 2010 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.commontk.org/LICENSE
  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. #-----------------------------------------------------------------------------
  25. # The following variable are expected to be define in the top-level script:
  26. set(expected_variables
  27. ADDITIONNAL_CMAKECACHE_OPTION
  28. CTEST_NOTES_FILES
  29. CTEST_SITE
  30. CTEST_DASHBOARD_ROOT
  31. CTEST_CMAKE_COMMAND
  32. CTEST_CMAKE_GENERATOR
  33. WITH_MEMCHECK
  34. WITH_COVERAGE
  35. WITH_DOCUMENTATION
  36. CTEST_BUILD_CONFIGURATION
  37. CTEST_TEST_TIMEOUT
  38. CTEST_BUILD_FLAGS
  39. TEST_TO_EXCLUDE_REGEX
  40. CTEST_PROJECT_NAME
  41. CTEST_SOURCE_DIRECTORY
  42. CTEST_BINARY_DIRECTORY
  43. CTEST_BUILD_NAME
  44. SCRIPT_MODE
  45. CTEST_COVERAGE_COMMAND
  46. CTEST_MEMORYCHECK_COMMAND
  47. CTEST_GIT_COMMAND
  48. QT_QMAKE_EXECUTABLE
  49. )
  50. if(WITH_DOCUMENTATION)
  51. list(APPEND expected_variables DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  52. endif()
  53. foreach(var ${expected_variables})
  54. if(NOT DEFINED ${var})
  55. message(FATAL_ERROR "Variable ${var} should be defined in top-level script !")
  56. endif()
  57. endforeach()
  58. # If the dashscript doesn't define a GIT_REPOSITORY variable, let's define it here.
  59. if (NOT DEFINED GIT_REPOSITORY OR GIT_REPOSITORY STREQUAL "")
  60. set(GIT_REPOSITORY http://github.com/commontk/CTK.git)
  61. endif()
  62. # Should binary directory be cleaned?
  63. set(empty_binary_directory FALSE)
  64. # Attempt to build and test also if 'ctest_update' returned an error
  65. set(force_build FALSE)
  66. # Set model options
  67. set(model "")
  68. if (SCRIPT_MODE STREQUAL "experimental")
  69. set(empty_binary_directory FALSE)
  70. set(force_build TRUE)
  71. set(model Experimental)
  72. elseif (SCRIPT_MODE STREQUAL "continuous")
  73. set(empty_binary_directory TRUE)
  74. set(force_build FALSE)
  75. set(model Continuous)
  76. elseif (SCRIPT_MODE STREQUAL "nightly")
  77. set(empty_binary_directory TRUE)
  78. set(force_build TRUE)
  79. set(model Nightly)
  80. else()
  81. message(FATAL_ERROR "Unknown script mode: '${SCRIPT_MODE}'. Script mode should be either 'experimental', 'continuous' or 'nightly'")
  82. endif()
  83. #message("script_mode:${SCRIPT_MODE}")
  84. #message("model:${model}")
  85. #message("empty_binary_directory:${empty_binary_directory}")
  86. #message("force_build:${force_build}")
  87. set(CTEST_USE_LAUNCHERS 1)
  88. if(empty_binary_directory)
  89. message("Directory ${CTEST_BINARY_DIRECTORY} cleaned !")
  90. ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
  91. endif()
  92. if(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}")
  93. set(CTEST_CHECKOUT_COMMAND "${CTEST_GIT_COMMAND} clone ${GIT_REPOSITORY} ${CTEST_SOURCE_DIRECTORY}")
  94. endif()
  95. set(CTEST_UPDATE_COMMAND "${CTEST_GIT_COMMAND}")
  96. #
  97. # run_ctest macro
  98. #
  99. MACRO(run_ctest)
  100. ctest_start(${model})
  101. ctest_update(SOURCE "${CTEST_SOURCE_DIRECTORY}" RETURN_VALUE res)
  102. #ctest_submit(PARTS Update Notes)
  103. # force a build if this is the first run and the build dir is empty
  104. if(NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
  105. message("First time build - Initialize CMakeCache.txt")
  106. set(res 1)
  107. # Write initial cache.
  108. file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "
  109. CTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS}
  110. QT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  111. SUPERBUILD_EXCLUDE_CTKBUILD_TARGET:BOOL=TRUE
  112. WITH_COVERAGE:BOOL=${WITH_COVERAGE}
  113. #DOCUMENTATION_TARGET_IN_ALL:BOOL=${WITH_DOCUMENTATION}
  114. DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
  115. ${ADDITIONNAL_CMAKECACHE_OPTION}
  116. ")
  117. endif()
  118. if (res GREATER 0 OR force_build)
  119. message("Configure SuperBuild")
  120. set_property(GLOBAL PROPERTY SubProject SuperBuild)
  121. set_property(GLOBAL PROPERTY Label SuperBuild)
  122. ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
  123. ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}")
  124. ctest_submit(PARTS Configure)
  125. ctest_submit(FILES "${CTEST_BINARY_DIRECTORY}/Project.xml")
  126. # Build top level
  127. message("----------- [ Build SuperBuild ] -----------")
  128. ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}" APPEND)
  129. ctest_submit(PARTS Build)
  130. ctest_test(
  131. BUILD "${CTEST_BINARY_DIRECTORY}"
  132. INCLUDE_LABEL "SuperBuild"
  133. PARALLEL_LEVEL 8
  134. EXCLUDE ${TEST_TO_EXCLUDE_REGEX})
  135. # runs only tests that have a LABELS property matching "${subproject}"
  136. ctest_submit(PARTS Test)
  137. set(ctk_build_dir "${CTEST_BINARY_DIRECTORY}/CTK-build")
  138. # To get CTEST_PROJECT_SUBPROJECTS definition
  139. include("${CTEST_BINARY_DIRECTORY}/CTestConfigSubProject.cmake")
  140. set(kit_suffixes
  141. CppTests
  142. #PythonTests
  143. Plugins
  144. )
  145. foreach(subproject ${CTEST_PROJECT_SUBPROJECTS})
  146. set_property(GLOBAL PROPERTY SubProject ${subproject})
  147. set_property(GLOBAL PROPERTY Label ${subproject})
  148. message("Build ${subproject}")
  149. # Configure target
  150. ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
  151. ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}")
  152. ctest_submit(PARTS Configure)
  153. # Build target
  154. set(CTEST_BUILD_TARGET "${subproject}")
  155. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  156. # Loop over kit suffixes and try to build the corresponding target
  157. foreach(kit_suffixe ${kit_suffixes})
  158. message("----------- [ Build ${subproject}${kit_suffixe} ] -----------")
  159. set(CTEST_BUILD_TARGET "${subproject}${kit_suffixe}")
  160. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  161. endforeach()
  162. ctest_submit(PARTS Build)
  163. endforeach()
  164. if (WITH_DOCUMENTATION)
  165. # Build Documentation target
  166. set(CTEST_BUILD_TARGET "doc")
  167. ctest_build(BUILD "${ctk_build_dir}" APPEND)
  168. endif()
  169. # HACK Unfortunately ctest_coverage ignores the build argument, try to force it...
  170. file(READ ${ctk_build_dir}/CMakeFiles/TargetDirectories.txt ctk_build_coverage_dirs)
  171. file(APPEND "${CTEST_BINARY_DIRECTORY}/CMakeFiles/TargetDirectories.txt" "${ctk_build_coverage_dirs}")
  172. foreach(subproject ${CTEST_PROJECT_SUBPROJECTS})
  173. set_property(GLOBAL PROPERTY SubProject ${subproject})
  174. set_property(GLOBAL PROPERTY Label ${subproject})
  175. message("----------- [ Test ${subproject} ] -----------")
  176. ctest_test(
  177. BUILD "${ctk_build_dir}"
  178. INCLUDE_LABEL "${subproject}"
  179. PARALLEL_LEVEL 8
  180. EXCLUDE ${test_to_exclude_regex})
  181. # runs only tests that have a LABELS property matching "${subproject}"
  182. ctest_submit(PARTS Test)
  183. # Coverage per sub-project (library, application or plugin)
  184. if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
  185. message("----------- [ Coverage ${subproject} ] -----------")
  186. ctest_coverage(BUILD "${ctk_build_dir}" LABELS "${subproject}")
  187. ctest_submit(PARTS Coverage)
  188. endif ()
  189. #if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
  190. # ctest_memcheck(BUILD "${ctk_build_dir}" INCLUDE_LABEL "${subproject}")
  191. # ctest_submit(PARTS MemCheck)
  192. #endif ()
  193. endforeach()
  194. set_property(GLOBAL PROPERTY SubProject SuperBuild)
  195. set_property(GLOBAL PROPERTY Label SuperBuild)
  196. # Global coverage ...
  197. if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
  198. message("----------- [ Global coverage ] -----------")
  199. ctest_coverage(BUILD "${ctk_build_dir}")
  200. ctest_submit(PARTS Coverage)
  201. endif ()
  202. # Global dynamic analysis ...
  203. if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
  204. message("----------- [ Global memcheck ] -----------")
  205. ctest_memcheck(BUILD "${ctk_build_dir}")
  206. ctest_submit(PARTS MemCheck)
  207. endif ()
  208. # Note should be at the end
  209. ctest_submit(PARTS Notes)
  210. endif()
  211. endmacro()
  212. if(SCRIPT_MODE STREQUAL "continuous")
  213. while(${CTEST_ELAPSED_TIME} LESS 68400)
  214. set(START_TIME ${CTEST_ELAPSED_TIME})
  215. run_ctest()
  216. # Loop no faster than once every 5 minutes
  217. message("Wait for 5 minutes ...")
  218. ctest_sleep(${START_TIME} 300 ${CTEST_ELAPSED_TIME})
  219. endwhile()
  220. else()
  221. run_ctest()
  222. endif()