-
Notifications
You must be signed in to change notification settings - Fork 206
/
CMakeLists.txt
108 lines (88 loc) · 3.26 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
# Note: FetchContent_MakeAvailable was added in CMake 3.14
cmake_minimum_required(VERSION 3.14)
project(weserv
VERSION 5.0.0
DESCRIPTION "Image cache and resize service"
LANGUAGES
C
CXX
)
# Set output directories in which to build the target files
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
# Options
option(ENABLE_COVERAGE "Compile in coverage mode" OFF)
option(ENABLE_SANITIZER "Build with clang sanitizer" OFF)
option(ENABLE_CLANG_TIDY "Enable source code checking using clang-tidy" OFF)
option(BUILD_TOOLS "Whether or not to build the tools" OFF)
option(BUILD_TESTS "Whether or not to build the tests" OFF)
option(INSTALL_NGX_MODULE "Build and install nginx along with the weserv module" ON)
# Set a default build type if none was specified
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()
# Let's enable C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Coverage flags
if (ENABLE_COVERAGE)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g --coverage")
set(CMAKE_EXE_LINKER_FLAGS "--coverage")
elseif (CMAKE_COMPILER_IS_GNUCXX)
# Compiler flags
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math") # Optimize for performance
set(CMAKE_EXE_LINKER_FLAGS "-s") # Strip binary
endif()
# AddressSanitizer flags
if (ENABLE_SANITIZER)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -g -O1")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer -g -O1")
endif()
if (ENABLE_CLANG_TIDY)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
if (NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found")
set(ENABLE_CLANG_TIDY OFF CACHE BOOL "" FORCE)
else()
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "-format-style=file")
endif()
endif()
include(ExternalProject)
include(FetchContent)
# Use GNUInstallDirs to install libraries into correct locations on all platforms
include(GNUInstallDirs)
# Find Catch2 (optional)
find_package(Catch2 3.0.1 QUIET)
# Find libvips (required)
find_package(PkgConfig)
pkg_check_modules(VIPS vips-cpp>=8.12 REQUIRED)
# Create the shared API library
add_subdirectory(src/api)
if (BUILD_TOOLS)
add_subdirectory(src/tools)
endif()
if (BUILD_TESTS)
enable_testing()
# Build Catch2 (a modern test framework), if necessary
if (NOT Catch2_FOUND)
add_subdirectory(third_party/catch2)
endif()
add_subdirectory(test/api)
endif()
# Install nginx along with the nginx weserv module, if necessary
if (INSTALL_NGX_MODULE)
add_subdirectory(third_party/rate-limit-nginx-module)
# Install the echo module only in debug builds
# (needed by the integration tests)
if (CMAKE_BUILD_TYPE MATCHES "Debug")
add_subdirectory(third_party/echo-nginx-module)
endif()
add_subdirectory(third_party/nginx)
endif()