Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
203 lines (173 loc) · 7.98 KB
/
Copy pathCMakeLists.txt
File metadata and controls
203 lines (173 loc) · 7.98 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
cmake_minimum_required(VERSION 3.14)
project(MessageFrame VERSION 1.1.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Global library type control (STATIC/SHARED) via a single option
option(MSGFRAME_BUILD_SHARED "Build shared library instead of static" OFF)
set(BUILD_SHARED_LIBS ${MSGFRAME_BUILD_SHARED})
# Enable Link-Time Optimization (LTO) for Release builds
include(CheckIPOSupported)
check_ipo_supported(RESULT lto_supported OUTPUT lto_error)
if(lto_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON)
endif()
# Global compiler optimizations for ALL targets in the project (library, tests, etc.)
if(MSVC)
# /MP - multi-threaded build (always safe)
# /utf-8 - Unicode support (always safe)
# /permissive- - strict C++ standard (always safe)
add_compile_options(/MP /utf-8 /permissive- /W4)
# Optimizations /O2 and /Oi are enabled STRICTLY for Release or MinSizeRel configurations
add_compile_options($<$<CONFIG:Release,MinSizeRel>:/O2> $<$<CONFIG:Release,MinSizeRel>:/Oi>)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options($<$<CONFIG:Release,MinSizeRel>:-O3>)
# Safely add -march=native (ignore AppleClang on macOS, where it breaks the build)
if(NOT APPLE)
add_compile_options($<$<CONFIG:Release,MinSizeRel>:-march=native>)
endif()
endif()
# Local paths to submodules in third_party (according to your folders)
set(ROBIN_MAP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/robin_map/include")
set(MSGPACK_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/msgpack/include")
# ------------------------------------------------------------------
# LIBRARY
# ------------------------------------------------------------------
add_library(msg_frame
src/Value.cpp
src/Header.cpp
src/HybridMessageMap.cpp
src/MessageFrame.cpp
)
# Automatic symbol export for Windows DLLs (if SHARED is enabled)
set_target_properties(msg_frame PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
# PUBLIC: The user only sees our include folder
# (include/messageframe/*.hpp -> #include <messageframe/Xxx.hpp>)
target_include_directories(msg_frame PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
# PRIVATE: Dependencies are needed ONLY for compilation inside src/
target_include_directories(msg_frame PRIVATE
${ROBIN_MAP_INCLUDE_DIR}
${MSGPACK_INCLUDE_DIR}
)
# Disable MsgPack dependency on Boost globally for the entire project.
# PUBLIC ensures the macro applies to all targets linking msg_frame
# (examples, benchmarks, tests), not only the library itself.
target_compile_definitions(msg_frame PUBLIC MSGPACK_NO_BOOST MSGPACK_DISABLE_BOOST)
# Windows-specific settings to protect against min/max macros (propagated everywhere
# that links msg_frame, thanks to INTERFACE)
if(WIN32)
target_compile_definitions(msg_frame INTERFACE NOMINMAX)
endif()
# ------------------------------------------------------------------
# EXAMPLES — minimal API demonstration, without timing measurements.
# Built by default; disable with: -DMSGFRAME_BUILD_EXAMPLES=OFF
# ------------------------------------------------------------------
option(MSGFRAME_BUILD_EXAMPLES "Build messageframe usage examples" ON)
if(MSGFRAME_BUILD_EXAMPLES)
add_executable(messageframe_example examples/basic_usage.cpp)
target_link_libraries(messageframe_example PRIVATE msg_frame)
add_executable(messageframe_extended_example examples/extended_usage.cpp)
target_link_libraries(messageframe_extended_example PRIVATE msg_frame)
endif()
# ------------------------------------------------------------------
# BENCHMARKS — performance measurements (add/serialize/deserialize).
# Built by default; disable with: -DMSGFRAME_BUILD_BENCHMARKS=OFF
# ------------------------------------------------------------------
option(MSGFRAME_BUILD_BENCHMARKS "Build messageframe performance benchmarks" ON)
if(MSGFRAME_BUILD_BENCHMARKS)
add_executable(messageframe_benchmark benchmarks/benchmark.cpp)
target_link_libraries(messageframe_benchmark PRIVATE msg_frame)
# Add dependencies only to the benchmark:
target_include_directories(messageframe_benchmark PRIVATE
${ROBIN_MAP_INCLUDE_DIR}
${MSGPACK_INCLUDE_DIR}
)
endif()
# ------------------------------------------------------------------
# CROSS-FORMAT BENCHMARK — optional; requires a system protobuf.
# Enable with: -DMSGFRAME_BUILD_CROSS_BENCHMARK=ON
# See docs/performance.md for results and methodology.
# ------------------------------------------------------------------
option(MSGFRAME_BUILD_CROSS_BENCHMARK "Build cross-format benchmark (MessageFrame vs protobuf vs JSON vs msgpack)" OFF)
if(MSGFRAME_BUILD_CROSS_BENCHMARK)
add_subdirectory(benchmarks/cross_format)
endif()
# ------------------------------------------------------------------
# TESTS — unit tests for correctness (zero-dependency harness).
# Built by default; disable with: -DMSGFRAME_BUILD_TESTS=OFF
# enable_testing()/add_test() allow running via `ctest`.
# ------------------------------------------------------------------
option(MSGFRAME_BUILD_TESTS "Build messageframe unit tests" ON)
if(MSGFRAME_BUILD_TESTS)
enable_testing()
# tests/test_framework.hpp is located next to the .cpp itself —
# no additional include_directories are needed, because #include "test_framework.hpp"
# resolves relative to the directory of the file that includes it.
# One executable per test file — keeps ctest results isolated so CI
# points at the exact failing module instead of a single combined blob.
add_executable(test_hybrid_map tests/test_hybrid_map.cpp)
target_link_libraries(test_hybrid_map PRIVATE msg_frame)
# Add dependencies only to tests:
target_include_directories(test_hybrid_map PRIVATE
${ROBIN_MAP_INCLUDE_DIR}
${MSGPACK_INCLUDE_DIR}
)
add_test(NAME HybridMessageMapTests COMMAND test_hybrid_map)
add_executable(test_message_frame tests/test_message_frame.cpp)
target_link_libraries(test_message_frame PRIVATE msg_frame)
# Add dependencies only to tests:
target_include_directories(test_message_frame PRIVATE
${ROBIN_MAP_INCLUDE_DIR}
${MSGPACK_INCLUDE_DIR}
)
add_test(NAME MessageFrameTests COMMAND test_message_frame)
add_executable(test_flat_key tests/test_flat_key.cpp)
target_link_libraries(test_flat_key PRIVATE msg_frame)
# Add dependencies only to tests:
target_include_directories(test_flat_key PRIVATE
${ROBIN_MAP_INCLUDE_DIR}
${MSGPACK_INCLUDE_DIR}
)
add_test(NAME FlatKeyTests COMMAND test_flat_key)
add_executable(test_messageframe_parameter_api tests/test_messageframe_parameter_api.cpp)
target_link_libraries(test_messageframe_parameter_api PRIVATE msg_frame)
target_include_directories(test_messageframe_parameter_api PRIVATE
${ROBIN_MAP_INCLUDE_DIR}
${MSGPACK_INCLUDE_DIR}
)
add_test(NAME MessageFrameParameterApiTests COMMAND test_messageframe_parameter_api)
endif()
# ------------------------------------------------------------------
# INSTALL (commented out)
# ------------------------------------------------------------------
# Below is an example install() section for distributing the library.
# Users can uncomment if they want to install msg_frame
# into system directories (e.g., /usr/local or Program Files).
#
# install(TARGETS msg_frame EXPORT msg_frameTargets
# ARCHIVE DESTINATION lib
# LIBRARY DESTINATION lib
# RUNTIME DESTINATION bin
# )
#
# install(DIRECTORY include/ DESTINATION include)
#
# export(EXPORT msg_frameTargets
# FILE "${CMAKE_CURRENT_BINARY_DIR}/msg_frameTargets.cmake"
# NAMESPACE msg_frame::
# )
#
# install(EXPORT msg_frameTargets
# FILE msg_frameTargets.cmake
# NAMESPACE msg_frame::
# DESTINATION lib/cmake/msg_frame
# )
#
# # This will allow other projects to use find_package(msg_frame CONFIG)