ctkDashboardDriverScript.cmake 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. # XXX This allows to support older scripts having the typo
  29. if(DEFINED ADDITIONNAL_CMAKECACHE_OPTION)
  30. set(ADDITIONAL_CMAKECACHE_OPTION ${ADDITIONNAL_CMAKECACHE_OPTION})
  31. endif()
  32. #-----------------------------------------------------------------------------
  33. # The following variable are expected to be define in the top-level script:
  34. set(expected_variables
  35. ADDITIONAL_CMAKECACHE_OPTION
  36. CTEST_NOTES_FILES
  37. CTEST_SITE
  38. CTEST_DASHBOARD_ROOT
  39. CTEST_CMAKE_GENERATOR
  40. WITH_MEMCHECK
  41. WITH_COVERAGE
  42. WITH_DOCUMENTATION
  43. CTEST_BUILD_CONFIGURATION
  44. CTEST_TEST_TIMEOUT
  45. CTEST_BUILD_FLAGS
  46. TEST_TO_EXCLUDE_REGEX
  47. CTEST_PROJECT_NAME
  48. CTEST_SOURCE_DIRECTORY
  49. CTEST_BINARY_DIRECTORY
  50. CTEST_BUILD_NAME
  51. SCRIPT_MODE
  52. CTEST_COVERAGE_COMMAND
  53. CTEST_MEMORYCHECK_COMMAND
  54. CTEST_GIT_COMMAND
  55. QT_QMAKE_EXECUTABLE
  56. )
  57. if(WITH_DOCUMENTATION)
  58. list(APPEND expected_variables DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  59. endif()
  60. foreach(var ${expected_variables})
  61. if(NOT DEFINED ${var})
  62. message(FATAL_ERROR "Variable ${var} should be defined in top-level script !")
  63. endif()
  64. endforeach()
  65. # If the dashscript doesn't define a GIT_REPOSITORY variable, let's define it here.
  66. if(NOT DEFINED GIT_REPOSITORY OR GIT_REPOSITORY STREQUAL "")
  67. set(GIT_REPOSITORY http://github.com/commontk/CTK.git)
  68. endif()
  69. set(repository ${GIT_REPOSITORY})
  70. set(git_branch_option "")
  71. if(NOT "${GIT_TAG}" STREQUAL "")
  72. set(git_branch_option "-b ${GIT_TAG}")
  73. endif()
  74. message("GIT_REPOSITORY ......: ${GIT_REPOSITORY}")
  75. message("GIT_TAG .............: ${GIT_TAG}")
  76. # Should binary directory be cleaned?
  77. set(empty_binary_directory FALSE)
  78. # Attempt to build and test also if 'ctest_update' returned an error
  79. set(force_build FALSE)
  80. # Ensure SCRIPT_MODE is lowercase
  81. string(TOLOWER ${SCRIPT_MODE} SCRIPT_MODE)
  82. # Set model options
  83. set(model "")
  84. if(SCRIPT_MODE STREQUAL "experimental")
  85. set(empty_binary_directory FALSE)
  86. set(force_build TRUE)
  87. set(model Experimental)
  88. elseif(SCRIPT_MODE STREQUAL "continuous")
  89. set(empty_binary_directory TRUE)
  90. set(force_build FALSE)
  91. set(model Continuous)
  92. elseif(SCRIPT_MODE STREQUAL "nightly")
  93. set(empty_binary_directory TRUE)
  94. set(force_build TRUE)
  95. set(model Nightly)
  96. else()
  97. message(FATAL_ERROR "Unknown script mode: '${SCRIPT_MODE}'. Script mode should be either 'experimental', 'continuous' or 'nightly'")
  98. endif()
  99. # For more details, see http://www.kitware.com/blog/home/post/11
  100. set(CTEST_USE_LAUNCHERS 1)
  101. if(NOT "${CTEST_CMAKE_GENERATOR}" MATCHES "Make")
  102. set(CTEST_USE_LAUNCHERS 0)
  103. endif()
  104. set(ENV{CTEST_USE_LAUNCHERS_DEFAULT} ${CTEST_USE_LAUNCHERS})
  105. if(empty_binary_directory)
  106. message("Directory ${CTEST_BINARY_DIRECTORY} cleaned !")
  107. ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
  108. endif()
  109. if(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}")
  110. set(CTEST_CHECKOUT_COMMAND "${CTEST_GIT_COMMAND} clone ${git_branch_option} ${GIT_REPOSITORY} ${CTEST_SOURCE_DIRECTORY}")
  111. endif()
  112. set(CTEST_UPDATE_COMMAND "${CTEST_GIT_COMMAND}")
  113. #
  114. # run_ctest macro
  115. #
  116. macro(run_ctest)
  117. message("----------- [ Start ${CTEST_PROJECT_NAME} ] -----------")
  118. ctest_start(${model})
  119. message("----------- [ Update ${CTEST_PROJECT_NAME} ] -----------")
  120. ctest_update(SOURCE "${CTEST_SOURCE_DIRECTORY}" RETURN_VALUE res)
  121. # force a build if this is the first run and the build dir is empty
  122. if(NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
  123. message("First time build - Initialize CMakeCache.txt")
  124. set(res 1)
  125. # Write initial cache.
  126. file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "
  127. QT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  128. WITH_COVERAGE:BOOL=${WITH_COVERAGE}
  129. DOCUMENTATION_TARGET_IN_ALL:BOOL=${WITH_DOCUMENTATION}
  130. DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
  131. ${ADDITIONAL_CMAKECACHE_OPTION}
  132. ")
  133. endif()
  134. if(res GREATER 0 OR force_build)
  135. #-----------------------------------------------------------------------------
  136. # Update
  137. #-----------------------------------------------------------------------------
  138. ctest_submit(PARTS Update)
  139. #-----------------------------------------------------------------------------
  140. # Configure
  141. #-----------------------------------------------------------------------------
  142. message("----------- [ Configure ${CTEST_PROJECT_NAME} ] -----------")
  143. ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
  144. ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}")
  145. ctest_submit(PARTS Configure)
  146. #-----------------------------------------------------------------------------
  147. # Build top level
  148. #-----------------------------------------------------------------------------
  149. set(build_errors)
  150. message("----------- [ Build ${CTEST_PROJECT_NAME} ] -----------")
  151. ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}" NUMBER_ERRORS build_errors APPEND)
  152. ctest_submit(PARTS Build)
  153. #-----------------------------------------------------------------------------
  154. # Inner build directory
  155. #-----------------------------------------------------------------------------
  156. set(ctk_build_dir "${CTEST_BINARY_DIRECTORY}/CTK-build")
  157. #-----------------------------------------------------------------------------
  158. # Test
  159. #-----------------------------------------------------------------------------
  160. message("----------- [ Test ${CTEST_PROJECT_NAME} ] -----------")
  161. ctest_test(
  162. BUILD "${ctk_build_dir}"
  163. PARALLEL_LEVEL ${CTEST_PARALLEL_LEVEL}
  164. EXCLUDE ${TEST_TO_EXCLUDE_REGEX})
  165. ctest_submit(PARTS Test)
  166. #-----------------------------------------------------------------------------
  167. # Global coverage ...
  168. #-----------------------------------------------------------------------------
  169. if(WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
  170. # HACK Unfortunately ctest_coverage ignores the build argument, try to force it...
  171. file(READ ${ctk_build_dir}/CMakeFiles/TargetDirectories.txt ctk_build_coverage_dirs)
  172. file(APPEND "${CTEST_BINARY_DIRECTORY}/CMakeFiles/TargetDirectories.txt" "${ctk_build_coverage_dirs}")
  173. message("----------- [ Coverage ] -----------")
  174. ctest_coverage(BUILD "${ctk_build_dir}")
  175. ctest_submit(PARTS Coverage)
  176. endif()
  177. #-----------------------------------------------------------------------------
  178. # Global dynamic analysis ...
  179. #-----------------------------------------------------------------------------
  180. if(WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
  181. message("----------- [ Memcheck ] -----------")
  182. ctest_memcheck(BUILD "${ctk_build_dir}")
  183. ctest_submit(PARTS MemCheck)
  184. endif()
  185. # Note should be at the end
  186. ctest_submit(PARTS Notes)
  187. endif()
  188. endmacro()
  189. if(SCRIPT_MODE STREQUAL "continuous")
  190. while(${CTEST_ELAPSED_TIME} LESS 46800) # Lasts 13 hours (Assuming it starts at 9am, it will end around 10pm)
  191. set(START_TIME ${CTEST_ELAPSED_TIME})
  192. run_ctest()
  193. # Loop no faster than once every 5 minutes
  194. message("Wait for 5 minutes ...")
  195. ctest_sleep(${START_TIME} 300 ${CTEST_ELAPSED_TIME})
  196. endwhile()
  197. else()
  198. run_ctest()
  199. endif()