Skip to content

Commit a1e7fa7

Browse files
committed
build: fix Windows build settings
1 parent 0769619 commit a1e7fa7

5 files changed

Lines changed: 22 additions & 6 deletions

File tree

‎SConstruct‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ if env['PLATFORM'] == "win32":
7070
lib_path = pjoin(env['prefix'], 'Library', 'lib')
7171
shared_path = pjoin(env['prefix'], 'Library', 'share')
7272

73-
env['ENV']['TMP'] = os.environ['TMP']
73+
# Windows programs started by SCons, such as python for cxxtestgen,
74+
# fail without these system variables.
75+
for k in ('SYSTEMROOT', 'SYSTEMDRIVE', 'COMSPEC', 'PATHEXT', 'TEMP', 'TMP'):
76+
if k in os.environ:
77+
env['ENV'][k] = os.environ[k]
7478
else:
7579
include_path = pjoin(env['prefix'], 'include')
7680
lib_path = pjoin(env['prefix'], 'lib')

‎news/windows.rst‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Support building libdiffpy on Windows with MSVC, clang or MinGW, merged from the upstream ``windows`` branch.
44
* Export the public API from the Windows DLL with the ``DLL_EXPORT`` macro in ``diffpy/Export.hpp``.
55
* Install headers, libraries and data under ``$PREFIX`` or ``$CONDA_PREFIX`` by default, using the ``Library/`` layout on Windows.
6-
* Add a Windows build and test job to the pull request CI.
76
* Add a clang-format pre-commit hook and ``.git-blame-ignore-revs`` for the reformat commits.
87

98
**Changed:**

‎src/SConscript‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ if env['PLATFORM'] == 'darwin':
4848

4949
# Compiler specific options
5050
if env['PLATFORM'] == 'win32':
51-
# BUILD_DLL makes DLL_EXPORT export symbols, see diffpy/Export.hpp.
52-
env.AppendUnique(CPPDEFINES=['BUILD_DLL', '_USE_MATH_DEFINES'])
51+
env.AppendUnique(CPPDEFINES=['_USE_MATH_DEFINES'])
5352
if env['tool'] == 'clang':
5453
# clang++ on Windows
5554
env['CC'] = 'clang'
@@ -63,7 +62,10 @@ if env['PLATFORM'] == 'win32':
6362
env.AppendUnique(LINKFLAGS='-m64')
6463
else:
6564
# Visual C++
66-
env.PrependUnique(CCFLAGS=['/Ox', '/EHsc', '/MD', '/Wall'])
65+
# /W3 rather than /Wall, which floods the log with warnings from the
66+
# standard library and boost headers. /bigobj is needed for the
67+
# boost serialization code.
68+
env.PrependUnique(CCFLAGS=['/Ox', '/EHsc', '/MD', '/W3', '/bigobj'])
6769
env.AppendUnique(CXXFLAGS='/std:c++latest')
6870
env.AppendUnique(CPPDEFINES={'NDEBUG': None})
6971
env.AppendUnique(LINKFLAGS=['/OPT:NOREF', '/OPT:NOICF'])
@@ -167,6 +169,10 @@ if 'sdist' in COMMAND_LINE_TARGETS:
167169

168170
# use new environment with extra libraries needed for libdiffpy.
169171
env_lib = env.Clone()
172+
if env['PLATFORM'] == 'win32':
173+
# Export the API from the DLL, see diffpy/Export.hpp. Code that uses
174+
# the library, including the unit tests, imports it instead.
175+
env_lib.AppendUnique(CPPDEFINES=['BUILD_DLL'])
170176
# The dladdr call in runtimepath.cpp requires the dl library.
171177
# Windows uses GetModuleHandleEx instead.
172178
if env['PLATFORM'] != 'win32':

‎src/diffpy/SConscript‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if env['PLATFORM'] == "win32":
1212

1313
env_rt = env.Clone()
1414
env_rt.AppendUnique(CPPDEFINES=dict(DIFFPYRUNTIMERELPATH=rtrp))
15+
if env['PLATFORM'] == "win32":
16+
# runtimepath is part of the DLL, see BUILD_DLL in src/SConscript.
17+
env_rt.AppendUnique(CPPDEFINES=['BUILD_DLL'])
1518
rtso = env_rt.SharedObject('runtimepath', 'runtimepath.cpp')
1619
env['lib_sources'] += rtso
1720

‎src/tests/SConscript‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ else:
1515
use_our_library = not env['test_installed']
1616

1717
env_test.PrependUnique(LIBS='diffpy', LIBPATH=lib_dir, delete_existing=1)
18-
env_test.PrependUnique(LINKFLAGS="-Wl,-rpath,%r" % lib_dir)
18+
if env['PLATFORM'] == 'win32':
19+
# Windows has no rpath. Let the test program find diffpy.dll on PATH.
20+
env_test.PrependENVPath('PATH', lib_dir)
21+
else:
22+
env_test.PrependUnique(LINKFLAGS="-Wl,-rpath,%r" % lib_dir)
1923

2024
# Targets --------------------------------------------------------------------
2125

0 commit comments

Comments
 (0)