-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
CMakeLists.txt
1529 lines (1369 loc) · 48 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
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# AUTOGENERATED COPYRIGHT HEADER START
# Copyright (C) 2017-2023 Michael Fabian 'Xaymar' Dirks <[email protected]>
# Copyright (C) 2019 Cat Stevens <[email protected]>
# Copyright (C) 2020 Brandon Edens <[email protected]>
# Copyright (C) 2021 Christopher P Yarger <[email protected]>
# Copyright (C) 2022 Carsten Braun <[email protected]>
# Copyright (C) 2022 Romain Vigier <[email protected]>
# Copyright (C) 2023 Isaac Nudelman <[email protected]>
# AUTOGENERATED COPYRIGHT HEADER END
# ToDo:
# - Explore RESOURCE property: https://cmake.org/cmake/help/latest/prop_tgt/RESOURCE.html
# - Explore PUBLIC_HEADER property: https://cmake.org/cmake/help/latest/prop_tgt/PUBLIC_HEADER.html
# CMake Setup
cmake_minimum_required(VERSION 3.26)
list(APPEND CMAKE_MESSAGE_INDENT "[StreamFX] ")
project(StreamFX)
################################################################################
# Modules
################################################################################
# Search Paths
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/clang"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/version"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)
# Include required Modules
# - Stock
include("CheckIPOSupported")
# - Custom
include("util")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version/version.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/version/version.cmake")
else()
message(FATAL_ERROR "Please ensure you've cloned recursively and try again. Thank you!")
endif()
# Include optional Modules
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/clang/Clang.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/clang/Clang.cmake")
endif()
################################################################################
# Bootstrapping
################################################################################
# MacOSX: Require at least MacOSX 10.15 for C++17 support.
if(APPLE)
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.15)
CacheSet(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
endif()
endif()
# Check if this is standalone or bundled.
set(STANDALONE ON)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
set(GROUPED OFF)
set(PREFIX "")
else()
set(GROUPED ON)
set(PREFIX "StreamFX_")
if(GROUPED AND ((TARGET libobs) OR (TARGET OBS::libobs)))
set(STANDALONE OFF)
endif()
endif()
# Operating System
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(D_PLATFORM_OS "windows")
set(D_PLATFORM_WINDOWS 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(D_PLATFORM_OS "linux")
set(D_PLATFORM_LINUX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(D_PLATFORM_OS "macos")
set(D_PLATFORM_MAC 1)
else()
set(D_PLATFORM_OS "unknown")
set(D_PLATFORM_UNKNOWN 1)
message(WARNING "The operating system '${CMAKE_SYSTEM_NAME}' is unknown to to this script, continue at your own risk.")
endif()
# Architecture
set(ARCH_INSTR_32 "i386;i686;x86;arm;ARM")
set(ARCH_INSTR_64 "x86_64;AMD64;IA64;arm64;ARM64")
set(ARCH_INSTR_X86 "i386;i686;x86;x86_64;AMD64")
set(ARCH_INSTR_ARM "arm;ARM;arm64;ARM64")
set(ARCH_INSTR_ITANIUM "IA64")
set(ARCH_BITS 0)
set(ARCH_BITS_POINTER 0)
set(ARCH_INST "")
# - Bitness
list(FIND ARCH_INSTR_32 "${CMAKE_SYSTEM_PROCESSOR}" FOUND)
if(FOUND GREATER -1)
set(ARCH_BITS 32)
endif()
list(FIND ARCH_INSTR_64 "${CMAKE_SYSTEM_PROCESSOR}" FOUND)
if(FOUND GREATER -1)
set(ARCH_BITS 64)
endif()
set(D_PLATFORM_BITS ${ARCH_BITS})
# - Pointer Size (bits)
math(EXPR ARCH_BITS_POINTER "8*${CMAKE_SIZEOF_VOID_P}")
set(D_PLATFORM_BITS_PTR ${ARCH_BITS_POINTER})
# - Basic Instruction Set
list(FIND ARCH_INSTR_X86 "${CMAKE_SYSTEM_PROCESSOR}" FOUND)
if(FOUND GREATER -1)
list(APPEND ARCH_INST "x86")
set(D_PLATFORM_INSTR_X86 ON)
set(D_PLATFORM_ARCH_X86 ON)
endif()
list(FIND ARCH_INSTR_ARM "${CMAKE_SYSTEM_PROCESSOR}" FOUND)
if(FOUND GREATER -1)
list(APPEND ARCH_INST "ARM")
set(D_PLATFORM_INSTR_ARM ON)
set(D_PLATFORM_ARCH_ARM ON)
endif()
list(FIND ARCH_INSTR_ITANIUM "${CMAKE_SYSTEM_PROCESSOR}" FOUND)
if(FOUND GREATER -1)
list(APPEND ARCH_INST "Itanium")
set(D_PLATFORM_INSTR_ITANIUM ON)
set(D_PLATFORM_ARCH_ITANIUM ON)
endif()
# Interprocedural Optimization
check_ipo_supported(RESULT D_HAS_IPO)
set(D_PLATFORM_INSTR ${ARCH_INST})
set(D_PLATFORM_ARCH ${ARCH_INST})
message(STATUS "Target is ${D_PLATFORM_BITS}bit ${ARCH_INST} with a pointer size of ${D_PLATFORM_BITS_PTR}bit.")
################################################################################
# Versioning
################################################################################
version(GENERATE _VERSION COMPRESSED MAJOR 0 MINOR 0 PATCH 0 TWEAK 0 REQUIRE "PATCH;")
version(PARSE _VERSION "${_VERSION}" REQUIRE "PATCH;TWEAK")
# If possible, automatically generate versions from git.
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
find_program(GIT
NAMES
git
git.exe
)
if(EXISTS "${GIT}")
# Try and calculate the exist version using git.
execute_process(COMMAND "${GIT}" describe --tags --long --abbrev=8 HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL ""))
# Result will be MAJOR.MINOR.PATCH-TWEAK-gHASH
string(REPLACE "-" ";" GIT_OUTPUT "${GIT_OUTPUT}")
string(REPLACE "." ";" GIT_OUTPUT "${GIT_OUTPUT}")
# Split into components
list(GET GIT_OUTPUT 0 GIT_OUTPUT_MAJOR)
list(GET GIT_OUTPUT 1 GIT_OUTPUT_MINOR)
list(GET GIT_OUTPUT 2 GIT_OUTPUT_PATCH)
list(GET GIT_OUTPUT 3 GIT_OUTPUT_TWEAK)
list(GET GIT_OUTPUT 4 GIT_OUTPUT_BUILD)
# Special case: Tag contains prerelease
if(GIT_OUTPUT_PATCH MATCHES "([0-9]+)([a-zA-Z]+)([0-9]*)")
# Patch requires special parsing.
set(GIT_OUTPUT_PATCH "${CMAKE_MATCH_1}")
if(CMAKE_MATCH_3 GREATER 0)
set(GIT_OUTPUT_PRERELEASE "${CMAKE_MATCH_2}")
else()
set(GIT_OUTPUT_PRERELEASE "a")
endif()
MATH(EXPR GIT_OUTPUT_TWEAK "${GIT_OUTPUT_TWEAK} + ${CMAKE_MATCH_3}")
# Modify the global version
version(MODIFY _VERSION "${_VERSION}" COMPRESS
MAJOR "${GIT_OUTPUT_MAJOR}"
MINOR "${GIT_OUTPUT_MINOR}"
PATCH "${GIT_OUTPUT_PATCH}"
TWEAK "${GIT_OUTPUT_TWEAK}"
BUILD "${GIT_OUTPUT_BUILD}"
PRERELEASE "${GIT_OUTPUT_PRERELEASE}"
REQUIRE "PATCH;TWEAK"
)
else()
# Modify the global version
version(MODIFY _VERSION "${_VERSION}" COMPRESS
MAJOR "${GIT_OUTPUT_MAJOR}"
MINOR "${GIT_OUTPUT_MINOR}"
PATCH "${GIT_OUTPUT_PATCH}"
TWEAK "${GIT_OUTPUT_TWEAK}"
BUILD "${GIT_OUTPUT_BUILD}"
PRERELEASE "a"
REQUIRE "PATCH;TWEAK"
)
endif()
else()
execute_process(COMMAND "${GIT}" rev-list --count HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL ""))
version(MODIFY _VERSION "${_VERSION}" COMPRESS
TWEAK "${GIT_OUTPUT}"
PRERELEASE "a"
REQUIRE "PATCH;TWEAK"
)
# Determine the build using git.
execute_process(COMMAND "${GIT}" log -1 "--pretty=format:g%h" --abbrev=8 HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL ""))
version(MODIFY _VERSION "${_VERSION}" COMPRESS
BUILD "${GIT_OUTPUT}"
REQUIRE "PATCH;TWEAK"
)
else()
message(WARNING "Failed to detect build version with 'git'.")
endif()
else()
message(WARNING "Failed to automatically detect version with 'git'.")
endif()
endif()
else()
message(WARNING "'git' not found, automatic version detection disabled.")
endif()
else()
message(STATUS "Not a git repository, automatic version detection disabled.")
endif()
version(PARSE _VERSION "${_VERSION}" REQUIRE "PATCH;TWEAK")
# Allow manual overrides of the detected version.
if(NOT ("${${PREFIX}VERSION}" STREQUAL ""))
version(PARSE _VERSION_CFG "${${PREFIX}VERSION}" REQUIRE "PATCH;TWEAK")
if("${_VERSION_CFG_BUILD}" STREQUAL "")
set(_VERSION_CFG_BUILD "${_VERSION_BUILD}")
endif()
version(GENERATE _VERSION COMPRESS
MAJOR "${_VERSION_CFG_MAJOR}"
MINOR "${_VERSION_CFG_MINOR}"
PATCH "${_VERSION_CFG_PATCH}"
TWEAK "${_VERSION_CFG_TWEAK}"
PRERELEASE "${_VERSION_CFG_PRERELEASE}"
BUILD "${_VERSION_CFG_BUILD}"
)
endif()
set(_VERSION_THIN "${_VERSION_MAJOR}.${_VERSION_MINOR}.${_VERSION_PATCH}")
if(NOT (_VERSION_PRERELEASE STREQUAL ""))
set(_VERSION_THIN "${_VERSION_THIN}${_VERSION_PRERELEASE}${_VERSION_TWEAK}")
endif()
if(NOT (VERSION_COMMIT STREQUAL ""))
set(_VERSION_THIN "${_VERSION_THIN}-${_VERSION_BUILD}")
endif()
# Parse & Log the detected version.
message(STATUS "Version ${_VERSION_THIN}")
################################################################################
# Options
################################################################################
# Don't enable stability affecting features by default.
if(_VERSION_PRERELEASE STREQUAL "a")
set(FEATURE_DEPRECATED ON)
set(FEATURE_EXPERIMENTAL ON)
set(FEATURE_UNSTABLE ON)
set(FEATURE_STABLE ON)
elseif(_VERSION_PRERELEASE STREQUAL "b")
set(FEATURE_DEPRECATED ON)
set(FEATURE_EXPERIMENTAL OFF)
set(FEATURE_UNSTABLE ON)
set(FEATURE_STABLE ON)
elseif(_VERSION_PRERELEASE STREQUAL "c")
set(FEATURE_DEPRECATED ON)
set(FEATURE_EXPERIMENTAL OFF)
set(FEATURE_UNSTABLE OFF)
set(FEATURE_STABLE ON)
else()
set(FEATURE_DEPRECATED ON)
set(FEATURE_EXPERIMENTAL OFF)
set(FEATURE_UNSTABLE OFF)
set(FEATURE_STABLE ON)
endif()
# Version override
set(${PREFIX}VERSION "" CACHE STRING "Specify an override for the automatically detected version. Accepts a mixture of SemVer 2.0 and CMake Version.")
# Compile/Link Related
set(${PREFIX}ENABLE_FASTMATH ON CACHE BOOL "Enable fast math optimizations, which sacrifice precision and stability.")
if(D_PLATFORM_ARCH_X86)
set(${PREFIX}TARGET_X86_64_V4 OFF CACHE BOOL "Target x86-64-v4 (x86-64-v3, AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL).")
set(${PREFIX}TARGET_X86_64_V3 OFF CACHE BOOL "Target x86-64-v3 (x86-64-v2, AVX, AVX2, BMI1, BMI2, F16C, FMA, LZCNT, MOVBE, OSXSAVE).")
set(${PREFIX}TARGET_X86_64_V2_EX ON CACHE BOOL "Target extended x86-64-v2 (x86-64-v2, AVX, BMI1, BMI2, F16C, FMA, MOVBE).")
set(${PREFIX}TARGET_X86_64_V2 ON CACHE BOOL "Target x86-64-v2 (x86-64, CMPXCHG16B, LAHF-SAHF, POPCNT, SSE3, SSE4.1, SSE4.2, SSSE3).")
set(${PREFIX}TARGET_X86_64 ON CACHE BOOL "Target x86-64 (CMOV, CX8, FPU, FXSR, MMX, OSFXSR, SCE, SSE, SSE2).")
endif()
if(NOT MSVC)
set(${PREFIX}TARGET_NATIVE OFF CACHE BOOL "Target the native CPU architecture. Enable it for development or personal builds, but disable it for distribution.")
endif()
# Installation / Packaging
if(STANDALONE)
if(D_PLATFORM_LINUX)
set(STRUCTURE_PACKAGEMANAGER CACHE BOOL "Install for use in a Package Manager (system-wide installation)")
endif()
set(PACKAGE_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "Where to place the packages?")
set(PACKAGE_NAME "StreamFX" CACHE STRING "What should the package be called?")
set(PACKAGE_SUFFIX "" CACHE STRING "Any suffix for the package name? (Defaults to the current version string)")
endif()
# Dependencies
if(STANDALONE)
set(libobs_DIR "" CACHE PATH "Path to libobs and obs-frontend-api")
set(Qt_DIR "" CACHE PATH "Path to Qt6 or Qt5")
set(CURL_DIR "" CACHE PATH "Path to CURL")
set(FFmpeg_DIR "" CACHE PATH "Path to FFmpeg")
endif()
set(AOM_DIR "" CACHE PATH "Path to AOM library")
################################################################################
# Project
################################################################################
# Metadata
version(GENERATE PROJECT_VERSION
MAJOR "${_VERSION_MAJOR}"
MINOR "${_VERSION_MINOR}"
PATCH "${_VERSION_PATCH}"
TWEAK "${_VERSION_TWEAK}"
REQUIRE "PATCH;TWEAK"
)
project(
StreamFX
VERSION ${PROJECT_VERSION}
DESCRIPTION "Additional sources, filters, transitions and encoders for OBS Studio."
HOMEPAGE_URL "https://streamfx.xaymar.com/"
)
set(PROJECT_IDENTIFER "com.xaymar.StreamFX.obs")
set(PROJECT_TITLE "StreamFX (for OBS Studio)")
set(PROJECT_AUTHORS "Michael Fabian 'Xaymar' Dirks <[email protected]>")
set(PROJECT_COPYRIGHT "2017 - 2022, Michael Fabian Dirks. All Rights Reserved")
set(PROJECT_TRADEMARKS "")
list(APPEND PROJECT_TRADEMARKS
"AMD is a trademark of Advanced Micro Devices Inc."
"NVIDIA is a trademark of Nvidia Corporation"
)
# Component search paths
list(APPEND CMAKE_PREFIX_PATH
"${${PREFIX}AOM_PATH}"
"${${PREFIX}OBSDEPS_PATH}"
"${${PREFIX}QT_PATH}"
"${AOM_DIR}"
"${CURL_DIR}"
"${DepsPath}"
"${FFmpeg_DIR}"
"${libobs_DIR}"
"${Qt_DIR}"
"${Qt5_DIR}"
"${Qt6_DIR}"
"${QTDIR}"
)
if(D_PLATFORM_MAC)
list(APPEND CMAKE_PREFIX_PATH
"${${PREFIX}AOM_PATH}/Frameworks"
"${${PREFIX}OBSDEPS_PATH}/Frameworks"
"${${PREFIX}QT_PATH}/Frameworks"
"${AOM_DIR}/Frameworks"
"${CURL_DIR}/Frameworks"
"${DepsPath}/Frameworks"
"${FFmpeg_DIR}/Frameworks"
"${libobs_DIR}/Frameworks"
"${Qt_DIR}/Frameworks"
"${Qt5_DIR}/Frameworks"
"${Qt6_DIR}/Frameworks"
"${QTDIR}/Frameworks"
)
endif()
set_property(GLOBAL PROPERTY AUTOGEN_SOURCE_GROUP "User-Interface Files/Generated")
################################################################################
# Dependencies
################################################################################
#- OBS: Library
if(STANDALONE)
find_package("libobs" REQUIRED CONFIG)
elseif(NOT TARGET OBS::libobs)
# Add the missing OBS::libobs alias target if possible.
add_library(OBS::libobs ALIAS libobs)
endif()
if(D_PLATFORM_MAC)
# We may need to reconstruct the include directories on MacOS.
get_target_property(libobs_INTERFACE_INCLUDE_DIRECTORIES OBS::libobs INTERFACE_INCLUDE_DIRECTORIES)
if("${libobs_INTERFACE_INCLUDE_DIRECTORIES}" STREQUAL "libobs_INTERFACE_INCLUDE_DIRECTORIES-NOTFOUND")
get_target_property(libobs_IMPORTED_LOCATION_RELEASE OBS::libobs IMPORTED_LOCATION_RELEASE)
get_filename_component(libobs_IMPORTED_LOCATION_RELEASE "${libobs_IMPORTED_LOCATION_RELEASE}" DIRECTORY)
get_filename_component(libobs_IMPORTED_LOCATION_RELEASE "${libobs_IMPORTED_LOCATION_RELEASE}" DIRECTORY)
get_filename_component(libobs_IMPORTED_LOCATION_RELEASE "${libobs_IMPORTED_LOCATION_RELEASE}" DIRECTORY)
set(libobs_IMPORTED_LOCATION_RELEASE "${libobs_IMPORTED_LOCATION_RELEASE}/Headers")
set_target_properties(OBS::libobs PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
"${libobs_IMPORTED_LOCATION_RELEASE}"
)
endif()
endif()
#- OBS: Front-End API
if(STANDALONE)
find_package("obs-frontend-api" CONFIG)
set(obs-frontend-api_FOUND "${obs-frontend-api_FOUND}")
elseif(TARGET obs-frontend-api)
set(obs-frontend-api_FOUND ON)
endif()
if(NOT TARGET OBS::obs-frontend-api)
add_library(OBS::obs-frontend-api ALIAS obs-frontend-api)
endif()
#- CURL
find_package("CURL")
#- JSON
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/third-party/nlohmann-json/single_include")
message(FATAL_ERROR "Please make sure to update git submodules to their latest supported version.")
return()
else()
set(JSON_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/third-party/nlohmann-json/single_include")
endif()
#- Qt 6
find_package("Qt6"
COMPONENTS Core Gui Widgets
CONFIG
)
################################################################################
# Helpers
################################################################################
define_property(TARGET PROPERTY COMPONENT_LABEL)
define_property(TARGET PROPERTY COMPONENT_NAME)
define_property(TARGET PROPERTY COMPONENT_OPTION)
define_property(TARGET PROPERTY COMPONENT_RESOLVER)
define_property(TARGET PROPERTY COMPONENT_DEPENDS)
function(streamfx_add_library TARGET_NAME TARGET_TYPE)
add_library(${TARGET_NAME} ${TARGET_TYPE})
set_target_properties(${TARGET_NAME} PROPERTIES
# Always generate position independent code.
POSITION_INDEPENDENT_CODE ON
# Set C++ Standard and Extensions
C_STANDARD 17
C_STANDARD_REQUIRED ON
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
# Remove prefix from generated files.
PREFIX ""
IMPORT_PREFIX ""
)
if(D_PLATFORM_MAC)
set_target_properties(${TARGET_NAME} PROPERTIES
# @rpath in installed binaries
INSTALL_RPATH "@executable_path/../Frameworks/;@loader_path/../Frameworks/;@loader_path/../Resources/"
)
if(STANDALONE)
set_target_properties(${TARGET_NAME} PROPERTIES
# @rpath in built binaries
BUILD_WITH_INSTALL_RPATH ON
)
endif()
endif()
target_compile_definitions(${TARGET_NAME} PRIVATE
__STDC_WANT_LIB_EXT1__=1
)
if(D_PLATFORM_WINDOWS)
target_compile_definitions(${TARGET_NAME}
PUBLIC
# Microsoft Visual C++
_CRT_SECURE_NO_WARNINGS
_ENABLE_EXTENDED_ALIGNED_STORAGE
PUBLIC
# windows.h
# - Disable MIN/MAX macro as this breaks a lot of code.
NOMINMAX
# - Disable IN/OUT macro as this breaks a lot of code.
NOINOUT
)
endif()
# C/C++ Compiler Adjustments
if(D_PLATFORM_WINDOWS AND ((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")))
# MSVC/ClangCL
# - Dynamically link Microsoft C/C++ Redistributable.
target_compile_options(${TARGET_NAME} PRIVATE
$<$<CONFIG:>:/MD>
$<$<CONFIG:Debug>:/MDd>
$<$<CONFIG:Release>:/MD>
$<$<CONFIG:RelWithDebInfo>:/MD>
$<$<CONFIG:MinSizeRel>:/MD>
)
# - Treat Warnings as Errors
target_compile_options(${TARGET_NAME} PRIVATE "/Wall")
# - Explicitly disable treating all Warnings as Errors
target_compile_options(${TARGET_NAME} PRIVATE "/WX-")
# - Disable useless warnings
set(DISABLED_WARNINGS
# Don't warn about unused variables, parameters, labels, functions, or typedefs.
"4100"
"4101"
"4102"
"4505"
"4514"
"5245"
"5264"
# Don't warn about unreferenced variables or parameters which are assigned/initialized.
"4189"
# Don't warn about not-explicitly-handled enumeration identifiers
"4061"
# Ignore automatic padding warnings.
"4820"
# Ignore assignment/move/copy being implicit '= delete;'.
"4623"
"4625"
"4626"
"5026"
"5027"
# Relative include paths are fine.
"4464"
# Buggy warning: printf expects string literal
"4774"
# Buggy warning: subobject initialization should be wrapped in braces
"5246"
# Ignore undefined, unused or unreferenced pre-processor macros
"4688"
# Ignore non-inlined functions
"4710"
# Ignore Spectre mitigation insertions
"5045"
# Ignore inserted padding.
"4324"
# Ignore non-standard nameless struct/union.
"4201"
# Intended behavior: Replace undefined macros with 0
"4668"
)
foreach(WARN ${DISABLED_WARNINGS})
target_compile_options(${TARGET_NAME} PRIVATE "/wd${WARN}")
endforeach()
# - Require enabled instruction sets.
if(D_PLATFORM_ARCH_X86)
if(${PREFIX}TARGET_X86_64_V4)
target_compile_options(${TARGET_NAME} PRIVATE "/arch:AVX512")
elseif(${PREFIX}TARGET_X86_64_V3)
target_compile_options(${TARGET_NAME} PRIVATE "/arch:AVX2")
elseif(${PREFIX}TARGET_X86_64_V2_EX)
target_compile_options(${TARGET_NAME} PRIVATE "/arch:AVX")
elseif(${PREFIX}TARGET_X86_64_V2)
target_compile_options(${TARGET_NAME} PRIVATE "/d2archSSE42")
elseif(${PREFIX}TARGET_X86_64)
#target_compile_options(${TARGET_NAME} PRIVATE "/arch:SSE2")
endif()
endif()
# - Use fast unordered math if possible.
if(${PREFIX}ENABLE_FASTMATH)
target_compile_options(${TARGET_NAME} PRIVATE "/fp:fast")
else()
target_compile_options(${TARGET_NAME} PRIVATE "/fp:precise")
if(MSVC_VERSION GREATER 1930)
# Keep original behavior in VS2022 and up.
target_compile_options(${TARGET_NAME} PRIVATE "/fp:contract")
endif()
endif()
# - Disable incremental builds
target_compile_options(${TARGET_NAME} PRIVATE "/INCREMENTAL:NO")
# - Enable C++ exceptions with SEH exceptions.
target_compile_options(${TARGET_NAME} PRIVATE "/EHa")
# - Enable multi-processor compiling.
target_compile_options(${TARGET_NAME} PRIVATE "/MP")
# - Enable updated __cplusplus macro
target_compile_options(${TARGET_NAME} PRIVATE "/Zc:__cplusplus")
elseif(D_PLATFORM_LINUX AND ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")))
# GCC/Clang
# - Enable all warnings.
target_compile_options(${TARGET_NAME} PRIVATE "-Wall")
target_compile_options(${TARGET_NAME} PRIVATE "-Wextra")
# - Disable useless warnings
set(DISABLED_WARNINGS
# Don't warn about unused variables, parameters, labels, functions, or typedefs.
"unused-function"
"unused-label"
"unused-local-typedefs"
"unused-parameter"
"unused-result"
"unused-const-variable"
"unused-variable"
"unused-value"
# Don't warn about unreferenced variables or parameters which are assigned/initialized.
"unused-but-set-parameter"
"unused-but-set-variable"
# Don't warn about not-explicitly-handled enumeration identifiers
"switch"
# Ignore automatic padding warnings.
"padded"
# Ignore implicit '= delete;'.
# Ignore extra arguments for printf
"format-extra-args"
# Ignore undefined, unused or unreferenced pre-processor macros
"unused-macros"
)
foreach(WARN ${DISABLED_WARNINGS})
target_compile_options(${TARGET_NAME} PRIVATE "-Wno-${WARN}")
endforeach()
# - Require enabled instruction sets.
if(${PREFIX}TARGET_NATIVE)
target_compile_options(${TARGET_NAME} PRIVATE
"-march=native"
)
elseif(D_PLATFORM_ARCH_X86)
if(${PREFIX}TARGET_X86_64_V4)
target_compile_options(${TARGET_NAME} PRIVATE
"-march=x86-64-v4"
)
elseif(${PREFIX}TARGET_X86_64_V3)
target_compile_options(${TARGET_NAME} PRIVATE
"-march=x86-64-v3"
)
elseif(${PREFIX}TARGET_X86_64_V2_EX)
target_compile_options(${TARGET_NAME} PRIVATE
"-march=x86-64-v2"
"-mavx"
"-mbmi2"
"-mbmi"
"-mfma"
"-mf16c"
"-mmovbe"
"-mpclmul"
"-mpopcnt"
)
elseif(${PREFIX}TARGET_X86_64_V2)
target_compile_options(${TARGET_NAME} PRIVATE
"-march=x86-64-v2"
)
elseif(${PREFIX}TARGET_X86_64)
target_compile_options(${TARGET_NAME} PRIVATE
"-march=x86-64"
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${TARGET_NAME} PRIVATE
"-mtune=generic"
)
else()
target_compile_options(${TARGET_NAME} PRIVATE
"-mtune=x86-64"
)
endif()
endif()
# - Use fast unordered math if possible.
if(${PREFIX}ENABLE_FASTMATH)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${TARGET_NAME} PRIVATE
"-ffast-math"
)
else()
target_compile_options(${TARGET_NAME} PRIVATE
"-ffp-model=fast"
)
endif()
else()
target_compile_options(${TARGET_NAME} PRIVATE
"-ffp-model=precise"
)
endif()
# - Don't export by default, require attributes.
# add_compile_options("-fvisibility=hidden")
elseif(D_PLATFORM_MAC AND (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
# AppleClang
# - Enable most useful warnings.
target_compile_options(${TARGET_NAME} PRIVATE "-Wall")
target_compile_options(${TARGET_NAME} PRIVATE "-Wextra")
# - Disable useless warnings
set(DISABLED_WARNINGS
# Don't warn about unused variables, parameters, labels, functions, or typedefs.
"unused-function"
"unused-label"
"unused-local-typedefs"
"unused-parameter"
"unused-result"
"unused-const-variable"
"unused-variable"
"unused-value"
# Don't warn about unreferenced variables or parameters which are assigned/initialized.
"unused-but-set-parameter"
"unused-but-set-variable"
# Don't warn about not-explicitly-handled enumeration identifiers
"switch"
# Ignore automatic padding warnings.
"padded"
# Ignore implicit '= delete;'.
# Ignore extra arguments for printf
"format-extra-args"
# Ignore undefined, unused or unreferenced pre-processor macros
"unused-macros"
)
foreach(WARN ${DISABLED_WARNINGS})
target_compile_options(${TARGET_NAME} PRIVATE "-Wno-${WARN}")
endforeach()
# - Require enabled instruction sets.
if(${PREFIX}TARGET_NATIVE)
target_compile_options(${TARGET_NAME} PRIVATE
"-march=native"
)
message(WARNING "Targeting native architecture. Binaries will not be distributable to other systems!")
endif()
# - Use fast unordered math if possible.
# FIXME: Appears to not be supported.
# - Don't export by default, require attributes.
# add_compile_options("-fvisibility=hidden")
endif()
endfunction()
function(streamfx_sanitize_name TEXT _OUTPUT_NAME _OUTPUT_TARGET _OUTPUT_OPTION)
string(REGEX REPLACE "^[ \t]+" "" TEXT "${TEXT}")
string(REGEX REPLACE "[ \t]+$" "" TEXT "${TEXT}")
string(REGEX REPLACE "[^a-zA-Z0-9_-]+" "_" TEXT2 "${TEXT}")
string(REGEX REPLACE "_[_]+" "_" TEXT2 "${TEXT2}")
string(TOUPPER "${TEXT2}" TEXT3)
set(${_OUTPUT_NAME} "${TEXT}" PARENT_SCOPE)
set(${_OUTPUT_TARGET} "${TEXT2}" PARENT_SCOPE)
set(${_OUTPUT_OPTION} "${TEXT3}" PARENT_SCOPE)
endfunction()
function(streamfx_add_component COMPONENT_NAME)
cmake_parse_arguments(PARSE_ARGV 1 _ARG
""
"RESOLVER"
""
)
# Sanitize name for further use.
streamfx_sanitize_name("${COMPONENT_NAME}" COMPONENT_NAME COMPONENT_SANITIZED_NAME COMPONENT_OPTION_NAME)
set(COMPONENT_OPTION "${PREFIX}COMPONENT_${COMPONENT_OPTION_NAME}")
set(COMPONENT_OPTION "${COMPONENT_OPTION}" PARENT_SCOPE)
# Define the necessary targets.
set(COMPONENT_TARGET "StreamFX_${COMPONENT_SANITIZED_NAME}")
set(COMPONENT_TARGET "${COMPONENT_TARGET}" PARENT_SCOPE)
set(COMPONENT_ALIAS "StreamFX::${COMPONENT_SANITIZED_NAME}")
set(COMPONENT_ALIAS "${COMPONENT_ALIAS}" PARENT_SCOPE)
streamfx_add_library(${COMPONENT_TARGET} STATIC EXCLUDE_FROM_ALL)
add_library(${COMPONENT_ALIAS} ALIAS ${COMPONENT_TARGET})
set_target_properties(${COMPONENT_TARGET} PROPERTIES
COMPONENT_LABEL "${COMPONENT_NAME}"
COMPONENT_NAME "${COMPONENT_ALIAS}"
COMPONENT_OPTION "${COMPONENT_OPTION}"
)
# Always depend on StreamFX::Core
target_link_libraries(${COMPONENT_TARGET} PUBLIC $<LINK_LIBRARY:WHOLE_ARCHIVE,StreamFX_Core>)
# Register the component globally.
get_target_property(_DEPENDS StreamFX COMPONENT_DEPENDS)
if(_DEPENDS)
list(APPEND _DEPENDS "${COMPONENT_SANITIZED_NAME}")
else()
set(_DEPENDS "${COMPONENT_SANITIZED_NAME}")
endif()
set_target_properties(StreamFX PROPERTIES
COMPONENT_DEPENDS "${_DEPENDS}"
)
# If there is a resolver function, register it.
if(_ARG_RESOLVER)
set_target_properties(${COMPONENT_TARGET} PROPERTIES
COMPONENT_RESOLVER "${_ARG_RESOLVER}"
)
endif()
# Allow disabling this component.
set(${COMPONENT_OPTION} ON CACHE BOOL "Enable the ${COMPONENT_NAME} component?")
set(${COMPONENT_OPTION}_DISABLED OFF CACHE INTERNAL "Disable the ${_NAME} component?" FORCE)
# Add common include directories
target_include_directories(${COMPONENT_TARGET}
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/source"
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
# Add files in common places.
file(GLOB_RECURSE TEMPLATES FOLLOW_SYMLINKS CONFIGURE_DEPENDS "templates/*")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/templates" PREFIX "Templates" FILES ${TEMPLATES})
file(GLOB_RECURSE DATA FOLLOW_SYMLINKS CONFIGURE_DEPENDS "data/*")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/data" PREFIX "Data" FILES ${DATA})
file(GLOB_RECURSE SOURCE_PRIVATE FOLLOW_SYMLINKS CONFIGURE_DEPENDS "ui/*")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/ui" PREFIX "User-Interface Files" FILES ${USERINTERFACE})
file(GLOB_RECURSE SOURCE_PRIVATE FOLLOW_SYMLINKS CONFIGURE_DEPENDS "source/*")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/source" PREFIX "Private Files" FILES ${SOURCE_PRIVATE})
file(GLOB_RECURSE UI_PRIVATE FOLLOW_SYMLINKS CONFIGURE_DEPENDS "source/ui/*")
file(GLOB_RECURSE GENERATED_PRIVATE FOLLOW_SYMLINKS CONFIGURE_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/source/*")
source_group(TREE "${CMAKE_CURRENT_BINARY_DIR}/source" PREFIX "Private Files/Generated" FILES ${GENERATED_PRIVATE})
file(GLOB_RECURSE SOURCE_PUBLIC FOLLOW_SYMLINKS CONFIGURE_DEPENDS "include/*")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/include" PREFIX "Public Files" FILES ${SOURCE_PUBLIC})
file(GLOB_RECURSE UI_PUBLIC FOLLOW_SYMLINKS CONFIGURE_DEPENDS "include/ui/*")
file(GLOB_RECURSE GENERATED_PUBLIC FOLLOW_SYMLINKS CONFIGURE_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/*")
source_group(TREE "${CMAKE_CURRENT_BINARY_DIR}/include" PREFIX "Public Files/Generated" FILES ${GENERATED_PUBLIC})
target_sources(${COMPONENT_TARGET}
PRIVATE
${DATA}
${TEMPLATES}
${USERINTERFACE}
${SOURCE_PRIVATE}
${GENERATED_PRIVATE}
${SOURCE_PUBLIC}
${GENERATED_PUBLIC}
)
# Ignore data only files.
set_source_files_properties(
${DATA}
${TEMPLATES}
${USERINTERFACE}
PROPERTIES
HEADER_FILE_ONLY ON
)
# Enable Qt if needed
set_target_properties(${TARGET_NAME} PROPERTIES
AUTOUIC ON
AUTOUIC_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/ui"
AUTOMOC ON
AUTORCC ON
AUTOGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated"
)
set_source_files_properties(
${TEMPLATES}
${SOURCE_PRIVATE}
${GENERATED_PRIVATE}
${SOURCE_PUBLIC}
${GENERATED_PUBLIC}
PROPERTIES
SKIP_AUTOGEN ON
SKIP_AUTOMOC ON
SKIP_AUTORCC ON
SKIP_AUTOUIC ON
)
set_source_files_properties(
${UI_PRIVATE}
${UI_PUBLIC}
PROPERTIES
SKIP_AUTOGEN OFF
SKIP_AUTOMOC OFF
SKIP_AUTORCC OFF
SKIP_AUTOUIC OFF
)
endfunction()
function(streamfx_has_component _NAME _OUTPUT)
streamfx_sanitize_name("${_NAME}" _NAME _TARGET _OPTION)
set(${_OUTPUT} OFF PARENT_SCOPE)
if(TARGET "StreamFX_${_TARGET}")
set(${_OUTPUT} ON PARENT_SCOPE)
endif()
endfunction()
function(streamfx_enabled_component _NAME _OUTPUT)
streamfx_sanitize_name("${_NAME}" _NAME _TARGET _OPTION)
if(NOT TARGET "StreamFX_${_TARGET}")
message(FATAL_ERROR "Unknown component '${_NAME}'.")
endif()
get_target_property(_OPTION "StreamFX_${_TARGET}" COMPONENT_OPTION)
set(${_OUTPUT} OFF PARENT_SCOPE)
if(${_OPTION} AND NOT (${_OPTION}_DISABLED))
set(${_OUTPUT} ON PARENT_SCOPE)
endif()
endfunction()
# Use this to add a dependency on another component.
function(streamfx_add_component_dependency _NAME)
cmake_parse_arguments(PARSE_ARGV 1 _ARG
"OPTIONAL"
""
""
)
streamfx_sanitize_name("${_NAME}" _NAME _TARGET _OPTION)
set(DEPENDENCY "${_TARGET}")
if(_ARG_OPTIONAL)
list(APPEND DEPENDENCY "OPTIONAL")
endif()
string(REPLACE ";" "\\;" DEPENDENCY "${DEPENDENCY}")
get_target_property(DEPENDS "${COMPONENT_TARGET}" COMPONENT_DEPENDS)
if(DEPENDS)
list(APPEND DEPENDS "${DEPENDENCY}")
else()
set(DEPENDS "${DEPENDENCY}")
endif()
set_target_properties("${COMPONENT_TARGET}" PROPERTIES COMPONENT_DEPENDS "${DEPENDS}")
endfunction()
# Use this to disable a component via script.
function(streamfx_disable_component _NAME)
cmake_parse_arguments(PARSE_ARGV 1 _ARG
""
"REASON"
""
)
streamfx_sanitize_name("${_NAME}" _NAME _TARGET _OPTION)
if(NOT (_TARGET MATCHES "^StreamFX_"))
set(_TARGET "StreamFX_${_TARGET}")
endif()
# If the component doesn't exist, skip it.
if(NOT TARGET ${_TARGET})
message(WARNING "Not disabling invalid component '${_NAME}'.")
return()
endif()
get_target_property(_LABEL ${_TARGET} COMPONENT_LABEL)
get_target_property(_OPTION ${_TARGET} COMPONENT_OPTION)
CacheSet(${_OPTION}_DISABLED ON)
if(_ARG_REASON)
message(STATUS "[${_LABEL}] Disabled due to: ${_ARG_REASON}")
endif()
endfunction()
################################################################################
# Register Library
################################################################################
streamfx_add_library(StreamFX MODULE) # We are a module for libOBS.
# Ensure there is at least one file.
if(D_PLATFORM_WINDOWS)
target_sources(StreamFX
PRIVATE
"source/windll.cpp"
)
else()
target_sources(StreamFX
PRIVATE
"/dev/null"
)
endif()
# version.rc (can't be part of a static library)
if(D_PLATFORM_WINDOWS) # Windows-exclusive
# Version Resource
set(PROJECT_PRODUCT_NAME "${PROJECT_FULL_NAME}")
set(PROJECT_COMPANY_NAME "${PROJECT_AUTHORS}")
set(PROJECT_COPYRIGHT "${PROJECT_AUTHORS} © ${PROJECT_COPYRIGHT_YEARS}")