forked from bitchatz/bitchatz-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
206 lines (174 loc) · 6.45 KB
/
CMakeLists.txt
File metadata and controls
206 lines (174 loc) · 6.45 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
cmake_minimum_required(VERSION 3.20)
project(bitchat)
# General settings
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Testing option
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
option(ENABLE_TESTS "Enable Tests" OFF)
option(BUILD_EXECUTABLE "Build The Main Executable" ON)
# UI type option
set(BITCHAT_GUI "CONSOLE" CACHE STRING "UI Type: CONSOLE or DUMMY")
set_property(CACHE BITCHAT_GUI PROPERTY STRINGS "CONSOLE" "DUMMY")
if(ENABLE_TESTS)
enable_testing()
endif()
# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Include CPM for dependency management
include(cmake/CPM.cmake)
set(CPM_SOURCE_CACHE "${CMAKE_SOURCE_DIR}/dependencies")
# Include custom functions
include(cmake/functions.cmake)
# Include noise-c configuration
include(cmake/noise-c.cmake)
# Include lz4 configuration
include(cmake/lz4.cmake)
# Platform-specific settings
if(APPLE)
set(PLATFORM_APPLE TRUE)
find_library(FRAMEWORK_COREBLUETOOTH CoreBluetooth)
find_library(FRAMEWORK_FOUNDATION Foundation)
find_library(FRAMEWORK_IOKIT IOKit)
find_library(FRAMEWORK_COREFOUNDATION CoreFoundation)
elseif(WIN32)
set(PLATFORM_WINDOWS TRUE)
# TODO: Add Windows Bluetooth libraries
elseif(UNIX AND NOT APPLE)
set(PLATFORM_LINUX TRUE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(BLUEZ REQUIRED bluez)
endif()
# Add dependencies via CPM
CPMAddPackage(
NAME spdlog
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.15.3
)
CPMAddPackage("gh:nlohmann/json@3.12.0")
# Add Google Test only if tests are enabled
if(ENABLE_TESTS)
CPMAddPackage("gh:google/googletest@1.17.0")
endif()
# Find OpenSSL
find_package(OpenSSL REQUIRED)
# Common libraries
set(COMMON_LIBRARIES
spdlog::spdlog
nlohmann_json::nlohmann_json
noise-c
lz4
OpenSSL::SSL
OpenSSL::Crypto
)
# Source files
set(COMMON_SOURCES
${CMAKE_SOURCE_DIR}/src/bitchat/core/bitchat_data.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/core/bitchat_manager.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/compression_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/datetime_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/noise_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/protocol_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/helpers/string_helper.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/identity/identity_models.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_hybrid_key_exchange.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_post_quantum_key_exchange.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_protocol.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_protocol_migration.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_pq_handshake_pattern.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_security_error.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/noise/noise_session_default.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/message_padding.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/packet_serializer.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/protocol/packet.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/runners/bluetooth_announce_runner.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/runners/cleanup_runner.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/crypto_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/identity_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/message_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/network_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/services/noise_service.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/ui/dummy_ui.cpp
${CMAKE_SOURCE_DIR}/src/bitchat/ui/console_ui.cpp
)
set(SOURCES ${COMMON_SOURCES})
if(BUILD_EXECUTABLE)
set(SOURCES ${SOURCES} src/main.cpp)
endif()
# Platform-specific source files
if(PLATFORM_APPLE)
set(SOURCES ${SOURCES}
src/platforms/apple/bluetooth_factory.mm
src/platforms/apple/bluetooth.mm
src/platforms/apple/bluetooth_bridge.mm
)
set_source_files_properties(src/platforms/apple/bluetooth.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
set_source_files_properties(src/platforms/apple/bluetooth_bridge.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
set_source_files_properties(src/platforms/apple/bluetooth_factory.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
elseif(PLATFORM_LINUX)
set(SOURCES ${SOURCES}
src/platforms/linux/bluetooth.cpp
src/platforms/linux/bluetooth_factory.cpp
)
endif()
# Create executable only if BUILD_EXECUTABLE is enabled
if(BUILD_EXECUTABLE)
add_executable(bitchat ${SOURCES})
# Include directories
target_include_directories(bitchat PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/vendor
)
# Add UI macro
target_compile_definitions(bitchat PRIVATE BITCHAT_GUI_${BITCHAT_GUI})
# Link libraries
target_link_libraries(bitchat ${COMMON_LIBRARIES})
endif()
# Platform-specific linking
if(BUILD_EXECUTABLE)
if(PLATFORM_APPLE)
target_link_libraries(bitchat
${FRAMEWORK_COREBLUETOOTH}
${FRAMEWORK_FOUNDATION}
${FRAMEWORK_IOKIT}
${FRAMEWORK_COREFOUNDATION}
)
elseif(PLATFORM_LINUX)
target_link_libraries(bitchat ${BLUEZ_LIBRARIES})
target_include_directories(bitchat PRIVATE ${BLUEZ_INCLUDE_DIRS})
endif()
endif()
# Apply compiler flags to main executable
if(BUILD_EXECUTABLE)
apply_compiler_flags(bitchat)
# AddressSanitizer option
if(ENABLE_ASAN)
message(STATUS "Building with AddressSanitizer enabled")
set(ASAN_FLAGS -fsanitize=address -fno-omit-frame-pointer)
target_compile_options(bitchat PRIVATE ${ASAN_FLAGS})
target_link_options(bitchat PRIVATE -fsanitize=address)
endif()
endif()
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()
# Install target
if(BUILD_EXECUTABLE)
install(TARGETS bitchat
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()
# Print configuration info
message(STATUS "Platform: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Testing enabled: ${ENABLE_TESTS}")
message(STATUS "Building executable: ${BUILD_EXECUTABLE}")
# CPack configuration
include(cmake/cpack.cmake)