Skip to content

Commit 71d7507

Browse files
committed
Update build configuration for windows (visual studio)
1 parent 4ed41c9 commit 71d7507

File tree

3 files changed

+112
-38
lines changed

3 files changed

+112
-38
lines changed

SConstruct

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ SCons construction environment can be customized in sconscript.local script.
1717
"""
1818

1919
import os
20+
from os.path import join as pjoin
2021
import platform
2122

2223
def subdictionary(d, keyset):
2324
return dict(kv for kv in d.items() if kv[0] in keyset)
2425

26+
def getsyspaths(*names):
27+
pall = sum((os.environ.get(n, '').split(os.pathsep) for n in names), [])
28+
rv = [p for p in pall if os.path.exists(p)]
29+
return rv
30+
2531
# copy system environment variables related to compilation
2632
DefaultEnvironment(ENV=subdictionary(os.environ, '''
2733
PATH CPATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_RUN_PATH
@@ -39,21 +45,52 @@ env.EnsureSConsVersion(0, 98, 1)
3945
# Customizable compile variables
4046
vars = Variables('sconsvars.py')
4147

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))
48+
if 'CONDA_PREFIX' in os.environ:
49+
# building for a conda environment
50+
vars.Add(PathVariable(
51+
'prefix',
52+
'installation prefix directory',
53+
os.environ['CONDA_PREFIX']))
54+
vars.Update(env)
55+
if platform.system().lower() == "windows":
56+
vars.Add(PathVariable(
57+
'libdir',
58+
'installation directory for compiled library [prefix/Library/lib]',
59+
pjoin(env['prefix'],'Library', 'Lib'),
60+
PathVariable.PathAccept))
61+
vars.Add(PathVariable(
62+
'includedir',
63+
'installation directory for C++ header files [prefix/Library/include]',
64+
pjoin(env['prefix'],'Library', 'include'),
65+
PathVariable.PathAccept))
66+
else:
67+
vars.Add(PathVariable(
68+
'libdir',
69+
'installation directory for compiled library [prefix/lib]',
70+
pjoin(env['prefix'], 'Lib'),
71+
PathVariable.PathAccept))
72+
vars.Add(PathVariable(
73+
'includedir',
74+
'installation directory for C++ header files [prefix/include]',
75+
pjoin(env['prefix'], 'include'),
76+
PathVariable.PathAccept))
77+
else:
78+
vars.Add(PathVariable(
79+
'prefix',
80+
'installation prefix directory',
81+
'/usr/local'))
82+
vars.Update(env)
83+
vars.Add(PathVariable(
84+
'libdir',
85+
'installation directory for compiled library [prefix/lib]',
86+
env['prefix'] + '/lib',
87+
PathVariable.PathAccept))
88+
vars.Add(PathVariable(
89+
'includedir',
90+
'installation directory for C++ header files [prefix/include]',
91+
env['prefix'] + '/include',
92+
PathVariable.PathAccept))
93+
5794
vars.Add(EnumVariable(
5895
'build',
5996
'compiler settings',
@@ -71,6 +108,26 @@ vars.Add(BoolVariable(
71108
vars.Update(env)
72109
env.Help(MY_SCONS_HELP % vars.GenerateHelpText(env))
73110

111+
if platform.system().lower() == "windows":
112+
# See https://scons.org/faq.html#Linking_on_Windows_gives_me_an_error
113+
env['ENV']['TMP'] = os.environ['TMP']
114+
# the CPPPATH directories are checked by scons dependency scanner
115+
cpppath = getsyspaths('CPLUS_INCLUDE_PATH', 'CPATH')
116+
env.AppendUnique(CPPPATH=cpppath)
117+
# Insert LIBRARY_PATH explicitly because some compilers
118+
# ignore it in the system environment.
119+
env.PrependUnique(LIBPATH=getsyspaths('LIBRARY_PATH'))
120+
if 'CONDA_PREFIX' in os.environ:
121+
env.Append(CPPPATH=pjoin(os.environ['CONDA_PREFIX'],'include'))
122+
env.Append(CPPPATH=pjoin(os.environ['CONDA_PREFIX'],'Library','include'))
123+
env.Append(LIBPATH=pjoin(os.environ['CONDA_PREFIX'],'Library','lib'))
124+
# This disable automated versioned named e.g. libboost_date_time-vc142-mt-s-x64-1_73.lib
125+
# so we can use conda-installed libraries
126+
env.AppendUnique(CPPDEFINES='BOOST_ALL_NO_LIB')
127+
# Prevent the generation of an import lib (.lib) in addition to the dll
128+
# Unused as we are using as static library for windows
129+
# env.AppendUnique(no_import_lib=1)
130+
74131
builddir = env.Dir('build/%s-%s' % (env['build'], platform.machine()))
75132

76133
Export('env')

src/ObjCryst/version.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ struct libobjcryst_version_info {
8080
static const char* date;
8181
static const char* git_commit;
8282
// git_sha is deprecated. Use git_commit instead.
83+
#ifndef _MSC_VER
8384
static const char* git_sha __attribute__ ((deprecated));
85+
#else
86+
__declspec(deprecated) static const char* git_sha;
87+
#endif
8488

8589
};
8690

src/SConscript

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import platform
23

34
Import('env')
45

@@ -26,27 +27,33 @@ if env['PLATFORM'] == 'darwin':
2627
fast_linkflags[:] = []
2728

2829
# Compiler specific options
29-
if icpc:
30-
# options for Intel C++ compiler on hpc dev-intel07
31-
env.PrependUnique(CCFLAGS=['-w1', '-fp-model', 'precise'])
32-
env.PrependUnique(LIBS=['imf'])
33-
fast_optimflags = ['-fast', '-no-ipo']
34-
else:
35-
# g++ options
36-
env.PrependUnique(CCFLAGS=['-Wall'])
37-
fast_optimflags = ['-ffast-math']
38-
39-
# Configure build variants
40-
if env['build'] == 'debug':
41-
env.Append(CCFLAGS='-g')
42-
elif env['build'] == 'fast':
43-
env.AppendUnique(CCFLAGS=['-O3'] + fast_optimflags)
30+
if platform.system().lower() == "windows":
31+
# Visual c++
32+
env.PrependUnique(CCFLAGS=['/Ox', '/EHsc'])
4433
env.AppendUnique(CPPDEFINES={'NDEBUG' : None})
45-
env.AppendUnique(LINKFLAGS=fast_linkflags)
46-
47-
if env['profile']:
48-
env.AppendUnique(CCFLAGS='-pg')
49-
env.AppendUnique(LINKFLAGS='-pg')
34+
# env.AppendUnique(LINKFLAGS='/EXPORT')
35+
else:
36+
if icpc:
37+
# options for Intel C++ compiler on hpc dev-intel07
38+
env.PrependUnique(CCFLAGS=['-w1', '-fp-model', 'precise'])
39+
env.PrependUnique(LIBS=['imf'])
40+
fast_optimflags = ['-fast', '-no-ipo']
41+
else:
42+
# g++ options
43+
env.PrependUnique(CCFLAGS=['-Wall'])
44+
fast_optimflags = ['-ffast-math']
45+
46+
# Configure build variants
47+
if env['build'] == 'debug':
48+
env.Append(CCFLAGS='-g')
49+
elif env['build'] == 'fast':
50+
env.AppendUnique(CCFLAGS=['-O3'] + fast_optimflags)
51+
env.AppendUnique(CPPDEFINES={'NDEBUG' : None})
52+
env.AppendUnique(LINKFLAGS=fast_linkflags)
53+
54+
if env['profile']:
55+
env.AppendUnique(CCFLAGS='-pg')
56+
env.AppendUnique(LINKFLAGS='-pg')
5057

5158
# Lists for storing built objects and header files
5259
env['newmatobjs'] = []
@@ -72,9 +79,15 @@ newmatobjs = env["newmatobjs"]
7279
cctbxobjs = env["cctbxobjs"]
7380
objcrystobjs = env["objcrystobjs"]
7481

75-
# This builds the shared library
76-
libobjcryst = env.SharedLibrary("libObjCryst",
77-
objcrystobjs + cctbxobjs + newmatobjs)
82+
# This builds the library
83+
if platform.system().lower() == "windows":
84+
# Use a static library (does not require __declspec(dllexport) all over the code)
85+
libobjcryst = env.StaticLibrary("libObjCryst",
86+
objcrystobjs + cctbxobjs + newmatobjs)
87+
else:
88+
libobjcryst = env.SharedLibrary("libObjCryst",
89+
objcrystobjs + cctbxobjs + newmatobjs)
90+
7891
lib = Alias('lib', [libobjcryst, env['lib_includes']])
7992
Default(lib)
8093

0 commit comments

Comments
 (0)