-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
148 lines (122 loc) · 3.72 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
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
cmake_minimum_required(VERSION 3.23)
enable_testing()
set(CMAKE_CXX_STANDARD 20
CACHE STRING "C++ Standard version")
set(CMAKE_VERBOSE_MAKEFILE ON
CACHE BOOL "Show makefiles commands on build"
)
set(ZMQ_TARGET "ozmqpp"
CACHE STRING "ZeroMQ target name"
)
project(${ZMQ_TARGET})
if (STATIC_LIBRARY EQUAL ON)
message(STATUS "Build: Static")
add_library(${ZMQ_TARGET} STATIC)
else()
message(STATUS "Build: Shared")
add_library(${ZMQ_TARGET} SHARED)
endif()
message(STATUS "Configuration type: ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions("DEBUG")
target_compile_options(${ZMQ_TARGET}
PRIVATE
# Increased reliability of backtraces
-fasynchronous-unwind-tables
# Store compiler flags in debugging information
-grecord-gcc-switches
)
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_options(${ZMQ_TARGET}
PRIVATE
# Optimizations
-O3
# Run-time buffer overflow detection
-D_FORTIFY_SOURCE=2
)
# Check and enable LTO support if possible
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if (supported)
message(STATUS "IPO / LTO support: enabled")
set_property(TARGET ${ZMQ_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO support: disabled (<${error}>)")
endif()
endif()
# Add extra flags to the compiler
target_compile_options(${ZMQ_TARGET}
PRIVATE
-Werror
-Wall
-Wextra
-Wpedantic
# Run-time bounds checking for C++ strings and containers
-D_GLIBCXX_ASSERTIONS
# Enable table-based thread cancellation
-fexceptions
# No text relocations for shared libraries
-fpic
# Increased reliability of stack overflow detection
-fstack-clash-protection
# Stack smashing protector
-fstack-protector-strong
# Detect and reject underlinking
-Wl,-z,defs
# Disable lazy binding
-Wl,-z,now
# Read-only segments after relocation
-Wl,-z,relro
)
if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "64Bit")
target_compile_options(${ZMQ_TARGET}
PRIVATE
# Control flow integrity protection
-fcf-protection
)
endif ()
target_include_directories(${ZMQ_TARGET}
PUBLIC
$<INSTALL_INTERFACE:include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
)
target_link_libraries(${ZMQ_TARGET}
PUBLIC
zmq
)
target_compile_definitions(${ZMQ_TARGET}
PRIVATE
ZMQ_BUILD
)
add_subdirectory(deps)
add_subdirectory(include/ozmqpp)
add_subdirectory(src)
add_subdirectory(tests)
###
# INSTALL
###
include(GNUInstallDirs)
install(TARGETS ${ZMQ_TARGET}
EXPORT "${ZMQ_TARGET}Config"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT ${ZMQ_TARGET}
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT "${ZMQ_TARGET}Config"
FILE "${ZMQ_TARGET}Config.cmake"
NAMESPACE ${ZMQ_TARGET}::
DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake
)
# Add uninstall target
if (NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif ()