forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
4784 lines (4515 loc) · 153 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
cmake_minimum_required(VERSION 3.21)
# lint_cmake: -readability/wonkycase
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
# CMAKE_CXX_COMPILER_ID: Distinguish between "AppleClang" and "Clang"
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()
# MACOSX_RPATH is set by default
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
# Support new IN_LIST if() operator
if(POLICY CMP0057)
cmake_policy(SET CMP0057 NEW)
endif()
# Enforce interprocedural optimization
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()
# Let AUTOMOC and AUTOUIC process GENERATED files
if(POLICY CMP0071)
cmake_policy(SET CMP0071 NEW)
endif()
# Propagate interface link properties
if(POLICY CMP0099)
# This avoids a warning when qt deals with different behaviours controlled by this policy
# in its cmake functions. See
# https://github.com/qt/qtbase/commit/e3e1007f9778d8fc629a06f7d3d216bb7f81351b
cmake_policy(SET CMP0099 NEW)
endif()
# An imported target missing its location property fails during generation.
if(POLICY CMP0111)
cmake_policy(SET CMP0111 NEW)
endif()
# Set the timestamp of extracted files to the time of the extraction instead of
# the archived timestamp to make sure that dependent files are rebuilt if the
# URL changes.
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
# Use this function to throw an error because the build environment is not set
# up correctly.
function(fatal_error_missing_env)
if(WIN32)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
message(
FATAL_ERROR
"Did you download the Mixxx build environment using `${CMAKE_SOURCE_DIR}/tools/windows_buildenv.bat`?"
)
else()
message(
FATAL_ERROR
"Did you download the Mixxx build environment using `${CMAKE_SOURCE_DIR}/tools/windows_release_buildenv.bat` or `${CMAKE_SOURCE_DIR}/tools/windows_buildenv.bat`(includes Debug)?"
)
endif()
elseif(APPLE AND NOT IOS)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
message(
FATAL_ERROR
"Did you download the Mixxx build environment using `${CMAKE_SOURCE_DIR}/tools/macos_buildenv.sh`"
)
else()
message(
FATAL_ERROR
"Did you download the Mixxx build environment using `${CMAKE_SOURCE_DIR}/tools/macos_release_buildenv.sh` or `${CMAKE_SOURCE_DIR}/tools/macos_buildenv.sh`(includes Debug)?"
)
endif()
elseif(LINUX)
message(
FATAL_ERROR
"Did you install the Debian dev packages via `${CMAKE_SOURCE_DIR}/tools/debian_buildenv.sh` or the equivalent packages using your package manager?"
)
elseif(DEFINED VCPKG_TARGET_TRIPLET)
message(
FATAL_ERROR
"You are targeting ${VCPKG_TARGET_TRIPLET}, which does not have a prebuilt environment. Please make sure that -DMIXXX_VCPKG_ROOT points to a vcpkg environment containing installed dependencies for ${VCPKG_TARGET_TRIPLET}!"
)
else()
message(
FATAL_ERROR
"You are building for an unknown platform and are missing a build environment. Please set -DVCPKG_TARGET_TRIPLET and make sure that -DMIXXX_VCPKG_ROOT points to a vcpkg environment containing installed dependencies for your target platform!"
)
endif()
endfunction()
# We use here ENV{MIXXX_VCPKG_ROOT} as a workaround to find the overlay folders
# in manifest mode https://github.com/microsoft/vcpkg/issues/12289.
# Note: VCPKG_ROOT, the default location for the vcpkg cli tool is later
# adjusted by CMAKE_TOOLCHAIN_FILE.
if(DEFINED ENV{MIXXX_VCPKG_ROOT} AND NOT DEFINED MIXXX_VCPKG_ROOT)
set(MIXXX_VCPKG_ROOT "$ENV{MIXXX_VCPKG_ROOT}")
endif()
if(DEFINED MIXXX_VCPKG_ROOT)
if(
EXISTS "$ENV{MIXXX_VCPKG_ROOT}/overlay/ports"
OR NOT EXISTS "$ENV{MIXXX_VCPKG_ROOT}/ports"
)
# MIXXX_VCPKG_ROOT points to our vcpkg environment
# and we configure the CMAKE_TOOLCHAIN_FILE and overlays accordingly
message(STATUS "Using MIXXX_VCPKG_ROOT: $ENV{MIXXX_VCPKG_ROOT}")
else()
message(
STATUS
"MIXXX_VCPKG_ROOT not correct (missing $ENV{MIXXX_VCPKG_ROOT}/overlay/ports)"
)
fatal_error_missing_env()
endif()
if(NOT DEFINED VCPKG_OVERLAY_PORTS)
# required for manifest mode
set(VCPKG_OVERLAY_PORTS "${MIXXX_VCPKG_ROOT}/overlay/ports")
if(APPLE)
list(APPEND VCPKG_OVERLAY_PORTS "${MIXXX_VCPKG_ROOT}/overlay/osx")
elseif(WIN32)
list(APPEND VCPKG_OVERLAY_PORTS "${MIXXX_VCPKG_ROOT}/overlay/windows")
endif()
endif()
if(NOT DEFINED VCPKG_OVERLAY_TRIPLETS)
# required for manifest mode
set(VCPKG_OVERLAY_TRIPLETS "${MIXXX_VCPKG_ROOT}/overlay/triplets")
endif()
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(
CMAKE_TOOLCHAIN_FILE
"${MIXXX_VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING
""
)
endif()
endif()
if(NOT DEFINED VCPKG_TARGET_TRIPLET)
if(DEFINED ENV{VCPKG_TARGET_TRIPLET})
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_TARGET_TRIPLET}")
elseif(DEFINED ENV{VCPKG_DEFAULT_TRIPLET})
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}")
endif()
endif()
set(
X_VCPKG_APPLOCAL_DEPS_INSTALL
ON
CACHE BOOL
"Automatically copy dependencies into the install target directory for executables."
FORCE
)
# Set a default build type if none was specified
# See https://blog.kitware.com/cmake-and-the-default-build-type/ for details.
set(default_build_type "RelWithDebInfo")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND NOT WIN32)
# On Windows, Debug builds are linked to unoptimized libs
# generating unusable slow Mixxx builds.
set(default_build_type "Debug")
endif()
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
message(
STATUS
"Setting CMAKE_BUILD_TYPE to '${default_build_type}' as none was specified."
)
set(
CMAKE_BUILD_TYPE
"${default_build_type}"
CACHE STRING
"Choose the type of build."
FORCE
)
# Set the possible values of build type for cmake-gui
set_property(
CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo"
)
elseif(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo)$")
message(
FATAL_ERROR
"CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} is not supported, use one of Debug, Release or RelWithDebInfo."
)
endif()
endif()
include(CMakeDependentOption)
option(QT6 "Build with Qt6" ON)
cmake_dependent_option(
QML
"Build with QML"
ON
"QT6"
OFF
)
option(QOPENGL "Use QOpenGLWindow based widget instead of QGLWidget" ON)
if(QOPENGL)
add_compile_definitions(MIXXX_USE_QOPENGL)
endif()
if(QML)
add_compile_definitions(MIXXX_USE_QML)
endif()
if(VCPKG_TARGET_TRIPLET MATCHES "^wasm(32|64)-emscripten")
message(STATUS "Targeting Emscripten (${VCPKG_TARGET_TRIPLET})")
if(DEFINED ENV{EMSDK})
message(STATUS "Found EMSDK at $ENV{EMSDK}")
else()
message(
FATAL_ERROR
"Please make sure emsdk is installed and the environment variable EMSDK is set (see https://emscripten.org/docs/getting_started/downloads.html)"
)
endif()
if(NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
set(
VCPKG_CHAINLOAD_TOOLCHAIN_FILE
"$ENV{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
CACHE STRING
""
)
endif()
# Enabling this causes Qt's FindWrapRt C++ compile check to fail as it tries
# to run `clang-scan-deps` (because we set the C++ standard to 20). Emscripten
# does not ship this binary yet, though. Potentially relevant upstream bug:
# https://github.com/emscripten-core/emscripten/issues/21042
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
elseif(APPLE)
# Check if xcode-select is installed
execute_process(
COMMAND xcode-select -v
RESULT_VARIABLE XCODE_SELECT_RESULT
OUTPUT_QUIET
)
if(XCODE_SELECT_RESULT)
# xcode-select command failed, meaning it is not installed or not configured properly
message(
FATAL_ERROR
"'xcode-select -v' failed with '${XCODE_SELECT_RESULT}'. You may need to install Xcode and run 'sudo xcode-select --install'."
)
endif()
if(VCPKG_TARGET_TRIPLET MATCHES "^[a-zA-Z0-9]+-osx")
message(STATUS "Targeting macOS (${VCPKG_TARGET_TRIPLET})")
set(CMAKE_SYSTEM_NAME Darwin CACHE STRING "Target macOS")
if(VCPKG_TARGET_TRIPLET MATCHES "^arm64-")
# Minimum macOS version for arm64 Support
set(
CMAKE_OSX_DEPLOYMENT_TARGET
11.0
CACHE STRING
"Minimum macOS version the build will be able to run on"
)
set(CMAKE_OSX_ARCHITECTURES arm64 CACHE STRING "The target architecture")
set(
CMAKE_SYSTEM_PROCESSOR
arm64
CACHE STRING
"The target system processor"
)
else()
if(QT6)
# Minimum macOS version supported by Qt 6
set(
CMAKE_OSX_DEPLOYMENT_TARGET
10.15
CACHE STRING
"Minimum macOS version the build will be able to run on"
)
else()
# Minimum macOS version supported by Qt 5.12
set(
CMAKE_OSX_DEPLOYMENT_TARGET
10.12
CACHE STRING
"Minimum macOS version the build will be able to run on"
)
# Needed for deployment target < 10.14
add_compile_options(-fno-aligned-allocation)
endif()
endif()
elseif(VCPKG_TARGET_TRIPLET MATCHES "^[a-zA-Z0-9]+-ios")
message(STATUS "Targeting iOS (${VCPKG_TARGET_TRIPLET})")
set(CMAKE_SYSTEM_NAME iOS CACHE STRING "Target iOS")
set(
CMAKE_OSX_DEPLOYMENT_TARGET
14.0
CACHE STRING
"Minimum iOS version to target"
)
else()
message(
WARNING
"Targeting an Apple platform, but VCPKG_TARGET_TRIPLET is not set. This is not a supported scenario!"
)
endif()
endif()
project(mixxx VERSION 2.6.0)
enable_language(C CXX)
# Work around missing version suffixes support https://gitlab.kitware.com/cmake/cmake/-/issues/16716
set(MIXXX_VERSION_PRERELEASE "alpha") # set to "alpha" "beta" or ""
set(CMAKE_PROJECT_HOMEPAGE_URL "https://www.mixxx.org")
set(
CMAKE_PROJECT_DESCRIPTION
"Mixxx is Free DJ software that gives you everything you need to perform live mixes."
)
# Used for force control of color output
set(BUILD_COLORS "auto" CACHE STRING "Try to use colors auto/always/no")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(CheckSymbolExists)
include(CheckIncludeFileCXX)
include(ExternalProject)
include(GNUInstallDirs)
include(DefaultOption)
include(IsStaticLibrary)
# Verify VCPKG settings
if(DEFINED _VCPKG_INSTALLED_DIR)
if(NOT EXISTS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}")
# Fail early if this part of CMAKE_PREFIX_PATH does not exist
# else the library lookups below will fail with misleading error messages
message(
STATUS
"VCPKG_TARGET_TRIPLET dir not found: ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET} "
"Make sure the VCPKG build environment is installed and contains the build for the selected triplet."
)
fatal_error_missing_env()
else()
message(STATUS "Using VCPKG_TARGET_TRIPLET: ${VCPKG_TARGET_TRIPLET}")
endif()
endif()
#######################################################################
# Compilers and toolchains
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# GNU is GNU GCC
set(GNU_GCC true)
else()
set(GNU_GCC false)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
set(LLVM_CLANG false)
set(MSVC true)
else()
# using regular Clang or AppleClang
set(LLVM_CLANG true)
endif()
else()
set(LLVM_CLANG false)
endif()
# CMake implicitly sets the variable MSVC to true for Microsoft
# Visual C++ or another compiler simulating Visual C++.
# https://cmake.org/cmake/help/latest/variable/MSVC.html
#######################################################################
set(CMAKE_CXX_STANDARD 20)
if(MSVC)
# Ensure MSVC populates __cplusplus correctly.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
# Remove unreferenced code and data
# Since c++11 they can safely be removed to speed up linking.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:inline")
endif()
# Speed up builds on HDDs and prevent wearing of SDDs
#
# This is only applies to gcc/clang, therefore this option is forcibly set to
# ON on all other compilers.
cmake_dependent_option(
BUILD_LOW_MEMORY
"Store temporary build files on disk by disabling the build option -pipe"
OFF
"GNU_GCC OR LLVM_CLANG"
ON
)
if(NOT BUILD_LOW_MEMORY)
add_compile_options(-pipe)
endif()
# Coverage
#
# This is only available with GCC, therefore this option is forcibly set to OFF
# for all other compilers.
cmake_dependent_option(
COVERAGE
"Coverage (i.e. gcov) support"
OFF
"GNU_GCC"
OFF
)
if(COVERAGE)
add_compile_options(--coverage -fprofile-arcs -ftest-coverage)
add_link_options(--coverage -fprofile-arcs -ftest-coverage)
endif()
# Profiling
#
# This is only available on Linux, therefore this option is forcibly set to OFF
# on all other platforms.
cmake_dependent_option(
PROFILING
"Profiling (e.g. gprof) support"
OFF
"UNIX;NOT APPLE"
OFF
)
if(PROFILING)
add_compile_options(-pg)
add_link_options(-pg)
endif()
#
# Optimizations
#
set(
OPTIMIZE
"portable"
CACHE STRING
"Optimization and Tuning (set to off, portable, native, legacy)"
)
set_property(
CACHE OPTIMIZE
PROPERTY STRINGS "off" "portable" "native" "legacy"
)
string(TOLOWER "${OPTIMIZE}" OPTIMIZE)
message(STATUS "Optimization level: ${OPTIMIZE}")
# CMAKE_INTERPROCEDURAL_OPTIMIZATION can be defined to override the default behaviour.
# We keep CMAKE_INTERPROCEDURAL_OPTIMIZATION unset (IPO disabled) to save
# build time at the cost of a bigger memory footprint at run-time.
# See https://github.com/mixxxdj/mixxx/pull/3589 for some test results
# Note: IPO has caused issues on Fedora https://bugzilla.rpmfusion.org/show_bug.cgi?id=5829
# Uncomment the following code to enable IPO for Release builds
#if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT OPTIMIZE STREQUAL "off")
# include(CheckIPOSupported)
# check_ipo_supported(RESULT HAVE_IPO)
# if(HAVE_IPO)
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
# endif()
#endif()
if(MSVC)
# Microsoft Visual Studio Compiler
add_compile_options(/UTF8)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# Target architecture is x64 -> x64 has alsways SSE and SSE2 instruction sets
message(STATUS "x64 Enabling SSE2 CPU optimizations (>= Pentium 4)")
# Define gcc/clang style defines for SSE and SSE2 for compatibility
add_compile_definitions("__SSE__" "__SSE2__")
endif()
# Needed for sccache
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
string(
REPLACE
"/Zi"
"/Z7"
CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE}"
)
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
string(
REPLACE
"/Zi"
"/Z7"
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
)
string(
REPLACE
"/Zi"
"/Z7"
CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO}"
)
endif()
if(NOT OPTIMIZE STREQUAL "off")
# Use the fastest floating point math library
# http://msdn.microsoft.com/en-us/library/e7s85ffb.aspx
# http://msdn.microsoft.com/en-us/library/ms235601.aspx
add_compile_options(/fp:fast)
# Suggested for unused code removal
# http://msdn.microsoft.com/en-us/library/ms235601.aspx
# http://msdn.microsoft.com/en-us/library/xsa71f43.aspx
# http://msdn.microsoft.com/en-us/library/bxwfs976.aspx
add_compile_options(/Gy)
# For repeated local development builds, /INCREMENTAL offers much faster build times with the same performance of the executable,
# unless link time code generation (like CMAKE_INTERPROCEDURAL_OPTIMIZATION) is used, which is contrary to incremental linking.
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
#optimize Debug Builds as well, to have "normal" behaviour of mixxx during development
string(REPLACE "/Od" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Od" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS}")
string(REPLACE "/Ob0" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Ob0" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS}")
add_compile_options(/O2) # this implies /Od2
# Remove /RTC1 flag set by CMAKE by default (conflicts with /O2)
string(
REPLACE
"/RTC1"
""
CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG}"
)
string(REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
# For some reasons cmake uses /Ob1 in RelWithDebInfo https://gitlab.kitware.com/cmake/cmake/-/issues/20812
# /O2 is applied by CMake and this implies /Od2
string(
REPLACE
"/Ob1"
""
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
)
string(
REPLACE
"/Ob1"
""
CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO}"
)
# Reduce the size of the binary in RelWithDebInfo builds
# Do not use /OPT:ICF because it has no effect.
# https://github.com/mixxxdj/mixxx/pull/3660#pullrequestreview-600137258
add_link_options(/OPT:REF)
# /INCREMENTAL is incompatible with /OPT:REF, but it's the CMake default for RelWithDebInfo
# The CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO can be defined by the user in the GUI or in CMakeSettings.json,
# therefore we can't rely on the default.
string(
FIND
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
"/INCREMENTAL:NO"
INCREMENTAL_NO_POSITION
)
if(INCREMENTAL_NO_POSITION EQUAL -1)
message(
STATUS
"Overwriting /INCREMENTAL by /INCREMENTAL:NO to allow link time code optimization"
)
string(
REPLACE
"/INCREMENTAL"
"/INCREMENTAL:NO"
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
"${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}"
)
endif()
# Note: CMAKE_INTERPROCEDURAL_OPTIMIZATION sets the /GL and /LTCG flags for us
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
# Reduce the size of the binary in Release builds
# Do not use /OPT:ICF because it has no effect.
# https://github.com/mixxxdj/mixxx/pull/3660#pullrequestreview-600137258
add_link_options(/OPT:REF)
endif()
if(OPTIMIZE STREQUAL "portable")
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
# Target architecture is x86 with SSE and SSE2
message(STATUS "x86 Enabling SSE2 CPU optimizations (>= Pentium 4)")
# Define gcc/clang style defines for SSE and SSE2 for compatibility
add_compile_definitions("__SSE__" "__SSE2__")
# Set compiler option for SSE/SSE2
add_compile_options(/arch:SSE2)
endif()
elseif(OPTIMIZE STREQUAL "native")
message("Enabling optimizations for native system, specified by user")
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
# Target architecture is x86 with SSE and SSE2
message(STATUS "x86 Enabling SSE2 CPU optimizations (>= Pentium 4)")
# Define gcc/clang style defines for SSE and SSE2 for compatibility
add_compile_definitions("__SSE__" "__SSE2__")
endif()
# Define the target processor instruction and other compiler optimization flags here:
# https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64?view=msvc-160
# add_compile_options(/arch:AVX512)
message(
FATAL_ERROR
"User need to set the MSVC compiler flags for the native processor here!"
)
add_compile_options("/favor:${CMAKE_SYSTEM_PROCESSOR}")
elseif(OPTIMIZE STREQUAL "legacy")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
message("Enabling pure x64 instruction set (without AVX etc.)")
else()
message("Enabling pure i386 instruction set (without SSE/SSE2 etc.)")
endif()
else()
message(
FATAL_ERROR
"Invalid value passed to OPTIMIZE option: ${OPTIMIZE}"
)
endif()
else()
# OPTIMIZE=off
if(CMAKE_BUILD_TYPE STREQUAL "Release")
#Remove optimize flags set by cmake defaults
string(
REPLACE
"/O2"
""
CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE}"
)
string(REPLACE "/O2" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(
REPLACE
"/Ob2"
""
CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE}"
)
string(REPLACE "/Ob2" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
add_compile_options(/Od) # this implies /Ob0
add_compile_options(/RTC1)
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
#Remove optimize flags set by cmake defaults
string(
REPLACE
"/O2"
""
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
)
string(
REPLACE
"/O2"
""
CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO}"
)
# For some reasons cmake uses /Ob1 in RelWithDebInfo https://gitlab.kitware.com/cmake/cmake/-/issues/20812
string(
REPLACE
"/Ob1"
""
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
)
string(
REPLACE
"/Ob1"
""
CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO}"
)
add_compile_options(/Od) # this implies /Ob0
add_compile_options(/RTC1)
endif()
endif()
elseif(GNU_GCC OR LLVM_CLANG)
if(NOT OPTIMIZE STREQUAL "off")
# Common flags to all optimizations.
# -ffast-math will prevent a performance penalty by denormals
# (floating point values almost Zero are treated as Zero)
# unfortunately that work only on 64 bit CPUs or with sse2 enabled
# The following optimisation flags makes the engine code ~3 times
# faster, measured on a Atom CPU.
add_compile_options(-ffast-math -funroll-loops)
if(EMSCRIPTEN)
# Optimize for size + speed when targeting Emscripten/WebAssembly
# This is recommended as we use asyncify:
# See https://doc.qt.io/qt-6/wasm.html#asyncify
add_compile_options(-Os)
else()
add_compile_options(-O3)
endif()
# set -fomit-frame-pointer when we don't profile and are not using
# Clang sanitizers.
# Note: It is only included in -O on machines where it does not
# interfere with debugging
if(NOT PROFILING AND NOT SANITIZERS)
add_compile_options(-fomit-frame-pointer)
endif()
if(OPTIMIZE STREQUAL "portable")
# portable: sse2 CPU (>= Pentium 4)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i[3456]86|x86|x64|x86_64|AMD64)$")
message(STATUS "Enabling SSE2 CPU optimizations (>= Pentium 4)")
if(NOT EMSCRIPTEN)
add_compile_options(-mtune=generic)
endif()
# -mtune=generic picks the most common, but compatible options.
# on arm platforms equivalent to -march=arch
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
# the sse flags are not set by default on 32 bit builds
# but are not supported on arm builds
add_compile_options(-msse2)
if(EMSCRIPTEN)
add_compile_options(-msimd128)
else()
add_compile_options(-mfpmath=sse)
endif()
endif()
# TODO(rryan): macOS can use SSE3, and possibly SSE 4.1 once
# we require macOS 10.12.
# https://stackoverflow.com/questions/45917280/mac-osx-minumum-support-sse-version
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv7.*)$") # but not armv8
add_compile_options(-mfloat-abi=hard -mfpu=neon)
endif()
# this sets macros __SSE2_MATH__ __SSE_MATH__ __SSE2__ __SSE__
# This should be our default build for distribution
# It's a little sketchy, but turning on SSE2 will gain
# 100% performance in our filter code and allows us to
# turns on denormal zeroing.
# We don't really support CPU's earlier than Pentium 4,
# which is the class of CPUs this decision affects.
# The downside of this is that we aren't truly
# i386 compatible, so builds that claim 'i386' will crash.
# -- rryan 2/2011
# Note: SSE2 is a core part of x64 CPUs
elseif(OPTIMIZE STREQUAL "native")
message("Enabling native optimizations for ${CMAKE_SYSTEM_PROCESSOR}")
add_compile_options(-march=native)
# Note: requires gcc >= 4.2.0
# macros like __SSE2_MATH__ __SSE_MATH__ __SSE2__ __SSE__
# are set automatically
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv7.*)$") # but not armv8
add_compile_options(-mfloat-abi=hard -mfpu=neon)
endif()
elseif(OPTIMIZE STREQUAL "legacy")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i[3456]86|x86|x64|x86_64|AMD64)$")
message("Enabling pure i386 code")
add_compile_options(-mtune=generic)
# -mtune=generic pick the most common, but compatible options.
# on arm platforms equivalent to -march=arch
endif()
else()
message(
FATAL_ERROR
"Invalid value passed to OPTIMIZE option: ${OPTIMIZE}"
)
endif()
endif()
endif()
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
if(WIN32)
# Add support for lib prefix on Windows
set(CMAKE_FIND_LIBRARY_PREFIXES "" "lib")
endif()
if(MSVC)
if(NOT DEFINED CMAKE_DISABLE_PRECOMPILE_HEADERS)
# With MSVC, PCH is faster than caching
set(CMAKE_DISABLE_PRECOMPILE_HEADERS OFF)
endif()
set(
CMAKE_DISABLE_PRECOMPILE_HEADERS
${CMAKE_DISABLE_PRECOMPILE_HEADERS}
CACHE BOOL
"Disable precompiled headers"
)
# sccache support
find_program(SCCACHE_EXECUTABLE "sccache")
if(SCCACHE_EXECUTABLE)
message(STATUS "Found sccache: ${SCCACHE_EXECUTABLE}")
else()
message(STATUS "Could NOT find sccache (missing executable)")
endif()
default_option(SCCACHE_SUPPORT "Enable sccache support" "SCCACHE_EXECUTABLE;CMAKE_DISABLE_PRECOMPILE_HEADERS")
message(STATUS "Support for sccache: ${SCCACHE_SUPPORT}")
if(SCCACHE_SUPPORT)
if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
message(
WARNING
"sccache: Does not work with precompiled headers. Set CMAKE_DISABLE_PRECOMPILE_HEADERS=ON"
)
endif()
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_EXECUTABLE}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_EXECUTABLE}")
endif()
else()
# ccache support
find_program(CCACHE_EXECUTABLE "ccache")
if(CCACHE_EXECUTABLE)
message(STATUS "Found ccache: ${CCACHE_EXECUTABLE}")
else()
message(STATUS "Could NOT find ccache (missing executable)")
endif()
default_option(CCACHE_SUPPORT "Enable ccache support" "CCACHE_EXECUTABLE")
if(NOT DEFINED CMAKE_DISABLE_PRECOMPILE_HEADERS)
set(CMAKE_DISABLE_PRECOMPILE_HEADERS ${CCACHE_SUPPORT})
endif()
set(
CMAKE_DISABLE_PRECOMPILE_HEADERS
${CMAKE_DISABLE_PRECOMPILE_HEADERS}
CACHE BOOL
"Disable precompiled headers"
)
if(CCACHE_SUPPORT)
if(GNU_GCC OR LLVM_CLANG)
# without this compiler messages in `make` backend would be uncolored
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -fdiagnostics-color=${BUILD_COLORS}"
)
endif()
if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
execute_process(
COMMAND "${CCACHE_EXECUTABLE}" "--get-config=sloppiness"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
OUTPUT_VARIABLE CCACHE_CONFIGURED_SLOPPINESS
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(
NOT CCACHE_CONFIGURED_SLOPPINESS MATCHES "pch_defines"
OR NOT CCACHE_CONFIGURED_SLOPPINESS MATCHES "time_macros"
)
message(
WARNING
"ccache: For use with precompiled headers, the setting \"sloppiness\" needs to "
"be set to \"pch_defines,time_macros\". This can be done via the environment variable "
"\"CCACHE_SLOPPINESS=pch_defines,time_macros\" or permanent via "
"\"ccache --set-config=sloppiness=pch_defines,time_macros\"."
)
endif()
endif()
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
endif()
message(STATUS "Support for ccache: ${CCACHE_SUPPORT}")
endif()
if(NOT MSVC)
# Try to configure mold as linker via -fuse-ld=mold, support from gcc 12.1, gcc 11.2.0-16 or clang
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=mold -Wl,--version
ERROR_QUIET
OUTPUT_VARIABLE MOLD_FUSE_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(MOLD_FUSE_VERSION_STRING)
set(MOLD_FUSE_FOUND TRUE)
endif()
if(NOT MOLD_FUSE_FOUND)
# check if the symlink ld is in the mold folder for older compiler
find_program(MOLD_SYMLINK "${CMAKE_INSTALL_LIBEXECDIR}/mold/ld")
get_filename_component(MOLD_SYMLINK_DIRECTORY ${MOLD_SYMLINK} DIRECTORY)
endif()
if(MOLD_SYMLINK)
set(MOLD_SYMLINK_FOUND TRUE)
endif()
default_option(MOLD_SUPPORT "Use 'mold' for linking" "MOLD_FUSE_FOUND OR MOLD_SYMLINK_FOUND")
if(MOLD_SUPPORT)
if(MOLD_FUSE_FOUND)
message(STATUS "Selecting mold as linker")
add_link_options("-fuse-ld=mold")
elseif(MOLD_SYMLINK_FOUND)
message(
STATUS
"Selecting mold as linker via ld symlink in ${MOLD_SYMLINK_DIRECTORY}"
)
add_link_options("-B${MOLD_SYMLINK_DIRECTORY}")
else()
message(FATAL_ERROR "Could NOT find mold (missing executable)")
endif()
else()
# Try to configure lld as linker
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=lld -Wl,--version
ERROR_QUIET
OUTPUT_VARIABLE LLD_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(LLD_VERSION_STRING)
string(
REGEX MATCH
"LLD ([0-9]+\\.[0-9]+\\.[0-9]+)"
LLD_VERSION_MATCH
"${LLD_VERSION_STRING}"
)
if(LLD_VERSION_MATCH)
set(LLD_VERSION ${CMAKE_MATCH_1})
message(STATUS "Found ld.lld with version: ${LLD_VERSION}")
else()
message(
WARNING
"Failed to parse ld.lld version from: ${LLD_VERSION_STRING}"
)
endif()
endif()
# LLD 10.0.0 does not work because of https://bugs.llvm.org/show_bug.cgi?id=45769
default_option(LLD_SUPPORT "Use 'ld.lld' for linking" "LLD_VERSION VERSION_GREATER 10.0.0")
if(LLD_SUPPORT)
if(LLD_VERSION_STRING)
if(LLD_VERSION VERSION_GREATER 10.0.0)
message(STATUS "Selecting lld as linker")
add_link_options("-fuse-ld=lld")
else()
message(FATAL_ERROR "Could NOT find ld.lld > 10.0.0")
endif()
else()
message(FATAL_ERROR "Could NOT find ld.lld (missing executable)")
endif()
endif()
endif()
endif()
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
set(
CLANG_TIDY
""
CACHE STRING
"CMAKE_CXX_CLANG_TIDY equivalent that only applies to mixxx sources, not bundled dependencies"
)
# Mixxx itself
add_library(
mixxx-lib
STATIC
EXCLUDE_FROM_ALL
src/analyzer/analyzerbeats.cpp
src/analyzer/analyzerebur128.cpp
src/analyzer/analyzergain.cpp
src/analyzer/analyzerkey.cpp
src/analyzer/analyzerscheduledtrack.cpp
src/analyzer/analyzersilence.cpp
src/analyzer/analyzerthread.cpp
src/analyzer/analyzertrack.cpp
src/analyzer/analyzerwaveform.cpp
src/analyzer/plugins/analyzerqueenmarybeats.cpp
src/analyzer/plugins/analyzerqueenmarykey.cpp
src/analyzer/plugins/analyzersoundtouchbeats.cpp
src/analyzer/plugins/buffering_utils.cpp
src/analyzer/trackanalysisscheduler.cpp
src/audio/frame.cpp
src/audio/signalinfo.cpp
src/audio/streaminfo.cpp
src/audio/types.cpp
src/control/control.cpp
src/control/controlaudiotaperpot.cpp
src/control/controlbehavior.cpp
src/control/controlcompressingproxy.cpp
src/control/controleffectknob.cpp
src/control/controlencoder.cpp
src/control/controlindicator.cpp
src/control/controlindicatortimer.cpp
src/control/controllinpotmeter.cpp
src/control/controllogpotmeter.cpp
src/control/controlobject.cpp
src/control/controlobjectscript.cpp
src/control/controlpotmeter.cpp
src/control/controlproxy.cpp
src/control/controlpushbutton.cpp
src/control/controlttrotary.cpp
src/controllers/controller.cpp
src/controllers/controllerenumerator.cpp
src/controllers/controllerinputmappingtablemodel.cpp
src/controllers/controllerlearningeventfilter.cpp
src/controllers/controllermanager.cpp
src/controllers/controllermappinginfo.cpp
src/controllers/legacycontrollersettings.cpp
src/controllers/legacycontrollersettingslayout.cpp
src/controllers/controllermappinginfoenumerator.cpp
src/controllers/controllermappingtablemodel.cpp
src/controllers/controlleroutputmappingtablemodel.cpp
src/controllers/controlpickermenu.cpp
src/controllers/legacycontrollermappingfilehandler.cpp
src/controllers/legacycontrollermapping.cpp