-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
164 lines (134 loc) · 6.46 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
cmake_minimum_required(VERSION 3.23...3.30)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
# if (IS_CLANG)
# set(CMAKE_CXX_STANDARD 20)
# else ()
# set(CMAKE_CXX_STANDARD 23)
# endif ()
# set(CXX_STANDARD ${CMAKE_CXX_STANDARD})
# set(CMAKE_CXX_EXTENSIONS OFF)
project(webpp
VERSION 1.0.0
LANGUAGES CXX
)
enable_language(CXX)
set(LIB_NAME ${PROJECT_NAME})
set(LIB_SOVERSION 1)
set(BIN_SOVERSION 1)
set(LIB_VERSION 1.0.0)
set(BIN_VERSION 1.0.0)
# output the libraries and executables in the cmake home directory instead of
# their own folders
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${CMAKE_BINARY_DIR}/webpp")
set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/webpp")
set(EXAMPLES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/examples")
set(LIB_INCLUDE_DIR "${LIB_DIR}")
set(SDK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/sdk")
set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests")
set(BENCHMARKS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/benchmarks")
set(INSTALL_LIBDIR $<IF:$<BOOL:${CMAKE_INSTALL_LIBDIR}>,${CMAKE_INSTALL_LIBDIR},lib>)
set(INSTALL_BINDIR $<IF:$<BOOL:${CMAKE_INSTALL_BINDIR}>,${CMAKE_INSTALL_BINDIR},bin>)
set(INSTALL_INCLUDEDIR $<IF:$<BOOL:${CMAKE_INSTALL_INCLUDEDIR}>,${CMAKE_INSTALL_INCLUDEDIR},include>)
set(INSTALL_ARCHIVEDIR ${INSTALL_LIBDIR})
set(gcc_min_version 12.1.0)
set(clang_min_version 14.0.6)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(IS_DEBUG TRUE)
message(STATUS "Debug mode is enabled.")
else ()
set(IS_DEBUG FALSE)
message(STATUS "Debug mode is disabled.")
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(IS_GCC TRUE)
set(IS_CLANG FALSE)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${gcc_min_version})
message(FATAL_ERROR "This version of GCC is not supported. We need at least version ${gcc_min_version}.")
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(IS_GCC FALSE)
set(IS_CLANG TRUE)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${clang_min_version})
message(FATAL_ERROR "This version of Clang is not supported. We need at least version ${clang_min_version}.")
endif ()
endif ()
option(WEBPP_DEV "Enable/Disable Web++ library development (for developers of the webpp library only)" OFF)
#option(SHARED_LIBRARY_EXECUTABLE "Make the shared library executable." OFF)
option(NATIVE_ARCH "Optimize the binaries for this system architecture only." OFF)
option(VERBOSE "Verbose printing" OFF)
option(USE_EVE "Use Eve Library for vectorization" OFF)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
option(USE_OS_LIBURING "Use OS liburing instead of our own header-only liburing" OFF)
endif ()
if (WEBPP_DEV)
if (IS_CLANG AND IS_DEBUG)
option(FUZZ_TESTS "Enable Building of fuzz tests" ON)
else ()
option(FUZZ_TESTS "Enable Building of fuzz tests" OFF)
endif ()
message(STATUS "CMake Version : ${CMAKE_VERSION}")
message(STATUS "Project name : ${PROJECT_NAME}")
message(STATUS "C++ Standard Version : C++${CMAKE_CXX_STANDARD}")
message(STATUS "Library version : ${LIB_VERSION}")
message(STATUS "Library soversion : ${LIB_SOVERSION}")
message(STATUS "Binary version : ${BIN_VERSION}")
message(STATUS "Binary soversion : ${BIN_SOVERSION}")
message(STATUS "Library name : ${LIB_NAME}")
message(STATUS "EXPORT_NAME : ${EXPORT_NAME}")
message(STATUS "Compiler : ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} (${CMAKE_CXX_COMPILER})")
message(STATUS "prefix path : ${CMAKE_PREFIX_PATH}")
message(STATUS "Library path : ${LIB_DIR}")
message(STATUS "Library include path : ${LIB_INCLUDE_DIR}")
message(STATUS "Binary path : ${SDK_DIR}")
message(STATUS "Tests path : ${TESTS_DIR}")
message(STATUS "Benchmarks path : ${BENCHMARKS_DIR}")
message(STATUS "Install lib dir expression : ${INSTALL_LIBDIR}")
message(STATUS "Install archive dir expression : ${INSTALL_ARCHIVEDIR}")
message(STATUS "Install bin dir expression : ${INSTALL_BINDIR}")
message(STATUS "Install include dir expression : ${INSTALL_INCLUDEDIR}")
message(STATUS "Building Fuzz Tests : ${FUZZ_TESTS}")
message(STATUS "Use eve library : ${USE_EVE}")
add_compile_definitions(WEBPP_PROJECT_ROOT=${CMAKE_CURRENT_SOURCE_DIR})
if (IS_DEBUG)
enable_testing()
endif ()
# if (IS_CLANG AND LIBCXX)
# # This is not the perfect way to do this, but ...
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
# endif ()
if (IS_GCC AND IS_DEBUG)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -fconcepts-diagnostics-depth=10 -ftemplate-backtrace-limit=0 -Wall -Wpedantic -Wextra -Wconversion -Wshadow")
# For profiling (https://www.jetbrains.com/help/clion/cpu-profiler.html#UsingTheProfiler)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -fno-omit-frame-pointer")
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ftime-report")
elseif (IS_CLANG AND IS_DEBUG)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -Wall -Wpedantic -Wextra -Wconversion -Wshadow")
# For profiling (https://www.jetbrains.com/help/clion/cpu-profiler.html#UsingTheProfiler)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer")
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ftime-trace")
endif ()
if (IS_CLANG)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif ()
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
if (${FORCE_COLORED_OUTPUT})
if (IS_GCC)
add_compile_options(-fdiagnostics-color=always)
elseif (IS_CLANG)
add_compile_options(-fcolor-diagnostics)
endif ()
endif ()
endif () # Development
include(./cmake/import.cmake)
add_subdirectory(${LIB_DIR})
add_subdirectory(${SDK_DIR})
if (WEBPP_DEV)
if (IS_DEBUG)
add_subdirectory(${TESTS_DIR} EXCLUDE_FROM_ALL)
add_subdirectory(${BENCHMARKS_DIR} EXCLUDE_FROM_ALL)
endif ()
add_subdirectory(${EXAMPLES_DIR} EXCLUDE_FROM_ALL)
endif ()