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