• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# CMake build control file for Serialization Library tests
2
3cmake_minimum_required(VERSION 3.0)
4
5if (POLICY CMP0054)
6  cmake_policy (SET CMP0054 NEW)
7endif (POLICY CMP0054)
8
9if (POLICY CMP0063)
10  cmake_policy (SET CMP0063 NEW)
11endif (POLICY CMP0063)
12
13project("serialization")
14
15#
16# Compiler settings
17#
18
19message(STATUS "compiler is ${CMAKE_CXX_COMPILER_ID}" )
20add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
21
22if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
23  add_definitions( -ftemplate-depth=255 )
24  # we use gcc to test for C++03 compatibility
25  add_definitions( -std=c++03 )
26  message(STATUS "compiler is g++ c++03")
27  set(COMPILER_SUPPORTS_CXX11 FALSE)
28elseif( CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
29  add_definitions( /wd4996 )
30  message(STATUS "compiler is MSVC")
31  set(COMPILER_SUPPORTS_CXX11 TRUE)
32elseif( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
33  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=300")
34  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
35  #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
36  set(CMAKE_CXX_FLAGS_DEBUG "-g -O0" )
37  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3" )
38  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -dead_strip")
39  set(COMPILER_SUPPORTS_CXX11 FALSE)
40endif()
41
42#
43# Locate Project Prerequisites
44#
45
46# Boost
47
48# note: we're assuming that boost has been built with:
49# ./b2 toolset=clang-darwin link=static,shared variant=debug,release stage
50
51#
52# Project settings
53#
54option(BUILD_SHARED_LIBS "Build Shared Libraries" true)
55
56find_package(Boost 1.74 REQUIRED COMPONENTS system filesystem)
57
58if(NOT Boost_FOUND)
59  message("Boost NOT Found!")
60else()
61  message(STATUS "Boost Found!")
62endif()
63set(CMAKE_CXX_VISIBILITY_PRESET hidden)
64set(VISIBILITY_INLINES_HIDDEN YES)
65
66# enable usage of CHECK_INCLUDE_FILE_CXX
67include(CheckIncludeFileCXX)
68
69# list of archive names for which tests should be generated
70set(archive_list text_archive text_warchive binary_archive xml_archive xml_warchive)
71# set(archive_list xml_warchive)
72
73# list of tests generated by each function call
74set(test_list)
75
76###########################
77# library builds
78
79add_library(serialization
80  ../src/archive_exception.cpp
81  ../src/basic_archive.cpp
82  ../src/basic_iarchive.cpp
83  ../src/basic_iserializer.cpp
84  ../src/basic_oarchive.cpp
85  ../src/basic_oserializer.cpp
86  ../src/basic_pointer_iserializer.cpp
87  ../src/basic_pointer_oserializer.cpp
88  ../src/basic_serializer_map.cpp
89  ../src/basic_text_iprimitive.cpp
90  ../src/basic_text_oprimitive.cpp
91  ../src/basic_xml_archive.cpp
92  ../src/binary_iarchive.cpp
93  ../src/binary_oarchive.cpp
94  ../src/extended_type_info.cpp
95  ../src/extended_type_info_typeid.cpp
96  ../src/extended_type_info_no_rtti.cpp
97  ../src/stl_port.cpp
98  ../src/text_iarchive.cpp
99  ../src/text_oarchive.cpp
100  ../src/polymorphic_iarchive.cpp
101  ../src/polymorphic_oarchive.cpp
102  ../src/polymorphic_text_iarchive.cpp
103  ../src/polymorphic_text_oarchive.cpp
104  ../src/polymorphic_binary_iarchive.cpp
105  ../src/polymorphic_binary_oarchive.cpp
106  ../src/polymorphic_xml_iarchive.cpp
107  ../src/polymorphic_xml_oarchive.cpp
108  ../src/void_cast.cpp
109  ../src/xml_grammar.cpp
110  ../src/xml_iarchive.cpp
111  ../src/xml_oarchive.cpp
112  ../src/xml_archive_exception.cpp
113  ../src/codecvt_null.cpp
114  ../src/utf8_codecvt_facet.cpp
115  ../src/basic_xml_grammar.ipp # doesn't show up in "Source Files" in Xcode"'
116)
117target_include_directories(serialization PUBLIC ${Boost_INCLUDE_DIR})
118
119add_library(wserialization
120  ../src/basic_text_wiprimitive.cpp
121  ../src/basic_text_woprimitive.cpp
122  ../src/text_wiarchive.cpp
123  ../src/text_woarchive.cpp
124  ../src/polymorphic_text_wiarchive.cpp
125  ../src/polymorphic_text_woarchive.cpp
126  ../src/xml_wiarchive.cpp
127  ../src/xml_woarchive.cpp
128  ../src/polymorphic_xml_wiarchive.cpp
129  ../src/polymorphic_xml_woarchive.cpp
130  ../src/xml_wgrammar.cpp
131  ../src/basic_xml_grammar.ipp # doesn't show up in "Source Files" in Xcode"'
132)
133target_include_directories(wserialization PUBLIC ${Boost_INCLUDE_DIR})
134target_link_libraries(wserialization PUBLIC serialization)
135
136# end library build
137###########################
138
139###########################
140# test targets
141
142function( serialization_test test_name)
143  set(arglist)
144  foreach(a IN ITEMS ${ARGN} )
145    set(arglist ${arglist} ../test/${a}.cpp)
146  endforeach()
147  message(STATUS ${test_name})
148  add_executable( ${test_name} ../test/${test_name}.cpp ${arglist} )
149  target_include_directories(${test_name} PUBLIC ${Boost_INCLUDE_DIR})
150  target_link_libraries(${test_name} serialization wserialization Boost::filesystem)
151  add_test( ${test_name} ${test_name} )
152endfunction(serialization_test)
153
154function(archive_test test_name)
155  set(test_listx)
156  set(arglist)
157  foreach(a IN ITEMS ${ARGN} )
158    set(arglist ${arglist} ../test/${a}.cpp)
159  endforeach()
160  foreach(
161    archive-name
162    IN ITEMS ${archive_list}
163  )
164    set(amended_test_name ${test_name}_${archive-name})
165    add_executable(${amended_test_name} ../test/${test_name}.cpp ${arglist})
166    set_property(
167      TARGET ${amended_test_name}
168      PROPERTY COMPILE_DEFINITIONS BOOST_ARCHIVE_TEST=${archive-name}.hpp
169    )
170    target_include_directories(${amended_test_name} PUBLIC ${Boost_INCLUDE_DIR})
171    target_link_libraries(${amended_test_name} serialization wserialization Boost::filesystem)
172    add_test(${amended_test_name} ${amended_test_name})
173    set(test_listx ${test_listx} ${amended_test_name})
174  endforeach()
175  set(test_list ${test_listx} PARENT_SCOPE)
176endfunction(archive_test)
177
178function(polymorphic_archive_test test_name)
179  set(test_listx)
180  set(arglist)
181  foreach(a IN ITEMS ${ARGN} )
182    set(arglist ${arglist} ../test/${a}.cpp)
183  endforeach()
184  foreach(
185    archive-name
186    IN ITEMS ${archive_list}
187  )
188    set(amended_archive_name polymorphic_${archive-name})
189    set(amended_test_name ${test_name}_${amended_archive_name})
190    add_executable(${amended_test_name} ../test/${test_name}.cpp ${arglist})
191    set_property(
192      TARGET ${amended_test_name}
193      PROPERTY COMPILE_DEFINITIONS BOOST_ARCHIVE_TEST=${amended_archive_name}.hpp
194    )
195    message(STATUS ${amended_test_name} " " ${arglist} " " ${amended_archive_name})
196    target_include_directories(${amended_test_name} PUBLIC ${Boost_INCLUDE_DIR})
197    target_link_libraries(${amended_test_name} serialization wserialization Boost::filesystem)
198    add_test(${amended_test_name} ${amended_test_name})
199    set(test_listx ${test_listx} ${amended_test_name})
200endforeach()
201set(test_list ${test_listx} PARENT_SCOPE)
202endfunction(polymorphic_archive_test)
203
204enable_testing()
205
206message(STATUS dll_a)
207add_library(dll_a SHARED ../test/dll_a.cpp)
208target_link_libraries(dll_a serialization)
209
210message(STATUS dll_polymorphic_base)
211add_library(dll_polymorphic_base SHARED ../test/dll_polymorphic_base.cpp)
212target_link_libraries(dll_polymorphic_base serialization)
213
214message(STATUS dll_polymorphic_derived2)
215add_library(dll_polymorphic_derived2 SHARED ../test/dll_polymorphic_derived2.cpp)
216target_link_libraries(dll_polymorphic_derived2 dll_polymorphic_base serialization)
217
218# compile test_dll_plugin.cpp
219# Running the following test requires that the test know the directory
220# in which the dll is stored. I don't know how to extract this from bjam
221# serialization(test_dll_plugin : : dll_polymorphic_derived2_lib)
222
223if(BUILD_SHARED_LIBS)
224  # this test can only be made to work if we're linking with shared
225  # libraries. Basically the build systems like to have all shared
226  # or all static so if we're building with static C++ libraries
227  # then linking with a shared one - we need multiple C++ libraries
228  # and things get complex.  So just run this test when we're
229  # building with shared libraries (dll in windows speak)
230  serialization_test(test_dll_simple)
231  target_link_libraries(test_dll_simple dll_a serialization)
232endif()
233
234serialization_test(test_private_ctor)
235serialization_test(test_reset_object_address A)
236serialization_test(test_void_cast)
237serialization_test(test_mult_archive_types)
238serialization_test(test_iterators)
239serialization_test(test_iterators_base64)
240serialization_test(test_inclusion)
241serialization_test(test_inclusion2)
242serialization_test(test_smart_cast)
243serialization_test(test_codecvt_null)
244serialization_test(test_strong_typedef)
245serialization_test(test_singleton)
246serialization_test(test_singleton_inherited)
247serialization_test(test_singleton_plain)
248
249archive_test(test_native_array A)
250archive_test(test_boost_array A)
251if(COMPILER_SUPPORTS_CXX11)
252  archive_test(test_array A)
253endif()
254archive_test(test_binary)
255archive_test(test_bitset)
256archive_test(test_class_info_save)
257archive_test(test_class_info_load)
258archive_test(test_complex)
259archive_test(test_contained_class A)
260archive_test(test_cyclic_ptrs A)
261archive_test(test_delete_pointer)
262archive_test(test_deque A)
263archive_test(test_derived)
264archive_test(test_derived_class A)
265archive_test(test_diamond)
266archive_test(test_diamond_complex)
267CHECK_INCLUDE_FILE_CXX(forward_list FORWARD_LIST_FOUND)
268if(FORWARD_LIST_FOUND)
269  message(STATUS "forward_list header found")
270  archive_test(test_forward_list A)
271  archive_test(test_forward_list_ptrs A)
272else()
273  message(STATUS "forward_list header NOT found")
274endif()
275archive_test(test_helper_support)
276archive_test(test_interrupts)
277archive_test(test_list A)
278archive_test(test_list_ptrs A)
279archive_test(test_map A)
280if(COMPILER_SUPPORTS_CXX11)
281  archive_test(test_map_unordered A)
282else()
283  CHECK_INCLUDE_FILE_CXX(hash_map HASH_MAP_FOUND)
284  if(HASH_MAP_FOUND)
285    archive_test(test_map_hashed A)
286  endif()
287endif()
288archive_test(test_map_boost_unordered A)
289archive_test(test_mi)
290archive_test(test_multiple_ptrs A)
291archive_test(test_multiple_inheritance)
292archive_test(test_new_operator A)
293archive_test(test_non_intrusive)
294archive_test(test_non_default_ctor)
295archive_test(test_non_default_ctor2)
296archive_test(test_null_ptr)
297archive_test(test_nvp A)
298archive_test(test_object)
299archive_test(test_optional)
300archive_test(test_primitive)
301archive_test(test_priority_queue A)
302archive_test(test_private_base)
303archive_test(test_private_base2)
304archive_test(test_queue A)
305archive_test(test_recursion A)
306archive_test(test_registered)
307archive_test(test_set A)
308archive_test(test_set_boost_unordered A)
309if(COMPILER_SUPPORTS_CXX11)
310  archive_test(test_set_unordered A)
311else()
312  CHECK_INCLUDE_FILE_CXX(hash_set HASH_SET_FOUND)
313  if(HASH_SET_FOUND)
314    archive_test(test_set_hashed A)
315  endif()
316endif()
317archive_test(test_shared_ptr)
318archive_test(test_shared_ptr_multi_base)
319archive_test(test_shared_ptr_132)
320archive_test(test_simple_class A)
321archive_test(test_simple_class_ptr A)
322CHECK_INCLUDE_FILE_CXX(slist SLIST_FOUND)
323if(SLIST_FOUND)
324  message(STATUS "slist header found")
325  archive_test(test_slist A)
326  archive_test(test_slist_ptr A)
327else()
328  message(STATUS "slist header NOT found")
329endif()
330archive_test(test_stack A)
331archive_test(test_split)
332archive_test(test_tracking)
333archive_test(test_unregistered)
334archive_test(test_unique_ptr)
335archive_test(test_valarray)
336archive_test(test_variant A)
337archive_test(test_vector A)
338
339polymorphic_archive_test(test_dll_exported polymorphic_derived1)
340foreach(test_name IN ITEMS ${test_list} )
341    target_link_libraries(${test_name} dll_polymorphic_derived2 dll_polymorphic_base serialization wserialization)
342endforeach()
343
344polymorphic_archive_test(test_no_rtti polymorphic_base polymorphic_derived1 polymorphic_derived2)
345polymorphic_archive_test(test_exported polymorphic_base polymorphic_derived1 polymorphic_derived2)
346polymorphic_archive_test(test_polymorphic test_polymorphic_A A)
347polymorphic_archive_test(test_polymorphic2 test_polymorphic2imp)
348polymorphic_archive_test(test_p_helper)
349
350# end test targets
351####################
352
353####################
354# add headers in IDE
355
356# for serialization
357
358file(GLOB x
359  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
360  "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/*.hpp"
361)
362add_custom_target(archive SOURCES ${x})
363set_property(TARGET archive PROPERTY FOLDER "serialization")
364
365file(GLOB x
366  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
367  "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/detail/*.hpp"
368)
369add_custom_target(archive-detail SOURCES ${x})
370set_property(TARGET archive-detail PROPERTY FOLDER "serialization")
371
372file(GLOB x
373  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
374  "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/impl/*.ipp"
375)
376add_custom_target(archive-impl SOURCES ${x})
377set_property(TARGET archive-impl PROPERTY FOLDER "serialization")
378
379file(GLOB x
380  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
381  "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/iterators/*.hpp"
382)
383add_custom_target(archive-iterators SOURCES ${x})
384set_property(TARGET archive-iterators PROPERTY FOLDER "serialization")
385
386file(GLOB x
387  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
388  "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/serialization/*.hpp"
389)
390add_custom_target(serialization-headers SOURCES ${x})
391set_property(TARGET serialization-headers PROPERTY FOLDER "serialization")
392
393file(GLOB x
394  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
395  "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/serialization/detail/*.hpp"
396)
397add_custom_target(serialization-detail SOURCES ${x})
398set_property(TARGET serialization-detail PROPERTY FOLDER "serialization")
399
400# for wserialization
401
402file(GLOB x
403  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
404  "${CMAKE_CURRENT_SOURCE_DIR}/../include/boost/archive/*_w*.hpp"
405)
406add_custom_target(wserialization_headers SOURCES ${x})
407set_property(TARGET wserialization_headers PROPERTY FOLDER "wserialization")
408
409# end headers in IDE
410####################
411
412#####################
413# add test project to run misc tests
414
415add_executable( test_z ../test/test_z.cpp)
416target_link_libraries(test_z serialization wserialization ${Boost_LIBRARIES})
417
418# end test project
419#####################
420