-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
117 lines (93 loc) · 3.09 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
cmake_minimum_required(VERSION 3.16)
# Project name and version
project(TaskService VERSION 1.0 LANGUAGES CXX)
# Set C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set default build type to Release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
# Add the main include directory
include_directories(${CMAKE_SOURCE_DIR}/include)
# Add the vendor include directory
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/include/vendor)
# Define source and include directories
set(SRC_DIR "src")
set(INCLUDE_DIR "include")
set(BIN_DIR "build")
file(GLOB SOURCES ${SRC_DIR}/*.cpp)
# Output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/${BIN_DIR})
# Include directories
include_directories(${INCLUDE_DIR})
# Find dependencies
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
find_package(spdlog REQUIRED)
# Brotli (assumes it is installed using Homebrew or similar package manager)
if(APPLE AND EXISTS "/opt/homebrew")
set(BROTLI_ROOT "/opt/homebrew")
else()
set(BROTLI_ROOT "/usr/local")
endif()
find_path(BROTLI_INCLUDE_DIR brotli PATHS ${BROTLI_ROOT}/include)
find_library(BROTLI_COMMON_LIBRARY NAMES brotlicommon PATHS ${BROTLI_ROOT}/lib)
find_library(BROTLI_ENC_LIBRARY NAMES brotlienc PATHS ${BROTLI_ROOT}/lib)
find_library(BROTLI_DEC_LIBRARY NAMES brotlidec PATHS ${BROTLI_ROOT}/lib)
if(NOT BROTLI_INCLUDE_DIR OR NOT BROTLI_COMMON_LIBRARY OR NOT BROTLI_ENC_LIBRARY OR NOT BROTLI_DEC_LIBRARY)
message(FATAL_ERROR "Brotli libraries not found. Make sure they are installed.")
endif()
# Libraries for dependencies
set(DEPENDENT_LIBRARIES
OpenSSL::SSL
OpenSSL::Crypto
ZLIB::ZLIB
spdlog::spdlog
${BROTLI_COMMON_LIBRARY}
${BROTLI_ENC_LIBRARY}
${BROTLI_DEC_LIBRARY}
pthread
)
# Compiler definitions
add_definitions(
-DCPPHTTPLIB_OPENSSL_SUPPORT
-DCPPHTTPLIB_ZLIB_SUPPORT
-DCPPHTTPLIB_BROTLI_SUPPORT
)
# Add executable targets
add_executable(task-service
${SRC_DIR}/task-service.cpp
${SRC_DIR}/logging.cpp
${SRC_DIR}/service.cpp
${SRC_DIR}/taskdb.cpp
${SRC_DIR}/cli.cpp
)
add_executable(task-client
${SRC_DIR}/taskdb.cpp
${SRC_DIR}/task-client.cpp
)
add_executable(integration ${SRC_DIR}/integration.cpp)
# Link libraries to executables
target_link_libraries(task-service PRIVATE ${DEPENDENT_LIBRARIES})
target_link_libraries(task-client PRIVATE ${DEPENDENT_LIBRARIES})
target_link_libraries(integration PRIVATE ${DEPENDENT_LIBRARIES})
# Installation rules
install(TARGETS task-service task-client DESTINATION /usr/local/bin)
# Static linking for standalone executable
if(NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
endif()
# MacOS universal binary setup
if(APPLE)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
list(APPEND DEPENDENT_LIBRARIES
"-framework CoreFoundation"
"-framework Security"
)
endif()
# Debian container specific setup
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND EXISTS "/etc/debian_version")
# Debian specific configurations (if any)
endif()