CMakeLists.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #
  2. # Build examples.
  3. #
  4. # Requires CATCH_BUILD_EXAMPLES to be defined 'true', see ../CMakeLists.txt.
  5. #
  6. cmake_minimum_required( VERSION 3.0 )
  7. project( CatchExamples CXX )
  8. message( STATUS "Examples included" )
  9. # define folders used:
  10. set( EXAMPLES_DIR ${CATCH_DIR}/examples )
  11. set( HEADER_DIR ${CATCH_DIR}/single_include )
  12. set( REPORTER_HEADER_DIR ${CATCH_DIR}/include/reporters )
  13. # single-file sources:
  14. set( SOURCES_SINGLE_FILE
  15. 010-TestCase.cpp
  16. 231-Cfg-OutputStreams.cpp
  17. )
  18. # multiple-file modules:
  19. set( SOURCES_020
  20. 020-TestCase-1.cpp
  21. 020-TestCase-2.cpp
  22. )
  23. # main for idiomatic test sources:
  24. set( SOURCES_IDIOMATIC_MAIN
  25. 000-CatchMain.cpp
  26. )
  27. # sources to combine with 000-CatchMain.cpp:
  28. set( SOURCES_IDIOMATIC_TESTS
  29. 030-Asn-Require-Check.cpp
  30. 100-Fix-Section.cpp
  31. 110-Fix-ClassFixture.cpp
  32. 120-Bdd-ScenarioGivenWhenThen.cpp
  33. 210-Evt-EventListeners.cpp
  34. 300-Gen-OwnGenerator.cpp
  35. 301-Gen-MapTypeConversion.cpp
  36. 302-Gen-Table.cpp
  37. 310-Gen-VariablesInGenerators.cpp
  38. 311-Gen-CustomCapture.cpp
  39. )
  40. # main-s for reporter-specific test sources:
  41. set( SOURCES_REPORTERS_MAIN
  42. 200-Rpt-CatchMain.cpp
  43. )
  44. string( REPLACE ".cpp" "" BASENAMES_REPORTERS_MAIN 200-Rpt-CatchMain.cpp )
  45. set( NAMES_REPORTERS TeamCity )
  46. foreach( reporter ${NAMES_REPORTERS} )
  47. list( APPEND SOURCES_SPECIFIC_REPORTERS_MAIN ${BASENAMES_REPORTERS_MAIN}${reporter}.cpp )
  48. endforeach()
  49. # sources to combine with 200-Rpt-CatchMain{Reporter}.cpp:
  50. set( SOURCES_REPORTERS_TESTS
  51. 207-Rpt-TeamCityReporter.cpp
  52. )
  53. # check if all sources are listed, warn if not:
  54. set( SOURCES_ALL
  55. ${SOURCES_020}
  56. ${SOURCES_SINGLE_FILE}
  57. ${SOURCES_IDIOMATIC_MAIN}
  58. ${SOURCES_IDIOMATIC_TESTS}
  59. ${SOURCES_REPORTERS_MAIN}
  60. ${SOURCES_REPORTERS_TESTS}
  61. )
  62. foreach( name ${SOURCES_ALL} )
  63. list( APPEND SOURCES_ALL_PATH ${EXAMPLES_DIR}/${name} )
  64. endforeach()
  65. CheckFileList( SOURCES_ALL_PATH ${EXAMPLES_DIR} )
  66. # create target names:
  67. string( REPLACE ".cpp" "" BASENAMES_SINGLE_FILE "${SOURCES_SINGLE_FILE}" )
  68. string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_TESTS "${SOURCES_IDIOMATIC_TESTS}" )
  69. string( REPLACE ".cpp" "" BASENAMES_REPORTERS_TESTS "${SOURCES_REPORTERS_TESTS}" )
  70. string( REPLACE ".cpp" "" BASENAMES_REPORTERS_MAIN "${SOURCES_REPORTERS_MAIN}" )
  71. set( TARGETS_SINGLE_FILE ${BASENAMES_SINGLE_FILE} )
  72. set( TARGETS_IDIOMATIC_TESTS ${BASENAMES_IDIOMATIC_TESTS} )
  73. set( TARGETS_REPORTERS_TESTS ${BASENAMES_REPORTERS_TESTS} )
  74. set( TARGETS_REPORTERS_MAIN ${BASENAMES_REPORTERS_MAIN} )
  75. set( TARGETS_ALL
  76. ${TARGETS_SINGLE_FILE}
  77. 020-TestCase
  78. ${TARGETS_IDIOMATIC_TESTS} CatchMain
  79. ${TARGETS_REPORTERS_TESTS} CatchMainTeamCity
  80. )
  81. # define program targets:
  82. add_library( CatchMain OBJECT ${EXAMPLES_DIR}/${SOURCES_IDIOMATIC_MAIN} ${HEADER_DIR}/catch2/catch.hpp )
  83. #add_library( CatchMainAutomake OBJECT ${EXAMPLES_DIR}/200-Rpt-CatchMain.cpp ${HEADER_DIR}/catch2/catch.hpp )
  84. #add_library( CatchMainTap OBJECT ${EXAMPLES_DIR}/200-Rpt-CatchMain.cpp ${HEADER_DIR}/catch2/catch.hpp )
  85. add_library( CatchMainTeamCity OBJECT ${EXAMPLES_DIR}/200-Rpt-CatchMain.cpp ${HEADER_DIR}/catch2/catch.hpp )
  86. #target_compile_definitions( CatchMainAutomake PRIVATE CATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_automake.hpp\" )
  87. #target_compile_definitions( CatchMainTap PRIVATE CATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_tap.hpp\" )
  88. target_compile_definitions( CatchMainTeamCity PRIVATE CATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_teamcity.hpp\" )
  89. foreach( name ${TARGETS_SINGLE_FILE} )
  90. add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp ${HEADER_DIR}/catch2/catch.hpp )
  91. endforeach()
  92. foreach( name ${TARGETS_IDIOMATIC_TESTS} )
  93. add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp $<TARGET_OBJECTS:CatchMain> ${HEADER_DIR}/catch2/catch.hpp )
  94. endforeach()
  95. add_executable( 020-TestCase ${EXAMPLES_DIR}/020-TestCase-1.cpp ${EXAMPLES_DIR}/020-TestCase-2.cpp ${HEADER_DIR}/catch2/catch.hpp )
  96. #add_executable( 207-Rpt-AutomakeReporter ${EXAMPLES_DIR}/207-Rpt-AutomakeReporter.cpp $<TARGET_OBJECTS:CatchMainAutomake> ${HEADER_DIR}/catch2/catch.hpp )
  97. #add_executable( 207-Rpt-TapReporter ${EXAMPLES_DIR}/207-Rpt-TapReporter.cpp $<TARGET_OBJECTS:CatchMainTap> ${HEADER_DIR}/catch2/catch.hpp )
  98. add_executable( 207-Rpt-TeamCityReporter ${EXAMPLES_DIR}/207-Rpt-TeamCityReporter.cpp $<TARGET_OBJECTS:CatchMainTeamCity> ${HEADER_DIR}/catch2/catch.hpp )
  99. #foreach( name ${TARGETS_REPORTERS_TESTS} )
  100. # add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp $<TARGET_OBJECTS:CatchMain> ${HEADER_DIR}/catch2/catch.hpp )
  101. #endforeach()
  102. foreach( name ${TARGETS_ALL} )
  103. target_include_directories( ${name} PRIVATE ${HEADER_DIR} ${CATCH_DIR} )
  104. set_property(TARGET ${name} PROPERTY CXX_STANDARD 11)
  105. set_property(TARGET ${name} PROPERTY CXX_EXTENSIONS OFF)
  106. # Add desired warnings
  107. if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
  108. target_compile_options( ${name} PRIVATE -Wall -Wextra -Wunreachable-code )
  109. endif()
  110. # Clang specific warning go here
  111. if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
  112. # Actually keep these
  113. target_compile_options( ${name} PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn )
  114. endif()
  115. if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
  116. target_compile_options( ${name} PRIVATE /W4 /w44265 /WX )
  117. endif()
  118. endforeach()