forked from foonathan/type_safe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
153 lines (132 loc) · 6.41 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright (C) 2016-2019 Jonathan Müller <jonathanmueller.dev@gmail.com>
# This file is subject to the license terms in the LICENSE file
# found in the top-level directory of this distribution.
cmake_minimum_required(VERSION 3.1)
project(TYPE_SAFE)
include(external/external.cmake)
# options
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(_type_safe_default_assertions ON)
else()
set(_type_safe_default_assertions OFF)
endif()
option(TYPE_SAFE_ENABLE_ASSERTIONS "whether or not to enable internal assertions for the type_safe library" ${_type_safe_default_assertions})
if(${TYPE_SAFE_ENABLE_ASSERTIONS})
set(_type_safe_enable_assertions 1)
else()
set(_type_safe_enable_assertions 0)
endif()
option(TYPE_SAFE_ENABLE_PRECONDITION_CHECKS "whether or not to enable precondition checks" ON)
if(${TYPE_SAFE_ENABLE_PRECONDITION_CHECKS})
set(_type_safe_enable_precondition_checks 1)
else()
set(_type_safe_enable_precondition_checks 0)
endif()
option(TYPE_SAFE_ENABLE_WRAPPER "whether or not the wrappers in types.hpp are used" ON)
if(${TYPE_SAFE_ENABLE_WRAPPER})
set(_type_safe_enable_wrapper 1)
else()
set(_type_safe_enable_wrapper 0)
endif()
set(TYPE_SAFE_ARITHMETIC_POLICY "ub" CACHE STRING "which policy (ub/checked/default) is going to be used")
option(TYPE_SAFE_ARITHMETIC_UB "deprecated" ON)
if(NOT ${TYPE_SAFE_ARITHMETIC_UB})
set(_type_safe_arithmetic_policy 0)
message(DEPRECATION "option TYPE_SAFE_ARITHMETIC_UB is deprecated, use TYPE_SAFE_ARITHMETIC_POLICY instead")
message(STATUS "arithmetic_policy_default is default_arithmetic")
elseif(${TYPE_SAFE_ARITHMETIC_POLICY} STREQUAL "ub")
set(_type_safe_arithmetic_policy 1)
message(STATUS "arithmetic_policy_default is undefined_behavior_arithmetic")
elseif(${TYPE_SAFE_ARITHMETIC_POLICY} STREQUAL "checked")
set(_type_safe_arithmetic_policy 2)
message(STATUS "arithmetic_policy_default is checked_arithmetic")
else()
set(_type_safe_arithmetic_policy 0)
message(STATUS "arithmetic_policy_default is default_arithmetic")
endif()
# interface target
set(detail_header_files
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/aligned_union.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/all_of.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/assert.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/assign_or_construct.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/constant_parser.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/copy_move_control.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/force_inline.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/is_nothrow_swappable.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/map_invoke.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/detail/variant_impl.hpp)
set(header_files
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/config.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/arithmetic_policy.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/boolean.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/bounded_type.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/compact_optional.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/constrained_type.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/deferred_construction.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/downcast.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/flag.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/flag_set.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/floating_point.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/index.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/integer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/narrow_cast.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/optional.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/optional_ref.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/output_parameter.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/reference.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/strong_typedef.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/tagged_union.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/types.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/variant.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/type_safe/visitor.hpp)
add_library(type_safe INTERFACE)
target_sources(type_safe INTERFACE "$<BUILD_INTERFACE:${detail_header_files};${header_files}>")
target_include_directories(type_safe INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>)
target_include_directories(type_safe SYSTEM INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
target_compile_definitions(type_safe INTERFACE
TYPE_SAFE_ENABLE_ASSERTIONS=${_type_safe_enable_assertions}
TYPE_SAFE_ENABLE_PRECONDITION_CHECKS=${_type_safe_enable_precondition_checks}
TYPE_SAFE_ENABLE_WRAPPER=${_type_safe_enable_wrapper}
TYPE_SAFE_ARITHMETIC_POLICY=${_type_safe_arithmetic_policy})
target_link_libraries(type_safe INTERFACE debug_assert)
if(MSVC)
target_compile_options(type_safe INTERFACE /wd4800) # truncation to bool warning
endif()
# Setup package config
include( CMakePackageConfigHelpers )
set(CONFIG_PACKAGE_INSTALL_DIR lib/cmake/type_safe)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/type_safe-config-version.cmake
VERSION 0.2.1
COMPATIBILITY SameMajorVersion
)
# Install target
install(DIRECTORY include/type_safe DESTINATION include)
# Only export target when using imported targets
if(TYPE_SAFE_HAS_IMPORTED_TARGETS)
install(TARGETS type_safe
EXPORT type_safe-targets
DESTINATION lib)
install( EXPORT type_safe-targets
DESTINATION
${CONFIG_PACKAGE_INSTALL_DIR}
)
install( FILES
${CMAKE_CURRENT_SOURCE_DIR}/type_safe-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/type_safe-config-version.cmake
DESTINATION
${CONFIG_PACKAGE_INSTALL_DIR} )
endif()
# other subdirectories
# only add if not inside add_subdirectory()
option(TYPE_SAFE_BUILD_TEST_EXAMPLE "build test and example" OFF)
if(${TYPE_SAFE_BUILD_TEST_EXAMPLE} OR (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
enable_testing()
add_subdirectory(example/)
add_subdirectory(test/)
endif()
option(TYPE_SAFE_BUILD_DOC "generate documentation" OFF)
if(TYPE_SAFE_BUILD_DOC)
add_subdirectory(doc/)
endif()