-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
236 lines (207 loc) · 9.17 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
cmake_minimum_required(VERSION 3.25)
set(PLATFORM "win" CACHE STRING "Platform")
set(ARCH "x64" CACHE STRING "Arch")
option(BUILD_SHARED "Option to build shared library" ON)
option(BUILD_STATIC "Option to build static library" ON)
option(POST_BUILD_COPY_EXT_LIBS "Option to copy external libraries to build directory" ON)
message(STATUS "PLATFORM: ${PLATFORM}")
message(STATUS "ARCH: ${ARCH}")
message(STATUS "BUILD_SHARED: ${BUILD_SHARED}")
message(STATUS "BUILD_STATIC: ${BUILD_STATIC}")
message(STATUS "POST_BUILD_COPY_EXT_LIBS: ${POST_BUILD_COPY_EXT_LIBS}")
if(PLATFORM STREQUAL "macos")
set(CMAKE_OSX_DEPLOYMENT_TARGET 14.0)
elseif(PLATFORM STREQUAL "ios" OR PLATFORM STREQUAL "ios-simulator")
set(CMAKE_SYSTEM_NAME iOS)
if (PLATFORM STREQUAL "ios-simulator")
set(CMAKE_OSX_SYSROOT iphonesimulator)
endif()
set(CMAKE_OSX_DEPLOYMENT_TARGET 17.0)
elseif(PLATFORM STREQUAL "tvos")
set(CMAKE_SYSTEM_NAME tvOS)
set(CMAKE_OSX_DEPLOYMENT_TARGET 17.0)
elseif(PLATFORM STREQUAL "android")
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 30)
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
endif()
file(READ src/ZeDMD.h version)
string(REGEX MATCH "ZEDMD_VERSION_MAJOR[ ]+([0-9]+)" _tmp ${version})
set(VERSION_MAJOR "${CMAKE_MATCH_1}")
string(REGEX MATCH "ZEDMD_VERSION_MINOR[ ]+([0-9]+)" _tmp ${version})
set(VERSION_MINOR "${CMAKE_MATCH_1}")
string(REGEX MATCH "ZEDMD_VERSION_PATCH[ ]+([0-9]+)" _tmp ${version})
set(VERSION_PATCH "${CMAKE_MATCH_1}")
project(zedmd VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
DESCRIPTION "Cross-platform library for communicating with ZeDMD.")
if(PLATFORM STREQUAL "win")
if(ARCH STREQUAL "x86")
add_compile_definitions(WIN32)
endif()
elseif(PLATFORM STREQUAL "macos")
if (ARCH STREQUAL "arm64")
set(CMAKE_OSX_ARCHITECTURES arm64)
elseif(ARCH STREQUAL "x64")
set(CMAKE_OSX_ARCHITECTURES x86_64)
endif()
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "@executable_path")
elseif(PLATFORM STREQUAL "ios" OR PLATFORM STREQUAL "ios-simulator" OR PLATFORM STREQUAL "tvos")
set(CMAKE_OSX_ARCHITECTURES arm64)
elseif(PLATFORM STREQUAL "linux" OR PLATFORM STREQUAL "android")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(ZEDMD_SOURCES
src/ZeDMDComm.h
src/ZeDMDComm.cpp
src/ZeDMDWiFi.h
src/ZeDMDWiFi.cpp
src/ZeDMD.h
src/ZeDMD.cpp
third-party/include/miniz/miniz.h
third-party/include/miniz/miniz.c
)
set(ZEDMD_INCLUDE_DIRS
src
third-party/include
)
if(BUILD_SHARED)
add_library(zedmd_shared SHARED ${ZEDMD_SOURCES})
target_include_directories(zedmd_shared PUBLIC ${ZEDMD_INCLUDE_DIRS})
if(PLATFORM STREQUAL "win")
target_link_directories(zedmd_shared PUBLIC
third-party/build-libs/${PLATFORM}/${ARCH}
third-party/runtime-libs/${PLATFORM}/${ARCH}
)
if(ARCH STREQUAL "x64")
target_link_libraries(zedmd_shared PUBLIC libserialport64 ws2_32)
else()
target_link_libraries(zedmd_shared PUBLIC libserialport ws2_32)
endif()
elseif(PLATFORM STREQUAL "macos")
target_link_directories(zedmd_shared PUBLIC
third-party/runtime-libs/${PLATFORM}/${ARCH}
)
target_link_libraries(zedmd_shared PUBLIC serialport)
elseif(PLATFORM STREQUAL "linux")
target_link_directories(zedmd_shared PUBLIC
third-party/runtime-libs/${PLATFORM}/${ARCH}
)
target_link_libraries(zedmd_shared PUBLIC serialport)
endif()
if(PLATFORM STREQUAL "win" AND ARCH STREQUAL "x64")
set(ZEDMD_OUTPUT_NAME "zedmd64")
else()
set(ZEDMD_OUTPUT_NAME "zedmd")
endif()
set_target_properties(zedmd_shared PROPERTIES
OUTPUT_NAME ${ZEDMD_OUTPUT_NAME}
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
)
install(TARGETS zedmd_shared
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)
install(FILES src/ZeDMD.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
if(PLATFORM STREQUAL "win" OR PLATFORM STREQUAL "macos" OR PLATFORM STREQUAL "linux")
add_executable(zedmd_test
src/test.cpp
)
target_link_libraries(zedmd_test PUBLIC zedmd_shared)
if(POST_BUILD_COPY_EXT_LIBS)
if(PLATFORM STREQUAL "win")
if(ARCH STREQUAL "x64")
add_custom_command(TARGET zedmd_test POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/third-party/build-libs/${PLATFORM}/${ARCH}/libserialport64.lib" "$<TARGET_FILE_DIR:zedmd_test>"
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/libserialport64.dll" "$<TARGET_FILE_DIR:zedmd_test>"
)
else()
add_custom_command(TARGET zedmd_test POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/third-party/build-libs/${PLATFORM}/${ARCH}/libserialport.lib" "$<TARGET_FILE_DIR:zedmd_test>"
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/libserialport.dll" "$<TARGET_FILE_DIR:zedmd_test>"
)
endif()
elseif(PLATFORM STREQUAL "macos")
add_custom_command(TARGET zedmd_test POST_BUILD
COMMAND cp -a "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/*.dylib" "$<TARGET_FILE_DIR:zedmd_test>"
)
elseif(PLATFORM STREQUAL "linux")
add_custom_command(TARGET zedmd_test POST_BUILD
COMMAND cp -a "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/*.so" "$<TARGET_FILE_DIR:zedmd_test>"
COMMAND cp -a "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/*.so.*" "$<TARGET_FILE_DIR:zedmd_test>"
)
endif()
endif()
endif()
endif()
if(BUILD_STATIC)
add_library(zedmd_static STATIC ${ZEDMD_SOURCES})
target_include_directories(zedmd_static PUBLIC ${ZEDMD_INCLUDE_DIRS})
if(PLATFORM STREQUAL "win")
set_target_properties(zedmd_static PROPERTIES
OUTPUT_NAME "zedmd_static"
)
else()
set_target_properties(zedmd_static PROPERTIES
OUTPUT_NAME "zedmd"
)
endif()
install(TARGETS zedmd_static
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)
install(FILES src/ZeDMD.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
if(PLATFORM STREQUAL "win" OR PLATFORM STREQUAL "macos" OR PLATFORM STREQUAL "linux")
add_executable(zedmd_test_s
src/test.cpp
)
if(PLATFORM STREQUAL "win")
target_link_directories(zedmd_test_s PUBLIC
third-party/build-libs/${PLATFORM}/${ARCH}
third-party/runtime-libs/${PLATFORM}/${ARCH}
)
if(ARCH STREQUAL "x64")
target_link_libraries(zedmd_test_s PUBLIC zedmd_static libserialport64 ws2_32)
else()
target_link_libraries(zedmd_test_s PUBLIC zedmd_static libserialport ws2_32)
endif()
elseif(PLATFORM STREQUAL "macos")
target_link_directories(zedmd_test_s PUBLIC
third-party/runtime-libs/${PLATFORM}/${ARCH}
)
target_link_libraries(zedmd_test_s PUBLIC zedmd_static serialport)
elseif(PLATFORM STREQUAL "linux")
target_link_directories(zedmd_test_s PUBLIC
third-party/runtime-libs/${PLATFORM}/${ARCH}
)
target_link_libraries(zedmd_test_s PUBLIC zedmd_static serialport)
endif()
if(POST_BUILD_COPY_EXT_LIBS)
if(PLATFORM STREQUAL "win")
if(ARCH STREQUAL "x64")
add_custom_command(TARGET zedmd_test_s POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/third-party/build-libs/${PLATFORM}/${ARCH}/libserialport64.lib" "$<TARGET_FILE_DIR:zedmd_test_s>"
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/libserialport64.dll" "$<TARGET_FILE_DIR:zedmd_test_s>"
)
else()
add_custom_command(TARGET zedmd_test_s POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/third-party/build-libs/${PLATFORM}/${ARCH}/libserialport.lib" "$<TARGET_FILE_DIR:zedmd_test_s>"
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/libserialport.dll" "$<TARGET_FILE_DIR:zedmd_test_s>"
)
endif()
elseif(PLATFORM STREQUAL "macos")
add_custom_command(TARGET zedmd_test_s POST_BUILD
COMMAND cp -a "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/*.dylib" "$<TARGET_FILE_DIR:zedmd_test_s>"
)
elseif(PLATFORM STREQUAL "linux")
add_custom_command(TARGET zedmd_test_s POST_BUILD
COMMAND cp -a "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/*.so" "$<TARGET_FILE_DIR:zedmd_test_s>"
COMMAND cp -a "${CMAKE_SOURCE_DIR}/third-party/runtime-libs/${PLATFORM}/${ARCH}/*.so.*" "$<TARGET_FILE_DIR:zedmd_test_s>"
)
endif()
endif()
endif()
endif()