CMakeLists.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. # CMake build control file for Serialization Library tests
  2. cmake_minimum_required(VERSION 3.0)
  3. if (POLICY CMP0054)
  4. cmake_policy (SET CMP0054 NEW)
  5. endif (POLICY CMP0054)
  6. if (POLICY CMP0063)
  7. cmake_policy (SET CMP0063 NEW)
  8. endif (POLICY CMP0063)
  9. if(Boost_USE_STATIC_LIBS)
  10. project("Serialization-Static")
  11. else()
  12. project("Serialization-Shared")
  13. endif()
  14. #
  15. # Compiler settings
  16. #
  17. message(STATUS "compiler is ${CMAKE_CXX_COMPILER_ID}" )
  18. add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
  19. if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
  20. add_definitions( -ftemplate-depth=300 )
  21. # we use gcc to test for C++03 compatibility
  22. add_definitions( -std=c++03 )
  23. message(STATUS "compiler is g++ c++03")
  24. set(COMPILER_SUPPORTS_CXX11 FALSE)
  25. elseif( CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
  26. add_definitions( /wd4996 )
  27. message(STATUS "compiler is MSVC")
  28. set(COMPILER_SUPPORTS_CXX11 TRUE)
  29. elseif( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
  30. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=300")
  31. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
  32. #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  33. set(CMAKE_CXX_FLAGS_DEBUG "-g -O0" )
  34. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3" )
  35. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -dead_strip")
  36. set(COMPILER_SUPPORTS_CXX11 FALSE)
  37. endif()
  38. #
  39. # Locate Project Prerequisites
  40. #
  41. # Boost
  42. # note: we're assuming that boost has been built with:
  43. # ./b2 —-layout=versioned toolset=clang-darwin link=static,shared variant=debug,release stage
  44. ###########################
  45. # special notes for Xcode.
  46. # these three should result in CMake setting the variables
  47. # Boost_SERIALIZATION_LIBRARY_DEBUG … to the correct values.
  48. # But my current version of CMake doesn't automatically set the library names
  49. # to point to the the libraries to be used. The variables are created
  50. # but they are not initialized. So be prepared to set these variables by hand.
  51. # If you want to use the static libraries - point to the boost libraries ending
  52. # in ".a". If you want to use the shared boost libraries - point to the libraries
  53. # ending in ".dylib".
  54. # But wait - there's more.
  55. # if both lib.a and lib.dylib both exist in the library directory, Xcode will
  56. # automatically chose the *.dylib one - and there's nothing you can do to fix this.
  57. # So my recommendation is
  58. # a) to place the compiled libraries in two different directories
  59. # - e.g. stage/lib-static/*.a and stage/lib-shared/*.dylib
  60. # and set the CMake variable Boost_LIBRARY_DIR to point to one or the other
  61. # b) create two different CMake build directories - build-static and build-shared
  62. # and switch between projects as desired. I like to test both since
  63. # there are things like dead code elimination and visibility which vary
  64. # between the two environments.
  65. #
  66. # caveat - as I write this, I've been unable to get the tests on the shared
  67. # library to function. Problem is that one needs to either put the shared
  68. # libraries in a special known place or set an environmental
  69. # variable which points to the shared library directory. I prefer the latter
  70. # but I've been unable to figure out how to get Xcode to do on a global basis
  71. # and it's not practical to do this for 247 test targets one at a time.
  72. # c) The targets in the project will by default be built as universal 32/64 binaries
  73. # I have yet to experiment with these yet so I just set the target to 64 bit.
  74. # end special note for Xcode
  75. ############################
  76. #
  77. # IDE settings
  78. #
  79. set(Boost_DEBUG true)
  80. set(Boost_ADDRESS_MODEL 64 CACHE STRING "32/64 bits")
  81. set(Boost_USE_STATIC_LIBS TRUE CACHE BOOL "Use static libraries")
  82. set(Boost_USE_MULTITHREADED ON)
  83. set(Boost_DETAILED_FAILURE_MSG true)
  84. get_filename_component(BOOST_ROOT "../../.." ABSOLUTE)
  85. string(CONCAT boost_headers ${BOOST_ROOT} "/boost")
  86. if(NOT IS_DIRECTORY ${boost_headers})
  87. message(FATAL_ERROR "BOOST_ROOT not found")
  88. else()
  89. message(STATUS "BOOST_ROOT is ${BOOST_ROOT}")
  90. endif()
  91. if(Boost_USE_STATIC_LIBS)
  92. message(STATUS "Link to Boost static libraries")
  93. set(BUILD_SHARED_LIBS NO)
  94. string(CONCAT boost_stage ${BOOST_ROOT} "/stage/Debug/static")
  95. else()
  96. message(STATUS "Link to Boost shared libraries")
  97. set(BUILD_SHARED_LIBS YES)
  98. add_definitions( "-DBOOST_ALL_DYN_LINK=1")
  99. add_definitions( "-DBOOST_ALL_NO_LIB=1")
  100. add_definitions( "-DBOOST_LIB_DIAGNOSTICS=1")
  101. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  102. set(VISIBILITY_INLINES_HIDDEN YES)
  103. string(CONCAT boost_stage ${BOOST_ROOT} "/stage/Debug/shared")
  104. endif()
  105. include(CheckIncludeFileCXX)
  106. message(STATUS "Boost directories found at ${boost_headers}")
  107. message(STATUS "Boost libraries found at ${boost_stage}")
  108. set(CMAKE_LIBRARY_PATH ${boost_stage})
  109. # list of archive names for which tests should be generated
  110. #set(archive_list text_archive text_warchive binary_archive xml_archive xml_warchive)
  111. set(archive_list text_archive)
  112. # list of tests generated by each function call
  113. set(test_list)
  114. include_directories(BEFORE ${BOOST_ROOT})
  115. ###########################
  116. # library builds
  117. add_library(serialization
  118. ../src/archive_exception.cpp
  119. ../src/basic_archive.cpp
  120. ../src/basic_iarchive.cpp
  121. ../src/basic_iserializer.cpp
  122. ../src/basic_oarchive.cpp
  123. ../src/basic_oserializer.cpp
  124. ../src/basic_pointer_iserializer.cpp
  125. ../src/basic_pointer_oserializer.cpp
  126. ../src/basic_serializer_map.cpp
  127. ../src/basic_text_iprimitive.cpp
  128. ../src/basic_text_oprimitive.cpp
  129. ../src/basic_xml_archive.cpp
  130. ../src/binary_iarchive.cpp
  131. ../src/binary_oarchive.cpp
  132. ../src/extended_type_info_no_rtti.cpp
  133. ../src/extended_type_info_typeid.cpp
  134. ../src/extended_type_info.cpp
  135. ../src/polymorphic_iarchive.cpp
  136. ../src/polymorphic_oarchive.cpp
  137. ../src/polymorphic_text_iarchive.cpp
  138. ../src/polymorphic_text_oarchive.cpp
  139. ../src/stl_port.cpp
  140. ../src/text_iarchive.cpp
  141. ../src/text_oarchive.cpp
  142. ../src/void_cast.cpp
  143. ../src/xml_archive_exception.cpp
  144. ../src/xml_iarchive.cpp
  145. ../src/xml_oarchive.cpp
  146. ../src/xml_grammar.cpp
  147. ../src/utf8_codecvt_facet.cpp
  148. ../src/basic_xml_grammar.ipp # doesn't show up in "Source Files" in Xcode"'
  149. )
  150. add_library(wserialization
  151. ../src/codecvt_null.cpp
  152. ../src/basic_text_wiprimitive.cpp
  153. ../src/basic_text_woprimitive.cpp
  154. ../src/text_wiarchive.cpp
  155. ../src/text_woarchive.cpp
  156. ../src/xml_wiarchive.cpp
  157. ../src/xml_woarchive.cpp
  158. ../src/xml_wgrammar.cpp
  159. ../src/basic_xml_grammar.ipp # doesn't show up in "Source Files" in Xcode"'
  160. )
  161. set_property(TARGET wserialization PROPERTY LINK_LIBRARIES serialization)
  162. # end library build
  163. ###########################
  164. add_library(filesystem SHARED IMPORTED GLOBAL ) # or STATIC instead of SHARED
  165. set_target_properties(filesystem PROPERTIES
  166. IMPORTED_LOCATION "${CMAKE_LIBRARY_PATH}/libboost_filesystem-clang-darwin-mt-d-x64-1_69.dylib"
  167. )
  168. get_property(loc TARGET filesystem PROPERTY LOCATION)
  169. message(STATUS "filesystem library located at:${loc}")
  170. ###########################
  171. # test targets
  172. function( serialization_test test_name)
  173. set(arglist)
  174. foreach(a IN ITEMS ${ARGN} )
  175. set(arglist ${arglist} ../test/${a}.cpp)
  176. endforeach()
  177. message(STATUS ${test_name})
  178. add_executable( ${test_name} ../test/${test_name}.cpp ${arglist} )
  179. target_link_libraries(${test_name} serialization wserialization filesystem)
  180. add_test( ${test_name} ${test_name} )
  181. endfunction(serialization_test)
  182. function(archive_test test_name)
  183. set(test_list)
  184. set(arglist)
  185. foreach(a IN ITEMS ${ARGN} )
  186. set(arglist ${arglist} ../test/${a}.cpp)
  187. endforeach()
  188. foreach(
  189. archive-name
  190. IN ITEMS ${archive_list}
  191. )
  192. set(amended_test_name ${test_name}_${archive-name})
  193. add_executable(${amended_test_name} ../test/${test_name}.cpp ${arglist})
  194. set_property(
  195. TARGET ${amended_test_name}
  196. PROPERTY COMPILE_DEFINITIONS BOOST_ARCHIVE_TEST=${archive-name}.hpp
  197. )
  198. message(STATUS ${amended_test_name} " " ${arglist} " " ${archive-name})
  199. target_link_libraries(${amended_test_name} serialization wserialization filesystem)
  200. add_test(${amended_test_name} ${amended_test_name})
  201. set(test_list ${test_list} ${amended_test_name} PARENT_SCOPE)
  202. endforeach()
  203. endfunction(archive_test)
  204. function(polymorphic_archive_test test_name)
  205. set(test_list)
  206. set(arglist)
  207. foreach(a IN ITEMS ${ARGN} )
  208. set(arglist ${arglist} ../test/${a}.cpp)
  209. endforeach()
  210. foreach(
  211. archive-name
  212. IN ITEMS ${archive_list}
  213. )
  214. set(amended_archive_name polymorphic_${archive-name})
  215. set(amended_test_name ${test_name}_${amended_archive_name})
  216. add_executable(${amended_test_name} ../test/${test_name}.cpp ${arglist})
  217. set_property(
  218. TARGET ${amended_test_name}
  219. PROPERTY COMPILE_DEFINITIONS BOOST_ARCHIVE_TEST=${amended_archive_name}.hpp
  220. )
  221. message(STATUS ${amended_test_name} " " ${arglist} " " ${amended_archive_name})
  222. target_link_libraries(${amended_test_name} serialization wserialization filesystem)
  223. add_test(${amended_test_name} ${amended_test_name})
  224. set(test_list ${test_list} ${amended_test_name} PARENT_SCOPE)
  225. endforeach()
  226. endfunction(polymorphic_archive_test)
  227. enable_testing()
  228. message(STATUS dll_a)
  229. add_library(dll_a SHARED ../test/dll_a.cpp)
  230. target_link_libraries(dll_a serialization)
  231. serialization_test(test_dll_simple)
  232. target_link_libraries(test_dll_simple dll_a serialization)
  233. message(STATUS dll_polymorphic_base)
  234. add_library(dll_polymorphic_base SHARED ../test/dll_polymorphic_base.cpp)
  235. target_link_libraries(dll_polymorphic_base serialization)
  236. message(STATUS dll_polymorphic_derived2)
  237. add_library(dll_polymorphic_derived2 SHARED ../test/dll_polymorphic_derived2.cpp)
  238. target_link_libraries(dll_polymorphic_derived2 dll_polymorphic_base serialization)
  239. # compile test_dll_plugin.cpp
  240. # Running the following test requires that the test know the directory
  241. # in which the dll is stored. I don't know how to extract this from bjam
  242. # serialization(test_dll_plugin : : dll_polymorphic_derived2_lib)
  243. serialization_test(test_private_ctor)
  244. serialization_test(test_reset_object_address A)
  245. serialization_test(test_void_cast)
  246. serialization_test(test_mult_archive_types)
  247. serialization_test(test_iterators)
  248. serialization_test(test_iterators_base64)
  249. serialization_test(test_inclusion)
  250. serialization_test(test_inclusion2)
  251. serialization_test(test_smart_cast)
  252. serialization_test(test_codecvt_null ../src/codecvt_null)
  253. serialization_test(test_strong_typedef)
  254. serialization_test(test_singleton)
  255. serialization_test(test_singleton_inherited)
  256. serialization_test(test_singleton_plain)
  257. archive_test(test_native_array A)
  258. archive_test(test_boost_array A)
  259. if(COMPILER_SUPPORTS_CXX11)
  260. archive_test(test_array A)
  261. endif()
  262. archive_test(test_binary)
  263. archive_test(test_bitset)
  264. archive_test(test_class_info_save)
  265. archive_test(test_class_info_load)
  266. archive_test(test_complex)
  267. archive_test(test_contained_class A)
  268. archive_test(test_cyclic_ptrs A)
  269. archive_test(test_delete_pointer)
  270. archive_test(test_deque A)
  271. archive_test(test_derived)
  272. archive_test(test_derived_class A)
  273. archive_test(test_diamond)
  274. archive_test(test_diamond_complex)
  275. archive_test(test_forward_list A)
  276. archive_test(test_forward_list_ptrs A)
  277. archive_test(test_helper_support)
  278. archive_test(test_interrupts)
  279. archive_test(test_list A)
  280. archive_test(test_list_ptrs A)
  281. archive_test(test_map A)
  282. archive_test(test_map_boost_unordered A)
  283. archive_test(test_mi)
  284. archive_test(test_multiple_ptrs A)
  285. archive_test(test_multiple_inheritance)
  286. archive_test(test_new_operator A)
  287. archive_test(test_non_intrusive)
  288. archive_test(test_non_default_ctor)
  289. archive_test(test_non_default_ctor2)
  290. archive_test(test_null_ptr)
  291. archive_test(test_nvp A)
  292. archive_test(test_object)
  293. archive_test(test_optional)
  294. archive_test(test_primitive)
  295. archive_test(test_priority_queue A)
  296. archive_test(test_private_base)
  297. archive_test(test_private_base2)
  298. archive_test(test_queue A)
  299. archive_test(test_recursion A)
  300. archive_test(test_registered)
  301. archive_test(test_shared_ptr)
  302. archive_test(test_shared_ptr_multi_base)
  303. archive_test(test_shared_ptr_132)
  304. archive_test(test_simple_class A)
  305. archive_test(test_simple_class_ptr A)
  306. CHECK_INCLUDE_FILE_CXX(slist SLIST_FOUND)
  307. if(SLIST_FOUND)
  308. message(STATUS "slist header found")
  309. archive_test(test_slist A)
  310. archive_test(test_slist_ptr A)
  311. else()
  312. message(STATUS "slist header NOT found")
  313. endif()
  314. archive_test(test_stack A)
  315. archive_test(test_split)
  316. archive_test(test_tracking)
  317. archive_test(test_unregistered)
  318. archive_test(test_unique_ptr)
  319. archive_test(test_valarray)
  320. archive_test(test_variant A)
  321. archive_test(test_vector A)
  322. archive_test(test_set A)
  323. archive_test(test_set_boost_unordered A)
  324. if(COMPILER_SUPPORTS_CXX11)
  325. archive_test(test_set_unordered A)
  326. else()
  327. CHECK_INCLUDE_FILE_CXX(hash_set HASH_SET_FOUND)
  328. if(HASH_SET_FOUND)
  329. archive_test(test_set_hashed A)
  330. endif()
  331. endif()
  332. if(COMPILER_SUPPORTS_CXX11)
  333. archive_test(test_map_unordered A)
  334. else()
  335. CHECK_INCLUDE_FILE_CXX(hash_map HASH_MAP_FOUND)
  336. if(HASH_MAP_FOUND)
  337. archive_test(test_map_hashed A)
  338. endif()
  339. endif()
  340. polymorphic_archive_test(test_dll_exported polymorphic_derived1)
  341. foreach(test_name IN ITEMS ${test_list} )
  342. target_link_libraries(${test_name} dll_polymorphic_derived2 dll_polymorphic_base)
  343. message(STATUS " " target_link_libraries " " dll_polymorphic_derived2 " " dll_polymorphic_base)
  344. endforeach()
  345. polymorphic_archive_test(test_no_rtti polymorphic_base polymorphic_derived1 polymorphic_derived2)
  346. polymorphic_archive_test(test_exported polymorphic_base polymorphic_derived1 polymorphic_derived2)
  347. polymorphic_archive_test(test_polymorphic test_polymorphic_A A)
  348. polymorphic_archive_test(test_polymorphic2 test_polymorphic2imp)
  349. polymorphic_archive_test(test_p_helper)
  350. # end test targets
  351. ####################
  352. ####################
  353. # add headers in IDE
  354. # for serialization
  355. file(GLOB x
  356. RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  357. "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/*.hpp"
  358. )
  359. add_custom_target(archive SOURCES ${x})
  360. set_property(TARGET archive PROPERTY FOLDER "serialization")
  361. file(GLOB x
  362. RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  363. "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/detail/*.hpp"
  364. )
  365. add_custom_target(archive-detail SOURCES ${x})
  366. set_property(TARGET archive-detail PROPERTY FOLDER "serialization")
  367. file(GLOB x
  368. RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  369. "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/impl/*.ipp"
  370. )
  371. add_custom_target(archive-impl SOURCES ${x})
  372. set_property(TARGET archive-impl PROPERTY FOLDER "serialization")
  373. file(GLOB x
  374. RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  375. "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/iterators/*.hpp"
  376. )
  377. add_custom_target(archive-iterators SOURCES ${x})
  378. set_property(TARGET archive-iterators PROPERTY FOLDER "serialization")
  379. file(GLOB x
  380. RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  381. "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/serialization/*.hpp"
  382. )
  383. add_custom_target(serialization-headers SOURCES ${x})
  384. set_property(TARGET serialization-headers PROPERTY FOLDER "serialization")
  385. file(GLOB x
  386. RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  387. "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/serialization/detail/*.hpp"
  388. )
  389. add_custom_target(serialization-detail SOURCES ${x})
  390. set_property(TARGET serialization-detail PROPERTY FOLDER "serialization")
  391. # for wserialization
  392. file(GLOB x
  393. RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  394. "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/*_w*.hpp"
  395. )
  396. add_custom_target(wserialization_headers SOURCES ${x})
  397. set_property(TARGET wserialization_headers PROPERTY FOLDER "wserialization")
  398. # end headers in IDE
  399. ####################
  400. #####################
  401. # add test project to run misc tests
  402. add_executable( test_z ../test/test_z.cpp)
  403. target_link_libraries(test_z serialization wserialization ${Boost_LIBRARIES})
  404. # end test project
  405. #####################