@@ -17,18 +17,27 @@ SCons construction environment can be customized in sconscript.local script.
1717"""
1818
1919import os
20+ from os .path import join as pjoin
2021import platform
2122
23+
2224def subdictionary (d , keyset ):
2325 return dict (kv for kv in d .items () if kv [0 ] in keyset )
2426
27+
28+ def getsyspaths (* names ):
29+ pall = sum ((os .environ .get (n , '' ).split (os .pathsep ) for n in names ), [])
30+ rv = [p for p in pall if os .path .exists (p )]
31+ return rv
32+
33+
2534# copy system environment variables related to compilation
2635DefaultEnvironment (ENV = subdictionary (os .environ , '''
2736 PATH CPATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_RUN_PATH
2837 LD_LIBRARY_PATH DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH
2938 MACOSX_DEPLOYMENT_TARGET
3039 ''' .split ())
31- )
40+ )
3241
3342# Create construction environment
3443env = DefaultEnvironment ().Clone ()
@@ -39,21 +48,54 @@ env.EnsureSConsVersion(0, 98, 1)
3948# Customizable compile variables
4049vars = Variables ('sconsvars.py' )
4150
42- vars .Add (PathVariable (
43- 'prefix' ,
44- 'installation prefix directory' ,
45- '/usr/local' ))
46- vars .Update (env )
47- vars .Add (PathVariable (
48- 'libdir' ,
49- 'installation directory for compiled library [prefix/lib]' ,
50- env ['prefix' ] + '/lib' ,
51- PathVariable .PathAccept ))
52- vars .Add (PathVariable (
53- 'includedir' ,
54- 'installation directory for C++ header files [prefix/include]' ,
55- env ['prefix' ] + '/include' ,
56- PathVariable .PathAccept ))
51+ # TODO: also amend paths when VIRTUAL_ENV variable exists,
52+ # if CONDA_PREFIX does not exist ?
53+ if 'CONDA_PREFIX' in os .environ :
54+ # building for a conda environment
55+ vars .Add (PathVariable (
56+ 'prefix' ,
57+ 'installation prefix directory' ,
58+ os .environ ['CONDA_PREFIX' ]))
59+ vars .Update (env )
60+ if platform .system ().lower () == "windows" :
61+ vars .Add (PathVariable (
62+ 'libdir' ,
63+ 'installation directory for compiled library [prefix/Library/lib]' ,
64+ pjoin (env ['prefix' ], 'Library' , 'Lib' ),
65+ PathVariable .PathAccept ))
66+ vars .Add (PathVariable (
67+ 'includedir' ,
68+ 'installation directory for C++ header files [prefix/Library/include]' ,
69+ pjoin (env ['prefix' ], 'Library' , 'include' ),
70+ PathVariable .PathAccept ))
71+ else :
72+ vars .Add (PathVariable (
73+ 'libdir' ,
74+ 'installation directory for compiled library [prefix/lib]' ,
75+ pjoin (env ['prefix' ], 'lib' ),
76+ PathVariable .PathAccept ))
77+ vars .Add (PathVariable (
78+ 'includedir' ,
79+ 'installation directory for C++ header files [prefix/include]' ,
80+ pjoin (env ['prefix' ], 'include' ),
81+ PathVariable .PathAccept ))
82+ else :
83+ vars .Add (PathVariable (
84+ 'prefix' ,
85+ 'installation prefix directory' ,
86+ '/usr/local' ))
87+ vars .Update (env )
88+ vars .Add (PathVariable (
89+ 'libdir' ,
90+ 'installation directory for compiled library [prefix/lib]' ,
91+ env ['prefix' ] + '/lib' ,
92+ PathVariable .PathAccept ))
93+ vars .Add (PathVariable (
94+ 'includedir' ,
95+ 'installation directory for C++ header files [prefix/include]' ,
96+ env ['prefix' ] + '/include' ,
97+ PathVariable .PathAccept ))
98+
5799vars .Add (EnumVariable (
58100 'build' ,
59101 'compiler settings' ,
@@ -68,9 +110,38 @@ vars.Add(BoolVariable(
68110vars .Add (BoolVariable (
69111 'with_shared_cctbx' ,
70112 'compile and link with the shared cctbx library' , False ))
113+
71114vars .Update (env )
72115env .Help (MY_SCONS_HELP % vars .GenerateHelpText (env ))
73116
117+ if platform .system ().lower () == "windows" :
118+ # See https://scons.org/faq.html#Linking_on_Windows_gives_me_an_error
119+ env ['ENV' ]['TMP' ] = os .environ ['TMP' ]
120+ # Prevent the generation of an import lib (.lib) in addition to the dll
121+ # Unused as we are using as static library for windows
122+ # env.AppendUnique(no_import_lib=1)
123+ if 'CONDA_PREFIX' in os .environ :
124+ env .Append (CPPPATH = [pjoin (os .environ ['CONDA_PREFIX' ], 'include' )])
125+ env .Append (CPPPATH = [pjoin (os .environ ['CONDA_PREFIX' ], 'Library' , 'include' )])
126+ env .Append (LIBPATH = pjoin (os .environ ['CONDA_PREFIX' ], 'Library' , 'lib' ))
127+ else :
128+ if 'CONDA_PREFIX' in os .environ :
129+ env .Append (CPPPATH = pjoin (os .environ ['CONDA_PREFIX' ], 'include' ))
130+ env .Append (LIBPATH = pjoin (os .environ ['CONDA_PREFIX' ], 'lib' ))
131+ # Specify minimum C++ standard. Allow later standard from sconscript.local.
132+ # In case of multiple `-std` options the last option holds.
133+ env .PrependUnique (CXXFLAGS = '-std=c++11' , delete_existing = 1 )
134+
135+ # the CPPPATH directories are checked by scons dependency scanner
136+ cpppath = getsyspaths ('CPLUS_INCLUDE_PATH' , 'CPATH' )
137+ env .AppendUnique (CPPPATH = cpppath )
138+ # Insert LIBRARY_PATH explicitly because some compilers
139+ # ignore it in the system environment.
140+ env .PrependUnique (LIBPATH = getsyspaths ('LIBRARY_PATH' ))
141+ # This disable automated versioned named e.g. libboost_date_time-vc142-mt-s-x64-1_73.lib
142+ # so we can use conda-installed libraries
143+ env .AppendUnique (CPPDEFINES = 'BOOST_ALL_NO_LIB' )
144+
74145builddir = env .Dir ('build/%s-%s' % (env ['build' ], platform .machine ()))
75146
76147Export ('env' )
0 commit comments