-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
170 lines (154 loc) · 6.7 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
162
163
164
165
166
167
168
169
170
# NOTE: C++20 supported since 3.12
cmake_minimum_required(VERSION 3.12.0)
# Set default build type to "Release".
# NOTE: this should be done before the project command since the latter can set
# CMAKE_BUILD_TYPE itself (it does so for nmake).
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
# NOTE: technically a C++ only project, but we are compiling
# sqlite.c in the tests.
project(tanuki VERSION 1.0.0 LANGUAGES CXX C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "tanuki version: ${tanuki_VERSION}")
# Run the YACMA compiler setup.
include(YACMACompilerLinkerSettings)
# The build options.
option(TANUKI_BUILD_TESTS "Build unit tests." OFF)
option(TANUKI_BUILD_TUTORIALS "Build tutorials." OFF)
option(TANUKI_WITH_BOOST_S11N "Enable support for the Boost.Serialization library." OFF)
option(TANUKI_CLANG_TIDY "Enable clang-tidy when building the unit tests." OFF)
mark_as_advanced(TANUKI_CLANG_TIDY)
set(TANUKI_CLANG_TIDY_PATH "clang-tidy" CACHE STRING "Path to clang-tidy.")
mark_as_advanced(TANUKI_CLANG_TIDY_PATH)
# NOTE: on Unix systems, the correct library installation path
# could be something other than just "lib", such as "lib64",
# "lib32", etc., depending on platform/configuration. Apparently,
# CMake provides this information via the GNUInstallDirs module.
# Let's enable this for now on all Unixes except OSX.
# NOTE: potentially, this could be applicable to Cygwin as well.
#
# https://cmake.org/cmake/help/v3.15/module/GNUInstallDirs.html
# https://cmake.org/pipermail/cmake/2013-July/055375.html
if(UNIX AND NOT APPLE)
include(GNUInstallDirs)
set(_TANUKI_INSTALL_LIBDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}")
else()
set(_TANUKI_INSTALL_LIBDIR_DEFAULT "lib")
endif()
if(NOT TANUKI_INSTALL_LIBDIR)
set(TANUKI_INSTALL_LIBDIR "${_TANUKI_INSTALL_LIBDIR_DEFAULT}" CACHE STRING
"Library installation directory." FORCE)
endif()
mark_as_advanced(TANUKI_INSTALL_LIBDIR)
message(STATUS "Library installation directory: ${TANUKI_INSTALL_LIBDIR}")
# Assemble the flags.
set(TANUKI_CXX_FLAGS_DEBUG ${YACMA_CXX_FLAGS} ${YACMA_CXX_FLAGS_DEBUG})
set(TANUKI_CXX_FLAGS_RELEASE ${YACMA_CXX_FLAGS})
if(YACMA_COMPILER_IS_MSVC)
# On both cl and clang-cl, disable the idiotic minmax macros and enable the bigobj option.
# Also, enable the WIN32_LEAN_AND_MEAN definition:
# https://stackoverflow.com/questions/11040133/what-does-defining-win32-lean-and-mean-exclude-exactly
list(APPEND TANUKI_CXX_FLAGS_DEBUG "-DNOMINMAX" "/bigobj" "-DWIN32_LEAN_AND_MEAN")
list(APPEND TANUKI_CXX_FLAGS_RELEASE "-DNOMINMAX" "/bigobj" "-DWIN32_LEAN_AND_MEAN")
if(YACMA_COMPILER_IS_CLANGXX)
# clang-cl emits various warnings, let's just silence them.
# NOTE: at one point in the recent past, MSVC added an options similar to GCC's isystem:
# https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/
# We probably just need to wait for this to be picked up by CMake/clang-cl. Let's
# revisit the issue in the future.
list(APPEND _TANUKI_CLANG_CL_DISABLED_WARNINGS
"-Wno-unused-variable"
"-Wno-inconsistent-dllimport"
"-Wno-unknown-pragmas"
"-Wno-unused-parameter"
"-Wno-sign-compare"
"-Wno-deprecated-declarations"
"-Wno-deprecated-dynamic-exception-spec"
"-Wno-old-style-cast"
"-Wno-sign-conversion"
"-Wno-non-virtual-dtor"
"-Wno-deprecated"
"-Wno-shadow"
"-Wno-shorten-64-to-32"
"-Wno-reserved-id-macro"
"-Wno-undef"
"-Wno-c++98-compat-pedantic"
"-Wno-documentation-unknown-command"
"-Wno-zero-as-null-pointer-constant"
"-Wno-language-extension-token"
"-Wno-gnu-anonymous-struct"
"-Wno-nested-anon-types"
"-Wno-documentation"
"-Wno-comma"
"-Wno-nonportable-system-include-path"
"-Wno-global-constructors"
"-Wno-redundant-parens"
"-Wno-exit-time-destructors"
"-Wno-missing-noreturn"
"-Wno-switch-enum"
"-Wno-covered-switch-default"
"-Wno-float-equal"
"-Wno-double-promotion"
"-Wno-microsoft-enum-value"
"-Wno-missing-prototypes"
"-Wno-implicit-fallthrough"
"-Wno-format-nonliteral"
"-Wno-cast-qual"
"-Wno-disabled-macro-expansion"
"-Wno-unused-private-field"
"-Wno-unused-template"
"-Wno-unused-macros"
"-Wno-extra-semi-stmt"
"-Wno-c++98-compat")
list(APPEND TANUKI_CXX_FLAGS_DEBUG ${_TANUKI_CLANG_CL_DISABLED_WARNINGS})
list(APPEND TANUKI_CXX_FLAGS_RELEASE ${_TANUKI_CLANG_CL_DISABLED_WARNINGS})
unset(_TANUKI_CLANG_CL_DISABLED_WARNINGS)
else()
# Same as above, disable some cl warnings.
list(APPEND TANUKI_CXX_FLAGS_DEBUG "/wd4459" "/wd4127" "/wd4251" "/wd4661")
list(APPEND TANUKI_CXX_FLAGS_RELEASE "/wd4459" "/wd4127" "/wd4251" "/wd4661")
endif()
# Enable strict conformance mode, if supported.
set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("/permissive-" _TANUKI_MSVC_SUPPORTS_STRICT_CONFORMANCE)
unset(CMAKE_REQUIRED_QUIET)
if(_TANUKI_MSVC_SUPPORTS_STRICT_CONFORMANCE)
message(STATUS "The '/permissive-' flag is supported, enabling it.")
list(APPEND TANUKI_CXX_FLAGS_DEBUG "/permissive-")
list(APPEND TANUKI_CXX_FLAGS_RELEASE "/permissive-")
endif()
unset(_TANUKI_MSVC_SUPPORTS_STRICT_CONFORMANCE)
endif()
# Optional Boost.Serialization support.
if(TANUKI_WITH_BOOST_S11N)
# NOTE: we rely on Boost.align to check alignment of pointers
# at runtime in debug mode. The Boost.align library appeared in
# version 1.59.0 but its API was updated in 1.61.0.
find_package(Boost 1.61.0 REQUIRED serialization)
add_library(tanuki_boost_s11n INTERFACE)
target_link_libraries(tanuki_boost_s11n INTERFACE Boost::serialization)
target_compile_definitions(tanuki_boost_s11n INTERFACE TANUKI_WITH_BOOST_S11N)
endif()
# Create the tanuki header-only library.
add_library(tanuki INTERFACE)
# Ensure that C++20 is employed when consuming tanuki.
target_compile_features(tanuki INTERFACE cxx_std_20)
target_include_directories(tanuki INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
# Configure the doc files.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/doc/conf.py.in" "${CMAKE_CURRENT_SOURCE_DIR}/doc/conf.py" @ONLY)
if(TANUKI_BUILD_TESTS OR TANUKI_BUILD_TUTORIALS)
enable_testing()
endif()
if(TANUKI_BUILD_TESTS)
add_subdirectory(test)
endif()
if(TANUKI_BUILD_TUTORIALS)
add_subdirectory(tutorial)
endif()