Skip to content

Commit

Permalink
Merge pull request #17 from diffpy/windows
Browse files Browse the repository at this point in the history
Windows
  • Loading branch information
vincefn authored Sep 25, 2022
2 parents 47fb77e + a6bab58 commit ce2de47
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 61 deletions.
103 changes: 87 additions & 16 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ SCons construction environment can be customized in sconscript.local script.
"""

import os
from os.path import join as pjoin
import platform


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


def getsyspaths(*names):
pall = sum((os.environ.get(n, '').split(os.pathsep) for n in names), [])
rv = [p for p in pall if os.path.exists(p)]
return rv


# copy system environment variables related to compilation
DefaultEnvironment(ENV=subdictionary(os.environ, '''
PATH CPATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_RUN_PATH
LD_LIBRARY_PATH DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH
MACOSX_DEPLOYMENT_TARGET
'''.split())
)
)

# Create construction environment
env = DefaultEnvironment().Clone()
Expand All @@ -39,21 +48,54 @@ env.EnsureSConsVersion(0, 98, 1)
# Customizable compile variables
vars = Variables('sconsvars.py')

vars.Add(PathVariable(
'prefix',
'installation prefix directory',
'/usr/local'))
vars.Update(env)
vars.Add(PathVariable(
'libdir',
'installation directory for compiled library [prefix/lib]',
env['prefix'] + '/lib',
PathVariable.PathAccept))
vars.Add(PathVariable(
'includedir',
'installation directory for C++ header files [prefix/include]',
env['prefix'] + '/include',
PathVariable.PathAccept))
# TODO: also amend paths when VIRTUAL_ENV variable exists,
# if CONDA_PREFIX does not exist ?
if 'CONDA_PREFIX' in os.environ:
# building for a conda environment
vars.Add(PathVariable(
'prefix',
'installation prefix directory',
os.environ['CONDA_PREFIX']))
vars.Update(env)
if platform.system().lower() == "windows":
vars.Add(PathVariable(
'libdir',
'installation directory for compiled library [prefix/Library/lib]',
pjoin(env['prefix'], 'Library', 'Lib'),
PathVariable.PathAccept))
vars.Add(PathVariable(
'includedir',
'installation directory for C++ header files [prefix/Library/include]',
pjoin(env['prefix'], 'Library', 'include'),
PathVariable.PathAccept))
else:
vars.Add(PathVariable(
'libdir',
'installation directory for compiled library [prefix/lib]',
pjoin(env['prefix'], 'lib'),
PathVariable.PathAccept))
vars.Add(PathVariable(
'includedir',
'installation directory for C++ header files [prefix/include]',
pjoin(env['prefix'], 'include'),
PathVariable.PathAccept))
else:
vars.Add(PathVariable(
'prefix',
'installation prefix directory',
'/usr/local'))
vars.Update(env)
vars.Add(PathVariable(
'libdir',
'installation directory for compiled library [prefix/lib]',
env['prefix'] + '/lib',
PathVariable.PathAccept))
vars.Add(PathVariable(
'includedir',
'installation directory for C++ header files [prefix/include]',
env['prefix'] + '/include',
PathVariable.PathAccept))

vars.Add(EnumVariable(
'build',
'compiler settings',
Expand All @@ -68,9 +110,38 @@ vars.Add(BoolVariable(
vars.Add(BoolVariable(
'with_shared_cctbx',
'compile and link with the shared cctbx library', False))

vars.Update(env)
env.Help(MY_SCONS_HELP % vars.GenerateHelpText(env))

if platform.system().lower() == "windows":
# See https://scons.org/faq.html#Linking_on_Windows_gives_me_an_error
env['ENV']['TMP'] = os.environ['TMP']
# Prevent the generation of an import lib (.lib) in addition to the dll
# Unused as we are using as static library for windows
# env.AppendUnique(no_import_lib=1)
if 'CONDA_PREFIX' in os.environ:
env.Append(CPPPATH=[pjoin(os.environ['CONDA_PREFIX'], 'include')])
env.Append(CPPPATH=[pjoin(os.environ['CONDA_PREFIX'], 'Library', 'include')])
env.Append(LIBPATH=pjoin(os.environ['CONDA_PREFIX'], 'Library', 'lib'))
else:
if 'CONDA_PREFIX' in os.environ:
env.Append(CPPPATH=pjoin(os.environ['CONDA_PREFIX'], 'include'))
env.Append(LIBPATH=pjoin(os.environ['CONDA_PREFIX'], 'lib'))
# Specify minimum C++ standard. Allow later standard from sconscript.local.
# In case of multiple `-std` options the last option holds.
env.PrependUnique(CXXFLAGS='-std=c++11', delete_existing=1)

# the CPPPATH directories are checked by scons dependency scanner
cpppath = getsyspaths('CPLUS_INCLUDE_PATH', 'CPATH')
env.AppendUnique(CPPPATH=cpppath)
# Insert LIBRARY_PATH explicitly because some compilers
# ignore it in the system environment.
env.PrependUnique(LIBPATH=getsyspaths('LIBRARY_PATH'))
# This disable automated versioned named e.g. libboost_date_time-vc142-mt-s-x64-1_73.lib
# so we can use conda-installed libraries
env.AppendUnique(CPPDEFINES='BOOST_ALL_NO_LIB')

builddir = env.Dir('build/%s-%s' % (env['build'], platform.machine()))

Export('env')
Expand Down
4 changes: 4 additions & 0 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scons -j%CPU_COUNT%
if errorlevel 1 exit 1
scons install prefix=%PREFIX%
if errorlevel 1 exit 1
6 changes: 5 additions & 1 deletion conda-recipe/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
boost:
- 1.67
- 1.73

# only for local build ? see https://github.com/conda/conda-build/issues/4064#issuecomment-702983257
#CONDA_BUILD_SYSROOT:
# - /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
9 changes: 5 additions & 4 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package:
source:
# git_url: https://github.com/diffpy/libobjcryst.git
git_url: ..
# path: .. # To build from modified local tree

build:
number: 0
Expand All @@ -17,12 +18,12 @@ requirements:
build:
- {{ compiler('cxx') }}
- scons
host:
- libboost {{ boost }}
- boost-cpp {{ boost }}
- python

test:
commands:
- test -f $PREFIX/lib/libObjCryst${SHLIB_EXT}
commands: # [not win]
- test -f $PREFIX/lib/libObjCryst${SHLIB_EXT} # [not win]

about:
home: https://github.com/diffpy/libobjcryst/
Expand Down
20 changes: 11 additions & 9 deletions conda-recipe/sconscript.local
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
Import('env')

import os
import platform

# Apply environment settings for Anaconda compilers
env.Replace(CXX=os.environ['CXX'])
env.MergeFlags(os.environ['CFLAGS'])
env.MergeFlags(os.environ['CPPFLAGS'])
env.MergeFlags(os.environ['CXXFLAGS'])
env.MergeFlags(os.environ['LDFLAGS'])
if platform.system() != 'Darwin':
# Apply environment settings for Anaconda compilers
env.Replace(CXX=os.environ['CXX'])
env.MergeFlags(os.environ['CFLAGS'])
env.MergeFlags(os.environ['CPPFLAGS'])
env.MergeFlags(os.environ['CXXFLAGS'])
env.MergeFlags(os.environ['LDFLAGS'])

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

# Silence copious warnings from the boost headers.
P = os.environ['PREFIX']
Expand Down
2 changes: 1 addition & 1 deletion site_scons/fallback_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
Update FALLBACK_VERSION when tagging a new release.
'''

FALLBACK_VERSION = '2021.1.1.post0'
FALLBACK_VERSION = '2022.1.post0'
11 changes: 8 additions & 3 deletions src/ObjCryst/ObjCryst/Molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <algorithm>
#include <iomanip>
#include <ctime>
#include <boost/format.hpp>

#include "ObjCryst/Quirks/VFNStreamFormat.h"
#include "ObjCryst/ObjCryst/Molecule.h"
Expand Down Expand Up @@ -2292,8 +2293,12 @@ void Molecule::XMLOutput(ostream &os,int indent)const
for(pos=mvRigidGroup.begin();pos!=mvRigidGroup.end();++pos)
{
XMLCrystTag tagg("RigidGroup",false,true);
for(set<MolAtom *>::const_iterator at=(*pos)->begin();at!=(*pos)->end();++at)
tagg.AddAttribute("Atom",(*at)->GetName());
// Need to use Atom1, Atom2 etc.. so a valid XML is produced
// See https://github.com/vincefn/objcryst/issues/52
// This won't be backwards-compatible
int idx = 0;
for (set<MolAtom*>::const_iterator at = (*pos)->begin(); at != (*pos)->end(); ++at)
tagg.AddAttribute((boost::format("Atom%d") %idx++).str(), (*at)->GetName());
/*
tagg.AddAttribute("Q0",(*pos)->mQuat.Q0());
tagg.AddAttribute("Q1",(*pos)->mQuat.Q1());
Expand Down Expand Up @@ -2384,7 +2389,7 @@ void Molecule::XMLInput(istream &is,const XMLCrystTag &tag)
{
RigidGroup s;
for(unsigned int i=0;i<tagg.GetNbAttribute();i++)
if("Atom"==tagg.GetAttributeName(i))
if(tagg.GetAttributeName(i).rfind("Atom", 0)==0)
s.insert(&(this->GetAtom(tagg.GetAttributeValue(i))));
this->AddRigidGroup(s);
}
Expand Down
15 changes: 14 additions & 1 deletion src/ObjCryst/ObjCryst/PowderPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,19 @@ unsigned int PowderPatternDiffraction::GetProfileFitNetNbObs()const
return nb;
}

bool PowderPatternDiffraction::HasFhklObsSq() const
{
if(mpLeBailData==NULL) return false;
return mpLeBailData->GetFhklObsSq().size() > 0;
}

const CrystVector_REAL& PowderPatternDiffraction::GetFhklObsSq() const
{
if(mpLeBailData==NULL)
throw ObjCrystException("PowderPatternDiffraction::GetFhklObsSq(): no extracted intensities available");
return mpLeBailData->GetFhklObsSq();
}

void PowderPatternDiffraction::CalcPowderPattern() const
{
this->GetNbReflBelowMaxSinThetaOvLambda();
Expand Down Expand Up @@ -6559,7 +6572,7 @@ void PowderPattern::PrepareIntegratedRfactor()const
for(int i=0;i<mPowderPatternComponentRegistry.GetNb();i++)
{
const CrystVector_long vLim=mPowderPatternComponentRegistry.GetObj(i).GetBraggLimits();
for(i=0;i<vLim.numElements();i++) vLimits.push_back(vLim(i));
for(int j=0;j<vLim.numElements();j++) vLimits.push_back(vLim(j));
}
if(vLimits.size()<2)
{
Expand Down
10 changes: 10 additions & 0 deletions src/ObjCryst/ObjCryst/PowderPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@ class PowderPatternDiffraction : virtual public PowderPatternComponent,public Sc
* No over paremeters (profile, background) are taken into account
*/
unsigned int GetProfileFitNetNbObs()const;
/// Return true if there are extracted (le Bail) squared structure factors, false otherwise
bool HasFhklObsSq() const;
/** Get the extracted structure factors modulus (squared), e.g. using the Le Bail method.
*
* Note that the number of reflections listed is limited to the evaluated ones,
*which is usually smaller than the H,K and L arrays.
*
* Raises an exception if this is not available.
*/
const CrystVector_REAL& GetFhklObsSq() const;
protected:
virtual void CalcPowderPattern() const;
virtual void CalcPowderPattern_FullDeriv(std::set<RefinablePar *> &vPar);
Expand Down
6 changes: 3 additions & 3 deletions src/ObjCryst/RefinableObj/RefinableObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,19 +736,19 @@ template<class T> class ObjRegistry
* but the objects themselves can be modified.
* This iterator should remain valid even if an object is removed.
*/
typename list<T*>::const_iterator list_begin() const;
typename std::list<T*>::const_iterator list_begin() const;
/** low-level access to the underlying list end().
* Const access as we do not want the number and order of objects to change,
* but the objects themselves can be modified.
* This iterator should remain valid even if an object is removed.
*/
typename list<T*>::const_iterator list_end() const;
typename std::list<T*>::const_iterator list_end() const;
private:
/// The registry of objects
vector<T*> mvpRegistry;
/// Another view of the registry of objects - this time as a std::list, which
/// will not be invalidated if one object is deleted
list<T*> mvpRegistryList;
std::list<T*> mvpRegistryList;
/// Name of this registry
string mName;
/// Last time an object was added or removed
Expand Down
4 changes: 4 additions & 0 deletions src/ObjCryst/version.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ struct libobjcryst_version_info {
static const char* date;
static const char* git_commit;
// git_sha is deprecated. Use git_commit instead.
#ifndef _MSC_VER
static const char* git_sha __attribute__ ((deprecated));
#else
__declspec(deprecated) static const char* git_sha;
#endif

};

Expand Down
Loading

0 comments on commit ce2de47

Please sign in to comment.