forked from apple/turicreate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1306 lines (1141 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
project(Turi)
# We require a recent version of cmake and automatically
# install a compatible version when using the cmake lists,
# if one is not already present.
cmake_minimum_required(VERSION 3.12.0)
# Libraries linked via full path no longer produce linker search paths.
cmake_policy(SET CMP0003 NEW)
# Preprocessor definition values are now escaped automatically.
cmake_policy(SET CMP0005 NEW)
# for cmake 3.0
cmake_policy(SET CMP0045 OLD)
cmake_policy(SET CMP0046 OLD)
cmake_policy(SET CMP0042 NEW)
# Generate a compilation database for use with automated tools like IDE/editor
# plugins. See http://clang.llvm.org/docs/JSONCompilationDatabase.html
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
# Determine where additional Turi specific cmake modules are
# defined
set(DEPS_CMAKE ${CMAKE_SOURCE_DIR}/deps/cmake)
set(CMAKE_MODULE_PATH ${DEPS_CMAKE};${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/deps/local)
set(ENV{PATH} "${CMAKE_SOURCE_DIR}/deps/local/bin:${CMAKE_SOURCE_DIR}/deps/env/bin:$ENV{PATH}")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(TC_BUILD_PYTHON)
message("Building python libraries.")
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/deps/env/)
message(FATAL, "Internal error: Python toolchain expected; not present.")
endif()
include(UseCython)
add_definitions(-DTC_HAS_PYTHON)
add_definitions(-DTC_BUILD_VISUALIZATION_CLIENT)
else()
message("Skipping python libraries.")
endif()
set(TC_PLATFORM_APPLE false)
set(TC_PLATFORM_LINUX false)
set(TC_PLATFORM_WIN32 false)
if (APPLE)
set(TC_PLATFORM_APPLE true)
add_definitions(-DTC_PLATFORM_APPLE)
find_library(ACCELERATE NAMES Accelerate)
find_library(APPKIT AppKit)
find_library(CORE_GRAPHICS CoreGraphics)
find_library(JAVASCRIPT_CORE JavaScriptCore)
find_library(FOUNDATION Foundation)
find_library(CORE_IMAGE NAMES CoreImage)
find_library(CORE_ML CoreML)
find_library(CORE_VIDEO CoreVideo)
find_library(METAL NAMES Metal)
find_library(METAL_PERFORMANCE_SHADERS NAMES MetalPerformanceShaders)
elseif (WIN32)
set(TC_PLATFORM_WIN32 true)
add_definitions(-DTC_PLATFORM_WIN32)
else()
set(TC_PLATFORM_LINUX true)
add_definitions(-DTC_PLATFORM_LINUX)
endif()
include(CheckLibraryExists)
include(CheckFunctionExists)
include(ExternalProject)
include(CheckCXXSourceCompiles)
include(CheckCXXCompilerFlag)
if (${TC_HAS_LLVM})
find_package(LLVM REQUIRED PATHS ${TC_LLVM_PATH}/lib/cmake)
if (${LLVM_VERSION_MAJOR} EQUAL 6 AND ${LLVM_VERSION_MINOR} EQUAL 0)
message("Found LLVM.")
add_definitions(-DTC_HAS_LLVM)
FOREACH(DIR ${LLVM_INCLUDE_DIRS})
include_directories(SYSTEM ${DIR})
ENDFOREACH()
link_directories("${TC_LLVM_PATH}/lib")
else()
message("Found LLVM, but only version 6.0 is currently supported; skipping.")
set(TC_HAS_LLVM false)
endif()
else()
message("LLVM not provided; skipping.")
set(TC_HAS_LLVM false)
endif()
set(TC_HAS_LIBUNWIND false)
set(TC_HAS_LIBUNWIND_STANDALONE false)
if (TC_PLATFORM_APPLE)
if (TC_HAS_LLVM)
message("Using libunwind from LLVM.")
set(TC_HAS_LIBUNWIND true)
set(TC_HAS_LIBUNWIND_STANDALONE false)
add_definitions(-DTC_HAS_LIBUNWIND)
else()
set(TC_HAS_LIBUNWIND false)
set(TC_HAS_LIBUNWIND_STANDALONE false)
endif()
elseif (TC_PLATFORM_LINUX)
find_library(TC_LIBUNWIND unwind)
if (${TC_LIBUNWIND} STREQUAL "TC_LIBUNWIND-NOTFOUND")
message("Did not find libunwind; skipping.")
set(TC_HAS_LIBUNWIND false)
else()
message("Found libunwind.")
set(TC_HAS_LIBUNWIND true)
set(TC_HAS_LIBUNWIND_STANDALONE true)
add_definitions(-DTC_HAS_LIBUNWIND)
endif()
endif()
if (${TC_STACK_DISPLAY})
if (${TC_HAS_LIBUNWIND} AND ${TC_HAS_LLVM})
message("Enabling display of annotated stack traces.")
add_definitions(-DTC_STACK_DISPLAY)
else()
set(TC_STACK_DISPLAY false)
endif()
else()
message("Disabling display of annotated stack traces.")
endif()
#**************************************************************************/
#* */
#* Global Link and Include Flags */
#* */
#**************************************************************************/
include_directories(SYSTEM
${CMAKE_SOURCE_DIR}/deps/local/include)
link_directories(${CMAKE_SOURCE_DIR}/deps/local/lib)
if (EXISTS ${CMAKE_SOURCE_DIR}/deps/local/lib64)
link_directories(${CMAKE_SOURCE_DIR}/deps/local/lib64)
endif()
#**************************************************************************
#* *
#* Platform Specific Stuff *
#* *
#**************************************************************************
if(APPLE)
if(TC_BUILD_IOS)
SET(TC_BASE_SDK iphoneos)
SET(COMPILER_FLAGS "${COMPILER_FLAGS} -miphoneos-version-min=10.0 -Wno-c++11-narrowing")
else()
SET(TC_BASE_SDK macosx)
# Modify COMPILER_FLAGS instead of setting CMAKE_OSX_DEPLOYMENT_TARGET so
# that this setting propagates to external dependencies.
SET(COMPILER_FLAGS "${COMPILER_FLAGS} -mmacosx-version-min=10.12")
endif()
EXEC_PROGRAM(xcrun ARGS --sdk ${TC_BASE_SDK} --show-sdk-version OUTPUT_VARIABLE TC_BASE_SDK_VERSION RETURN_VALUE _xcrun_ret)
if(NOT ${_xcrun_ret} EQUAL 0)
message(ERROR, "xcrun command failed with return code ${_xcrun_ret}.")
endif()
EXEC_PROGRAM(xcrun ARGS --sdk ${TC_BASE_SDK} --show-sdk-path OUTPUT_VARIABLE TC_BASE_SDK_PATH RETURN_VALUE _xcrun_ret)
if(NOT ${_xcrun_ret} EQUAL 0)
message(ERROR, "xcrun command failed with return code ${_xcrun_ret}.")
endif()
SET(CMAKE_OSX_SYSROOT "${TC_BASE_SDK_PATH}")
SET(COMPILER_FLAGS "${COMPILER_FLAGS} -isysroot ${TC_BASE_SDK_PATH}")
# Core ML is only present on macOS 10.13 or higher.
# Logic reversed to get around what seems to be a CMake bug.
if(NOT TC_BASE_SDK_VERSION VERSION_LESS 10.13)
add_definitions(-DHAS_CORE_ML)
set(HAS_CORE_ML TRUE)
endif()
# Core ML only supports batch inference on macOS 10.14 or higher
# Logic reversed to get around what seems to be a CMake bug.
if(NOT TC_BASE_SDK_VERSION VERSION_LESS 10.14)
add_definitions(-DHAS_CORE_ML_BATCH_INFERENCE)
# GPU-accelerated training with MPS backend requires macOS 10.14 or higher
add_definitions(-DHAS_MPS)
set(HAS_MPS TRUE)
# CoreML MLCustomModel requires macOS 10.14 or higher
set(HAS_MLCUSTOMMODEL TRUE)
endif()
if(NOT TC_BASE_SDK_VERSION VERSION_LESS 10.15)
add_definitions(-DHAS_MACOS_10_15)
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CLANG false)
elseif(WIN32)
# for whatever reason on windows the compiler identification is an empty string
set(CLANG false)
else()
set(CLANG true)
endif()
if(CMAKE_GENERATOR MATCHES "MinGW Makefiles")
SET(MINGW_MAKEFILES true)
else()
SET(MINGW_MAKEFILES false)
endif()
if(CMAKE_GENERATOR MATCHES "MSYS Makefiles")
SET(MSYS_MAKEFILES true)
else()
SET(MSYS_MAKEFILES false)
endif()
if(WIN32 AND MINGW)
SET(COMPILER_FLAGS "${COMPILER_FLAGS} -Wa,-mbig-obj")
endif()
set(MINGW_ROOT "/mingw64/bin")
# Separate variable so that cython's CMakeLists.txt can use it too
if (WIN32)
set(INSTALLATION_SYSTEM_BINARY_FILES
${CMAKE_SOURCE_DIR}/deps/local/bin/libsodium-13.dll
${MINGW_ROOT}/libiconv-2.dll
${MINGW_ROOT}/libssh2-1.dll
${MINGW_ROOT}/zlib1.dll
${MINGW_ROOT}/libwinpthread-1.dll
${MINGW_ROOT}/libgcc_s_seh-1.dll
${MINGW_ROOT}/libstdc++-6.dll
${MINGW_ROOT}/libeay32.dll)
else()
if (EXISTS ${CMAKE_SOURCE_DIR}/deps/local/lib64/libgomp.so.1)
list(APPEND INSTALLATION_SYSTEM_BINARY_FILES ${CMAKE_SOURCE_DIR}/deps/local/lib64/libgomp.so.1)
endif()
endif()
#**************************************************************************/
#* */
#* Common Defines */
#* */
#**************************************************************************/
set(CMAKE_CXX_STANDARD 11)
if(WIN32)
add_definitions(-DWINVER=0x0600)
add_definitions(-D_WIN32_WINNT=0x0600)
endif()
if(TC_BUILD_IOS)
add_definitions(-DTC_BUILD_IOS)
if(${TC_BUILD_REMOTEFS})
message(ERROR "RemoteFS must be disabled for building iOS.")
endif()
endif()
if(NOT ${TC_BUILD_REMOTEFS})
add_definitions(-DTC_DISABLE_REMOTEFS)
endif()
if (${TC_EXTRA_OPTIMIZATION_FLAGS})
message("Enabling extra optimization flags.")
add_definitions(-DTC_EXTRA_OPTIMIZATION_FLAGS)
else()
message("Disabling extra optimization flags.")
endif()
add_definitions(-DTC_BUILD_PATH_BASE="${CMAKE_SOURCE_DIR}")
add_definitions(-DCURL_STATICLIB)
add_definitions(-DIN_TURI_SOURCE_TREE)
add_definitions(-DFUSION_MAX_VECTOR_SIZE=20)
add_definitions(-DBOOST_SPIRIT_THREAD_SAFE)
# These determine the maximum number of arguments for extension functions
add_definitions(-DBOOST_FUSION_INVOKE_MAX_ARITY=12)
add_definitions(-DBOOST_FUSION_INVOKE_PROCEDURE_MAX_ARITY=12)
add_definitions(-DBOOST_FUSION_INVOKE_FUNCTION_OBJECT_MAX_ARITY=12)
# Workaround for https://svn.boost.org/trac10/ticket/10443 in Boost 1.68.0
add_definitions(-DBOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)
#**************************************************************************/
#* */
#* Apple Legal Defines */
#* */
#**************************************************************************/
add_definitions(-DEIGEN_MPL2_ONLY)
#**************************************************************************/
#* */
#* Force Disable OpenMP */
if(NOT TC_COREMLTOOLS_DIR)
set(TC_COREMLTOOLS_DIR ${CMAKE_SOURCE_DIR}/src/external/coremltools_wrap/coremltools/)
else()
message("Using mlmodel interface in source directory ${TC_COREMLTOOLS_DIR}/mlmodel.")
endif()
include_directories(${TC_COREMLTOOLS_DIR})
#* */
#**************************************************************************/
add_library(openmp INTERFACE)
target_compile_definitions(openmp INTERFACE __NO_OPENMP__)
message(WARNING "OpenMP Libraries were not found")
#**************************************************************************/
#* */
#* coremltools */
#* */
#**************************************************************************/
if(NOT TC_COREMLTOOLS_DIR)
set(TC_COREMLTOOLS_DIR ${CMAKE_SOURCE_DIR}/src/external/coremltools_wrap/coremltools/)
endif()
message("Using ${TC_COREMLTOOLS_DIR} for coremltools directory.")
include_directories(${TC_COREMLTOOLS_DIR}/)
#**************************************************************************/
#* */
#* Adapt Compiler and Linker Flags to the system */
#* */
#**************************************************************************/
if (CLANG)
set(_cpp11_optional_flags "")
check_cxx_compiler_flag("-Wno-stdlibcxx-not-found" __no_stdlibcxx_not_found)
if(${__no_stdlibcxx_not_found})
set(_cpp11_optional_flags "${_cpp11_optional_flags} -Wno-stdlibcxx-not-found")
endif()
check_cxx_compiler_flag("-Wno-deprecated-register" __no_deprecated_register)
if(${__no_deprecated_register})
set(_cpp11_optional_flags "${_cpp11_optional_flags} -Wno-deprecated-register")
endif()
# clang on Linux gives unused argument warnings all over the place
# they look useful, but let's suppress them for now since there are tons
# (and with warning-as-error, they break the build)
check_cxx_compiler_flag("-Qunused-arguments" __qunused_arguments)
if(${__qunused_arguments})
add_compile_options(-Qunused-arguments)
endif()
# clang on Linux with libstdc++ from GCC 4.8.1 gives errors about class vs. struct hash.
# apparently it's defined as both in separate places in libstdc++
# and GCC 4.8.1 doesn't care, but clang does.
# Not sure how to tell whether we're using libstdc++ specifically, so for now,
# we'll just avoid this warning-as-error on non-Apple platforms entirely.
if(NOT APPLE)
check_cxx_compiler_flag("-Wno-mismatched-tags" __no_mismatched_tags)
if (${__no_mismatched_tags})
set(_cpp11_optional_flags "${_cpp11_optional_flags} -Wno-error=mismatched-tags")
set(_cpp11_optional_flags "${_cpp11_optional_flags} -Wno-mismatched-tags")
endif()
endif()
set(CPP11_FLAGS "-Wno-enum-compare -Wno-conversion-null -Wno-constant-logical-operand -Wno-parentheses-equality -ftemplate-depth=900 ${_cpp11_optional_flags}")
set(WERROR_FLAGS "-Werror -Wall -Wsign-compare")
else()
# non-clang
set(CPP11_FLAGS "-Wno-enum-compare -Wno-conversion-null -ftemplate-depth=900 -Wno-unknown-pragmas")
set(WERROR_FLAGS "-Werror")
endif()
# same goes for unknown warning group (for #pragma clang or #pragma GCC warning suppression)
# seems different clang distributions have quite different warning arguments
check_cxx_compiler_flag("-Wno-unknown-warning-option" __no_unknown_warning_option)
if(${__no_unknown_warning_option})
add_compile_options(-Wno-unknown-warning-option)
endif()
if (${TC_STACK_DISPLAY})
set(DEBUG_INFO_FLAGS "-g3 -fno-omit-frame-pointer")
else()
set(DEBUG_INFO_FLAGS "-g")
endif()
# Shared compiler flags used by all builds (debug, profile, release)
# Allow COMPILER_FLAGS to be used as options from the ./configure without
# forcing all the other options I want to add to be lost
set(C_REAL_COMPILER_FLAGS "-Wall ${DEBUG_INFO_FLAGS} ${COMPILER_FLAGS}")
set(CPP_REAL_COMPILER_FLAGS "-Wall ${DEBUG_INFO_FLAGS} ${CPP11_FLAGS} ${COMPILER_FLAGS}")
if (CLANG)
# clang 9.0.0 and earlier will warn (error with -Werror) on unused -pthread during linking
# so adding only to compile options is what we need.
add_compile_options(-pthread)
else()
set(C_REAL_COMPILER_FLAGS "${C_REAL_COMPILER_FLAGS} -pthread")
set(CPP_REAL_COMPILER_FLAGS "${CPP_REAL_COMPILER_FLAGS} -pthread")
endif()
# Disable address space randomization for OSX lion and above
if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -no_pie")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -no_pie")
# if mac, but not using clang, we should use the clang linker anyway since
# the gcc linker seems to cause problems. Especially with -march=native
#
# see:
# http://stackoverflow.com/questions/9840207/how-to-use-avx-pclmulqdq-on-mac-os-x-lion
if (NOT CLANG)
set(ALTERNATE_LINKER "-Wa,-q")
endif()
endif()
# Install time rpath gets highest priority, we should always use rpath relative to the installation location first.
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,${CMAKE_SOURCE_DIR}/deps/local/bin")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/mingw64/bin")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-rpath,/mingw64/bin")
elseif (APPLE)
# For whatever reason just adding -rpath=@loader_path has issues on 10.9 but not 10.10
# Here are two possible alternatives that "may" fix the issue. If they fix it
# I am not sure which line was the one which actually worked
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,@loader_path/.")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,.")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,@loader_path -Wl,-rpath,@loader_path/..")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-rpath,@loader_path -Wl,-rpath,@loader_path/..")
else()
# LINUX
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ORIGIN")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,$ORIGIN -Wl,-rpath,$ORIGIN/..")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-rpath,$ORIGIN -Wl,-rpath,$ORIGIN/..")
endif()
# if (EXISTS ${CMAKE_SOURCE_DIR}/deps/local/lib64)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,${CMAKE_SOURCE_DIR}/deps/local/lib64")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,${CMAKE_SOURCE_DIR}/deps/local/lib64")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-rpath,${CMAKE_SOURCE_DIR}/deps/local/lib64")
# endif()
# if (EXISTS ${CMAKE_SOURCE_DIR}/deps/local/lib)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,${CMAKE_SOURCE_DIR}/deps/local/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,${CMAKE_SOURCE_DIR}/deps/local/lib")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-rpath,${CMAKE_SOURCE_DIR}/deps/local/lib")
# endif()
if (MARCH)
set(ARCH_FLAG "-march=${MARCH}")
elseif (ARCH)
set(ARCH_FLAG "-arch ${ARCH}")
else()
check_cxx_compiler_flag(-march=core2 HAS_MARCH_CORE2)
if(HAS_MARCH_CORE2)
# Old CPU archetecture; enables SSE up to 3
set(MARCH "core2")
else()
# Old CPU archetecture
set(MARCH "x86_64")
endif()
set(ARCH_FLAG "-march=${MARCH}")
endif()
# check if MTUNE is set
if (NOT MTUNE)
set(MTUNE "-mtune=generic") # Reommended way of setting this for generic distributions
endif()
set(EXTRA_OPTIMIZATION_FLAGS "")
set(DISABLE_WARNING_FLAGS "")
# If profiling mode is enabled then additional profiling flags are set for
# the compiler
if (COMPILE_PROFILING MATCHES 1)
set(PROFILING_FLAGS "-DUSE_EVENT_LOG -DUSE_TRACEPOINT")
set(EXTRA_OPTIMIZATION_FLAGS "${EXTRA_OPTIMIZATION_FLAGS} ${PROFILING_FLAGS}")
endif()
# Set up the 128 bit integer support; defines INT128_FLAGS
include(FindInt128)
Find_Int128_Types()
#disable Wno-unused-local-typedefs if available
check_cxx_compiler_flag(-Wno-unused-local-typedefs HAS_WNO_LOCAL_TYPEDEFS)
if(HAS_WNO_LOCAL_TYPEDEFS)
set(DISABLE_WARNING_FLAGS "${DISABLE_WARNING_FLAGS} -Wno-unused-local-typedefs")
endif()
#disable gcc-only flags on clang (newer clang with XCode 5.1 errors on these)
check_cxx_compiler_flag(-fpeel-loops HAS_FPEEL_LOOPS)
if(HAS_FPEEL_LOOPS)
set(EXTRA_OPTIMIZATION_FLAGS "${EXTRA_OPTIMIZATION_FLAGS} -fpeel-loops")
endif()
check_cxx_compiler_flag(-funswitch-loops HAS_FUNSWITCH_LOOPS)
if(HAS_FUNSWITCH_LOOPS)
set(EXTRA_OPTIMIZATION_FLAGS "${EXTRA_OPTIMIZATION_FLAGS} -funswitch-loops")
endif()
check_cxx_compiler_flag(-ftracer HAS_FTRACER)
if(HAS_FTRACER)
set(EXTRA_OPTIMIZATION_FLAGS "${EXTRA_OPTIMIZATION_FLAGS} -ftracer")
endif()
if(${DEBUG_OPT_FOR_SIZE})
set(DEBUG_OPTIMIZATION_FLAGS "-Os")
else()
set(DEBUG_OPTIMIZATION_FLAGS "-O0 -fno-inline")
endif()
if(${RELEASE_OPT_FOR_SIZE})
set(RELEASE_OPTIMIZATION_FLAGS "-Os -DNDEBUG")
else()
set(RELEASE_OPTIMIZATION_FLAGS "-O3 -DNDEBUG")
endif()
if(WIN32)
# on windows due to some string table limitations + template
# insanities, on -O0 we run out of string table entries or something
# like that.
set(DEBUG_OPTIMIZATION_FLAGS -O2)
endif()
# Set the debug flags
set(EXTERNAL_CMAKE_C_FLAGS_DEBUG
"${DEBUG_OPTIMIZATION_FLAGS} -Wno-attributes ${ARCH_FLAG} -Winit-self ${PROFILING_FLAGS} ${C_REAL_COMPILER_FLAGS} -fno-inline ${ALTERNATE_LINKER} -DHAVE_PTHREAD=1"
CACHE STRING "compiler options" FORCE)
set(CMAKE_C_FLAGS_DEBUG
"${EXTERNAL_CMAKE_C_FLAGS_DEBUG} ${WERROR_FLAGS} -Wuninitialized "
CACHE STRING "compiler options" FORCE)
set(EXTERNAL_CMAKE_CXX_FLAGS_DEBUG
"${DEBUG_OPTIMIZATION_FLAGS} ${DISABLE_WARNING_FLAGS} -Wno-attributes ${ARCH_FLAG} -Winit-self ${PROFILING_FLAGS} ${CPP_REAL_COMPILER_FLAGS} ${INT128_FLAGS} ${ALTERNATE_LINKER} -fno-inline -DHAVE_PTHREAD=1"
CACHE STRING "compiler options" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG
"${EXTERNAL_CMAKE_CXX_FLAGS_DEBUG} ${WERROR_FLAGS} -Wuninitialized"
CACHE STRING "compiler options" FORCE)
set(CMAKE_C_FLAGS_RELEASE
"${RELEASE_OPTIMIZATION_FLAGS} -Wno-attributes ${ARCH_FLAG} ${MTUNE} ${PROFILING_FLAGS} ${C_REAL_COMPILER_FLAGS} ${WERROR_FLAGS} -DNDEBUG ${ALTERNATE_LINKER} -DHAVE_PTHREAD=1"
CACHE STRING "compiler options" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE
"${RELEASE_OPTIMIZATION_FLAGS} ${EXTRA_OPTIMIZATION_FLAGS} ${DISABLE_WARNING_FLAGS} ${PROFILING_FLAGS} -Wno-attributes ${ARCH_FLAG} ${MTUNE} ${CPP_REAL_COMPILER_FLAGS} ${WERROR_FLAGS} ${INT128_FLAGS} ${ALTERNATE_LINKER} -DNDEBUG -DHAVE_PTHREAD=1"
CACHE STRING "compiler options" FORCE)
#**************************************************************************/
#* */
#* Some C++ Implementation Oddities between libc++ and stdc++ */
#* */
#**************************************************************************/
set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
check_cxx_source_compiles("#include <ios>
#include <system_error>
int main(int argc, char** argv) {
throw std::ios_base::failure(\"hello\", std::error_code());
}" COMPILER_HAS_IOS_BASE_FAILURE_WITH_ERROR_CODE)
if(COMPILER_HAS_IOS_BASE_FAILURE_WITH_ERROR_CODE)
message(STATUS "Compiler supports ios_base::failure(str, error_code)")
add_definitions(-DCOMPILER_HAS_IOS_BASE_FAILURE_WITH_ERROR_CODE)
else()
message(STATUS "Compiler does not support ios_base::failure(str, error_code)")
endif()
check_cxx_source_compiles("#include <ios>
#include <system_error>
class io_error : public std::ios_base::failure {
public: /* The noexcept here is different between C++ 17 and C++ 11. */
const char *what() const noexcept { return \"\"; }
};
int main(int argc, char** argv) { return 0; }"
COMPILER_HAS_NOEXCEPT_WHAT_ON_EXCEPTIONS)
if(COMPILER_HAS_NOEXCEPT_WHAT_ON_EXCEPTIONS)
message(STATUS "Compiler supports noexcept on what() with ios_base::failure.")
add_definitions(-DCOMPILER_HAS_NOEXCEPT_WHAT_ON_EXCEPTIONS)
else()
message(STATUS "Compiler uses throw() on what() with ios_base::failure.")
endif()
#**************************************************************************/
#* */
#* Final Flags */
#* */
#**************************************************************************/
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Build Type")
if (CMAKE_BUILD_TYPE MATCHES "Release")
message(STATUS "Release build with C++ flags: " ${CMAKE_CXX_FLAGS_RELEASE})
message(STATUS "Release build with C flags: " ${CMAKE_C_FLAGS_RELEASE})
elseif(CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Debug build with C++ flags: " ${CMAKE_CXX_FLAGS_DEBUG})
message(STATUS "Debug build with C flags: " ${CMAKE_C_FLAGS_DEBUG})
else()
message(FATAL_ERROR "Unknown build type: " ${CMAKE_BUILD_TYPE} "!. Rerun ./configure")
endif()
#**************************************************************************/
#* */
#* Definitions and options to support dependencies */
#* */
#**************************************************************************/
add_compile_options(-Dgoogle=__tc_google)
add_compile_options(-DCoreML=__tc_CoreML)
add_compile_options(-DHAVE_PTHREAD=1)
##############################################################################
##############################################################################
##############################################################################
##############################################################################
##############################################################################
##############################################################################
# We are done with the system configuration. Now everything else below here
# is about getting dependencies and macros and various build behaviors
##############################################################################
##############################################################################
##############################################################################
##############################################################################
##############################################################################
##############################################################################
# some useful utilities
include(copy_file)
include(CMakeParseArguments)
include(eval)
# This is an internal function and should not be used
# Usage:
# make_target_impl(target compile_flags sources requirements is_library SHARED)
#
# Example:
# make_target_impl(fileio "-fPIC"
# "asyncurl.cpp;sysutils.cpp"
# "logger;dl;pthread;z"
# TRUE FALSE)
#
# This generates a target library/binary with the given name. The optional
# compile_flags are appended to the target compile flags. "-fPIC" is ALWAYS
# added for libraries. "sources" is a list listing all the library/binary
# source files. "requirements" is a list listing all the libraries, and
# builtins this target depends on. IS_LIBRARY must be "TRUE" or "FALSE"
#
# if DYNAMIC is true, a dynamic library is built.
#
# Boost, pthread is always added as a default dependency. OpenMP is added
# when possible.
macro(make_target_impl NAME FLAGS REQUIREMENTS IS_LIBRARY SHARED SHARED_ALL_DEFINED OBJECT)
# create the target
if (${IS_LIBRARY})
message(STATUS "Adding Library: ${NAME}")
else()
message(STATUS "Adding Executable: ${NAME}")
# default dependencies
target_link_libraries(${NAME} boost pthread openmp)
endif()
set_property(TARGET ${NAME} PROPERTY IS_LIBRARY ${IS_LIBRARY})
# add a custom property to the target listing its dependencies
if(NOT ${FLAGS} STREQUAL "")
set_property(TARGET ${NAME} APPEND_STRING PROPERTY COMPILE_FLAGS " ${FLAGS}")
endif()
if (${IS_LIBRARY})
if (NOT WIN32)
#windows is always fPIC
set_property(TARGET ${NAME} APPEND_STRING PROPERTY COMPILE_FLAGS " -fPIC")
endif()
if (APPLE)
if (${SHARED})
if (NOT ${SHARED_ALL_DEFINED})
set_property(TARGET ${NAME} APPEND_STRING PROPERTY LINK_FLAGS " -undefined dynamic_lookup")
endif()
endif()
endif()
endif()
if (${IS_LIBRARY})
if(${SHARED})
target_link_libraries(${NAME} PRIVATE ${REQUIREMENTS})
elseif(${OBJECT})
# TODO we can link the requirements from here when target_link_libraries
# works with OBJECT library targets (requires CMake 3.12)
# See https://gitlab.kitware.com/cmake/cmake/issues/14778
# For now, do nothing.
else()
target_link_libraries(${NAME} PUBLIC ${REQUIREMENTS})
endif()
else()
target_link_libraries(${NAME} ${REQUIREMENTS})
endif()
# make sure boost is always built
add_dependencies(${NAME} boost)
endmacro()
# This is an external function
# Usage:
# make_library(NAME target
# SOURCES a.cpp b.cpp
# REQUIRES libx liby
# MAC_REQUIRES libz libzz
# LINUX_REQUIRES libk libj
# [SHARED] [OUTPUT_NAME xxxx] [SHARED_ALL_DEFINED]
# [OBJECT]
# )
# Example:
#
# make_library(NAME fileio
# SOURCES
# asyncurl.cpp
# sysutils.cpp
# wsconn.cpp
# s3_api.cpp
# hdfs.cpp
# REQUIRES
# logger dl pthread z curl xml2 openssl
# MAC_REQUIRES
# iconv
# )
# This generates a library with the provided target name.
#
# NAME and SOURCES must be specified.
# REQUIRES lists all dependent libraries. These can be:
# - other libraries built by the the turicreate build system
# - builtin libraries
# - system libraries
# MAC_REQUIRES lists all dependent libraries which are included only on Mac.
# LINUX_REQUIRES lists all dependent libraries which are included only on Linux.
# SHARED will build a shared library instead of a static library
# EXTERNAL_VISIBILITY will make the symbols be publicly visible. Default is hidden
# SHARED_ALL_DEFINED will require shared libraries to have all symbols defined
# OBJECT will build an object library instead of a static library
#
# All other targets which depends on this library (using the "requires" function)
# will automatically include all recursive dependencies.
#
# Boost, pthread is always added as a default dependency. OpenMP is added
# when possible.
macro(make_library NAME)
set(options SHARED EXTERNAL_VISIBILITY SHARED_ALL_DEFINED DEAD_STRIP OBJECT)
set(one_value_args COMPILE_FLAGS OUTPUT_NAME EXPORT_LINUX_MAP_FILE EXPORT_OSX_MAP_FILE)
set(multi_value_args
SOURCES REQUIRES MAC_REQUIRES LINUX_REQUIRES
COMPILE_FLAGS_EXTRA COMPILE_FLAGS_EXTRA_CLANG COMPILE_FLAGS_EXTRA_GCC)
CMAKE_PARSE_ARGUMENTS(make_library "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
if(NOT make_library_SOURCES)
MESSAGE(FATAL_ERROR "make_library call with no sources")
endif()
if (APPLE)
if (make_library_MAC_REQUIRES)
set(make_library_REQUIRES ${make_library_REQUIRES} ${make_library_MAC_REQUIRES})
endif()
else()
if (make_library_LINUX_REQUIRES)
set(make_library_REQUIRES ${make_library_REQUIRES} ${make_library_LINUX_REQUIRES})
endif()
endif()
if (${make_library_SHARED})
add_library(${NAME} SHARED ${make_library_SOURCES})
elseif(${make_library_OBJECT})
add_library(${NAME} OBJECT ${make_library_SOURCES})
else()
add_library(${NAME} STATIC ${make_library_SOURCES})
endif()
make_target_impl("${NAME}" "${make_library_COMPILE_FLAGS}"
"${make_library_REQUIRES}" TRUE "${make_library_SHARED}" "${make_library_SHARED_ALL_DEFINED}" "${make_library_OBJECT}")
if (make_library_OUTPUT_NAME)
message(STATUS "make_library ${NAME} ===> ${make_library_OUTPUT_NAME}")
set_target_properties(${NAME} PROPERTIES OUTPUT_NAME ${make_library_OUTPUT_NAME})
endif()
if (make_library_COMPILE_FLAGS_EXTRA)
target_compile_options(${NAME} PRIVATE ${make_library_COMPILE_FLAGS_EXTRA})
endif()
if (CLANG)
if (make_library_COMPILE_FLAGS_EXTRA_CLANG)
target_compile_options(${NAME} PRIVATE ${make_library_COMPILE_FLAGS_EXTRA_CLANG})
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (make_library_COMPILE_FLAGS_EXTRA_GCC)
target_compile_options(${NAME} PRIVATE ${make_library_COMPILE_FLAGS_EXTRA_GCC})
endif()
endif()
if (${make_library_EXTERNAL_VISIBILITY} OR ${make_library_OBJECT})
# do nothing
message(STATUS "External Visibility: " ${NAME})
target_compile_options(${NAME} PRIVATE "-fvisibility=default")
target_compile_options(${NAME} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fvisibility-inlines-hidden>)
else()
target_compile_options(${NAME} PRIVATE "-fvisibility=hidden")
target_compile_options(${NAME} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fvisibility-inlines-hidden>)
endif()
if(NOT CLANG)
if (NOT WIN32)
# set_property(TARGET ${NAME} APPEND_STRING PROPERTY LINK_FLAGS " -static-libstdc++ ")
endif()
endif()
if(APPLE)
if(make_library_EXPORT_OSX_MAP_FILE)
set_property(TARGET ${NAME} APPEND PROPERTY LINK_DEPENDS "${make_library_EXPORT_OSX_MAP_FILE}")
set_property(TARGET ${NAME} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-exported_symbols_list,${make_library_EXPORT_OSX_MAP_FILE} ")
endif()
if(make_library_DEAD_STRIP)
set_property(TARGET ${NAME} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dead_strip")
endif()
else()
if(make_library_EXPORT_LINUX_MAP_FILE)
set_property(TARGET ${NAME} APPEND PROPERTY LINK_DEPENDS "${make_library_EXPORT_LINUX_MAP_FILE}")
set_property(TARGET ${NAME} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--version-script=${make_library_EXPORT_LINUX_MAP_FILE} ")
endif()
endif()
endmacro()
# This is an external function
# Usage:
# make_empty_library(NAME target
# REQUIRES libx liby
# MAC_REQUIRES libz libzz
# LINUX_REQUIRES libk libj
# [OUTPUT_NAME xxxx])
# Example:
#
# make_empty_library(NAME graph
# REQUIRES
# logger dl pthread z curl xml2 openssl
# MAC_REQUIRES
# iconv
# )
# This generates an empty target with the provided target name, but all
# other targets which require this target will inherit all REQUIRED
# dependencies.
#
# NAME must be specified
# REQUIRES lists all dependent libraries. These can be:
# - other libraries built by the the turicreate build system
# - builtin libraries
# - system libraries
# MAC_REQUIRES lists all dependent libraries which are included only on Mac.
# LINUX_REQUIRES lists all dependent libraries which are included only on Linux.
#
# All other targets which depends on this library (using the "requires" function)
# will automatically include all recursive dependencies.
macro(make_empty_library NAME)
set(one_value_args COMPILE_FLAGS)
set(multi_value_args REQUIRES MAC_REQUIRES LINUX_REQUIRES)
CMAKE_PARSE_ARGUMENTS(make_library "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
if (APPLE)
if (make_library_MAC_REQUIRES)
set(make_library_REQUIRES ${make_library_REQUIRES} ${make_library_MAC_REQUIRES})
endif()
else()
if (make_library_LINUX_REQUIRES)
set(make_library_REQUIRES ${make_library_REQUIRES} ${make_library_LINUX_REQUIRES})
endif()
endif()
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/dummy.cpp)
file(WRITE ${CMAKE_SOURCE_DIR}/dummy.cpp "")
endif()
add_library(${NAME} STATIC ${CMAKE_SOURCE_DIR}/dummy.cpp)
make_target_impl("${NAME}" ""
"${make_library_REQUIRES}" TRUE FALSE FALSE FALSE)
set_target_properties(${NAME} PROPERTIES EMPTY_LIBRARY TRUE)
endmacro()
# This is an external function
# Usage:
# make_binary(NAME target
# SOURCES a.cpp b.cpp
# REQUIRES libx liby
# MAC_REQUIRES libz libzz
# LINUX_REQUIRES libk libj)
# Example:
#
# make_binary(NAME wscmd
# SOURCES
# wscmd.cpp
# REQUIRES
# fileio
# )
#
# This generates a binary with the provided target name.
#
# NAME and SOURCES must be specified.
# REQUIRES lists all dependent libraries. These can be:
# - other libraries built by the the turicreate build system
# - builtin libraries
# - system libraries
# MAC_REQUIRES lists all dependent libraries which are included only on Mac.
# LINUX_REQUIRES lists all dependent libraries which are included only on Linux.
# OUTPUT_NAME is the final output name of the target. Defaults to the target name
# if not specified
#
# All other targets which depends on this library (using the "requires" function)
# will automatically include all recursive dependencies.
#
# Boost, pthread is always added as a default dependency. OpenMP is added
# when possible.
function (make_executable NAME)
set(one_value_args COMPILE_FLAGS OUTPUT_NAME)
set(multi_value_args
SOURCES REQUIRES MAC_REQUIRES LINUX_REQUIRES
COMPILE_FLAGS_EXTRA COMPILE_FLAGS_EXTRA_CLANG COMPILE_FLAGS_EXTRA_GCC)
CMAKE_PARSE_ARGUMENTS(make_library "" "${one_value_args}" "${multi_value_args}" ${ARGN})
if(NOT make_library_SOURCES)
MESSAGE(FATAL_ERROR "make_executable call with no sources")
endif()
if (APPLE)
if (make_library_MAC_REQUIRES)
set(make_library_REQUIRES ${make_library_REQUIRES} ${make_library_MAC_REQUIRES})
endif()
else()
if (make_library_LINUX_REQUIRES)
set(make_library_REQUIRES ${make_library_REQUIRES} ${make_library_LINUX_REQUIRES})
endif()
endif()
add_executable(${NAME} ${make_library_SOURCES})
if (make_library_COMPILE_FLAGS_EXTRA)
target_compile_options(${NAME} PRIVATE ${make_library_COMPILE_FLAGS_EXTRA})
endif()
if (CLANG)
if (make_library_COMPILE_FLAGS_EXTRA_CLANG)
target_compile_options(${NAME} PRIVATE ${make_library_COMPILE_FLAGS_EXTRA_CLANG})
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (make_library_COMPILE_FLAGS_EXTRA_GCC)
target_compile_options(${NAME} PRIVATE ${make_library_COMPILE_FLAGS_EXTRA_GCC})
endif()
endif()
make_target_impl("${NAME}" "${make_library_COMPILE_FLAGS}"
"${make_library_REQUIRES}" FALSE FALSE FALSE FALSE)
if (make_library_OUTPUT_NAME)
message(STATUS "make_executable ${NAME} ===> ${make_library_OUTPUT_NAME}")
set_target_properties(${NAME} PROPERTIES OUTPUT_NAME ${make_library_OUTPUT_NAME})
endif()
# this is really annoying
# There really isn't a clean way to this, but on Mac Anaconda's libpython2.7.dylib
# has it's install name set to just libpython2.7.dylib and not @rapth/libpython2.7.dylib
# We need to patch this.
if (APPLE)
add_custom_command(TARGET ${NAME} POST_BUILD
COMMAND install_name_tool $<TARGET_FILE:${NAME}> -change libpython2.7.dylib @rpath/libpython2.7.dylib)
endif()
if(NOT CLANG)
if (NOT WIN32)
# set_property(TARGET ${NAME} APPEND_STRING PROPERTY LINK_FLAGS "-static-libstdc++")
endif()
endif()
endfunction()
function (make_boost_test NAME)
set (SOURCES ${NAME})
set(args ${ARGN})
make_executable(${NAME}test SOURCES ${SOURCES} ${args})
target_link_libraries(${NAME}test boost_test)
add_test(${NAME} ${NAME}test)