-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
161 lines (144 loc) · 5.24 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
154
155
156
157
158
159
160
161
cmake_minimum_required(VERSION 3.20 FATAL_ERROR )
include(CheckCXXCompilerFlag)
include(cmake/extract_version.cmake)
project(small_vectors
VERSION ${small_vectors_version}
LANGUAGES CXX
HOMEPAGE_URL "https://github.com/arturbac/small_vectors"
)
include(GNUInstallDirs)
if( PROJECT_IS_TOP_LEVEL )
include(FeatureSummary)
endif()
if( PROJECT_IS_TOP_LEVEL )
message(STATUS "small_vectors v${small_vectors_version}")
endif()
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()
set(CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake
)
option(SMALL_VECTORS_ENABLE_CPM_PACKAGING "cmake packaging by cpm" ON)
option(SMALL_VECTORS_EXPECTED_VTABLE_INSTANTATION "builds static library with vtable of bad_expected_access" ON)
add_feature_info("SMALL_VECTORS_EXPECTED_VTABLE_INSTANTATION" SMALL_VECTORS_EXPECTED_VTABLE_INSTANTATION "builds static library with vtable of bad_expected_access")
if(SMALL_VECTORS_ENABLE_CPM_PACKAGING)
include(cmake/CPM.cmake)
# ---- Add dependencies via CPM ----
# see https://github.com/cpm-cmake/CPM.cmake for more info
CPMAddPackage(
NAME PackageProject.cmake
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
VERSION 1.11.2
)
endif()
#-----------------------------------------------------------------------------
# options
#-----------------------------------------------------------------------------
if(SMALL_VECTORS_ENABLE_CPM_PACKAGING AND PROJECT_IS_TOP_LEVEL )
option(SMALL_VECTORS_ENABLE_UNIT_TESTS "unit tests available from CTest" ${PROJECT_IS_TOP_LEVEL} )
add_feature_info("SMALL_VECTORS_ENABLE_UNIT_TESTS" SMALL_VECTORS_ENABLE_UNIT_TESTS "unit test available from CTest")
else()
set(SMALL_VECTORS_ENABLE_UNIT_TESTS OFF)
endif()
if(SMALL_VECTORS_ENABLE_UNIT_TESTS AND PROJECT_IS_TOP_LEVEL )
#----------------------------------------------------------------
# boost-ext/ut
#----------------------------------------------------------------
CPMAddPackage(
ut
GITHUB_REPOSITORY arturbac/ut-ext
GIT_TAG master
)
endif()
message(STATUS "CMake install directory: " ${CMAKE_INSTALL_INCLUDEDIR})
if(SMALL_VECTORS_EXPECTED_VTABLE_INSTANTATION)
add_library(small_vectors STATIC)
target_sources(small_vectors PRIVATE source/expected.cc)
target_compile_definitions( small_vectors PUBLIC SMALL_VECTORS_EXPECTED_VTABLE_INSTANTATION=1)
else()
add_library(small_vectors INTERFACE)
endif()
if(NOT DEFINED INCLUDE_INSTALL_DIR)
set(INCLUDE_INSTALL_DIR include/${PROJECT_NAME})
endif()
if(SMALL_VECTORS_EXPECTED_VTABLE_INSTANTATION)
target_include_directories(small_vectors
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
)
else()
target_include_directories(small_vectors
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 20 )
if(SMALL_VECTORS_EXPECTED_VTABLE_INSTANTATION)
target_compile_features(small_vectors PUBLIC cxx_std_20)
else()
target_compile_features(small_vectors INTERFACE cxx_std_20)
endif()
endif()
if( PROJECT_IS_TOP_LEVEL )
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
option(SMALL_VECTORS_ENABLE_LLD_LINKER "enable lld linker for linking unit tests" ON )
add_feature_info("SMALL_VECTORS_ENABLE_LLD_LINKER" SMALL_VECTORS_ENABLE_LLD_LINKER "enable lld linker for linking unit tests")
set(SMALL_VECTORS_COMPILE_OPTIONS
-Weverything
-Werror
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-pre-c++14-compat
-Wno-pre-c++17-compat
-Wno-pre-c++20-compat-pedantic
-Wno-c++20-compat
-Wno-unused-parameter
-Wno-padded
-Wno-unused-command-line-argument
)
check_cxx_compiler_flag(-Wunsafe-buffer-usage WUNSAFE_BUFFER_USAGE)
if(WUNSAFE_BUFFER_USAGE)
list(APPEND SMALL_VECTORS_COMPILE_OPTIONS -Wno-unsafe-buffer-usage)
endif()
check_cxx_compiler_flag(-Wswitch-default WNO_SWITCH_DEFAULT)
if(WNO_SWITCH_DEFAULT)
list(APPEND SMALL_VECTORS_COMPILE_OPTIONS -Wno-switch-default)
endif()
if(SMALL_VECTORS_ENABLE_LLD_LINKER)
add_link_options( -fuse-ld=lld )
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(SMALL_VECTORS_COMPILE_OPTIONS
-Wall
-Wextra
-Werror
)
endif()
endif()
if(SMALL_VECTORS_ENABLE_CPM_PACKAGING)
packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
NAMESPACE small_vectors
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION ${INCLUDE_INSTALL_DIR}
COMPATIBILITY SameMajorVersion
)
endif()
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${INCLUDE_INSTALL_DIR} )
if(SMALL_VECTORS_ENABLE_UNIT_TESTS AND PROJECT_IS_TOP_LEVEL)
add_custom_target( unit_tests )
endif()
if( SMALL_VECTORS_ENABLE_UNIT_TESTS AND PROJECT_IS_TOP_LEVEL)
enable_testing( TRUE )
add_subdirectory(unit_tests)
endif()
if( PROJECT_IS_TOP_LEVEL )
feature_summary(WHAT ALL)
endif()