summaryrefslogtreecommitdiffhomepage
path: root/CMakeLists.txt
blob: e447c4b826127d33e9a77fafb021de6efa37e3a3 (plain)
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
project(opentrack)
cmake_minimum_required(VERSION 2.8.11)
cmake_policy(SET CMP0020 NEW)
if(POLICY CMP0058)
    cmake_policy(SET CMP0058 OLD)
endif()
if(POLICY CMP0028)
    cmake_policy(SET CMP0028 OLD)
endif()
if(POLICY CMP0042)
    cmake_policy(SET CMP0042 NEW)
endif()

include(CMakeParseArguments)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/)
include(GetGitRevisionDescription)
find_package(Git QUIET)
if(GIT_FOUND)
    git_describe(OPENTRACK_COMMIT --tags --always --dirty)
    git_describe(OPENTRACK_TAG_EXACT --tag --exact)
endif()

file(WRITE ${CMAKE_BINARY_DIR}/opentrack-version.h "#define OPENTRACK_VERSION \"${OPENTRACK_COMMIT}\"")

## start crapola

set(version-string "
#include \"opentrack-compat/export.hpp\"

#ifdef __cplusplus
extern \"C\"
#endif
OPENTRACK_EXPORT
const char* opentrack_version;

const char* opentrack_version = \"${OPENTRACK_COMMIT}\";
")

set(crapola-ver)
if(EXISTS ${CMAKE_BINARY_DIR}/version.cc)
    file(READ ${CMAKE_BINARY_DIR}/version.cc crapola-ver)
endif()

if(NOT (crapola-ver STREQUAL version-string))
    file(WRITE ${CMAKE_BINARY_DIR}/version.cc "${version-string}")
endif()

## end crapola

SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_SKIP_INSTALL_RPATH FALSE)
SET(CMAKE_SKIP_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

find_package(OpenCV 3.0)

find_package(Qt5 REQUIRED COMPONENTS Core Xml Network Widgets Gui QUIET)
find_package(Qt5 COMPONENTS SerialPort QUIET)
include_directories(SYSTEM ${Qt5Core_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Xml_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS})

if(MSVC)
    add_definitions(-DNOMINMAX -D_CRT_SECURE_NO_WARNINGS)
endif()

set(MY_QT_LIBS ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Xml_LIBRARIES})

# note, hatire supports both ftnoir and opentrack
# don't remove without being sure as hell -sh 20140922
add_definitions(-DOPENTRACK_API)

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
    set(CMAKE_COMPILER_IS_GNUCC TRUE)
    set(CMAKE_COMPILER_IS_GNUCXX TRUE)
endif()

if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE)
    if(MINGW)
        set(version-script mingw)
    else()
        set(version-script posix)
    endif()
endif()

if(APPLE)
    set(CMAKE_MACOSX_RPATH OFF)
    set(apple-frameworks "-stdlib=libc++ -framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon")
    set(CMAKE_SHARED_LINKER_FLAGS " ${apple-frameworks} ${CMAKE_SHARED_LINKER_FLAGS}")
    #set(CMAKE_STATIC_LINKER_FLAGS " ${apple-frameworks} ${CMAKE_STATIC_LINKER_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS " ${apple-frameworks} ${CMAKE_EXE_LINKER_FLAGS}")
    set(CMAKE_MODULE_LINKER_FLAGS " ${apple-frameworks} ${CMAKE_MODULE_LINKER_FLAGS}")
    set(CMAKE_CXX_FLAGS " -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR APPLE)
    set(CMAKE_CXX_FLAGS " -std=c++11 ${CMAKE_CXX_FLAGS} ")
endif()

set_property(GLOBAL PROPERTY USE_FOLDERS OFF)

macro(opentrack_module n dir)
    file(GLOB ${n}-c ${dir}/*.cpp ${dir}/*.c ${dir}/*.h ${dir}/*.hpp)
    file(GLOB ${n}-res ${dir}/*.rc)
    foreach(f ${n}-res)
        set_source_files_properties(${f} PROPERTIES LANGUAGE RC)
    endforeach()
    file(GLOB ${n}-ui ${dir}/*.ui)
    file(GLOB ${n}-rc ${dir}/*.qrc)
endmacro()

macro(opentrack_qt n)
    qt5_wrap_cpp(${n}-moc ${${n}-c} OPTIONS --no-notes)
    QT5_WRAP_UI(${n}-uih ${${n}-ui})
    QT5_ADD_RESOURCES(${n}-rcc ${${n}-rc})
    set(${n}-all ${${n}-c} ${${n}-rc} ${${n}-rcc} ${${n}-uih} ${${n}-moc} ${${n}-res})
endmacro()

set(msvc-subsystem "/VERSION:5.1 /SUBSYSTEM:WINDOWS,5.01")
function(opentrack_compat target)
    if(MSVC)
        set_target_properties(${target} PROPERTIES LINK_FLAGS "${msvc-subsystem} /DEBUG /OPT:ICF")
    endif()
endfunction()

macro(opentrack_library n dir)
    cmake_parse_arguments(foolib "" "LINK;COMPILE;GNU-LINK;GNU-COMPILE;STATIC" "" ${ARGN})
    if(NOT " ${foolib_UNPARSED_ARGUMENTS}" STREQUAL " ")
        message(FATAL_ERROR "opentrack_library bad formals")
    endif()
    opentrack_module(${n} ${dir})
    opentrack_qt(${n})
    set(link-mode SHARED)
    if (foolib_STATIC)
        set(link-mode STATIC)
    endif()
    add_library(${n} ${link-mode} ${${n}-all})
    target_link_libraries(${n} opentrack-api ${MY_QT_LIBS} opentrack-compat)
    if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE)
        SET_TARGET_PROPERTIES(${n} PROPERTIES
            LINK_FLAGS "${foolib_LINK} ${foolib_GNU-LINK} -Wl,--as-needed -Wl,--version-script=\"${CMAKE_SOURCE_DIR}/opentrack-compat/${version-script}-version-script.txt\""
            COMPILE_FLAGS "${foolib_COMPILE} ${foolib_GNU-COMPILE} -fvisibility=hidden -fvisibility-inlines-hidden"
        )
    else()
        set(link-flags)
        if(MSVC)
            set(link-flags "${msvc-subsystem} /DEBUG /OPT:ICF")
        endif()
        set_target_properties(${n} PROPERTIES LINK_FLAGS "${link-flags} ${foolib_LINK}" COMPILE_FLAGS "${foolib_COMPILE}")
    endif()
    if(NOT foolib_STATIC)
        install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .)
    endif()
    opentrack_compat(${n})
endmacro()

function(link_with_dinput8 n)
    if(WIN32)
        target_link_libraries(${n} dinput8 dxguid strmiids)
    endif()
endfunction()

# ----

# cache variables

# ----

IF(WIN32)
    SET(SDK_VJOY "" CACHE PATH "VJoy SDK path")
    SET(SDK_CONSOLE_DEBUG FALSE CACHE BOOL "Console window visible at runtime")
ENDIF()

IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    set(LINUX TRUE)
endif()

if(LINUX OR APPLE)
    set(SDK_XPLANE "" CACHE PATH "Path to X-Plane SDK")
    set(SDK_ENABLE_LIBEVDEV FALSE CACHE BOOL "libevdev virtual joystick protocol support")
endif()

SET(SDK_HYDRA "" CACHE PATH "libSixense path for Razer Hydra")
SET(SDK_HYDRA_AMD64 FALSE CACHE BOOL "whether libSixense is amd64 (else ia-32)")
SET(SDK_RIFT "" CACHE PATH "libOVR path for Oculus Rift")
SET(SDK_RIFT_025 "" CACHE PATH "libOVR 0.2.5 path for Oculus Rift")

set(SDK_ARUCO_LIBPATH "" CACHE FILEPATH "Aruco paper marker tracker static library path")

set(SDK_HT "" CACHE FILEPATH "Path to headtracker library")
set(SDK_HT_FLANDMARK "" CACHE FILEPATH "Path to flandmark library for headtracker")

if(WIN32)
    set(SDK_FSUIPC "" CACHE PATH "FSUIPC for older MS FSX path")
endif()

if(NOT WIN32)
    set(SDK_WINE_PREFIX "" CACHE PATH "Wine install prefix")
    set(SDK_WINE_NO_WRAPPER FALSE CACHE BOOL "disable Wine wrapper -- use Wine only for X-Plane")
endif()

# --- tarball

string(TIMESTAMP filename-date "%Y%m%d")
set(filename-ostype ${CMAKE_SYSTEM_NAME})
get_git_head_revision(filename-branch_0 filename-hash_0)
if(filename-hash_0)
    string(SUBSTRING "${filename-hash_0}" 0 7 filename-hash)
endif()
string(REPLACE "refs/heads/" "" filename-branch_1 "${filename-branch_0}")
string(REPLACE "/" "-" filename-branch "${filename-branch_1}")
set(filename_0 "${OPENTRACK_COMMIT}")
set(filename_1)
if (NOT OPENTRACK_TAG_EXACT STREQUAL OPENTRACK_COMMIT)
    string(TIMESTAMP filename_1 "-%Y%m%d%H%M%S")
endif()
set(filename "${CMAKE_BINARY_DIR}/${filename_0}${filename_1}.zip")

add_custom_target(tarball-real)
add_custom_target(tarball-real2)
add_custom_command(TARGET tarball-real COMMAND cmake -P ${CMAKE_SOURCE_DIR}/cmake/tarball.cmake)

add_custom_command(TARGET tarball-real2 COMMAND /usr/bin/env sh
    "${CMAKE_SOURCE_DIR}/make-tar.sh" "${CMAKE_INSTALL_PREFIX}"
    "${filename}" "${CMAKE_BINARY_DIR}")
add_custom_target(tarball DEPENDS tarball-real)

# -- end tarball

opentrack_module(opentrack-api opentrack)
opentrack_qt(opentrack-api)
add_library(opentrack-api STATIC ${opentrack-api-all})
opentrack_compat(opentrack-api)
target_link_libraries(opentrack-api ${MY_QT_LIBS})
if(NOT WIN32)
    target_link_libraries(opentrack-api dl)
else()
    target_link_libraries(opentrack-api winmm)
endif()

opentrack_module(opentrack-compat opentrack-compat)
add_library(opentrack-compat STATIC ${opentrack-compat-c})
opentrack_compat(opentrack-compat) # uh...
if(NOT WIN32 AND NOT APPLE)
    target_link_libraries(opentrack-compat rt)
endif()

# ----

# conditional targets

# ----

set(opentrack-perms PERMISSIONS WORLD_READ WORLD_EXECUTE OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)

if(WIN32)
  if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC)
    set(CMAKE_RC_COMPILER_INIT i686-w64-mingw32-windres)
    SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> --use-temp-file -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
  endif()
  ENABLE_LANGUAGE(RC)
endif(WIN32)

opentrack_module(opentrack-xplane-plugin x-plane-plugin)

if(SDK_XPLANE)
    # probably librt already included
    add_library(opentrack-xplane-plugin SHARED ${opentrack-xplane-plugin-c})
    target_include_directories(opentrack-xplane-plugin SYSTEM PUBLIC ${SDK_XPLANE}/CHeaders ${SDK_XPLANE}/CHeaders/XPLM)
    if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC AND NOT APPLE)
        SET_TARGET_PROPERTIES(opentrack-xplane-plugin
            PROPERTIES LINK_FLAGS
            "-Wl,--version-script=${CMAKE_SOURCE_DIR}/x-plane-plugin/version-script.txt -shared -rdynamic -nodefaultlibs -undefined_warning -fPIC"
            COMPILE_FLAGS "-Wall -O2 -pipe -fPIC -DLIN -DXPLM200 -DXPLM210"
            LIBRARY_OUTPUT_NAME "opentrack.xpl"
            PREFIX "" SUFFIX "")
    endif()
    if(APPLE)
        SET_TARGET_PROPERTIES(opentrack-xplane-plugin PROPERTIES
                              COMPILE_FLAGS "-iframework ${SDK_XPLANE}/Libraries/Mac/ -DAPL -DXPLM200 -DXPLM210 -framework XPLM -framework XPWidgets"
                              LINK_FLAGS "-F${SDK_XPLANE}/Libraries/Mac/ -framework XPLM -framework XPWidgets"
                              LIBRARY_OUTPUT_NAME "opentrack.xpl"
                              PREFIX "" SUFFIX "")
    endif()
    if(UNIX AND NOT APPLE)
        target_link_libraries(opentrack-xplane-plugin rt)
    endif()
endif()

opentrack_module(opentrack-csv csv)
add_library(opentrack-csv STATIC ${opentrack-csv-c})
opentrack_compat(opentrack-csv)
target_link_libraries(opentrack-csv ${MY_QT_LIBS})

opentrack_module(opentrack-pose-widget pose-widget)
opentrack_qt(opentrack-pose-widget)

add_library(opentrack-pose-widget STATIC ${opentrack-pose-widget-all})
opentrack_compat(opentrack-pose-widget)
target_include_directories(opentrack-pose-widget PUBLIC pose-widget/) # else Qt moc breaks
target_link_libraries(opentrack-pose-widget ${MY_QT_LIBS})

opentrack_module(opentrack-spline-widget qfunctionconfigurator)
opentrack_qt(opentrack-spline-widget)
add_library(opentrack-spline-widget STATIC ${opentrack-spline-widget-all})
opentrack_compat(opentrack-spline-widget)
target_include_directories(opentrack-spline-widget PUBLIC qfunctionconfigurator/)
target_link_libraries(opentrack-spline-widget ${MY_QT_LIBS})

add_library(opentrack-version STATIC ${CMAKE_BINARY_DIR}/version.cc)
opentrack_compat(opentrack-version)

opentrack_library(opentrack-filter-accela ftnoir_filter_accela)
target_link_libraries(opentrack-filter-accela opentrack-spline-widget)
opentrack_library(opentrack-filter-ewma ftnoir_filter_ewma2)

opentrack_library(opentrack-proto-fgfs ftnoir_protocol_fg)

if(SDK_VJOY)
    opentrack_library(opentrack-proto-vjoy ftnoir_protocol_vjoy GNU-LINK "-Wl,--enable-stdcall-fixup")
    if(MSVC)
        set(ext .lib)
    else()
        set(ext .dll)
    endif()
    target_link_libraries(opentrack-proto-vjoy ${MY_QT_LIBS} ${SDK_VJOY}/VJoy${ext})
    target_include_directories(opentrack-proto-vjoy SYSTEM PUBLIC ${SDK_VJOY})
endif()

if(SDK_ENABLE_LIBEVDEV)
    include(FindPkgConfig)
    opentrack_library(opentrack-proto-libevdev ftnoir_protocol_libevdev)
    pkg_check_modules(libevdev REQUIRED QUIET libevdev)
    target_link_libraries(opentrack-proto-libevdev ${libevdev_LIBRARIES})
    include_directories(opentrack-proto-libevdev SYSTEM PUBLIC ${libevdev_INCLUDE_DIRS})
endif()

if(SDK_FSUIPC)
    opentrack_library(opentrack-proto-fsuipc ftnoir_protocol_fsuipc)
    target_link_libraries(opentrack-proto-fsuipc ${SDK_FSUIPC}/FSUIPC_User.lib)
    target_include_directories(opentrack-proto-fsuipc SYSTEM PUBLIC ${SDK_FSUIPC})
    if(MSVC)
        set_target_properties(opentrack-proto-fsuipc PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBC.lib")
    endif()
    #target_link_directories(${SDK_FSUIPC})
endif()

if(WIN32)
    opentrack_library(opentrack-proto-simconnect ftnoir_protocol_sc)
endif()

if(WIN32)
    opentrack_library(opentrack-proto-freetrack ftnoir_protocol_ft)
    target_link_libraries(opentrack-proto-freetrack opentrack-csv opentrack-compat)
    opentrack_library(opentrack-proto-win32-mouse ftnoir_protocol_mouse)
endif()

opentrack_library(opentrack-proto-udp ftnoir_protocol_ftn)

if(WIN32)
    opentrack_library(opentrack-tracker-joystick ftnoir_tracker_joystick)
endif()

if(Qt5SerialPort_FOUND)
    opentrack_library(opentrack-tracker-hatire ftnoir_tracker_hatire)
    target_link_libraries(opentrack-tracker-hatire ${Qt5SerialPort_LIBRARIES})
    target_include_directories(opentrack-tracker-hatire SYSTEM PUBLIC ${Qt5SerialPort_INCLUDE_DIRS})
endif()

if(SDK_WINE_PREFIX)
    opentrack_library(opentrack-proto-wine ftnoir_protocol_wine)
    target_link_libraries(opentrack-proto-wine opentrack-compat opentrack-csv)
    if(NOT SDK_WINE_NO_WRAPPER)
        set(my-rt -lrt)
        if(APPLE)
            set(my-rt)
        endif()
        file(GLOB wine-deps ${CMAKE_SOURCE_DIR}/ftnoir_protocol_wine/*.cxx)
        add_custom_command(
          OUTPUT opentrack-wrapper-wine.exe.so
          DEPENDS ${wine-deps}
          COMMAND ${SDK_WINE_PREFIX}/bin/wineg++ -g -DNOMINMAX -O2 -m32 -std=c++11 -o
                  opentrack-wrapper-wine.exe -I "${CMAKE_SOURCE_DIR}"
                  ${wine-deps}
                  ${my-rt})
        add_custom_target(wine-wrapper ALL DEPENDS opentrack-wrapper-wine.exe.so)
        add_dependencies(opentrack-proto-wine wine-wrapper)
        add_dependencies(wine-wrapper opentrack-compat)
    endif()
endif()

opentrack_library(opentrack-tracker-udp ftnoir_tracker_udp)
opentrack_library(opentrack-tracker-freepie-udp ftnoir_tracker_freepie-udp)

if(WIN32)
	opentrack_library(opentrack-tracker-rs ftnoir_tracker_rs)
endif()

if(OpenCV_FOUND)
    opentrack_library(opentrack-tracker-pt ftnoir_tracker_pt)
    target_link_libraries(opentrack-tracker-pt ${OpenCV_LIBS})
    target_include_directories(opentrack-tracker-pt SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS})
    link_with_dinput8(opentrack-tracker-pt)

    if(SDK_ARUCO_LIBPATH)
        opentrack_library(opentrack-tracker-aruco ftnoir_tracker_aruco)
        target_link_libraries(opentrack-tracker-aruco ${SDK_ARUCO_LIBPATH} ${OpenCV_LIBS})
        target_include_directories(opentrack-tracker-aruco SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS})
        link_with_dinput8(opentrack-tracker-aruco)
    endif()

    opentrack_library(opentrack-filter-kalman ftnoir_filter_kalman)
    target_link_libraries(opentrack-filter-kalman ${OpenCV_LIBS})
    target_include_directories(opentrack-filter-kalman SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS})

    if(SDK_HT AND SDK_HT_FLANDMARK)
        opentrack_library(opentrack-tracker-ht ftnoir_tracker_ht)
        target_link_libraries(opentrack-tracker-ht ${SDK_HT} ${SDK_HT_FLANDMARK} ${OpenCV_LIBS})
        link_with_dinput8(opentrack-tracker-ht)
        target_include_directories(opentrack-tracker-ht SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS})
    endif()
endif()

link_with_dinput8(opentrack-tracker-joystick)

if(SDK_RIFT_025)
    set(link-flags)
    set(c-flags)
    if(APPLE)
        set(link-flags "-framework CoreFoundation -framework CoreGraphics -framework IOKit -framework Quartz")
        set(c-flags "-fno-strict-aliasing")
    else()
    if(NOT MSVC)
            set(c-flags "-fno-strict-aliasing")
    endif()
    endif()
    opentrack_library(opentrack-tracker-rift-025 ftnoir_tracker_rift_025 LINK ${link-flags} COMPILE ${c-flags})
    target_include_directories(opentrack-tracker-rift-025 SYSTEM PUBLIC ${SDK_RIFT_025}/Include ${SDK_RIFT_025}/Src)
    if(WIN32)
        if(MSVC)
            set(ext lib)
            set(p)
        else()
            set(ext a)
            set(p lib)
        endif()
        target_link_libraries(opentrack-tracker-rift-025 ${SDK_RIFT_025}/${p}LibOVR.${ext} winmm setupapi ws2_32 imagehlp wbemuuid)
    else()
        if(NOT APPLE)
                target_link_libraries(opentrack-tracker-rift-025 ${SDK_RIFT_025}/libLibOVR.a udev Xinerama)
        else()
                target_link_libraries(opentrack-tracker-rift-025 ${SDK_RIFT_025}/libLibOVR.a)
        endif()
    endif()
endif()

if(SDK_RIFT)
    set(link-flags)
    set(c-flags)
    if(APPLE)
        set(link-flags "-framework CoreFoundation -framework CoreGraphics -framework IOKit -framework Quartz")
        set(c-flags "-fno-strict-aliasing")
    else()
    if(NOT MSVC)
            set(c-flags "-fno-strict-aliasing")
    endif()
    endif()
    opentrack_library(opentrack-tracker-rift ftnoir_tracker_rift LINK ${link-flags} COMPILE ${c-flags})
    target_include_directories(opentrack-tracker-rift SYSTEM PUBLIC ${SDK_RIFT}/Include ${SDK_RIFT}/Src)
    if(WIN32)
        if(MSVC)
            set(ext lib)
            set(p)
        else()
            set(ext a)
            set(p lib)
        endif()
        target_link_libraries(opentrack-tracker-rift ${SDK_RIFT}/${p}LibOVR.${ext} winmm setupapi ws2_32 imagehlp wbemuuid)
    else()
        if(NOT APPLE)
                target_link_libraries(opentrack-tracker-rift ${SDK_RIFT}/libLibOVR.a udev Xinerama)
        else()
                target_link_libraries(opentrack-tracker-rift ${SDK_RIFT}/libLibOVR.a)
        endif()
    endif()
endif()

if(SDK_HYDRA)
    opentrack_library(opentrack-tracker-hydra ftnoir_tracker_hydra)
    target_include_directories(opentrack-tracker-hydra SYSTEM PUBLIC ${SDK_HYDRA}/include ${SDK_HYDRA}/include/sixense_utils)
    if(WIN32)
        if(MSVC)
            set(dir lib)
            set(ext lib)
        else()
            set(dir bin)
            set(ext dll)
        endif()
        target_link_libraries(opentrack-tracker-hydra
                              "${SDK_HYDRA}/${dir}/win32/release_dll/sixense.${ext}"
                              #"${SDK_HYDRA}/${dir}/win32/release_dll/sixense_utils.${ext}"
                             )
                    install(FILES "${SDK_HYDRA}/bin/win32/release_dll/sixense.dll"
                                  #"${SDK_HYDRA}/bin/win32/release_dll/sixense_utils.dll"
                            DESTINATION . ${opentrack-perms})
            else()
                    if(SDK_HYDRA_AMD64)
                            set(underscore-sixtyfour _x64)
                    else()
                            set(underscore-sixtyfour)
                    endif()
                    if(APPLE)
                            set(underscore-dll _dll)
                            set(soext dylib)
                            set(sixense-plat osx)
                    else()
                            set(underscore-dll)
                            set(soext so)
                            set(sixense-plat linux)
                    endif()
                    install(FILES
                            "${SDK_HYDRA}/lib/${sixense-plat}${underscore-sixtyfour}/release${underscore-dll}/libsixense${underscore-sixtyfour}.${soext}"
                            #"${SDK_HYDRA}/lib/${sixense-plat}${underscore-sixtyfour}/release${underscore-dll}/libsixense_utils${underscore-sixtyfour}.${soext}"
                            DESTINATION .
                    )
                    target_link_libraries(opentrack-tracker-hydra
                                          "${SDK_HYDRA}/lib/${sixense-plat}${underscore-sixtyfour}/release${underscore-dll}/libsixense${underscore-sixtyfour}.${soext}"
                                          #"${SDK_HYDRA}/lib/${sixense-plat}${underscore-sixtyfour}/release${underscore-dll}/libsixense_utils${underscore-sixtyfour}.${soext}"
                                         )
    endif()
endif()

if(UNIX OR APPLE)
    # Qxt bundled :: sorry for this, but gentoo ebuild is broken
    include_directories("qxt-mini/")
    if(APPLE)
        set(qxt-plat mac)
    else()
        set(qxt-plat x11)
    endif()
    file(GLOB qxt-mini-c qxt-mini/*.h qxt-mini/qxtglobalshortcut.cpp qxt-mini/plat/qxtglobalshortcut_${qxt-plat}.cpp)
    opentrack_qt(qxt-mini)
    add_library(opentrack-qxt-mini STATIC ${qxt-mini-all})
    target_link_libraries(opentrack-qxt-mini ${MY_QT_LIBS})
    if(NOT APPLE)
            target_link_libraries(opentrack-qxt-mini X11)
    endif()
endif()

if(WIN32 AND NOT SDK_CONSOLE_DEBUG)
    set(opentrack-win32-executable WIN32)
else()
    set(opentrack-win32-executable "")
endif()

opentrack_module(opentrack facetracknoir)
if(UNIX OR APPLE)
    list(APPEND opentrack-c qxt-mini/qxtglobalshortcut.h)
endif()
opentrack_qt(opentrack)
add_executable(opentrack ${opentrack-win32-executable} ${opentrack-all})
opentrack_compat(opentrack)
if(NOT WIN32)
    set_target_properties(opentrack PROPERTIES SUFFIX ".bin")
endif()
target_link_libraries(opentrack opentrack-api opentrack-version opentrack-pose-widget opentrack-spline-widget)

if(APPLE)
    SET_TARGET_PROPERTIES(opentrack-qxt-mini PROPERTIES LINK_FLAGS "-framework Carbon -framework CoreFoundation")
endif()

if(UNIX OR APPLE)
    target_link_libraries(opentrack opentrack-qxt-mini)
endif()

link_with_dinput8(opentrack)
target_link_libraries(opentrack ${MY_QT_LIBS})

if(APPLE)
    # for process detector
    target_link_libraries(opentrack proc)
endif()

if(LINUX)
    # for process detector
    target_link_libraries(opentrack procps)
endif()

# ----

# make install

# ----

install(FILES ${CMAKE_SOURCE_DIR}/README.md DESTINATION .)

if(SDK_XPLANE)
    install(TARGETS opentrack-xplane-plugin RUNTIME DESTINATION . LIBRARY DESTINATION .  )
endif()

install(DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty-notices DESTINATION .)

install(FILES "${CMAKE_SOURCE_DIR}/bin/freetrackclient.dll" DESTINATION . ${opentrack-perms})
install(FILES "${CMAKE_SOURCE_DIR}/bin/NPClient.dll" "${CMAKE_SOURCE_DIR}/bin/NPClient64.dll" "${CMAKE_SOURCE_DIR}/bin/TrackIR.exe" DESTINATION .
    ${opentrack-perms})
install(DIRECTORY "${CMAKE_SOURCE_DIR}/bin/settings" "${CMAKE_SOURCE_DIR}/contrib" DESTINATION .)

if(NOT WIN32 AND SDK_WINE_PREFIX AND NOT SDK_WINE_NO_WRAPPER)
    install(FILES "${CMAKE_BINARY_DIR}/opentrack-wrapper-wine.exe.so"
            DESTINATION .)
endif()

install(TARGETS opentrack DESTINATION .)

if(SDK_VJOY)
    install(FILES "${SDK_VJOY}/VJoy.dll" DESTINATION . ${opentrack-perms})
endif()

if(WIN32)
    install(FILES "${CMAKE_SOURCE_DIR}/bin/cleye.config" DESTINATION .)
endif()

if(WIN32)
    install(FILES "${CMAKE_SOURCE_DIR}/ftnoir_tracker_rs/rs_impl/bin/opentrack-tracker-rs-impl.exe" DESTINATION . ${opentrack-perms})
    install(FILES
        "${CMAKE_SOURCE_DIR}/ftnoir_tracker_rs/redist/intel_rs_sdk_runtime_websetup_6.0.21.6598.exe" DESTINATION ./contrib/ ${opentrack-perms})
endif()

if(APPLE)
    install(CODE "
    execute_process(COMMAND /bin/sh \"${CMAKE_SOURCE_DIR}/macosx/make-app-bundle.sh\"
                                    \"${CMAKE_SOURCE_DIR}/macosx\"
                                    \"${CMAKE_INSTALL_PREFIX}\"
                                    \"${CMAKE_BINARY_DIR}\"
                                    \"${OPENTRACK_COMMIT}\")
    ")
endif()