-
Notifications
You must be signed in to change notification settings - Fork 53
/
CMakeLists.txt
executable file
·275 lines (233 loc) · 10.4 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
cmake_minimum_required (VERSION 3.16)
project (OpenMAMA)
set (CMAKE_CXX_STANDARD 11)
enable_testing()
find_program(GIT_BIN git REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(${CMAKE_C_COMPILER_ID})
# Get the version including tag information
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
execute_process(
COMMAND "${GIT_BIN}" describe --tags
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE OPENMAMA_VERSION_GIT
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Check if code is dirty (local changes not committed)
execute_process(
COMMAND "${GIT_BIN}" diff-index --quiet HEAD --
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE is_current_source_dir_dirty)
# Strip out unwanted part of version from git
message(STATUS "OPENMAMA_VERSION_GIT: ${OPENMAMA_VERSION_GIT}")
STRING(REGEX REPLACE "^OpenMAMA-" "" OPENMAMA_VERSION ${OPENMAMA_VERSION_GIT})
STRING(REGEX REPLACE "-release" "" OPENMAMA_VERSION ${OPENMAMA_VERSION})
if(NOT is_current_source_dir_dirty EQUAL 0)
set(OPENMAMA_VERSION "${OPENMAMA_VERSION}-DIRTY")
endif()
else()
if (NOT OPENMAMA_VERSION)
message(FATAL_ERROR
"Non git build detected. In this case a version must be provided, e.g: -DOPENMAMA_VERSION=6.3.1")
endif ()
endif()
message(STATUS "OPENMAMA_VERSION: ${OPENMAMA_VERSION}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/VERSION "${OPENMAMA_VERSION}")
# Set up default cmake build type if not defined
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "The cmake build type to perform")
message(STATUS "No CMAKE_BUILD_TYPE provided - defaulting to ${CMAKE_BUILD_TYPE}")
else()
message(STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} provided")
endif()
# Build type options
set (WITH_EXAMPLES true CACHE BOOL "Include compiled example applications in the build (e.g. mamalistenc)")
set (WITH_TESTTOOLS true CACHE BOOL "Include test tools in the build (e.g. capturereplay)")
set (WITH_UNITTEST false CACHE BOOL "Include unit tests in the build (e.g. UnitTestMamaC)")
set (WITH_PROTON true CACHE BOOL "Include the qpid proton middleware and payload bridges in the build")
set (WITH_NOOP_BRIDGE false CACHE BOOL "Include the noop example middleware bridge in the build")
set (WITH_BASE_BRIDGE true CACHE BOOL "Include the base bridge in the build (required for qpid proton)")
set (WITH_OMPB_BRIDGE true CACHE BOOL "Include the OpenMAMA Playback bridge in the build (subscriber only)")
set (WITH_MAMDA true CACHE BOOL "Include MAMDA in the build")
set (WITH_CPP true CACHE BOOL "Include C++ bindings")
set (WITH_CSHARP false CACHE BOOL "Include C# bindings")
set (WITH_JAVA false CACHE BOOL "Include JAVA bindings")
set (WITH_DOC false CACHE BOOL "Include documentation")
set (WITH_TUTORIALS false CACHE BOOL "Include building of tutorial code")
set (ENTITLEMENTS "noop" CACHE STRING "Comma delimited list of entitlement bridges to allow to load at runtime")
if (WIN32)
set (DEFAULT_BIN_GRADLE "${CMAKE_SOURCE_DIR}/gradlew.bat")
else()
set (DEFAULT_BIN_GRADLE "${CMAKE_SOURCE_DIR}/gradlew")
endif()
# Set gradle binary override
set (BIN_GRADLE "${DEFAULT_BIN_GRADLE}" CACHE PATH "The 'gradle' executable to use (defaults to: ${DEFAULT_BIN_GRADLE} which requires internet access)")
# Dependency detection options
set (OEA_ROOT "${DEFAULT_OEA_ROOT}" CACHE PATH "OEA dependency install directory (for ef ENTITLEMENTS is set to oea)")
# Install / post-compilation options
set (INSTALL_RUNTIME_DEPENDENCIES true CACHE BOOL "Whether or not to include dependent .so or .dll files in the installation package")
option(ENABLE_ASAN "Build with address sanitizer" OFF)
if(ENABLE_ASAN)
message(STATUS "Instrumenting with Address Sanitizer")
add_definitions("-DENABLE_ASAN")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope")
endif()
option(ENABLE_TSAN "Build with thread sanitizer" OFF)
if(ENABLE_TSAN)
message(STATUS "Instrumenting with Thread Sanitizer")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=thread -fPIE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=thread -fPIE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
endif()
option(ENABLE_UBSAN "Build with undefined behavior sanitizer" OFF)
if(ENABLE_UBSAN)
message(STATUS "Instrumenting with Undefined Behavior Sanitizer")
set(CMAKE_BUILD_TYPE "Debug")
set(UBSAN_FLAGS "${UBSAN_FLAGS} -fno-omit-frame-pointer")
set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=undefined")
set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=implicit-conversion")
set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=implicit-integer-truncation")
set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=integer")
set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=nullability")
set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=vptr")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${UBSAN_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UBSAN_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${UBSAN_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${UBSAN_FLAGS}")
endif()
# Resolve common reusable dependencies
find_package(FLEX REQUIRED)
find_package(Libevent REQUIRED)
find_package(Threads REQUIRED)
find_package(APR REQUIRED)
if (WITH_PROTON)
find_package(Proton REQUIRED)
endif()
if (WITH_UNITTEST)
find_package(GTest REQUIRED)
endif()
if (NOT WIN32)
find_package(UUID REQUIRED)
endif()
if (WITH_JAVA)
find_package(JNI)
endif()
add_subdirectory (common)
add_subdirectory (mama)
if (WITH_MAMDA AND WITH_CPP)
add_subdirectory (mamda)
endif()
if (WITH_CSHARP)
include (ExternalProject)
find_program(BIN_DOTNET dotnet)
message(STATUS "Using dotnet: ${BIN_DOTNET}")
ExternalProject_Add(OpenMAMA-csharp
SOURCE_DIR "."
BUILD_COMMAND ""
CONFIGURE_COMMAND ${BIN_DOTNET} build -c Release /p:Platform="Any CPU" /p:IsInOpenMAMABuild=true /p:OutputPath=${CMAKE_CURRENT_BINARY_DIR}/OpenMAMA-csharp ${CMAKE_CURRENT_SOURCE_DIR}/OpenMAMA-csharp.sln
INSTALL_COMMAND ""
LOG_BUILD 1
DEPENDS mama)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/OpenMAMA-csharp/
DESTINATION bin
FILES_MATCHING
REGEX "^.*.exe$"
REGEX "^.*.dll$"
REGEX "^.*[0-9].*$" EXCLUDE
)
if (WITH_UNITTEST AND NOT IS_MSVC_32_BIT)
enable_testing()
add_test(NAME csharp_unittests COMMAND ${BIN_DOTNET} ${CMAKE_CURRENT_BINARY_DIR}/OpenMAMA-csharp/mamaunittestscs.dll)
set_tests_properties(csharp_unittests
PROPERTIES
ENVIRONMENT "middlewareName=qpid;transportName=pub")
endif()
endif()
if (WITH_JAVA)
include(ExternalProject)
find_package(Java)
message(STATUS "Using gradle: ${BIN_GRADLE}")
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/OpenMAMA-java/mamajni)
ExternalProject_Add(OpenMAMA-java
BUILD_IN_SOURCE 1
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
BUILD_COMMAND ""
CONFIGURE_COMMAND
${BIN_GRADLE} --no-daemon
-PmamaVersion=${OPENMAMA_VERSION}
-PmamdaVersion=${OPENMAMA_VERSION}
-PbuildDir=${CMAKE_CURRENT_BINARY_DIR}/OpenMAMA-java
-PmamaJniHeaderDir=${CMAKE_BINARY_DIR}/OpenMAMA-java/mamajni
jar testClasses
INSTALL_COMMAND ""
LOG_BUILD 1
DEPENDS mama)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/OpenMAMA-java/libs/
DESTINATION lib
FILES_MATCHING
REGEX "^.*.jar$"
)
install (DIRECTORY mama/jni/src/main/java/com/wombat/mama/examples/ DESTINATION examples/mamajni)
install (DIRECTORY mamda/java/src/main/java/com/wombat/mamda/examples/ DESTINATION examples/com/wombat/mamda/examples)
message(STATUS "Will use data dictionary: ${CMAKE_SOURCE_DIR}/mamda/java/src/test/resources/data.dict")
if (WITH_UNITTEST)
enable_testing()
add_test(NAME java_unittests
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND ${BIN_GRADLE} --no-daemon
-PbuildDir=${CMAKE_CURRENT_BINARY_DIR}/OpenMAMA-java
-PmamaVersion=${OPENMAMA_VERSION}
-PmamdaVersion=${OPENMAMA_VERSION}
-Ddictionary=${CMAKE_SOURCE_DIR}/mamda/java/src/test/resources/data.dict
test -i)
set_tests_properties(java_unittests
PROPERTIES
ENVIRONMENT "middlewareName=qpid;transportName=pub")
endif()
endif()
install(FILES LICENSE.md DESTINATION .)
install(FILES mama/c_cpp/src/examples/mama.properties DESTINATION config)
include(CPack)
include(CMakePackageConfigHelpers)
set(OPENMAMA_INSTALL_TARGETS wombatcommon mama mamabaseimpl)
if (WITH_CPP)
list(APPEND OPENMAMA_INSTALL_TARGETS wombatcommoncpp mamacpp)
endif()
if (WITH_MAMDA)
list(APPEND OPENMAMA_INSTALL_TARGETS mamda mamdanews mamdaoptions mamdabook)
set(OPENMAMA_INSTALL_TARGETS ${OPENMAMA_INSTALL_TARGETS} )
endif()
install(
TARGETS ${OPENMAMA_INSTALL_TARGETS}
EXPORT OpenMAMA-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(
EXPORT OpenMAMA-targets
DESTINATION lib/cmake/OpenMAMA
NAMESPACE OpenMAMA::
)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/OpenMAMAConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/OpenMAMAConfig.cmake
INSTALL_DESTINATION lib/cmake/OpenMAMA)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenMAMAConfig.cmake
DESTINATION lib/cmake/OpenMAMA
)
if (WITH_TUTORIALS)
add_subdirectory(tutorials/c)
if (WITH_CPP)
add_subdirectory(tutorials/cpp)
endif()
endif()