ctkDashboardDriverScript.cmake 7.7 KB

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