-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathCMakeLists.txt
230 lines (172 loc) · 7.63 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
cmake_minimum_required(VERSION 3.27)
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
endif()
project(serialosc VERSION 1.4.5)
set(CMAKE_C_STANDARD 17)
message(STATUS "configuring libuv")
add_subdirectory(third-party/libuv EXCLUDE_FROM_ALL)
message(STATUS "configuring confuse")
add_subdirectory(third-party/confuse EXCLUDE_FROM_ALL)
message(STATUS "configuring libmonome")
add_subdirectory(third-party/libmonome EXCLUDE_FROM_ALL)
message(STATUS "configuring liblo")
# ensure WITH_STATIC is not cleared
# when loading third-party/liblo/cmake for compatibility reasons
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(WITH_STATIC ON)
add_subdirectory(third-party/liblo/cmake EXCLUDE_FROM_ALL)
message(STATUS "configuring serialosc")
include_directories(include)
include_directories(third-party/liblo)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/third-party/liblo/cmake)
message(STATUS "checking git commit id")
execute_process(COMMAND "git" "rev-parse" "--verify" "--short" "HEAD" RESULT_VARIABLE GIT_COMMIT_RESULT OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT GIT_COMMIT_RESULT EQUAL 0)
set(GIT_COMMIT "unknown")
endif()
message(STATUS "checking git commit id - ${GIT_COMMIT}")
if(WIN32)
set(RC_VERSION ${CMAKE_PROJECT_VERSION_MAJOR},${CMAKE_PROJECT_VERSION_MINOR},${CMAKE_PROJECT_VERSION_PATCH})
set(RC_VERSION_STRING "${PROJECT_VERSION} (${GIT_COMMIT})")
set(RC_EXECUTABLE "serialosc-detector${CMAKE_EXECUTABLE_SUFFIX}")
configure_file(src/common/platform/winres/serialosc-cmake.rc.in
${CMAKE_BINARY_DIR}/winres/serialosc-detector.rc)
set(RC_EXECUTABLE "serialosc-device${CMAKE_EXECUTABLE_SUFFIX}")
configure_file(src/common/platform/winres/serialosc-cmake.rc.in
${CMAKE_BINARY_DIR}/winres/serialosc-device.rc)
set(RC_EXECUTABLE "serialoscd${CMAKE_EXECUTABLE_SUFFIX}")
configure_file(src/common/platform/winres/serialosc-cmake.rc.in
${CMAKE_BINARY_DIR}/winres/serialoscd.rc)
file(COPY_FILE src/common/platform/winres/logo.ico ${CMAKE_BINARY_DIR}/winres/logo.ico)
endif()
# common
add_library(serialosc_common OBJECT
src/common/ipc.c
src/common/util.c)
if(LINUX)
target_sources(serialosc_common PRIVATE src/common/platform/posix.c)
target_sources(serialosc_common PRIVATE src/common/platform/linux.c)
endif()
if(APPLE)
target_sources(serialosc_common PRIVATE src/common/platform/posix.c)
target_sources(serialosc_common PRIVATE src/common/platform/darwin.c)
endif()
if(WIN32)
target_sources(serialosc_common PRIVATE src/common/platform/windows.c)
endif()
target_link_libraries(serialosc_common monome_static)
# serialosc-detector
add_executable(serialosc-detector)
set_target_properties(serialosc-detector PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(LINUX)
include(FindPkgConfig)
pkg_check_modules(libudev REQUIRED IMPORTED_TARGET libudev)
target_sources(serialosc-detector PRIVATE src/serialosc-detector/libudev.c)
target_link_libraries(serialosc-detector PkgConfig::libudev)
endif()
if(APPLE)
target_sources(serialosc-detector PRIVATE src/serialosc-detector/iokitlib.c)
target_link_libraries(serialosc-detector "-framework IOKit")
target_link_libraries(serialosc-detector "-framework CoreFoundation")
endif()
if(WIN32)
target_sources(serialosc-detector PRIVATE src/serialosc-detector/windows.c)
target_sources(serialosc-detector PRIVATE ${CMAKE_BINARY_DIR}/winres/serialosc-detector.rc)
endif()
target_link_libraries(serialosc-detector serialosc_common)
# serialosc-device
if(NOT WIN32)
message(STATUS "checking for working poll()")
try_run(HAVE_WORKING_POLL_RUN_RESULT HAVE_WORKING_POLL_COMPILE_RESULT SOURCE_FROM_CONTENT working_poll.c [=[
#include <fcntl.h>
#include <stdlib.h>
#include <poll.h>
int main(int argc, char **argv) {
struct pollfd fds[1];
fds[0].fd = open("/dev/null", 1);
fds[0].events = POLLIN;
if (poll(fds, 1, 0) < 0 || fds[0].revents & POLLNVAL)
exit(1);
exit(0);
}
]=])
if(HAVE_WORKING_POLL_COMPILE_RESULT AND HAVE_WORKING_POLL_RUN_RESULT EQUAL 0)
message(STATUS "checking for working poll() - found")
set(HAVE_WORKING_POLL ON)
else()
message(STATUS "checking for working poll() - not found, will use select()")
set(HAVE_WORKING_POLL OFF)
endif()
endif()
if(WIN32)
set(CMAKE_REQUIRED_INCLUDES "C:\\Program Files\\Bonjour SDK\\include")
check_include_file("dns_sd.h" HAVE_DNS_SD_H)
if(HAVE_DNS_SD_H)
include_directories(SYSTEM "C:\\Program Files\\Bonjour SDK\\include")
endif()
else()
check_include_file("dns_sd.h" HAVE_DNS_SD_H)
endif()
cmake_dependent_option(build_with_zeroconf "enable zeroconf support" ON HAVE_DNS_SD_H OFF)
add_executable(serialosc-device)
set_target_properties(serialosc-device PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
target_sources(serialosc-device PRIVATE src/serialosc-device/config.c)
target_sources(serialosc-device PRIVATE src/serialosc-device/server.c)
target_sources(serialosc-device PRIVATE src/serialosc-device/main.c)
target_sources(serialosc-device PRIVATE src/serialosc-device/osc/util.c)
target_sources(serialosc-device PRIVATE src/serialosc-device/osc/sys_methods.c)
target_sources(serialosc-device PRIVATE src/serialosc-device/osc/mext_methods.c)
if(WIN32)
target_sources(serialosc-device PRIVATE src/serialosc-device/event_loop/windows.c)
target_sources(serialosc-device PRIVATE ${CMAKE_BINARY_DIR}/winres/serialosc-device.rc)
else()
if(HAVE_WORKING_POLL)
target_sources(serialosc-device PRIVATE src/serialosc-device/event_loop/poll.c)
else()
target_sources(serialosc-device PRIVATE src/serialosc-device/event_loop/select.c)
endif()
endif()
if(build_with_zeroconf)
target_sources(serialosc-device PRIVATE src/serialosc-device/zeroconf/common.c)
if(LINUX)
target_sources(serialosc-device PRIVATE src/serialosc-device/zeroconf/not_darwin.c)
endif()
if(APPLE)
target_sources(serialosc-device PRIVATE src/serialosc-device/zeroconf/darwin.c)
endif()
if(WIN32)
target_sources(serialosc-device PRIVATE src/serialosc-device/zeroconf/windows.c)
endif()
else()
add_compile_definitions(SOSC_NO_ZEROCONF)
target_sources(serialosc-device PRIVATE src/serialosc-device/zeroconf/dummy.c)
endif()
# TODO: fix the actual warnings
if(NOT MSVC)
target_compile_options(serialosc-device PRIVATE -Wno-incompatible-pointer-types)
endif()
target_include_directories(serialosc-device PRIVATE ${CMAKE_SOURCE_DIR}/third-party)
target_link_libraries(serialosc-device serialosc_common confuse monome_static liblo_static uv_a)
# serialoscd
add_executable(serialoscd)
set_target_properties(serialoscd PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(WIN32)
target_sources(serialoscd PRIVATE src/serialoscd/win_svc.c)
target_sources(serialoscd PRIVATE ${CMAKE_BINARY_DIR}/winres/serialoscd.rc)
endif()
target_sources(serialoscd PRIVATE src/serialoscd/uv.c)
# TODO: fix the actual warnings
if(NOT MSVC)
target_compile_options(serialoscd PRIVATE -Wno-incompatible-pointer-types)
endif()
target_include_directories(serialoscd PRIVATE ${CMAKE_SOURCE_DIR}/third-party)
target_compile_definitions(serialoscd PRIVATE VERSION="${PROJECT_VERSION}")
target_compile_definitions(serialoscd PRIVATE GIT_COMMIT="${GIT_COMMIT}")
target_link_libraries(serialoscd serialosc_common liblo_static uv_a)
message(STATUS "configuration summary:
version: ${PROJECT_VERSION} (${GIT_COMMIT})
prefix: ${CMAKE_INSTALL_PREFIX}
zeroconf: ${build_with_zeroconf}
")