ctkDashboardDriverScript.cmake 7.9 KB

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