-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
130 lines (105 loc) · 2.52 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
cmake_minimum_required(VERSION 3.16.3)
project(
"LeapWS"
VERSION 0.1.0
DESCRIPTION "Transmit hand data through a WebSocket"
LANGUAGES C
)
# Enforce building in a build folder
if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
message(FATAL_ERROR "Run CMake in a separate build directory to avoid source code contamination.")
endif ()
# For Libwebsockets (?)
SET(SERVER_NAME Server)
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_LIBRARY_ARCHITECTURE x64)
else()
set(CMAKE_LIBRARY_ARCHITECTURE x86)
endif()
endif()
# -------- Search for libwebsockets
find_package(libwebsockets CONFIG REQUIRED)
require_lws_config(LWS_ROLE_WS 1 requirements)
# Add libwebsockets to the project
if (websockets_shared)
find_library(LIBWEBSOCKETS_LIBS websockets_shared)
else()
find_library(LIBWEBSOCKETS_LIBS websockets)
endif()
# -------- Search for LeapC and include the headers and libraries
# Set path for cmake files
if (WIN32)
file(TO_CMAKE_PATH "$ENV{ProgramFiles}\\Ultraleap" ULTRALEAP_PATH_ROOT)
elseif (APPLE)
set(ULTRALEAP_PATH_ROOT "/Library/Application\ Support/Ultraleap/LeapSDK/lib/cmake/LeapSDK")
elseif (UNIX)
set(ULTRALEAP_PATH_ROOT "/usr/share/doc/ultraleap-hand-tracking-service/lib/cmake/LeapSDK")
endif()
find_package(LeapSDK
REQUIRED
PATHS
"${ULTRALEAP_PATH_ROOT}")
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
if (WIN32)
find_package(PThreads4W REQUIRED)
elseif (UNIX)
find_package(Threads REQUIRED)
endif()
find_package(Threads REQUIRED)
get_target_property(
LEAPC_IMPORTED_CONFIG
LeapSDK::LeapC
IMPORTED_CONFIGURATIONS
)
get_target_property(
LEAPC_SHARED_LIB_PATH
LeapSDK::LeapC
IMPORTED_LOCATION_${LEAPC_IMPORTED_CONFIG}
)
# -------- Set shared libraries and executables
# Build libUtils and link LeapC to it
add_library(
libUtils
OBJECT
"utils.c")
if (WIN32)
target_link_libraries(
libUtils
PUBLIC
LeapSDK::LeapC)
elseif (UNIX)
target_link_libraries(
libUtils
PUBLIC
LeapSDK::LeapC
m)
endif()
target_include_directories(
libUtils
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR})
# Build the executable and link libs to it
add_executable(Ultraleap-Tracking-WS "main.c")
if (WIN32)
target_link_libraries(
Ultraleap-Tracking-WS
PUBLIC
libUtils
PThreads4W::PThreads4W
${LIBWEBSOCKETS_LIBS})
elseif (UNIX)
target_link_libraries(
Ultraleap-Tracking-WS
PUBLIC
libUtils
Threads::Threads
${LIBWEBSOCKETS_LIBS})
endif()
add_custom_command(
TARGET Ultraleap-Tracking-WS
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy
${LEAPC_SHARED_LIB_PATH}
$<TARGET_FILE_DIR:Ultraleap-Tracking-WS>)