ctkDashboardDriverScript.cmake 7.6 KB

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