@@ -17,18 +17,27 @@ SCons construction environment can be customized in sconscript.local script.
17
17
"""
18
18
19
19
import os
20
+ from os .path import join as pjoin
20
21
import platform
21
22
23
+
22
24
def subdictionary (d , keyset ):
23
25
return dict (kv for kv in d .items () if kv [0 ] in keyset )
24
26
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
+
25
34
# copy system environment variables related to compilation
26
35
DefaultEnvironment (ENV = subdictionary (os .environ , '''
27
36
PATH CPATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_RUN_PATH
28
37
LD_LIBRARY_PATH DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH
29
38
MACOSX_DEPLOYMENT_TARGET
30
39
''' .split ())
31
- )
40
+ )
32
41
33
42
# Create construction environment
34
43
env = DefaultEnvironment ().Clone ()
@@ -39,21 +48,54 @@ env.EnsureSConsVersion(0, 98, 1)
39
48
# Customizable compile variables
40
49
vars = Variables ('sconsvars.py' )
41
50
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
+
57
99
vars .Add (EnumVariable (
58
100
'build' ,
59
101
'compiler settings' ,
@@ -68,9 +110,38 @@ vars.Add(BoolVariable(
68
110
vars .Add (BoolVariable (
69
111
'with_shared_cctbx' ,
70
112
'compile and link with the shared cctbx library' , False ))
113
+
71
114
vars .Update (env )
72
115
env .Help (MY_SCONS_HELP % vars .GenerateHelpText (env ))
73
116
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
+
74
145
builddir = env .Dir ('build/%s-%s' % (env ['build' ], platform .machine ()))
75
146
76
147
Export ('env' )
0 commit comments