-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
268 lines (229 loc) · 9.84 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
cmake_minimum_required(VERSION 3.6)
project(gd-mqtt-com)
option(BUILD_FOR_EDITOR "If true, create and install libs as release ready to use in the demo folder" FALSE)
if(DEFINED GODOT_GDEXTENSION_DIR)
set(GODOT_GDEXTENSION_DIR ${GODOT_GDEXTENSION_DIR} CACHE STRING "Path to GDExtension interface header directory")
else()
set(GODOT_GDEXTENSION_DIR godot-cpp/gdextension/ CACHE STRING "Path to GDExtension interface header directory")
endif()
message(STATUS "GODOT_GDEXTENSION_DIR: ${GODOT_GDEXTENSION_DIR}")
if(DEFINED CPP_BINDINGS_PATH)
set(CPP_BINDINGS_PATH ${CPP_BINDINGS_PATH} CACHE STRING "Path to C++ bindings")
else()
set(CPP_BINDINGS_PATH godot-cpp CACHE STRING "Path to C++ bindings")
endif()
message(STATUS "CPP_BINDINGS_PATH: ${CPP_BINDINGS_PATH}")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(TARGET_PATH x11)
set(LIB_EXT ".so")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(TARGET_PATH win64)
set(PAHO_MQTT_C_LIBRARIES "C:/Program Files (x86)/Eclipse Paho C/lib/paho-mqtt3as-static.lib" CACHE PATH "Paho C libraries directory override" FORCE)
set(PAHO_MQTT_C_INCLUDE_DIRS "C:/Program Files (x86)/Eclipse Paho C/include/" CACHE PATH "Paho C includes directory override" FORCE)
set(PahoMqttCpp_DIR "C:/Program Files (x86)/paho-mqtt-cpp/lib/cmake/PahoMqttCpp" CACHE PATH "Paho CPP directory override" FORCE)
set(LIB_EXT ".dll")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(TARGET_PATH macos)
set(LIB_EXT ".dylib")
else()
message(FATAL_ERROR "Not implemented support for ${CMAKE_SYSTEM_NAME}")
endif()
message(STATUS "Configured support for ${CMAKE_SYSTEM_NAME} system.")
# Change the output directory to the bin directory
set(BUILD_PATH ${CMAKE_SOURCE_DIR}/bin/${TARGET_PATH})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_PATH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_PATH}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_PATH}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
# Set the c++ standard to c++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(GODOT_COMPILE_FLAGS )
set(GODOT_LINKER_FLAGS )
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /WX") # /GF /MP
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /DTYPED_METHOD_BIND")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi
else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif(CMAKE_BUILD_TYPE MATCHES Debug)
# Disable conversion warning, truncation, unreferenced var, signed mismatch
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267")
add_definitions(-DNOMINMAX)
# Unkomment for warning level 4
#if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
#endif()
else()
#elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# using Clang
#elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC and maybe MinGW?
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(GODOT_LINKER_FLAGS "-Wl")
else()
set(GODOT_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-R,'$$ORIGIN'")
endif()
# Hmm.. maybe to strikt?
set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wchar-subscripts -Wcomment -Wdisabled-optimization")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wformat -Wformat=2 -Wformat-security -Wformat-y2k")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wimport -Winit-self -Winline -Winvalid-pch -Werror")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-braces -Wmissing-format-attribute")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpointer-arith")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wredundant-decls -Wreturn-type -Wsequence-point")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wswitch -Wswitch-enum -Wtrigraphs")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused-label")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wunused-value -Wvariadic-macros -Wvolatile-register-var -Wno-error=attributes")
# -Wshadow -Wextra -Wall -Weffc++ -Wfloat-equal -Wstack-protector -Wunused-parameter -Wsign-compare -Wunused-variable -Wcast-align
# -Wunused-function -Wstrict-aliasing -Wstrict-aliasing=2 -Wmissing-field-initializers
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wno-ignored-attributes")
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0")
else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3")
endif(CMAKE_BUILD_TYPE MATCHES Debug)
endif()
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
# saves around 20% of binary size and very significant build time (GH-80513).
option(GODOT_DISABLE_EXCEPTIONS OFF "Force disabling exception handling code")
if (GODOT_DISABLE_EXCEPTIONS)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -D_HAS_EXCEPTIONS=0")
else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-exceptions")
endif()
else()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /EHsc")
endif()
endif()
##################################################################################
if(DEFINED STATIC_PAHO_MQTT)
add_definitions(-DSTATIC_PAHO_MQTT=ON)
set(STATIC_PAHO_MQTT_PATH ${STATIC_PAHO_MQTT_PATH} CACHE STRING "Path to GLIB")
message(STATUS "STATIC_PAHO_MQTT_PATH: ${STATIC_PAHO_MQTT_PATH}")
# Define static linking
set(CMAKE_EXE_LINKER_FLAGS "-static")
# TODO envolope for windows build
set(PAHO_MQTT_INCLUDE_DIR
${STATIC_PAHO_MQTT_PATH}/include
)
set(PAHO_MQTT_LIBRARIES
#${CMAKE_SOURCE_DIR}/thirdparty/paho.mqtt.cpp/install/lib/libpaho-mqtt3a.a
#${CMAKE_SOURCE_DIR}/thirdparty/paho.mqtt.cpp/install/lib/libpaho-mqtt3c.a
${STATIC_PAHO_MQTT_PATH}/lib/libpaho-mqtt3as.a
${STATIC_PAHO_MQTT_PATH}/lib/libpaho-mqtt3cs.a
${STATIC_PAHO_MQTT_PATH}/lib/libpaho-mqttpp3.a
-lssl -lcrypto
-ldl -lpthread
)
else()
find_package(PahoMqttCpp REQUIRED)
set(PAHO_MQTT_LIBRARIES
PahoMqttCpp::paho-mqttpp3
/usr/lib/x86_64-linux-gnu/libpaho-mqtt3as.a
/usr/lib/x86_64-linux-gnu/libpaho-mqtt3cs.a
-lssl -lcrypto
-ldl -lpthread
)
endif()
##################################################################################
set(libmqtt_com mqtt-com)
add_library(${libmqtt_com} src/mqtt_com/mqtt_com.cpp)
target_include_directories(${libmqtt_com} SYSTEM PRIVATE
${CMAKE_SOURCE_DIR}/include
${PAHO_MQTT_INCLUDE_DIR}
)
target_link_libraries(${libmqtt_com}
${PAHO_MQTT_LIBRARIES}
)
set(test_mqtt_com test_mqtt_com)
add_executable(${test_mqtt_com} tests/test_mqtt_com.cpp)
target_include_directories(${test_mqtt_com} SYSTEM PRIVATE
${CMAKE_SOURCE_DIR}/include
${PAHO_MQTT_INCLUDE_DIR}
)
target_link_libraries(${test_mqtt_com}
${libmqtt_com}
)
# Get Sources
file(GLOB_RECURSE SOURCES src/*.c**)
file(GLOB_RECURSE HEADERS include/*.h**)
# Define our godot-cpp library
#add_library(${PROJECT_NAME} SHARED src/gd_mqtt_com.cpp)
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
${CMAKE_SOURCE_DIR}/include
${CPP_BINDINGS_PATH}/include
${CPP_BINDINGS_PATH}/build/gen/include
${GODOT_GDEXTENSION_DIR}
${PAHO_MQTT_INCLUDE_DIR}
)
# Create the correct name (godot.os.build_type.system_bits)
# Synchronized with godot-cpp's CMakeLists.txt
set(BITS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITS 64)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_CPP_BUILD_TYPE Debug)
else()
set(GODOT_CPP_BUILD_TYPE Release)
endif()
string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME)
string(TOLOWER ${GODOT_CPP_BUILD_TYPE} BUILD_TYPE)
if(ANDROID)
# Added the android abi after system name
set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI})
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_directories(${PROJECT_NAME}
PRIVATE
${CPP_BINDINGS_PATH}/bin/Debug # "Debug" Always seems to be a bug on Windows
)
target_link_libraries(${PROJECT_NAME}
godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>
${PAHO_MQTT_LIBRARIES}
)
else()
target_link_directories(${PROJECT_NAME}
PRIVATE
${CPP_BINDINGS_PATH}/build/bin/
)
target_link_libraries(${PROJECT_NAME}
#libgodot-cpp.linux.release.64.a
libgodot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>.a
${PAHO_MQTT_LIBRARIES}
)
endif()
# Add the compile flags
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS})
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS})
if(CMAKE_BUILD_TYPE MATCHES Debug)
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "${PROJECT_NAME}.debug")
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "${PROJECT_NAME}.release")
endif()
# Copy a fake debug
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${BUILD_PATH}/${PROJECT_NAME}.release${LIB_EXT} ${BUILD_PATH}/${PROJECT_NAME}.debug${LIB_EXT}
)
else()
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${BUILD_PATH}/lib${PROJECT_NAME}.release${LIB_EXT} ${BUILD_PATH}/lib${PROJECT_NAME}.debug${LIB_EXT}
)
endif()