-
Notifications
You must be signed in to change notification settings - Fork 205
/
SConstruct
2312 lines (1862 loc) · 79.8 KB
/
SConstruct
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
##########################################################################
#
# Copyright (c) 2011-2014, John Haddon. All rights reserved.
# Copyright (c) 2011-2014, Image Engine Design Inc. All rights reserved.
# Copyright 2019, Hypothetical Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# * Neither the name of John Haddon nor the names of
# any other contributors to this software may be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################
import os
import re
import sys
import glob
import inspect
import locale
import shutil
import subprocess
import tempfile
import distutils.dir_util
import codecs
EnsureSConsVersion( 3, 0, 2 ) # Substfile is a default builder as of 3.0.2
if codecs.lookup( locale.getpreferredencoding() ).name != "utf-8" :
# The `Substfile` builder uses `open()` without specifying an encoding, and
# so gets Python's default encoding. Unless this is `UTF-8`, any `.py` files
# containing unicode characters will be corrupted during installation.
sys.stderr.write( "ERROR : Preferred encoding must be 'UTF-8'. Set PYTHONUTF8 environment variable before running `scons`.\n" )
Exit( 1 )
###############################################################################################
# Version
###############################################################################################
gafferMilestoneVersion = 1 # for announcing major milestones - may contain all of the below
gafferMajorVersion = 5 # backwards-incompatible changes
gafferMinorVersion = 0 # new backwards-compatible features
gafferPatchVersion = 0 # bug fixes
gafferVersionSuffix = "" # used for alpha/beta releases : "a1", "b2", etc.
# All of the following must be considered when determining
# whether or not a change is backwards-compatible
#
# - Library ABIs
# - Python APIs
# - Node/Plug naming
# - Application command line arguments
###############################################################################################
# Command line options
###############################################################################################
optionsFile = None
if "GAFFER_OPTIONS_FILE" in os.environ :
optionsFile = os.environ["GAFFER_OPTIONS_FILE"]
if "OPTIONS" in ARGUMENTS :
optionsFile = ARGUMENTS["OPTIONS"]
options = Variables( optionsFile, ARGUMENTS )
options.Add(
"CXX",
"The C++ compiler.",
{"darwin" : "clang++", "win32" : "cl"}.get(sys.platform, "g++")
)
options.Add(
"CXXFLAGS",
"The extra flags to pass to the C++ compiler during compilation.",
# We want `-Wextra` because some of its warnings are useful, and further useful
# warnings may be added in future. But it does introduce warnings we find unhelpful - see
# the compiler sections below where we turn them back off again.
[ "-pipe", "-Wall", "-Wextra" ] if Environment()["PLATFORM"] != "win32" else [],
)
options.Add(
EnumVariable(
"BUILD_TYPE",
"Optimisation and debug symbol configuration",
"RELEASE",
allowed_values = ('RELEASE', 'DEBUG', 'RELWITHDEBINFO')
)
)
options.Add(
"CXXSTD",
"The C++ standard to build against. A minimum of C++17 is required.",
"c++17",
)
options.Add(
BoolVariable( "WARNINGS_AS_ERRORS", "Treat compiler and linker warnings as errors.", True )
)
options.Add(
"LINKFLAGS",
"The extra flags to pass to the C++ linker during compilation.",
""
)
options.Add(
BoolVariable( "ASAN", "Enable ASan when compiling with clang++", False)
)
options.Add(
"BUILD_DIR",
"The destination directory in which the build will be made.",
os.path.join( ".", "build", "gaffer-${GAFFER_MILESTONE_VERSION}.${GAFFER_MAJOR_VERSION}.${GAFFER_MINOR_VERSION}.${GAFFER_PATCH_VERSION}${GAFFER_VERSION_SUFFIX}-${GAFFER_PLATFORM}" ),
)
options.Add(
"BUILD_CACHEDIR",
"Specify a directory for SCons to cache build results in. This allows the sharing of build results"
"among multiple developers and can significantly reduce build times, particularly when switching"
"between multiple compilers and build options.",
""
)
options.Add(
"INSTALL_DIR",
"The destination directory for the installation.",
os.path.join( ".", "install", "gaffer-${GAFFER_MILESTONE_VERSION}.${GAFFER_MAJOR_VERSION}.${GAFFER_MINOR_VERSION}.${GAFFER_PATCH_VERSION}${GAFFER_VERSION_SUFFIX}-${GAFFER_PLATFORM}" ),
)
options.Add(
"PACKAGE_FILE",
"The file in which the final gaffer file will be created by the package target.",
"${INSTALL_DIR}.tar.gz" if sys.platform != "win32" else "${INSTALL_DIR}.zip",
)
options.Add(
"DELIGHT_ROOT",
"The directory in which 3delight is installed. Used to build GafferDelight, an NSI-based"
"3delight backend.",
"",
)
options.Add(
"VTUNE_ROOT",
"The directory in which VTune is installed.",
""
)
options.Add(
"ARNOLD_ROOT",
"The directory in which Arnold is installed. Used to build GafferArnold",
"",
)
# Variables to be used when making a build which will use dependencies previously
# installed in some central location, rather than using the precompiled dependencies
# provided by the GafferHQ/dependencies project.
options.Add(
"CYCLES_ROOT",
"The directory in which Cycles is installed. Used to build GafferCycles",
os.path.join( "$BUILD_DIR", "cycles" ),
)
options.Add(
"OSLHOME",
"The directory in which OpenShadingLanguage is installed.",
"$BUILD_DIR",
)
options.Add(
"LOCATE_DEPENDENCY_CPPPATH",
"Locations on which to search for include files "
"for the dependencies. These are included with -I.",
[],
)
options.Add(
"LOCATE_DEPENDENCY_SYSTEMPATH",
"Locations on which to search for include files "
"for the dependencies. These are included with -isystem.",
[],
)
options.Add(
"LOCATE_DEPENDENCY_LIBPATH",
"The locations on which to search for libraries for "
"the dependencies.",
"",
)
options.Add(
"LOCATE_DEPENDENCY_PYTHONPATH",
"The locations on which to search for python modules for "
"the dependencies.",
"",
)
options.Add(
"LOCATE_DEPENDENCY_RESOURCESPATH",
"The path to the resources provided by the gafferResources project. "
"If you follow the build instructions using the precompiled "
"dependencies then you will not need this option.",
"",
)
options.Add(
"IMATH_LIB_SUFFIX",
"The suffix used when locating the Imath library.",
"",
)
options.Add(
"BOOST_LIB_SUFFIX",
"The suffix used when locating the boost libraries.",
"",
)
options.Add(
"BOOST_PYTHON_LIB_SUFFIX",
"The suffix appended to the names of the python boost libraries. "
"You can modify this so that the correct python library name is used, "
"likely related to the specific python version.",
)
options.Add(
"GLEW_LIB_SUFFIX",
"The suffix used when locating the glew libraries.",
"",
)
options.Add(
"CORTEX_LIB_SUFFIX",
"The suffix used when locating the cortex libraries.",
"",
)
options.Add(
"CORTEX_PYTHON_LIB_SUFFIX",
"The suffix used when locating the IECorePython library.",
"",
)
options.Add(
"OIIO_LIB_SUFFIX",
"The suffix used when locating the OpenImageIO libraries.",
"",
)
options.Add(
"OCIO_LIB_SUFFIX",
"The suffix used when locating the OpenColorIO libraries.",
"",
)
options.Add(
"OSL_LIB_SUFFIX",
"The suffix used when locating the OpenShadingLanguage libraries.",
"",
)
options.Add(
"VDB_LIB_SUFFIX",
"The suffix used when locating the OpenVDB libraries.",
"",
)
options.Add(
"USD_LIB_PREFIX",
"The prefix to prepend to the names of the USD libraries. You can modify this "
"to link against libraries installed with non-default names. "
"Should match the USD build option PXR_LIB_PREFIX",
"usd_"
)
options.Add(
BoolVariable(
"USD_MONOLITHIC",
"Set if you are using a \"monolithic\" single lib install of USD.",
False
)
)
# general variables
options.Add(
BoolVariable(
"GAFFERCORTEX",
"Builds and installs the GafferCortex modules. These are deprecated and will "
"be removed completely in a future version.",
False
)
)
options.Add(
BoolVariable(
"GAFFERUSD",
"Builds and installs the GafferUSD modules.",
True
)
)
options.Add(
"ENV_VARS_TO_IMPORT",
"By default SCons ignores the environment it is run in, to avoid it contaminating the "
"build process. This can be problematic if some of the environment is critical for "
"running the applications used during the build. This space separated list of environment "
"variables is imported to help overcome these problems.",
"",
)
options.Add(
"INKSCAPE",
"Where to find the inkscape binary",
"inkscape",
)
options.Add(
"SPHINX",
"Where to find the sphinx-build program",
"sphinx-build",
)
options.Add(
"PYBIND11",
"The directory in which pybind11 is installed."
"",
)
options.Add(
"INSTALL_POST_COMMAND",
"A command which is run following a successful install process. "
"This could be used to customise installation further for a "
"particular site.",
"",
)
options.Add( "GAFFER_MILESTONE_VERSION", "Milestone version", str( gafferMilestoneVersion ) )
options.Add( "GAFFER_MAJOR_VERSION", "Major version", str( gafferMajorVersion ) )
options.Add( "GAFFER_MINOR_VERSION", "Minor version", str( gafferMinorVersion ) )
options.Add( "GAFFER_PATCH_VERSION", "Patch version", str( gafferPatchVersion ) )
options.Add( "GAFFER_VERSION_SUFFIX", "Version suffix", str( gafferVersionSuffix ) )
###############################################################################################
# Basic environment object. All the other environments will be based on this.
###############################################################################################
###########################################################################################
# All platforms
###########################################################################################
env = Environment(
MSVC_VERSION = "14.2",
options = options,
CPPDEFINES = [
( "BOOST_FILESYSTEM_VERSION", "3" ),
"BOOST_FILESYSTEM_NO_DEPRECATED",
],
CPPPATH = [
"include",
"$LOCATE_DEPENDENCY_CPPPATH",
],
LIBPATH = [
"./lib",
"$BUILD_DIR/lib",
"$LOCATE_DEPENDENCY_LIBPATH",
],
FRAMEWORKPATH = "$BUILD_DIR/lib",
)
# include 3rd party headers with -isystem rather than -I.
# this should turn off warnings from those headers, allowing us to
# build with -Werror. there are so many warnings from boost
# in particular that this would be otherwise impossible.
systemIncludeArgument = "/external:I" if env[ "PLATFORM" ] == "win32" else "-isystem"
for path in [
"$BUILD_DIR/include",
"$BUILD_DIR/include/Imath",
"$BUILD_DIR/include/GL",
] + env["LOCATE_DEPENDENCY_SYSTEMPATH"] :
env.Append(
CXXFLAGS = [ systemIncludeArgument, path ]
)
env["BUILD_DIR"] = os.path.abspath( env["BUILD_DIR"] )
for e in env["ENV_VARS_TO_IMPORT"].split() :
if e in os.environ :
env["ENV"][e] = os.environ[e]
if env["BUILD_CACHEDIR"] != "" :
CacheDir( env["BUILD_CACHEDIR"] )
###########################################################################################
# POSIX configuration
###########################################################################################
if env["PLATFORM"] != "win32" :
# DISPLAY and HOME are essential for running gaffer when generating
# the documentation. TERM is needed to get coloured output from the
# compiler.
for e in [ "DISPLAY", "HOME", "TERM" ] :
if e in os.environ :
env["ENV"][e] = os.environ[e]
# Platform-specific config
if env["PLATFORM"] == "darwin" :
env.Append( CXXFLAGS = [ "-D__USE_ISOC99" ] )
env["GAFFER_PLATFORM"] = "macos"
else :
env["GAFFER_PLATFORM"] = "linux"
# Compiler-specific config
if "clang++" in os.path.basename( env["CXX"] ) :
env.Append(
CXXFLAGS = [ "-Wno-unused-local-typedef" ]
)
# Turn off the parts of `-Wextra` that we don't like.
env.Append( CXXFLAGS = [ "-Wno-unused-parameter" ] )
elif "g++" in os.path.basename( env["CXX"] ) :
# Get GCC version.
gccVersion = subprocess.check_output( [ env["CXX"], "-dumpversion" ], env=env["ENV"], universal_newlines=True ).strip()
if "." not in gccVersion :
# GCC 7 onwards requires `-dumpfullversion` to get minor/patch, but this
# flag does not exist on earlier GCCs, where minor/patch was provided by `-dumpversion`.
gccVersion = subprocess.check_output( [ env["CXX"], "-dumpfullversion" ], env=env["ENV"], universal_newlines=True ).strip()
gccVersion = [ int( v ) for v in gccVersion.split( "." ) ]
# GCC emits spurious "assuming signed overflow does not occur"
# warnings, typically triggered by the comparisons in Box3f::isEmpty().
# Downgrade these back to warning status.
if gccVersion >= [ 4, 2 ] :
env.Append( CXXFLAGS = [ "-Wno-error=strict-overflow" ] )
if gccVersion >= [ 5, 1 ] and gccVersion < [ 11, 2 ] :
env.Append( CXXFLAGS = [ "-D_GLIBCXX_USE_CXX11_ABI=0" ] )
if gccVersion >= [ 9, 2 ] :
env.Append( CXXFLAGS = [ "-Wsuggest-override" ] )
# Turn off the parts of `-Wextra` that we don't like.
env.Append( CXXFLAGS = [ "-Wno-cast-function-type", "-Wno-unused-parameter" ] )
# Set this weird compiler flag that in general is expected to cause compiled code to be about
# half a percent slower, but works around this ridiculous bug:
# https://gcc.gnu.org/bugzilla//show_bug.cgi?id=51041
# It's a 10 year old bug that sometimes causes important inner loops to get 4X slower for no
# reason ( it affects use of visitPixels depending on exact register usage patterns at the call
# site ), and there appears to be no real solution ... maybe we should be moving away from GCC?
env.Append( CXXFLAGS = [ "-fira-region=all" ] )
env.Append(
CXXFLAGS = [ "-pthread" ],
SHLINKFLAGS = [ "-pthread", "-Wl,--no-undefined" ],
)
# Shared config
env.Append( CXXFLAGS = [ "-std=$CXXSTD", "-fvisibility=hidden" ] )
if env["BUILD_TYPE"] == "DEBUG" :
env.Append( CXXFLAGS = ["-g", "-O0", "-DTBB_USE_DEBUG=1"] )
elif env["BUILD_TYPE"] == "RELEASE" :
env.Append( CXXFLAGS = ["-DNDEBUG", "-DBOOST_DISABLE_ASSERTS", "-O3"] )
elif env["BUILD_TYPE"] == "RELWITHDEBINFO" :
env.Append( CXXFLAGS = ["-DNDEBUG", "-DBOOST_DISABLE_ASSERTS", "-O3", "-g", "-fno-omit-frame-pointer"] )
if env["WARNINGS_AS_ERRORS"] :
env.Append(
CXXFLAGS = [ "-Werror" ],
SHLINKFLAGS = [ "-Wl,-fatal_warnings" ],
)
# Address Sanitiser
if env["ASAN"] :
env.Append(
CXXFLAGS = [ "-fsanitize=address" ],
LINKFLAGS = [ "-fsanitize=address" ],
)
if "clang++" in os.path.basename( env["CXX"] ) :
env.Append(
CXXFLAGS = [ "-shared-libasan" ],
LINKFLAGS = [ "-shared-libasan" ],
)
###########################################################################################
# Windows configuration
###########################################################################################
else:
env.Append(
CXXFLAGS = [
"/nologo", # Suppress startup banner
"/DOPENEXR_DLL", # Link to dynamic OpenEXR library
"/DIMATH_DLL", # Link to dynamic Imath library
"/DNOMINMAX", # Suppress compiler definition of `min` and `max`
"/D__PRETTY_FUNCTION__=__FUNCSIG__",
"/DBOOST_ALL_DYN_LINK",
"/DBOOST_ALL_NO_LIB",
"/W4", # Warning level 4, one level less than all warnings
"/experimental:external", # Allow use of /external:I
"/external:W0", # Suppress warnings for headers included with /external:I
"/Zc:inline", # Remove unreferenced function or data if it is COMDAT or has internal linkage only
"/GR", # Enable RTTI
"/TP", # Treat all files as c++ (vs C)
"/FC", # Display full paths in diagnostics
"/EHsc", # Catch c++ exceptions only
"/MP", # Enable multiprocessing of builds
"/permissive-", # Disable permissive mode, which also enables standard compliant two phase name lookup
"/D_USE_MATH_DEFINES", # Required when permissive mode is off, for defining constants like M_PI used by OpenVDB
"/std:$CXXSTD",
"/DHAVE_SNPRINTF", # Fix a legacy issue for MSVC versions < 2019
]
)
if env["WARNINGS_AS_ERRORS"] :
env.Append(
CXXFLAGS = [
"/WX", # Treat warnings as errors
# We are building all client code in the exact same environment, so we can safely
# disable warnings about missing dll interfaces, and require clients to use
# the same compiler for maximum compatibility.
"/wd4251",
"/wd4100", # Suppress warning about unused parameters
"/wd4706", # Suppress warning about using assignment in conditionals
"/wd4267", # Suppress warning about conversion from int to size_t
"/wd4244", # Suppress warning about possible loss of data in type conversion
"/wd4305", # Suppress warning about conversion from double to float
"/D_CRT_SECURE_NO_WARNINGS", # Suppress warnings about getenv and similar
# NOTE : the following warnings are generated by external dependencies, even when using /external
# They may be able to be re-enabled after updating to MSVC 2022.
"/wd4127", # suppress warning "conditional expression is constant", Needed for USD
"/wd4456", # suppress warning "declaration of 'x' hides previous local declaration"
"/wd4459", # suppress warning "declaration of 'x' hides global declaration"
"/wd4201", # suppress warning "nonstandard extension used : nameless struct/union"
# suppress warning about exported class deriving from non-exported class. See
# comment for /wd4251 for more explanation.
"/wd4275",
"/wd4324", # suppress warning "structure was padded due to alignment specifier". Needed by cycles\kernel\types.h
"/wd4458", # suppress warning "declaration of 'variable' hides class member". Needed by cycles\scene\shader_nodes.h and cycles\util\ssef.h
"/wd4003", # suppress warning "not enough arguments for function-like macro invocation 'BOOST_PP_SEQ_DETAIL_IS_NOT_EMPTY'". Needed for USD.
"/wd4702", # suppress warning "unreachable code". Need for OpenVDB.
"/wd4180", # suppress warning "qualifier applied to function type has no meaning; ignored". Needed for OpenVDB
],
)
if env["BUILD_TYPE"] == "DEBUG" :
env.Append(
CXXFLAGS =
[
"/O0",
"/Zi",
"/MDd",
"/DBOOST_DISABLE_ASSERTS",
"/bigobj",
],
CCPDBFLAGS=
[
"/Zi",
"/Fd${TARGET}.pdb",
],
)
elif env["BUILD_TYPE"] == "RELEASE" :
env.Append(
CXXFLAGS =
[
"/DNDEBUG",
"/MD", # create multithreaded DLL
"/DBOOST_DISABLE_ASSERTS",
"/O2",
# /Og optimization (included via /O2) generates lots of unreachable
# code warnings from boost::intrusive_ptr. Disabled in release build only.
"/wd4702"
]
)
elif env["BUILD_TYPE"] == "RELWITHDEBINFO" :
env.Append(
CXXFLAGS =
[
"/DNDEBUG",
"/MD",
"/bigobj",
"/DBOOST_DISABLE_ASSERTS",
"/Zi",
],
LINKFLAGS =
[
"/DEBUG",
],
CCPDBFLAGS=
[
"/Zi",
"/Fd${TARGET}.pdb",
],
)
# Reorder build commands so that `/external:I` includes come after `/I` includes.
# Otherwise we'll pick up the Gaffer includes from the build directory, and not
# the ones in the source tree.
for command, cxxFlags in [
( "CXXCOM", "$CXXFLAGS" ),
( "SHCXXCOM", "$SHCXXFLAGS" )
] :
if env[command].index( cxxFlags ) < env[command].index( "$_CCCOMCOM" ) :
# `$_CCCOMCOM` contains the preprocessor flags, including `/I`. Swap
# it with `cxxFlags`, which contains `/external:I`.
env[command] = env[command].replace( cxxFlags, "<>" ).replace( "$_CCCOMCOM", cxxFlags ).replace( "<>", "$_CCCOMCOM" )
###############################################################################################
# Check for inkscape and sphinx
###############################################################################################
def findOnPath( file, path ) :
if os.path.isabs( file ) :
return file if os.path.exists( file ) else None
else :
if isinstance( path, str ) :
path = path.split( os.pathsep )
for p in path :
f = os.path.join( p, file )
if os.path.exists( f ) :
return f
return None
def checkInkscape(context):
context.Message('Checking for Inkscape... ')
result = bool( findOnPath( context.sconf.env['INKSCAPE'], os.environ["PATH"] ) )
context.Result(result)
return result
def checkSphinx( context ) :
context.Message( "Checking for Sphinx..." )
result = bool( findOnPath( context.sconf.env["SPHINX"], context.sconf.env["ENV"]["PATH"] ) )
context.Result( result )
return result
def checkQtVersion( context ) :
context.Message( "Checking for Qt..." )
program = """
#include <iostream>
#include "QtCore/qconfig.h"
int main()
{
#ifdef QT_VERSION_MAJOR
std::cout << QT_VERSION_MAJOR;
#else
std::cout << 4;
#endif
return 0;
}
"""
result = context.TryRun( program, ".cpp" )
if result[0] :
context.sconf.env["QT_VERSION"] = result[1]
context.Result( result[0] )
return result[0]
conf = Configure(
env,
custom_tests = {
"checkInkscape" : checkInkscape,
"checkSphinx" : checkSphinx,
"checkQtVersion" : checkQtVersion,
}
)
haveInkscape = conf.checkInkscape()
if not haveInkscape and env["INKSCAPE"] != "disableGraphics" :
sys.stderr.write( "ERROR : Inkscape not found. Check INKSCAPE build variable.\n" )
Exit( 1 )
if haveInkscape:
inkscapeHelp = subprocess.check_output( [ env["INKSCAPE"], "--help" ], universal_newlines=True )
env["INKSCAPE_USE_EXPORT_FILENAME"] = True if "--export-filename" in inkscapeHelp else False
haveSphinx = conf.checkSphinx()
if not conf.checkQtVersion() :
sys.stderr.write( "Qt not found\n" )
Exit( 1 )
###############################################################################################
# An environment for running commands with access to the applications we've built
###############################################################################################
def split( stringOrList, separator = os.path.pathsep ) :
if isinstance( stringOrList, list ) :
return stringOrList
else :
return stringOrList.split( separator )
commandEnv = env.Clone()
commandEnv["ENV"]["PATH"] = commandEnv.subst( "$BUILD_DIR/bin" + os.path.pathsep ) + commandEnv["ENV"]["PATH"]
if env["PLATFORM"] == "win32" :
commandEnv["ENV"]["PATH"] = commandEnv.subst( "$BUILD_DIR/lib" + os.path.pathsep ) + commandEnv["ENV"]["PATH"]
if commandEnv["PLATFORM"] == "darwin" :
commandEnv["ENV"]["DYLD_LIBRARY_PATH"] = commandEnv.subst( ":".join(
[ "/System/Library/Frameworks/ImageIO.framework/Resources", "$BUILD_DIR/lib" ] +
split( commandEnv["LOCATE_DEPENDENCY_LIBPATH"] )
) )
commandEnv["ENV"]["DYLD_FRAMEWORK_PATH"] = commandEnv.subst( ":".join(
[ "$BUILD_DIR/lib" ] + split( commandEnv["LOCATE_DEPENDENCY_LIBPATH"] )
) )
elif commandEnv["PLATFORM"] == "win32" :
commandEnv["ENV"]["PATH"] = commandEnv.subst( ";".join( [ "$BUILD_DIR/lib" ] + split( commandEnv[ "LOCATE_DEPENDENCY_LIBPATH" ] ) + [ commandEnv["ENV"]["PATH"] ] ) )
else:
commandEnv["ENV"]["LD_LIBRARY_PATH"] = commandEnv.subst( ":".join( [ "$BUILD_DIR/lib" ] + split( commandEnv["LOCATE_DEPENDENCY_LIBPATH"] ) ) )
commandEnv["ENV"]["PYTHONPATH"] = commandEnv.subst( os.path.pathsep.join( [ "$BUILD_DIR/python" ] + split( commandEnv["LOCATE_DEPENDENCY_PYTHONPATH"] ) ) )
# SIP on MacOS prevents DYLD_LIBRARY_PATH being passed down so we make sure
# we also pass through to gaffer the other base vars it uses to populate paths
# for third-party support.
for v in ( 'ARNOLD_ROOT', 'DELIGHT_ROOT' ) :
commandEnv["ENV"][ v ] = commandEnv[ v ]
def runCommand( command ) :
command = commandEnv.subst( command )
sys.stderr.write( command + "\n" )
return subprocess.check_output( command, shell=True, env=commandEnv["ENV"], universal_newlines=True )
###############################################################################################
# The basic environment for building libraries
###############################################################################################
baseLibEnv = env.Clone()
baseLibEnv.Append(
LIBS = [
"boost_filesystem$BOOST_LIB_SUFFIX",
"boost_regex$BOOST_LIB_SUFFIX",
"boost_chrono$BOOST_LIB_SUFFIX",
"tbb",
"fmt",
"Imath$IMATH_LIB_SUFFIX",
"IECore$CORTEX_LIB_SUFFIX",
"fmt"
],
)
# Determine boost version
boostVersionHeader = baseLibEnv.FindFile(
"boost/version.hpp",
[ "$BUILD_DIR/include" ] +
baseLibEnv["LOCATE_DEPENDENCY_SYSTEMPATH"] +
baseLibEnv["LOCATE_DEPENDENCY_CPPPATH"]
)
if not boostVersionHeader :
sys.stderr.write( "ERROR : unable to find \"boost/version.hpp\".\n" )
Exit( 1 )
with open( str( boostVersionHeader ) ) as f :
for line in f.readlines() :
m = re.match( "^#define BOOST_LIB_VERSION \"(.*)\"\s*$", line )
if m :
boostVersion = m.group( 1 )
m = re.match( "^([0-9]+)_([0-9]+)(?:_([0-9]+)|)$", boostVersion )
baseLibEnv["BOOST_MAJOR_VERSION"] = m.group( 1 )
baseLibEnv["BOOST_MINOR_VERSION"] = m.group( 2 )
if "BOOST_MAJOR_VERSION" not in baseLibEnv :
sys.stderr.write( "ERROR : unable to determine boost version from \"{}\".\n".format( boostVersionHeader ) )
Exit( 1 )
if ( int( baseLibEnv["BOOST_MAJOR_VERSION"] ), int( baseLibEnv["BOOST_MINOR_VERSION"] ) ) < ( 1, 80 ) :
# Older versions of boost deprecated `boost/bind.hpp` in favour of
# `boost/bind/bind.hpp`, but left `boost::python` and others still using the
# deprecated header, so we define BOOST_BIND_GLOBAL_PLACEHOLDERS to silence
# the reams of warnings triggered by that.
baseLibEnv.Append( CPPDEFINES = [ "BOOST_BIND_GLOBAL_PLACEHOLDERS" ] )
###############################################################################################
# The basic environment for building python modules
###############################################################################################
basePythonEnv = baseLibEnv.Clone()
pythonExecutable = shutil.which( "python", path = commandEnv["ENV"]["PATH"] )
basePythonEnv["PYTHON_VERSION"] = subprocess.check_output(
[ pythonExecutable, "-c", "import sys; print( '{}.{}'.format( *sys.version_info[:2] ) )" ],
env=commandEnv["ENV"], universal_newlines=True
).strip()
if basePythonEnv["PLATFORM"] == "win32" :
basePythonEnv["PYTHON_VERSION"] = basePythonEnv["PYTHON_VERSION"].replace( ".", "" )
basePythonEnv["PYTHON_ABI_VERSION"] = basePythonEnv["PYTHON_VERSION"]
basePythonEnv["PYTHON_ABI_VERSION"] += subprocess.check_output(
[ pythonExecutable, "-c", "import sysconfig; print( sysconfig.get_config_var( 'abiflags' ) or '' )" ],
env=commandEnv["ENV"], universal_newlines=True
).strip()
# if BOOST_PYTHON_LIB_SUFFIX is provided, use it
boostPythonLibSuffix = basePythonEnv.get( "BOOST_PYTHON_LIB_SUFFIX", None )
if boostPythonLibSuffix is None :
basePythonEnv["BOOST_PYTHON_LIB_SUFFIX"] = basePythonEnv["BOOST_LIB_SUFFIX"]
if ( int( basePythonEnv["BOOST_MAJOR_VERSION"] ), int( basePythonEnv["BOOST_MINOR_VERSION"] ) ) >= ( 1, 67 ) :
basePythonEnv["BOOST_PYTHON_LIB_SUFFIX"] = basePythonEnv["PYTHON_VERSION"].replace( ".", "" ) + basePythonEnv["BOOST_PYTHON_LIB_SUFFIX"]
basePythonEnv.Append(
CPPDEFINES = [
( "BOOST_PYTHON_MAX_ARITY", "20" ),
],
LIBS = [
"boost_python$BOOST_PYTHON_LIB_SUFFIX",
"IECorePython$CORTEX_PYTHON_LIB_SUFFIX",
"Gaffer",
"python$PYTHON_ABI_VERSION",
],
)
if basePythonEnv["PLATFORM"]=="darwin" :
basePythonEnv.Append(
CPPPATH = [ "$BUILD_DIR/lib/Python.framework/Versions/$PYTHON_VERSION/include/python$PYTHON_VERSION" ],
LIBS = [ "python$PYTHON_VERSION" ],
LIBPATH = [ "$BUILD_DIR/lib/Python.framework/Versions/$PYTHON_VERSION/lib" ]
)
else :
basePythonEnv.Append(
CPPPATH = [ "$BUILD_DIR/include/python$PYTHON_ABI_VERSION" ]
)
if basePythonEnv["PLATFORM"] == "win32" :
basePythonEnv.Append( LIBPATH = "$BUILD_DIR/libs" )
###############################################################################################
# Arnold configuration
###############################################################################################
arnoldInstallRoot = ""
if env["ARNOLD_ROOT"] :
# Version
arnoldHeader = env.subst( "$ARNOLD_ROOT/include/ai_version.h" )
if not os.path.exists( arnoldHeader ) :
sys.stderr.write( "ERROR : unable to find \"{}\".\n".format( arnoldHeader ) )
Exit( 1 )
arnoldVersions = {}
for line in open( arnoldHeader ) :
m = re.match( "^#define AI_VERSION_(ARCH|MAJOR)_NUM\s*([0-9]+)", line )
if m :
arnoldVersions[m.group(1)] = m.group( 2 )
if set( arnoldVersions.keys() ) != { "ARCH", "MAJOR" } :
sys.stderr.write( "ERROR : unable to parse \"{}\".\n".format( arnoldHeader ) )
Exit( 1 )
# Install root
arnoldInstallRoot = "${{BUILD_DIR}}/arnold/{ARCH}.{MAJOR}".format( **arnoldVersions )
###############################################################################################
# Definitions for the libraries we wish to build
###############################################################################################
# When Cycles is built, it uses several preprocessor variables that enable and
# disable various features, and sometimes those defines are used to omit or
# include members in public classes : *they affect ABI*. Traditionally a library
# would provide a header which reproduced such definitions for client code, but
# not Cycles : we must do that ourselves, to the point where we're even telling
# it what namespace it was built in.
#
# When encountering mysterious GafferCycles memory corruptions, your first port of
# call should be to ensure that these defines line up with Cycles' build-time
# settings, lest the ABIs be misaligned.
cyclesDefines = [
( "CCL_NAMESPACE_BEGIN", "namespace ccl {" ),
( "CCL_NAMESPACE_END", "}" ),
( "EMBREE_MAJOR_VERSION", "4" ),
( "PATH_GUIDING_LEVEL", "5" ),
( "WITH_ALEMBIC" ),
( "WITH_EMBREE" ),
( "WITH_OCIO" ),
( "WITH_OPENSUBDIV" ),
( "WITH_OPENVDB" ),
( "WITH_NANOVDB" ),
( "WITH_OSL" ),
( "WITH_PATH_GUIDING" ),
( "WITH_SYSTEM_PUGIXML" ),
# Technically these are not actually right for all builds - we
# currently only build GPU support for GCC 11 builds. But they
# don't currently affect ABI, and it won't be long till they
# apply everywhere.
( "WITH_CUDA" ),
( "WITH_CUDA_DYNLOAD" ),
( "WITH_OPTIX" ),
]
cyclesLibraries = [
"cycles_session", "cycles_scene", "cycles_graph", "cycles_bvh", "cycles_device", "cycles_kernel", "cycles_kernel_osl",
"cycles_integrator", "cycles_util", "cycles_subd", "extern_sky", "extern_cuew"
]
# It's very weird to link the Cycles static libraries twice, to both
# lib/libGafferCycles.so and python/GafferCycles/_GafferCycles.so, resulting in 2 copies of everything.
# This has caused issues on Ubuntu where the init stuff cycles_session runs twice, terminating Gaffer with an
# exception when the node buffer_pass is registered twice. It seems to work fine on Linux if we don't double
# link it - the symbols from the static library can be included just in libGafferCycles, and the dynamic linker
# will find them OK.
# But on Windows, it seems the symbols from the static libraries aren't made available in libGafferCycles, so
# it wouldn't work to just link them once. It is currently unknown why Windows doesn't have problems with
# running the initialization in cycles_session twice.
# Hopefully this hackery works for now - we're hoping in the long run, Cycles might ship as a dynamic lib, which
# would simplify all this.
includeCyclesLibrariesInPythonModule = env["PLATFORM"] == "win32"
libraries = {
"Gaffer" : {},
"GafferTest" : {
"envAppends" : {
"LIBS" : [ "Gaffer" ],
},
"pythonEnvAppends" : {
"LIBS" : [ "GafferTest", "GafferBindings" ],
},
"additionalFiles" : glob.glob( "python/GafferTest/*/*" ) + glob.glob( "python/GafferTest/*/*/*" ),
"apps" : [ "cli", "env", "license", "python", "stats", "test" ],
},
"GafferUI" : {
"envAppends" : {
## \todo Stop linking against `Iex`. It is only necessary on Windows Imath 2 builds.
"LIBS" : [ "Gaffer", "Iex$IMATH_LIB_SUFFIX", "IECoreGL$CORTEX_LIB_SUFFIX", "IECoreImage$CORTEX_LIB_SUFFIX", "IECoreScene$CORTEX_LIB_SUFFIX", "OpenImageIO$OIIO_LIB_SUFFIX", "OpenImageIO_Util$OIIO_LIB_SUFFIX" ],
},
"pythonEnvAppends" : {