Skip to content

Commit ce2de47

Browse files
authored
Merge pull request #17 from diffpy/windows
Windows
2 parents 47fb77e + a6bab58 commit ce2de47

12 files changed

+188
-61
lines changed

SConstruct

+87-16
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@ 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

23+
2224
def 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
2635
DefaultEnvironment(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
3443
env = DefaultEnvironment().Clone()
@@ -39,21 +48,54 @@ env.EnsureSConsVersion(0, 98, 1)
3948
# Customizable compile variables
4049
vars = 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+
5799
vars.Add(EnumVariable(
58100
'build',
59101
'compiler settings',
@@ -68,9 +110,38 @@ vars.Add(BoolVariable(
68110
vars.Add(BoolVariable(
69111
'with_shared_cctbx',
70112
'compile and link with the shared cctbx library', False))
113+
71114
vars.Update(env)
72115
env.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+
74145
builddir = env.Dir('build/%s-%s' % (env['build'], platform.machine()))
75146

76147
Export('env')

conda-recipe/bld.bat

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
scons -j%CPU_COUNT%
2+
if errorlevel 1 exit 1
3+
scons install prefix=%PREFIX%
4+
if errorlevel 1 exit 1

conda-recipe/conda_build_config.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
boost:
2-
- 1.67
2+
- 1.73
3+
4+
# only for local build ? see https://github.com/conda/conda-build/issues/4064#issuecomment-702983257
5+
#CONDA_BUILD_SYSROOT:
6+
# - /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

conda-recipe/meta.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package:
77
source:
88
# git_url: https://github.com/diffpy/libobjcryst.git
99
git_url: ..
10+
# path: .. # To build from modified local tree
1011

1112
build:
1213
number: 0
@@ -17,12 +18,12 @@ requirements:
1718
build:
1819
- {{ compiler('cxx') }}
1920
- scons
20-
host:
21-
- libboost {{ boost }}
21+
- boost-cpp {{ boost }}
22+
- python
2223

2324
test:
24-
commands:
25-
- test -f $PREFIX/lib/libObjCryst${SHLIB_EXT}
25+
commands: # [not win]
26+
- test -f $PREFIX/lib/libObjCryst${SHLIB_EXT} # [not win]
2627

2728
about:
2829
home: https://github.com/diffpy/libobjcryst/

conda-recipe/sconscript.local

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
Import('env')
44

55
import os
6+
import platform
67

7-
# Apply environment settings for Anaconda compilers
8-
env.Replace(CXX=os.environ['CXX'])
9-
env.MergeFlags(os.environ['CFLAGS'])
10-
env.MergeFlags(os.environ['CPPFLAGS'])
11-
env.MergeFlags(os.environ['CXXFLAGS'])
12-
env.MergeFlags(os.environ['LDFLAGS'])
8+
if platform.system() != 'Darwin':
9+
# Apply environment settings for Anaconda compilers
10+
env.Replace(CXX=os.environ['CXX'])
11+
env.MergeFlags(os.environ['CFLAGS'])
12+
env.MergeFlags(os.environ['CPPFLAGS'])
13+
env.MergeFlags(os.environ['CXXFLAGS'])
14+
env.MergeFlags(os.environ['LDFLAGS'])
1315

14-
# Use the default c++98 language standard
15-
cxxflags98 = [f for f in env['CXXFLAGS'] if not f.startswith('-std=')]
16-
env.Replace(CXXFLAGS=cxxflags98)
16+
# Use the default c++98 language standard
17+
cxxflags98 = [f for f in env['CXXFLAGS'] if not f.startswith('-std=')]
18+
env.Replace(CXXFLAGS=cxxflags98)
1719

1820
# Silence copious warnings from the boost headers.
1921
P = os.environ['PREFIX']

site_scons/fallback_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
Update FALLBACK_VERSION when tagging a new release.
88
'''
99

10-
FALLBACK_VERSION = '2021.1.1.post0'
10+
FALLBACK_VERSION = '2022.1.post0'

src/ObjCryst/ObjCryst/Molecule.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <algorithm>
2626
#include <iomanip>
2727
#include <ctime>
28+
#include <boost/format.hpp>
2829

2930
#include "ObjCryst/Quirks/VFNStreamFormat.h"
3031
#include "ObjCryst/ObjCryst/Molecule.h"
@@ -2292,8 +2293,12 @@ void Molecule::XMLOutput(ostream &os,int indent)const
22922293
for(pos=mvRigidGroup.begin();pos!=mvRigidGroup.end();++pos)
22932294
{
22942295
XMLCrystTag tagg("RigidGroup",false,true);
2295-
for(set<MolAtom *>::const_iterator at=(*pos)->begin();at!=(*pos)->end();++at)
2296-
tagg.AddAttribute("Atom",(*at)->GetName());
2296+
// Need to use Atom1, Atom2 etc.. so a valid XML is produced
2297+
// See https://github.com/vincefn/objcryst/issues/52
2298+
// This won't be backwards-compatible
2299+
int idx = 0;
2300+
for (set<MolAtom*>::const_iterator at = (*pos)->begin(); at != (*pos)->end(); ++at)
2301+
tagg.AddAttribute((boost::format("Atom%d") %idx++).str(), (*at)->GetName());
22972302
/*
22982303
tagg.AddAttribute("Q0",(*pos)->mQuat.Q0());
22992304
tagg.AddAttribute("Q1",(*pos)->mQuat.Q1());
@@ -2384,7 +2389,7 @@ void Molecule::XMLInput(istream &is,const XMLCrystTag &tag)
23842389
{
23852390
RigidGroup s;
23862391
for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
2387-
if("Atom"==tagg.GetAttributeName(i))
2392+
if(tagg.GetAttributeName(i).rfind("Atom", 0)==0)
23882393
s.insert(&(this->GetAtom(tagg.GetAttributeValue(i))));
23892394
this->AddRigidGroup(s);
23902395
}

src/ObjCryst/ObjCryst/PowderPattern.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,19 @@ unsigned int PowderPatternDiffraction::GetProfileFitNetNbObs()const
12981298
return nb;
12991299
}
13001300

1301+
bool PowderPatternDiffraction::HasFhklObsSq() const
1302+
{
1303+
if(mpLeBailData==NULL) return false;
1304+
return mpLeBailData->GetFhklObsSq().size() > 0;
1305+
}
1306+
1307+
const CrystVector_REAL& PowderPatternDiffraction::GetFhklObsSq() const
1308+
{
1309+
if(mpLeBailData==NULL)
1310+
throw ObjCrystException("PowderPatternDiffraction::GetFhklObsSq(): no extracted intensities available");
1311+
return mpLeBailData->GetFhklObsSq();
1312+
}
1313+
13011314
void PowderPatternDiffraction::CalcPowderPattern() const
13021315
{
13031316
this->GetNbReflBelowMaxSinThetaOvLambda();
@@ -6559,7 +6572,7 @@ void PowderPattern::PrepareIntegratedRfactor()const
65596572
for(int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
65606573
{
65616574
const CrystVector_long vLim=mPowderPatternComponentRegistry.GetObj(i).GetBraggLimits();
6562-
for(i=0;i<vLim.numElements();i++) vLimits.push_back(vLim(i));
6575+
for(int j=0;j<vLim.numElements();j++) vLimits.push_back(vLim(j));
65636576
}
65646577
if(vLimits.size()<2)
65656578
{

src/ObjCryst/ObjCryst/PowderPattern.h

+10
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,16 @@ class PowderPatternDiffraction : virtual public PowderPatternComponent,public Sc
420420
* No over paremeters (profile, background) are taken into account
421421
*/
422422
unsigned int GetProfileFitNetNbObs()const;
423+
/// Return true if there are extracted (le Bail) squared structure factors, false otherwise
424+
bool HasFhklObsSq() const;
425+
/** Get the extracted structure factors modulus (squared), e.g. using the Le Bail method.
426+
*
427+
* Note that the number of reflections listed is limited to the evaluated ones,
428+
*which is usually smaller than the H,K and L arrays.
429+
*
430+
* Raises an exception if this is not available.
431+
*/
432+
const CrystVector_REAL& GetFhklObsSq() const;
423433
protected:
424434
virtual void CalcPowderPattern() const;
425435
virtual void CalcPowderPattern_FullDeriv(std::set<RefinablePar *> &vPar);

src/ObjCryst/RefinableObj/RefinableObj.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -736,19 +736,19 @@ template<class T> class ObjRegistry
736736
* but the objects themselves can be modified.
737737
* This iterator should remain valid even if an object is removed.
738738
*/
739-
typename list<T*>::const_iterator list_begin() const;
739+
typename std::list<T*>::const_iterator list_begin() const;
740740
/** low-level access to the underlying list end().
741741
* Const access as we do not want the number and order of objects to change,
742742
* but the objects themselves can be modified.
743743
* This iterator should remain valid even if an object is removed.
744744
*/
745-
typename list<T*>::const_iterator list_end() const;
745+
typename std::list<T*>::const_iterator list_end() const;
746746
private:
747747
/// The registry of objects
748748
vector<T*> mvpRegistry;
749749
/// Another view of the registry of objects - this time as a std::list, which
750750
/// will not be invalidated if one object is deleted
751-
list<T*> mvpRegistryList;
751+
std::list<T*> mvpRegistryList;
752752
/// Name of this registry
753753
string mName;
754754
/// Last time an object was added or removed

src/ObjCryst/version.tpl

+4
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

0 commit comments

Comments
 (0)