CTestTargets.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. if(NOT RUN_FROM_CTEST_OR_DART)
  4. message(FATAL_ERROR "Do not include CTestTargets.cmake directly")
  5. endif()
  6. if(NOT PROJECT_BINARY_DIR)
  7. message(FATAL_ERROR "Do not include(CTest) before calling project().")
  8. endif()
  9. # make directories in the binary tree
  10. file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Testing/Temporary)
  11. get_filename_component(CMAKE_HOST_PATH ${CMAKE_COMMAND} PATH)
  12. set(CMAKE_TARGET_PATH ${EXECUTABLE_OUTPUT_PATH})
  13. find_program(CMAKE_CTEST_COMMAND ctest ${CMAKE_HOST_PATH} ${CMAKE_TARGET_PATH})
  14. mark_as_advanced(CMAKE_CTEST_COMMAND)
  15. # Use CTest
  16. # configure files
  17. block()
  18. if(NOT DEFINED CTEST_TLS_VERSION)
  19. if(DEFINED CMAKE_TLS_VERSION)
  20. set(CTEST_TLS_VERSION "${CMAKE_TLS_VERSION}")
  21. elseif(DEFINED ENV{CMAKE_TLS_VERSION})
  22. set(CTEST_TLS_VERSION "$ENV{CMAKE_TLS_VERSION}")
  23. endif()
  24. endif()
  25. if(NOT DEFINED CTEST_TLS_VERIFY)
  26. if(DEFINED CMAKE_TLS_VERIFY)
  27. set(CTEST_TLS_VERIFY "${CMAKE_TLS_VERIFY}")
  28. elseif(DEFINED ENV{CMAKE_TLS_VERIFY})
  29. set(CTEST_TLS_VERIFY "$ENV{CMAKE_TLS_VERIFY}")
  30. endif()
  31. endif()
  32. if(CTEST_NEW_FORMAT)
  33. configure_file(
  34. ${CMAKE_ROOT}/Modules/DartConfiguration.tcl.in
  35. ${PROJECT_BINARY_DIR}/CTestConfiguration.ini )
  36. else()
  37. configure_file(
  38. ${CMAKE_ROOT}/Modules/DartConfiguration.tcl.in
  39. ${PROJECT_BINARY_DIR}/DartConfiguration.tcl )
  40. endif()
  41. configure_file(
  42. ${CMAKE_ROOT}/Templates/CTestScript.cmake.in
  43. ${PROJECT_BINARY_DIR}/CMakeFiles/CTestScript.cmake @ONLY)
  44. endblock()
  45. #
  46. # Section 3:
  47. #
  48. # Custom targets to perform dashboard builds and submissions.
  49. # These should NOT need to be modified from project to project.
  50. #
  51. set(__conf_types "")
  52. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  53. if(_isMultiConfig)
  54. # We need to pass the configuration type on the test command line.
  55. set(__conf_types -C "$<CONFIG>")
  56. endif()
  57. # Add convenience targets. Do this at most once in case of nested
  58. # projects.
  59. define_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED
  60. BRIEF_DOCS "Internal property used by CTestTargets module."
  61. FULL_DOCS "Set by the CTestTargets module to track addition of testing targets."
  62. )
  63. get_property(_CTEST_TARGETS_ADDED GLOBAL PROPERTY CTEST_TARGETS_ADDED)
  64. if(NOT _CTEST_TARGETS_ADDED)
  65. set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
  66. # For all generators add basic testing targets.
  67. foreach(mode Experimental Nightly Continuous NightlyMemoryCheck)
  68. add_custom_target(${mode}
  69. COMMAND
  70. ${CMAKE_CTEST_COMMAND} ${__conf_types}
  71. -DMODEL=${mode} -S CMakeFiles/CTestScript.cmake -V
  72. USES_TERMINAL
  73. )
  74. set_property(TARGET ${mode} PROPERTY RULE_LAUNCH_CUSTOM "")
  75. set_property(TARGET ${mode} PROPERTY FOLDER "CTestDashboardTargets")
  76. endforeach()
  77. # For Makefile generators add more granular targets.
  78. if("${CMAKE_GENERATOR}" MATCHES "(Ninja|Make|FASTBuild)")
  79. # Make targets for Experimental builds
  80. foreach(mode Nightly Experimental Continuous)
  81. foreach(testtype
  82. Start Update Configure Build Test Coverage MemCheck Submit
  83. # missing purify
  84. )
  85. add_custom_target(${mode}${testtype}
  86. COMMAND
  87. ${CMAKE_CTEST_COMMAND} ${__conf_types}
  88. -DMODEL=${mode} -DACTIONS=${testtype}
  89. -S CMakeFiles/CTestScript.cmake -V
  90. USES_TERMINAL
  91. )
  92. set_property(TARGET ${mode}${testtype} PROPERTY RULE_LAUNCH_CUSTOM "")
  93. set_property(TARGET ${mode}${testtype} PROPERTY FOLDER "CTestDashboardTargets")
  94. endforeach()
  95. endforeach()
  96. endif()
  97. # If requested, add an alias that is the equivalent of the built-in "test"
  98. # or "RUN_TESTS" target:
  99. if(CTEST_TEST_TARGET_ALIAS)
  100. add_custom_target(${CTEST_TEST_TARGET_ALIAS}
  101. ${CMAKE_CTEST_COMMAND} ${CMAKE_CTEST_ARGUMENTS} ${__conf_types}
  102. USES_TERMINAL
  103. )
  104. endif()
  105. endif()