-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathCMakeLists.txt
136 lines (114 loc) · 4.34 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
############################################################################
# Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht #
# Copyright (c) QuantStack #
# #
# Distributed under the terms of the BSD 3-Clause License. #
# #
# The full license is in the file LICENSE, distributed with this software. #
############################################################################
cmake_minimum_required(VERSION 3.1)
find_package(doctest REQUIRED)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
project(xtl-test)
enable_testing()
find_package(xtl REQUIRED CONFIG)
find_package(nlohmann_json QUIET CONFIG)
set(XTL_INCLUDE_DIR ${xtl_INCLUDE_DIRS})
endif ()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting tests build type to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
else()
message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}")
endif()
include(CheckCXXCompilerFlag)
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
if(nlohmann_json_FOUND)
add_definitions(-DHAVE_NLOHMANN_JSON)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Intel)
add_compile_options(-Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion)
if(NOT CMAKE_CXX_FLAGS MATCHES "-march")
CHECK_CXX_COMPILER_FLAG(-march=native HAS_MARCH_NATIVE)
if (HAS_MARCH_NATIVE)
add_compile_options(-march=native)
endif()
endif()
if (XTL_DISABLE_EXCEPTIONS)
add_compile_options(-fno-exceptions)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
add_compile_options(/EHsc /MP /bigobj)
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
if (XTL_DISABLE_EXCEPTIONS)
add_compile_options(/EHs-c-)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
if(NOT WIN32)
add_compile_options(-Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion)
if(NOT CMAKE_CXX_FLAGS MATCHES "-march")
CHECK_CXX_COMPILER_FLAG(-march=native HAS_MARCH_NATIVE)
if (HAS_MARCH_NATIVE)
add_compile_options(-march=native)
endif()
endif()
if (XTL_DISABLE_EXCEPTIONS)
add_compile_options(-fno-exceptions)
endif()
else() # we are using clang-cl
add_compile_options(/EHsc /bigobj -fms-compatibility)
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
if (XTL_DISABLE_EXCEPTIONS)
add_compile_options(/EHs-c-)
endif()
endif()
endif()
find_package(Threads)
set(XTL_TESTS
test_xbase64.cpp
test_xbasic_fixed_string.cpp
test_xclosure.cpp
test_xcompare.cpp
test_xcomplex_sequence.cpp
test_xcomplex.cpp
test_xdynamic_bitset.cpp
test_xfunctional.cpp
test_xhalf_float.cpp
test_xhash.cpp
test_xhierarchy_generator.cpp
test_xiterator_base.cpp
test_xmasked_value.cpp
test_xmeta_utils.cpp
test_xmultimethods.cpp
test_xoptional.cpp
test_xplatform.cpp
test_xproxy_wrapper.cpp
test_xsequence.cpp
test_xsystem.cpp
test_xtype_traits.cpp
test_xvariant.cpp
test_xvisitor.cpp
)
if(nlohmann_json_FOUND)
# Version up to 3.1.2 export the target `nlohmann_json`
if(TARGET nlohmann_json)
set(nlohmann_json_TARGET nlohmann_json)
# Newer versions export the namespaced target `nlohmann_json::nlohmann_json`
elseif(TARGET nlohmann_json::nlohmann_json)
set(nlohmann_json_TARGET nlohmann_json::nlohmann_json)
endif()
endif()
foreach(filename IN LISTS XTL_TESTS)
get_filename_component(targetname ${filename} NAME_WE)
add_executable(${targetname} main.cpp ${filename} ${XTL_HEADERS})
target_include_directories(${targetname} PRIVATE ${XTL_INCLUDE_DIR})
target_link_libraries(${targetname} xtl doctest::doctest Threads::Threads ${nlohmann_json_TARGET})
add_test(NAME ${targetname} COMMAND ${targetname})
endforeach()
add_executable(test_xtl main.cpp ${XTL_TESTS} ${XTL_HEADERS})
target_include_directories(test_xtl PRIVATE ${XTL_INCLUDE_DIR})
target_link_libraries(test_xtl xtl doctest::doctest Threads::Threads ${nlohmann_json_TARGET})
add_custom_target(xtest COMMAND test_xtl DEPENDS test_xtl)
add_test(NAME xtest COMMAND test_xtl)