CMakeLists.txt 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. # Copyright 2014, Raffi Enficiaud
  2. # Use, modification, and distribution are subject to the
  3. # Boost Software License, Version 1.0. (See accompanying file
  4. # LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #
  6. # See http://www.boost.org/libs/test for the library home page.
  7. cmake_minimum_required(VERSION 2.8.11)
  8. project(BoostTest)
  9. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  10. set(CMAKE_MACOSX_RPATH ON)
  11. add_definitions(-DBOOST_TEST_NO_LIB)
  12. # build type, by default to release (with optimisations)
  13. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  14. message(STATUS "Setting build type to 'Release' as none was specified.")
  15. set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
  16. # Set the possible values of build type for cmake-gui
  17. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  18. endif()
  19. if(NOT WITHOUT_TESTS)
  20. # ctest sets BUILD_TESTING automatically, but does not seem to serve its purpose.
  21. include(CTest)
  22. enable_testing()
  23. endif()
  24. include(CheckCXXCompilerFlag)
  25. include(CheckIncludeFileCXX)
  26. if(NOT MSVC)
  27. # c++11 options
  28. check_cxx_compiler_flag(-std=c++11 HAS_CXX11_FLAG)
  29. check_cxx_compiler_flag(-std=c++0x HAS_CXX0X_FLAG)
  30. if(HAS_CXX11_FLAG)
  31. message(STATUS "Compiling with C++11 support")
  32. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  33. elseif(HAS_CXX0X_FLAG)
  34. #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  35. endif()
  36. endif()
  37. if(MSVC)
  38. add_definitions(-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS)
  39. set(MSVC_Additional_flags "/fp:fast /GF /Oy /GT /Ox /Ob2 /Oi /Os")
  40. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MSVC_Additional_flags}")
  41. endif()
  42. # global path
  43. set(BOOST_TEST_ROOT_DIR ${BoostTest_SOURCE_DIR}/..)
  44. set(BOOST_ROOT_DIR ${BOOST_TEST_ROOT_DIR}/../..)
  45. get_filename_component(BOOST_TEST_ROOT_DIR_ABS ${BoostTest_SOURCE_DIR}/.. ABSOLUTE)
  46. get_filename_component(BOOST_ROOT_DIR_ABS ${BOOST_ROOT_DIR} ABSOLUTE)
  47. # global include on boost
  48. include_directories(${BOOST_ROOT_DIR_ABS}/)
  49. # include globs
  50. file(GLOB_RECURSE
  51. BOOST_UTF_HEADERS
  52. ${BOOST_TEST_ROOT_DIR}/include/*.hpp
  53. ${BOOST_TEST_ROOT_DIR}/include/*.ipp)
  54. # organize files
  55. foreach(_h IN LISTS BOOST_UTF_HEADERS)
  56. get_filename_component(_hh ${_h} ABSOLUTE)
  57. file(RELATIVE_PATH _v ${BOOST_TEST_ROOT_DIR_ABS}/include/boost/test ${_hh})
  58. get_filename_component(_v "${_v}" DIRECTORY)
  59. string(REPLACE "/" "\\" _v "${_v}")
  60. source_group(${_v} FILES ${_h})
  61. endforeach()
  62. set(BOOST_UTF_SRC
  63. ${BOOST_TEST_ROOT_DIR}/src/compiler_log_formatter.cpp
  64. ${BOOST_TEST_ROOT_DIR}/src/debug.cpp
  65. ${BOOST_TEST_ROOT_DIR}/src/decorator.cpp
  66. ${BOOST_TEST_ROOT_DIR}/src/execution_monitor.cpp
  67. ${BOOST_TEST_ROOT_DIR}/src/framework.cpp
  68. ${BOOST_TEST_ROOT_DIR}/src/junit_log_formatter.cpp
  69. ${BOOST_TEST_ROOT_DIR}/src/plain_report_formatter.cpp
  70. ${BOOST_TEST_ROOT_DIR}/src/progress_monitor.cpp
  71. ${BOOST_TEST_ROOT_DIR}/src/results_collector.cpp
  72. ${BOOST_TEST_ROOT_DIR}/src/results_reporter.cpp
  73. ${BOOST_TEST_ROOT_DIR}/src/test_framework_init_observer.cpp
  74. ${BOOST_TEST_ROOT_DIR}/src/test_tools.cpp
  75. ${BOOST_TEST_ROOT_DIR}/src/test_tree.cpp
  76. ${BOOST_TEST_ROOT_DIR}/src/unit_test_log.cpp
  77. ${BOOST_TEST_ROOT_DIR}/src/unit_test_main.cpp
  78. ${BOOST_TEST_ROOT_DIR}/src/unit_test_monitor.cpp
  79. ${BOOST_TEST_ROOT_DIR}/src/unit_test_parameters.cpp
  80. ${BOOST_TEST_ROOT_DIR}/src/xml_log_formatter.cpp
  81. ${BOOST_TEST_ROOT_DIR}/src/xml_report_formatter.cpp
  82. )
  83. add_library(boost_test_framework
  84. STATIC
  85. ${BOOST_UTF_HEADERS}
  86. ${BOOST_UTF_SRC})
  87. #target_compile_definitions(boost_test_framework PUBLIC "-DBOOST_TEST_DYN_LINK=0")
  88. target_include_directories(boost_test_framework PUBLIC ${BOOST_TEST_ROOT_DIR}/include/)
  89. set_target_properties(boost_test_framework PROPERTIES FOLDER "UTF")
  90. add_library(boost_test_framework_shared
  91. SHARED
  92. ${BOOST_UTF_HEADERS}
  93. ${BOOST_UTF_SRC})
  94. target_compile_definitions(boost_test_framework_shared PUBLIC "-DBOOST_TEST_DYN_LINK=1")
  95. target_include_directories(boost_test_framework_shared PUBLIC ${BOOST_TEST_ROOT_DIR}/include/)
  96. set_target_properties(boost_test_framework_shared PROPERTIES FOLDER "UTF")
  97. ####
  98. # Documentation files (files only, no target)
  99. file(GLOB_RECURSE
  100. BOOST_UTF_DOC_FILES
  101. ${BOOST_TEST_ROOT_DIR}/doc/*.qbk)
  102. add_custom_target(
  103. quickbook
  104. SOURCES ${BOOST_UTF_DOC_FILES})
  105. set_property(TARGET quickbook PROPERTY FOLDER "Documentation/")
  106. ####
  107. # Unit tests
  108. # documentation tests
  109. file(GLOB_RECURSE
  110. BOOST_UTF_DOC_EXAMPLES
  111. CONFIGURE_DEPENDS
  112. ${BOOST_TEST_ROOT_DIR}/doc/examples/*.cpp)
  113. foreach(_h IN LISTS BOOST_UTF_DOC_EXAMPLES)
  114. get_filename_component(_hh ${_h} NAME_WE)
  115. add_executable(doc-${_hh} ${_h} ${BOOST_TEST_ROOT_DIR}/doc/examples/${_hh}.output)
  116. target_include_directories(doc-${_hh} PUBLIC ${BOOST_TEST_ROOT_DIR}/include/)
  117. set_target_properties(doc-${_hh} PROPERTIES FOLDER "Doc examples")
  118. add_test(NAME doc-${_hh}-test
  119. COMMAND doc-${_hh})
  120. get_filename_component(_ext ${_h} EXT)
  121. string(FIND ${_ext} "fail" _index_fail)
  122. if(${_index_fail} GREATER -1)
  123. message(STATUS "test ${_hh}.${_ext} = ${_index_fail}")
  124. set_tests_properties(doc-${_hh}-test PROPERTIES WILL_FAIL TRUE)
  125. endif()
  126. endforeach()
  127. # unit tests folder
  128. set(BOOST_TEST_UNITTESTS_FOLDER ${BOOST_TEST_ROOT_DIR}/test)
  129. set(BOOST_TEST_EXAMPLES_FOLDER ${BOOST_TEST_ROOT_DIR}/example)
  130. # datasets
  131. file(GLOB
  132. BOOST_TEST_UNITTESTS_DATASET
  133. CONFIGURE_DEPENDS
  134. ${BOOST_TEST_UNITTESTS_FOLDER}/test-organization-ts/datasets-test/*.cpp
  135. ${BOOST_TEST_UNITTESTS_FOLDER}/test-organization-ts/datasets-test/*.hpp)
  136. add_executable(boost_test_datasets ${BOOST_TEST_UNITTESTS_DATASET})
  137. target_include_directories(boost_test_datasets PUBLIC ${BOOST_TEST_ROOT_DIR}/include/)
  138. target_link_libraries(boost_test_datasets boost_test_framework)
  139. #target_compile_definitions(boost_test_datasets PUBLIC "BOOST_TEST_DYN_LINK=0")
  140. set_target_properties(boost_test_datasets PROPERTIES FOLDER "Unit tests")
  141. add_test(NAME bt-unittest-dataset
  142. COMMAND boost_test_datasets)
  143. ####
  144. # TS writing-test-ts
  145. set(BOOST_UTF_TESTS_IND_FILES
  146. writing-test-ts
  147. execution_monitor-ts
  148. framework-ts
  149. usage-variants-ts
  150. utils-ts
  151. test-organization-ts
  152. smoke-ts
  153. )
  154. foreach(_ts IN LISTS BOOST_UTF_TESTS_IND_FILES)
  155. message("parsing test suite ${_ts}")
  156. file(GLOB
  157. _boost_utf_current_tsuite
  158. ${BOOST_TEST_UNITTESTS_FOLDER}/${_ts}/*.cpp)
  159. foreach(_h IN LISTS _boost_utf_current_tsuite)
  160. get_filename_component(_hh ${_h} ABSOLUTE)
  161. get_filename_component(_name ${_h} NAME_WE)
  162. file(RELATIVE_PATH _v ${BOOST_TEST_UNITTESTS_FOLDER} ${_hh})
  163. #get_filename_component(_v "${_v}" DIRECTORY)
  164. message("adding ${_ts}/${_name}")
  165. add_executable(${_name} ${_hh})
  166. target_link_libraries(${_name} PRIVATE boost_test_framework)
  167. set_target_properties(${_name} PROPERTIES FOLDER "Unit tests/${_ts}")
  168. add_test(NAME bt-unittest-${_name}
  169. COMMAND ${_name})
  170. endforeach()
  171. unset(_boost_utf_current_tsuite)
  172. endforeach() # test suite
  173. #
  174. # Example code
  175. #
  176. set(LIST_EXAMPLES
  177. unit_test_example_01.cpp,shared,fail
  178. unit_test_example_02.cpp,static,fail
  179. unit_test_example_03.cpp,static,fail
  180. unit_test_example_04.cpp,shared,fail
  181. unit_test_example_05.cpp,shared,fail
  182. unit_test_example_06.cpp,shared,fail
  183. unit_test_example_07.cpp,shared,run
  184. unit_test_example_08.cpp,shared,run
  185. unit_test_example_09_1.cpp,unit_test_example_09_2.cpp,shared,run
  186. unit_test_example_10.cpp,static,fail
  187. unit_test_example_11.cpp,static,fail
  188. unit_test_example_12.cpp,static,link
  189. unit_test_example_13.cpp,shared,run
  190. unit_test_example_15.cpp,shared,fail
  191. unit_test_example_16.cpp,shared,run
  192. const_string_test.cpp,none,run
  193. named_param_example.cpp,none,run
  194. external_main_example_1.cpp,shared,fail
  195. external_main_example_2.cpp,shared,fail
  196. external_main_example_3.cpp,none,fail
  197. filtering_example.cpp,static,fail
  198. )
  199. foreach(_var IN LISTS LIST_EXAMPLES)
  200. string(REPLACE "," ";" _var_to_list "${_var}")
  201. list(REVERSE _var_to_list)
  202. list(GET _var_to_list 0 action)
  203. list(GET _var_to_list 1 boost_test_type)
  204. list(REMOVE_AT _var_to_list 0)
  205. list(REMOVE_AT _var_to_list 0)
  206. list(GET _var_to_list 0 first_file)
  207. get_filename_component(_name_example "${first_file}" NAME_WE)
  208. set(_list_files)
  209. foreach(_file IN LISTS _var_to_list)
  210. set(_list_files ${_list_files} ${BOOST_TEST_EXAMPLES_FOLDER}/${_file})
  211. endforeach()
  212. add_executable(${_name_example} ${_list_files})
  213. set_target_properties(${_name_example} PROPERTIES FOLDER "Examples")
  214. if("${boost_test_type}" STREQUAL "shared")
  215. target_link_libraries(${_name_example} PRIVATE boost_test_framework_shared)
  216. elseif("${boost_test_type}" STREQUAL "static")
  217. target_link_libraries(${_name_example} PRIVATE boost_test_framework)
  218. elseif(NOT "${boost_test_type}" STREQUAL "none")
  219. message(FATAL_ERROR "Wrong action for example target '${_name_example}'")
  220. endif()
  221. if("${action}" STREQUAL "run" OR "${action}" STREQUAL "run-fail")
  222. add_test(NAME bt-exampletest-${_name_example}
  223. COMMAND ${_name_example})
  224. if("${action}" STREQUAL "run-fail")
  225. set_tests_properties(bt-exampletest-${_name_example} PROPERTIES WILL_FAIL TRUE)
  226. endif()
  227. endif()
  228. endforeach()