forked from pistacheio/pistache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
95 lines (78 loc) · 2.97 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
# SPDX-FileCopyrightText: 2015 Mathieu Stefani
#
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required (VERSION 3.11)
set(CMAKE_BUILD_TYPE_INIT Release)
file(READ "version.txt" VERSION_FILE_RAW)
string(STRIP "${VERSION_FILE_RAW}" VERSION_FILE)
project (pistache
LANGUAGES C CXX
VERSION ${VERSION_FILE})
add_compile_options(-Wall -Wextra -Wpedantic -Wconversion -Wno-sign-conversion -Wno-missing-field-initializers)
option(BUILD_SHARED_LIBS "build shared library" ON)
option(PISTACHE_BUILD_TESTS "build tests alongside the project" OFF)
option(PISTACHE_ENABLE_FLAKY_TESTS "if tests are built, also run ones that are known to be flaky" ON)
option(PISTACHE_ENABLE_NETWORK_TESTS "if tests are built, run ones needing network access" ON)
option(PISTACHE_USE_SSL "add support for SSL server" OFF)
option(PISTACHE_PIC "Enable pistache PIC" ON)
option(PISTACHE_BUILD_FUZZ "Build fuzzer for oss-fuzz" OFF)
# require fat LTO objects in static library
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION OR CMAKE_CXX_FLAGS MATCHES "-flto" OR CMAKE_CXX_FLAGS MATCHES "-flto=thin")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(-ffat-lto-objects)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-flto=full)
endif()
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if (PISTACHE_USE_SSL)
find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
endif ()
# Set version numbers in a header file
set(VERSION_MAJOR ${pistache_VERSION_MAJOR})
set(VERSION_MINOR ${pistache_VERSION_MINOR})
set(VERSION_PATCH ${pistache_VERSION_PATCH})
set(VERSION_GIT_DATE ${pistache_VERSION_TWEAK})
configure_file (
"include/pistache/version.h.in"
"include/pistache/version.h"
@ONLY
)
add_subdirectory (src)
if (PISTACHE_BUILD_TESTS)
include(CTest)
find_package(GTest QUIET)
if (NOT GTEST_FOUND)
message("GoogleTest not found. Consider installing it on your system. Downloading it from source...")
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "origin/main"
GIT_SHALLOW true
)
set(BUILD_GMOCK OFF CACHE BOOL "")
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
endif()
add_subdirectory(tests)
endif()
if (PISTACHE_BUILD_FUZZ)
add_subdirectory(tests/fuzzers)
endif()
# format target
add_custom_target(format
COMMAND
./tools/format.sh
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
# CMake 3.21 defines this automatically
if (PROJECT_IS_TOP_LEVEL OR CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
install(CODE "message(FATAL_ERROR \"Please use Meson to install Pistache.
See the README for details: https://github.com/pistacheio/pistache#building-from-source\")")
endif()