From 738d4622f8fe3909621cfaf2ae5ee54f705f40ee Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 1 Feb 2025 18:09:37 -0500 Subject: [PATCH 1/4] gitignore --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 496ca8a9..449bdbd4 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,10 @@ tags # source distribution tarball libdiffpy-*.tar.gz + + +.vs/* +.exp +.lib +.dll +.vscode/* From 59d568851c39e93580fcdb74bb89c85982cea9a2 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 1 Feb 2025 18:10:57 -0500 Subject: [PATCH 2/4] fix win include and export --- src/diffpy/Attributes.hpp | 12 +++-- src/diffpy/EventTicker.hpp | 4 +- src/diffpy/Export.hpp | 11 ++++ src/diffpy/mathutils.ipp | 6 --- src/diffpy/runtimepath.cpp | 51 ++++++++++++++++++- src/diffpy/serialization.hpp | 8 ++- src/diffpy/serialization.ipp | 35 +++++++------ src/diffpy/srreal/AtomRadiiTable.cpp | 2 +- src/diffpy/srreal/AtomRadiiTable.hpp | 4 +- src/diffpy/srreal/AtomicStructureAdapter.hpp | 14 ++--- src/diffpy/srreal/BVParam.hpp | 8 +-- src/diffpy/srreal/BVParametersTable.hpp | 4 +- src/diffpy/srreal/BVSCalculator.hpp | 4 +- src/diffpy/srreal/BaseBondGenerator.hpp | 4 +- src/diffpy/srreal/BaseDebyeSum.hpp | 4 +- src/diffpy/srreal/BondCalculator.hpp | 4 +- src/diffpy/srreal/ConstantPeakWidth.hpp | 4 +- src/diffpy/srreal/ConstantRadiiTable.hpp | 4 +- src/diffpy/srreal/CroppedGaussianProfile.hpp | 4 +- src/diffpy/srreal/CrystalStructureAdapter.hpp | 12 +++-- src/diffpy/srreal/DebyePDFCalculator.hpp | 4 +- src/diffpy/srreal/DebyeWallerPeakWidth.hpp | 4 +- src/diffpy/srreal/GaussianProfile.hpp | 4 +- src/diffpy/srreal/JeongPeakWidth.hpp | 4 +- src/diffpy/srreal/LinearBaseline.hpp | 4 +- src/diffpy/srreal/NoMetaStructureAdapter.hpp | 6 ++- .../srreal/NoSymmetryStructureAdapter.hpp | 6 ++- .../srreal/ObjCrystStructureAdapter.hpp | 7 ++- src/diffpy/srreal/OverlapCalculator.hpp | 4 +- src/diffpy/srreal/PDFBaseline.cpp | 2 +- src/diffpy/srreal/PDFBaseline.hpp | 4 +- src/diffpy/srreal/PDFCalculator.hpp | 4 +- src/diffpy/srreal/PDFEnvelope.cpp | 2 +- src/diffpy/srreal/PDFEnvelope.hpp | 6 ++- src/diffpy/srreal/PDFUtils.hpp | 6 ++- src/diffpy/srreal/PQEvaluator.hpp | 12 +++-- src/diffpy/srreal/PairQuantity.hpp | 8 +-- src/diffpy/srreal/PeakProfile.cpp | 2 +- src/diffpy/srreal/PeakProfile.hpp | 4 +- src/diffpy/srreal/PeakWidthModel.cpp | 2 +- src/diffpy/srreal/PeakWidthModel.hpp | 6 ++- .../srreal/PeriodicStructureAdapter.hpp | 9 ++-- src/diffpy/srreal/QResolutionEnvelope.hpp | 4 +- src/diffpy/srreal/QuantityType.hpp | 4 +- src/diffpy/srreal/R3linalg.cpp | 4 ++ src/diffpy/srreal/R3linalg.hpp | 8 +-- src/diffpy/srreal/SFTElectron.hpp | 4 +- src/diffpy/srreal/SFTElectronNumber.hpp | 4 +- src/diffpy/srreal/SFTNeutron.hpp | 4 +- src/diffpy/srreal/SFTXray.hpp | 4 +- src/diffpy/srreal/ScaleEnvelope.hpp | 4 +- src/diffpy/srreal/ScatteringFactorTable.cpp | 2 +- src/diffpy/srreal/ScatteringFactorTable.hpp | 6 ++- src/diffpy/srreal/SphericalShapeEnvelope.hpp | 4 +- src/diffpy/srreal/StepCutEnvelope.hpp | 4 +- src/diffpy/srreal/StructureAdapter.hpp | 16 ++++-- src/diffpy/srreal/StructureDifference.hpp | 4 +- src/diffpy/srreal/ZeroBaseline.hpp | 4 +- src/diffpy/version.tpl | 4 +- 59 files changed, 280 insertions(+), 113 deletions(-) create mode 100644 src/diffpy/Export.hpp diff --git a/src/diffpy/Attributes.hpp b/src/diffpy/Attributes.hpp index 8e6a9ae6..3c84ea04 100644 --- a/src/diffpy/Attributes.hpp +++ b/src/diffpy/Attributes.hpp @@ -26,6 +26,8 @@ #include #include +#include + namespace diffpy { namespace attributes { @@ -46,7 +48,7 @@ class DoubleAttributeError : public std::runtime_error /// @class BaseDoubleAttribute /// @brief abstract base class for accessing a particular double attribute -class BaseDoubleAttribute +class DLL_EXPORT BaseDoubleAttribute { public: @@ -75,7 +77,7 @@ class BaseAttributesVisitor /// should derive from Attributes and register their setter and /// getter methods in their constructors. -class Attributes +class DLL_EXPORT Attributes { public: @@ -98,7 +100,7 @@ class Attributes protected: - friend void registerBaseDoubleAttribute(Attributes*, + friend DLL_EXPORT void registerBaseDoubleAttribute(Attributes*, const std::string&, attributes::BaseDoubleAttribute* pa); template void registerDoubleAttribute(const std::string& name, T* obj, Getter); @@ -186,10 +188,10 @@ class Attributes // non-member helpers -void registerBaseDoubleAttribute(Attributes* obj, +DLL_EXPORT void registerBaseDoubleAttribute(Attributes* obj, const std::string& name, BaseDoubleAttribute* pa); -void throwDoubleAttributeReadOnly(); +DLL_EXPORT void throwDoubleAttributeReadOnly(); } // namespace attributes } // namespace diffpy diff --git a/src/diffpy/EventTicker.hpp b/src/diffpy/EventTicker.hpp index 54d11ef7..c0024a9d 100644 --- a/src/diffpy/EventTicker.hpp +++ b/src/diffpy/EventTicker.hpp @@ -26,10 +26,12 @@ #include #include +#include + namespace diffpy { namespace eventticker { -class EventTicker +class DLL_EXPORT EventTicker { public: diff --git a/src/diffpy/Export.hpp b/src/diffpy/Export.hpp new file mode 100644 index 00000000..142b61fb --- /dev/null +++ b/src/diffpy/Export.hpp @@ -0,0 +1,11 @@ +#pragma once + +#if defined(_WIN32) + #if defined(BUILD_DLL) + #define DLL_EXPORT __declspec(dllexport) + #else + #define DLL_EXPORT __declspec(dllimport) + #endif +#else + #define DLL_EXPORT +#endif diff --git a/src/diffpy/mathutils.ipp b/src/diffpy/mathutils.ipp index acf4d24c..2c60d83a 100644 --- a/src/diffpy/mathutils.ipp +++ b/src/diffpy/mathutils.ipp @@ -34,12 +34,6 @@ inline double remainder(double x, double y) fmod(x, y) : (fmod(x, y) + y); } - -inline double log2(double x) -{ - return log(x) / log(2.0); -} - #endif // _MSC_VER namespace diffpy { diff --git a/src/diffpy/runtimepath.cpp b/src/diffpy/runtimepath.cpp index 0957e74e..0f7299ee 100644 --- a/src/diffpy/runtimepath.cpp +++ b/src/diffpy/runtimepath.cpp @@ -23,8 +23,57 @@ #include #include #include -#include +#include // not available on Windows, conda install dlfcn-win32 + +// libgen.h is not available on Windows +#ifdef _WIN32 +#include +#include + +// A simple replacement for dirname() on Windows. +inline std::string win_dirname(const std::string& path) +{ + // Find the last occurrence of either '\' or '/' + size_t pos = path.find_last_of("\\/"); + if (pos == std::string::npos) + return "."; // No directory found, return current directory + return path.substr(0, pos); +} + +// Overload to match the expected C-style interface if needed: +inline char* dirname(char* path) +{ + static std::string dir; + dir = win_dirname(std::string(path)); + return const_cast(dir.c_str()); +} +#else #include +#endif + +// S_ISDIR, PATH_MAX, realpath, etc. +#ifdef _WIN32 +#include +#include // for _fullpath +#include // for _stat +#include // for _getcwd, etc. + +// Define S_ISDIR using the Windows _S_IFDIR flag from sys/stat.h. +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & _S_IFDIR) == _S_IFDIR) +#endif + +// Use MAX_PATH from as PATH_MAX if not defined. +#ifndef PATH_MAX +#define PATH_MAX MAX_PATH +#endif + +// Define realpath in terms of _fullpath. +// _fullpath returns a pointer to the resolved path in the buffer you provide. +// The usage should be nearly equivalent. +#define realpath(N, R) _fullpath((R), (N), PATH_MAX) +#endif + #include #include diff --git a/src/diffpy/serialization.hpp b/src/diffpy/serialization.hpp index 9d80d14d..3c8f9015 100644 --- a/src/diffpy/serialization.hpp +++ b/src/diffpy/serialization.hpp @@ -32,9 +32,10 @@ namespace diffpy { template - std::string serialization_tostring(const T& tobj); +std::string serialization_tostring(const T& tobj); + template - void serialization_fromstring(T& tobj, const std::string& s); +void serialization_fromstring(T& tobj, const std::string& s); namespace serialization { @@ -44,4 +45,7 @@ typedef ::boost::archive::binary_oarchive oarchive; } // namespace serialization } // namespace diffpy +// Pull in the inline definitions and macro logic +#include "serialization.ipp" + #endif // SERIALIZATION_HPP_INCLUDED diff --git a/src/diffpy/serialization.ipp b/src/diffpy/serialization.ipp index fba56fff..6663b680 100644 --- a/src/diffpy/serialization.ipp +++ b/src/diffpy/serialization.ipp @@ -54,25 +54,30 @@ void serialization_fromstring(T& tobj, const std::string& s) ia >> tobj; } -} // namespace diffpy - // Macros -------------------------------------------------------------------- +// Macros for explicit instantiation: +// - On Windows (_WIN32), make them no-ops to avoid dllimport/dllexport issues. +// - On other platforms, keep them as they were. +#ifdef _WIN32 + + #define DIFFPY_INSTANTIATE_SERIALIZATION(C) /* no-op */ + #define DIFFPY_INSTANTIATE_PTR_SERIALIZATION(C) /* no-op */ -/// Insert explicit instantiations for serialization_tostring and -/// serialization_fromstring for class C. +#else -#define DIFFPY_INSTANTIATE_SERIALIZATION(C) \ - template \ - std::string \ - diffpy::serialization_tostring(const C&); \ - template \ - void \ - diffpy::serialization_fromstring(C&, const std::string&); \ + /// Insert explicit instantiations for serialization_tostring and + /// serialization_fromstring for class C. + #define DIFFPY_INSTANTIATE_SERIALIZATION(C) \ + template std::string diffpy::serialization_tostring(const C&); \ + template void diffpy::serialization_fromstring(C&, const std::string&); -/// Insert explicit instantiations for serialization_tostring and -/// serialization_fromstring for type boost::shared_ptr. + /// Insert explicit instantiations for serialization_tostring and + /// serialization_fromstring for type boost::shared_ptr. + #define DIFFPY_INSTANTIATE_PTR_SERIALIZATION(C) \ + DIFFPY_INSTANTIATE_SERIALIZATION(boost::shared_ptr) -#define DIFFPY_INSTANTIATE_PTR_SERIALIZATION(C) \ - DIFFPY_INSTANTIATE_SERIALIZATION(boost::shared_ptr) +#endif + +} // namespace diffpy #endif // SERIALIZATION_IPP_INCLUDED diff --git a/src/diffpy/srreal/AtomRadiiTable.cpp b/src/diffpy/srreal/AtomRadiiTable.cpp index 20995f69..ba338350 100644 --- a/src/diffpy/srreal/AtomRadiiTable.cpp +++ b/src/diffpy/srreal/AtomRadiiTable.cpp @@ -29,7 +29,7 @@ namespace diffpy { // Unique instantiation of the template registry base class. -template class HasClassRegistry; +template class DLL_EXPORT HasClassRegistry; namespace srreal { diff --git a/src/diffpy/srreal/AtomRadiiTable.hpp b/src/diffpy/srreal/AtomRadiiTable.hpp index 830adc40..7eb17034 100644 --- a/src/diffpy/srreal/AtomRadiiTable.hpp +++ b/src/diffpy/srreal/AtomRadiiTable.hpp @@ -32,10 +32,12 @@ #include +#include + namespace diffpy { namespace srreal { -class AtomRadiiTable : +class DLL_EXPORT AtomRadiiTable : public diffpy::HasClassRegistry { public: diff --git a/src/diffpy/srreal/AtomicStructureAdapter.hpp b/src/diffpy/srreal/AtomicStructureAdapter.hpp index 6eb3cbc2..640de9b4 100644 --- a/src/diffpy/srreal/AtomicStructureAdapter.hpp +++ b/src/diffpy/srreal/AtomicStructureAdapter.hpp @@ -24,10 +24,12 @@ #include +#include + namespace diffpy { namespace srreal { -class Atom +class DLL_EXPORT Atom { public: @@ -64,17 +66,17 @@ class Atom // Functions related to class Atom -bool operator<(const Atom&, const Atom&); +DLL_EXPORT bool operator<(const Atom&, const Atom&); inline bool operator>(const Atom& a0, const Atom& a1) { return a1 < a0; } inline bool operator<=(const Atom& a0, const Atom& a1) { return !(a1 < a0); } inline bool operator>=(const Atom& a0, const Atom& a1) { return !(a0 < a1); } -bool operator==(const Atom&, const Atom&); -bool operator!=(const Atom&, const Atom&); -size_t hash_value(const Atom&); +DLL_EXPORT bool operator==(const Atom&, const Atom&); +DLL_EXPORT bool operator!=(const Atom&, const Atom&); +DLL_EXPORT size_t hash_value(const Atom&); -class AtomicStructureAdapter : public StructureAdapter +class DLL_EXPORT AtomicStructureAdapter : public StructureAdapter { public: diff --git a/src/diffpy/srreal/BVParam.hpp b/src/diffpy/srreal/BVParam.hpp index 061fb98c..e36e692e 100644 --- a/src/diffpy/srreal/BVParam.hpp +++ b/src/diffpy/srreal/BVParam.hpp @@ -22,10 +22,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class BVParam +class DLL_EXPORT BVParam { public: @@ -56,14 +58,14 @@ class BVParam std::string mref_id; // hash function for cation-anion bond type only - class BondHash + class DLL_EXPORT BondHash { public: size_t operator()(const BVParam&) const; }; // equality test for cation-anion bond type - class BondEqual + class DLL_EXPORT BondEqual { public: bool operator()(const BVParam& bp0, const BVParam& bp1) const; diff --git a/src/diffpy/srreal/BVParametersTable.hpp b/src/diffpy/srreal/BVParametersTable.hpp index 690ecb04..55fc715b 100644 --- a/src/diffpy/srreal/BVParametersTable.hpp +++ b/src/diffpy/srreal/BVParametersTable.hpp @@ -27,12 +27,14 @@ #include #include +#include + namespace diffpy { namespace srreal { typedef boost::shared_ptr BVParametersTablePtr; -class BVParametersTable +class DLL_EXPORT BVParametersTable { public: diff --git a/src/diffpy/srreal/BVSCalculator.hpp b/src/diffpy/srreal/BVSCalculator.hpp index c864b31b..d7cb6514 100644 --- a/src/diffpy/srreal/BVSCalculator.hpp +++ b/src/diffpy/srreal/BVSCalculator.hpp @@ -22,10 +22,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class BVSCalculator : public PairQuantity +class DLL_EXPORT BVSCalculator : public PairQuantity { public: diff --git a/src/diffpy/srreal/BaseBondGenerator.hpp b/src/diffpy/srreal/BaseBondGenerator.hpp index 691c4666..849cdd25 100644 --- a/src/diffpy/srreal/BaseBondGenerator.hpp +++ b/src/diffpy/srreal/BaseBondGenerator.hpp @@ -23,13 +23,15 @@ #include #include +#include + namespace diffpy { namespace srreal { /// Use zero default for rmax so any misconfiguration of r-limits is obvious. const double DEFAULT_BONDGENERATOR_RMAX = 0.0; -class BaseBondGenerator +class DLL_EXPORT BaseBondGenerator { public: diff --git a/src/diffpy/srreal/BaseDebyeSum.hpp b/src/diffpy/srreal/BaseDebyeSum.hpp index 5eaea6f5..ac608fcc 100644 --- a/src/diffpy/srreal/BaseDebyeSum.hpp +++ b/src/diffpy/srreal/BaseDebyeSum.hpp @@ -23,10 +23,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class BaseDebyeSum : +class DLL_EXPORT BaseDebyeSum : public PairQuantity, public PeakWidthModelOwner { diff --git a/src/diffpy/srreal/BondCalculator.hpp b/src/diffpy/srreal/BondCalculator.hpp index 49c6876f..aceb700a 100644 --- a/src/diffpy/srreal/BondCalculator.hpp +++ b/src/diffpy/srreal/BondCalculator.hpp @@ -21,10 +21,12 @@ #include +#include + namespace diffpy { namespace srreal { -class BondCalculator : public PairQuantity +class DLL_EXPORT BondCalculator : public PairQuantity { public: diff --git a/src/diffpy/srreal/ConstantPeakWidth.hpp b/src/diffpy/srreal/ConstantPeakWidth.hpp index 8c0f552b..4ccddc4f 100644 --- a/src/diffpy/srreal/ConstantPeakWidth.hpp +++ b/src/diffpy/srreal/ConstantPeakWidth.hpp @@ -21,11 +21,13 @@ #include +#include + namespace diffpy { namespace srreal { -class ConstantPeakWidth : public PeakWidthModel +class DLL_EXPORT ConstantPeakWidth : public PeakWidthModel { public: diff --git a/src/diffpy/srreal/ConstantRadiiTable.hpp b/src/diffpy/srreal/ConstantRadiiTable.hpp index 5a047c75..8be15bba 100644 --- a/src/diffpy/srreal/ConstantRadiiTable.hpp +++ b/src/diffpy/srreal/ConstantRadiiTable.hpp @@ -21,10 +21,12 @@ #include +#include + namespace diffpy { namespace srreal { -class ConstantRadiiTable : public AtomRadiiTable +class DLL_EXPORT ConstantRadiiTable : public AtomRadiiTable { public: diff --git a/src/diffpy/srreal/CroppedGaussianProfile.hpp b/src/diffpy/srreal/CroppedGaussianProfile.hpp index ed1573ea..ac560ab1 100644 --- a/src/diffpy/srreal/CroppedGaussianProfile.hpp +++ b/src/diffpy/srreal/CroppedGaussianProfile.hpp @@ -23,10 +23,12 @@ #include +#include + namespace diffpy { namespace srreal { -class CroppedGaussianProfile : public GaussianProfile +class DLL_EXPORT CroppedGaussianProfile : public GaussianProfile { public: diff --git a/src/diffpy/srreal/CrystalStructureAdapter.hpp b/src/diffpy/srreal/CrystalStructureAdapter.hpp index 56645810..ef74e33d 100644 --- a/src/diffpy/srreal/CrystalStructureAdapter.hpp +++ b/src/diffpy/srreal/CrystalStructureAdapter.hpp @@ -25,6 +25,8 @@ #include +#include + namespace diffpy { namespace srreal { @@ -63,7 +65,7 @@ bool operator!=(const SymOpRotTrans& op0, const SymOpRotTrans& op1) } -class CrystalStructureAdapter : public PeriodicStructureAdapter +class DLL_EXPORT CrystalStructureAdapter : public PeriodicStructureAdapter { friend class CrystalStructureBondGenerator; @@ -111,7 +113,7 @@ class CrystalStructureAdapter : public PeriodicStructureAdapter bool isSymmetryCached() const; // comparison - friend bool operator==( + friend DLL_EXPORT bool operator==( const CrystalStructureAdapter&, const CrystalStructureAdapter&); // serialization @@ -133,11 +135,11 @@ typedef boost::shared_ptr CrystalStructureAdapterPtr; // Comparison functions -bool operator==(const CrystalStructureAdapter&, const CrystalStructureAdapter&); -bool operator!=(const CrystalStructureAdapter&, const CrystalStructureAdapter&); +DLL_EXPORT bool operator==(const CrystalStructureAdapter&, const CrystalStructureAdapter&); +DLL_EXPORT bool operator!=(const CrystalStructureAdapter&, const CrystalStructureAdapter&); -class CrystalStructureBondGenerator : public PeriodicStructureBondGenerator +class DLL_EXPORT CrystalStructureBondGenerator : public PeriodicStructureBondGenerator { public: diff --git a/src/diffpy/srreal/DebyePDFCalculator.hpp b/src/diffpy/srreal/DebyePDFCalculator.hpp index 512e2884..5fb21bf8 100644 --- a/src/diffpy/srreal/DebyePDFCalculator.hpp +++ b/src/diffpy/srreal/DebyePDFCalculator.hpp @@ -52,10 +52,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class DebyePDFCalculator : +class DLL_EXPORT DebyePDFCalculator : public BaseDebyeSum, public ScatteringFactorTableOwner, public PDFEnvelopeOwner diff --git a/src/diffpy/srreal/DebyeWallerPeakWidth.hpp b/src/diffpy/srreal/DebyeWallerPeakWidth.hpp index c900f7f1..25cb9f4b 100644 --- a/src/diffpy/srreal/DebyeWallerPeakWidth.hpp +++ b/src/diffpy/srreal/DebyeWallerPeakWidth.hpp @@ -22,11 +22,13 @@ #include +#include + namespace diffpy { namespace srreal { -class DebyeWallerPeakWidth : public PeakWidthModel +class DLL_EXPORT DebyeWallerPeakWidth : public PeakWidthModel { public: diff --git a/src/diffpy/srreal/GaussianProfile.hpp b/src/diffpy/srreal/GaussianProfile.hpp index 21b65b65..d193897d 100644 --- a/src/diffpy/srreal/GaussianProfile.hpp +++ b/src/diffpy/srreal/GaussianProfile.hpp @@ -22,10 +22,12 @@ #include +#include + namespace diffpy { namespace srreal { -class GaussianProfile : public PeakProfile +class DLL_EXPORT GaussianProfile : public PeakProfile { public: diff --git a/src/diffpy/srreal/JeongPeakWidth.hpp b/src/diffpy/srreal/JeongPeakWidth.hpp index 1acd9a19..6518e5c6 100644 --- a/src/diffpy/srreal/JeongPeakWidth.hpp +++ b/src/diffpy/srreal/JeongPeakWidth.hpp @@ -23,11 +23,13 @@ #include +#include + namespace diffpy { namespace srreal { -class JeongPeakWidth : public DebyeWallerPeakWidth +class DLL_EXPORT JeongPeakWidth : public DebyeWallerPeakWidth { public: diff --git a/src/diffpy/srreal/LinearBaseline.hpp b/src/diffpy/srreal/LinearBaseline.hpp index ab86aa7a..d1616f6c 100644 --- a/src/diffpy/srreal/LinearBaseline.hpp +++ b/src/diffpy/srreal/LinearBaseline.hpp @@ -21,13 +21,15 @@ #include +#include + namespace diffpy { namespace srreal { /// @class LinearBaseline /// @brief linear PDF baseline -class LinearBaseline : public PDFBaseline +class DLL_EXPORT LinearBaseline : public PDFBaseline { public: diff --git a/src/diffpy/srreal/NoMetaStructureAdapter.hpp b/src/diffpy/srreal/NoMetaStructureAdapter.hpp index da454fcc..2c8bd5f1 100644 --- a/src/diffpy/srreal/NoMetaStructureAdapter.hpp +++ b/src/diffpy/srreal/NoMetaStructureAdapter.hpp @@ -27,10 +27,12 @@ #include +#include + namespace diffpy { namespace srreal { -class NoMetaStructureAdapter : public StructureAdapter +class DLL_EXPORT NoMetaStructureAdapter : public StructureAdapter { public: @@ -75,7 +77,7 @@ class NoMetaStructureAdapter : public StructureAdapter // Routines ------------------------------------------------------------------ /// create NoMetaStructureAdapter from an existing StructureAdapter -StructureAdapterPtr nometa(StructureAdapterPtr stru); +DLL_EXPORT StructureAdapterPtr nometa(StructureAdapterPtr stru); /// create NoMetaStructureAdapter from an adaptable structure object diff --git a/src/diffpy/srreal/NoSymmetryStructureAdapter.hpp b/src/diffpy/srreal/NoSymmetryStructureAdapter.hpp index 5d8d87c4..cff5279b 100644 --- a/src/diffpy/srreal/NoSymmetryStructureAdapter.hpp +++ b/src/diffpy/srreal/NoSymmetryStructureAdapter.hpp @@ -29,10 +29,12 @@ #include +#include + namespace diffpy { namespace srreal { -class NoSymmetryStructureAdapter : public StructureAdapter +class DLL_EXPORT NoSymmetryStructureAdapter : public StructureAdapter { public: @@ -77,7 +79,7 @@ class NoSymmetryStructureAdapter : public StructureAdapter // Routines ------------------------------------------------------------------ /// create NoSymmetryStructureAdapter from an existing StructureAdapter -StructureAdapterPtr nosymmetry(StructureAdapterPtr stru); +DLL_EXPORT StructureAdapterPtr nosymmetry(StructureAdapterPtr stru); /// create NoSymmetryStructureAdapter from an adaptable structure object diff --git a/src/diffpy/srreal/ObjCrystStructureAdapter.hpp b/src/diffpy/srreal/ObjCrystStructureAdapter.hpp index 0cb21cc7..264578cc 100644 --- a/src/diffpy/srreal/ObjCrystStructureAdapter.hpp +++ b/src/diffpy/srreal/ObjCrystStructureAdapter.hpp @@ -24,6 +24,9 @@ #include #include #include + +#include + #include namespace diffpy { @@ -31,7 +34,7 @@ namespace srreal { // ObjCryst::Crystal is now adapted with CrystalStructureAdapter -StructureAdapterPtr +DLL_EXPORT StructureAdapterPtr createStructureAdapter(const ObjCryst::Crystal& cryst); // ObjCryst::Molecule can be adapted with AtomicStructureAdapter @@ -41,7 +44,7 @@ createStructureAdapter(const ObjCryst::Crystal& cryst); // molecule as a scattering component within an ObjCryst::Crystal. -StructureAdapterPtr +DLL_EXPORT StructureAdapterPtr createStructureAdapter(const ObjCryst::Molecule& molecule); } // namespace srreal diff --git a/src/diffpy/srreal/OverlapCalculator.hpp b/src/diffpy/srreal/OverlapCalculator.hpp index 0a6b5763..1f861a48 100644 --- a/src/diffpy/srreal/OverlapCalculator.hpp +++ b/src/diffpy/srreal/OverlapCalculator.hpp @@ -24,10 +24,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class OverlapCalculator : public PairQuantity +class DLL_EXPORT OverlapCalculator : public PairQuantity { public: diff --git a/src/diffpy/srreal/PDFBaseline.cpp b/src/diffpy/srreal/PDFBaseline.cpp index 96525875..aa20ccba 100644 --- a/src/diffpy/srreal/PDFBaseline.cpp +++ b/src/diffpy/srreal/PDFBaseline.cpp @@ -23,7 +23,7 @@ namespace diffpy { // Unique instantiation of the template registry base class. -template class HasClassRegistry; +template class DLL_EXPORT HasClassRegistry; } // namespace diffpy diff --git a/src/diffpy/srreal/PDFBaseline.hpp b/src/diffpy/srreal/PDFBaseline.hpp index 5329828f..8d2f1385 100644 --- a/src/diffpy/srreal/PDFBaseline.hpp +++ b/src/diffpy/srreal/PDFBaseline.hpp @@ -30,13 +30,15 @@ #include #include +#include + namespace diffpy { namespace srreal { /// @class PDFBaseline /// @brief abstract base class for PDF baseline function -class PDFBaseline : +class DLL_EXPORT PDFBaseline : public Attributes, public HasClassRegistry { diff --git a/src/diffpy/srreal/PDFCalculator.hpp b/src/diffpy/srreal/PDFCalculator.hpp index 79220e0a..f93795e3 100644 --- a/src/diffpy/srreal/PDFCalculator.hpp +++ b/src/diffpy/srreal/PDFCalculator.hpp @@ -26,10 +26,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class PDFCalculator : +class DLL_EXPORT PDFCalculator : public PairQuantity, public PeakWidthModelOwner, public ScatteringFactorTableOwner, diff --git a/src/diffpy/srreal/PDFEnvelope.cpp b/src/diffpy/srreal/PDFEnvelope.cpp index 04023176..3d6811d3 100644 --- a/src/diffpy/srreal/PDFEnvelope.cpp +++ b/src/diffpy/srreal/PDFEnvelope.cpp @@ -31,7 +31,7 @@ using diffpy::validators::ensureNonNull; namespace diffpy { // Unique instantiation of the template registry base class. -template class HasClassRegistry; +template class DLL_EXPORT HasClassRegistry; namespace srreal { diff --git a/src/diffpy/srreal/PDFEnvelope.hpp b/src/diffpy/srreal/PDFEnvelope.hpp index f7035737..7cb169ee 100644 --- a/src/diffpy/srreal/PDFEnvelope.hpp +++ b/src/diffpy/srreal/PDFEnvelope.hpp @@ -35,6 +35,8 @@ #include #include +#include + namespace diffpy { namespace srreal { @@ -42,7 +44,7 @@ namespace srreal { /// @class PDFEnvelope /// @brief abstract base class for PDF envelope scaling function -class PDFEnvelope : +class DLL_EXPORT PDFEnvelope : public diffpy::Attributes, public diffpy::HasClassRegistry { @@ -69,7 +71,7 @@ typedef PDFEnvelope::SharedPtr PDFEnvelopePtr; /// @brief storage of one or more PDFEnvelope functions and their /// application to unscaled x, y arrays -class PDFEnvelopeOwner +class DLL_EXPORT PDFEnvelopeOwner { public: diff --git a/src/diffpy/srreal/PDFUtils.hpp b/src/diffpy/srreal/PDFUtils.hpp index 97e2764a..b28686ba 100644 --- a/src/diffpy/srreal/PDFUtils.hpp +++ b/src/diffpy/srreal/PDFUtils.hpp @@ -28,6 +28,8 @@ #include #include +#include + namespace diffpy { namespace srreal { @@ -43,10 +45,10 @@ const double DEFAULT_QGRID_QMAX = 10.0; const double DEFAULT_QGRID_QSTEP = 0.05; /// fast Fourier transformation converting G(r) to F(Q) -QuantityType fftgtof(const QuantityType& g, double rstep, double rmin=0.0); +DLL_EXPORT QuantityType fftgtof(const QuantityType& g, double rstep, double rmin=0.0); /// fast Fourier transformation converting F(Q) to G(r) -QuantityType fftftog(const QuantityType& f, double qstep, double qmin=0.0); +DLL_EXPORT QuantityType fftftog(const QuantityType& f, double qstep, double qmin=0.0); /// shared methods for PDFCalculator and DebyePDFCalculator template QuantityType pdfutils_getQgrid(const T* pdfc); diff --git a/src/diffpy/srreal/PQEvaluator.hpp b/src/diffpy/srreal/PQEvaluator.hpp index 8fa5f228..2efd5aad 100644 --- a/src/diffpy/srreal/PQEvaluator.hpp +++ b/src/diffpy/srreal/PQEvaluator.hpp @@ -33,6 +33,8 @@ #include #include +#include + namespace diffpy { namespace srreal { @@ -51,11 +53,11 @@ enum PQEvaluatorFlag { FIXEDSITEINDEX = 2, }; -class PQEvaluatorBasic +class DLL_EXPORT PQEvaluatorBasic { public: - friend + friend DLL_EXPORT PQEvaluatorPtr createPQEvaluator(PQEvaluatorType, PQEvaluatorPtr); // constructor PQEvaluatorBasic(); @@ -98,7 +100,7 @@ class PQEvaluatorBasic }; -class PQEvaluatorOptimized : public PQEvaluatorBasic +class DLL_EXPORT PQEvaluatorOptimized : public PQEvaluatorBasic { public: @@ -127,7 +129,7 @@ class PQEvaluatorOptimized : public PQEvaluatorBasic }; -class PQEvaluatorCheck : public PQEvaluatorOptimized +class DLL_EXPORT PQEvaluatorCheck : public PQEvaluatorOptimized { public: @@ -149,7 +151,7 @@ class PQEvaluatorCheck : public PQEvaluatorOptimized // Factory function for PairQuantity evaluators ------------------------------ -PQEvaluatorPtr createPQEvaluator( +DLL_EXPORT PQEvaluatorPtr createPQEvaluator( PQEvaluatorType pqtp, PQEvaluatorPtr pqevsrc=PQEvaluatorPtr()); } // namespace srreal diff --git a/src/diffpy/srreal/PairQuantity.hpp b/src/diffpy/srreal/PairQuantity.hpp index b80086ec..04d8c841 100644 --- a/src/diffpy/srreal/PairQuantity.hpp +++ b/src/diffpy/srreal/PairQuantity.hpp @@ -32,12 +32,14 @@ #include #include +#include + namespace diffpy { namespace srreal { class BaseBondGenerator; -class PairQuantity : public diffpy::Attributes +class DLL_EXPORT PairQuantity : public diffpy::Attributes { public: @@ -84,7 +86,7 @@ class PairQuantity : public diffpy::Attributes friend class PQEvaluatorBasic; friend class PQEvaluatorOptimized; - friend StructureAdapterPtr + friend DLL_EXPORT StructureAdapterPtr replacePairQuantityStructure(PairQuantity&, StructureAdapterPtr); // methods @@ -171,7 +173,7 @@ void PairQuantity::setStructure(const T& stru) /// The purpose of this function is to support Python pickling of /// PairQuantity objects that hold Python-derived StructureAdapter classes. /// Use it only if you absolutely have to and you know what you do. -StructureAdapterPtr +DLL_EXPORT StructureAdapterPtr replacePairQuantityStructure(PairQuantity& pq, StructureAdapterPtr stru); } // namespace srreal diff --git a/src/diffpy/srreal/PeakProfile.cpp b/src/diffpy/srreal/PeakProfile.cpp index ced61f2b..e3211127 100644 --- a/src/diffpy/srreal/PeakProfile.cpp +++ b/src/diffpy/srreal/PeakProfile.cpp @@ -23,7 +23,7 @@ namespace diffpy { // Unique instantiation of the template registry base class. -template class HasClassRegistry; +template class DLL_EXPORT HasClassRegistry; namespace srreal { diff --git a/src/diffpy/srreal/PeakProfile.hpp b/src/diffpy/srreal/PeakProfile.hpp index 8f6d4e14..c5342012 100644 --- a/src/diffpy/srreal/PeakProfile.hpp +++ b/src/diffpy/srreal/PeakProfile.hpp @@ -33,10 +33,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class PeakProfile : +class DLL_EXPORT PeakProfile : public diffpy::Attributes, public diffpy::HasClassRegistry { diff --git a/src/diffpy/srreal/PeakWidthModel.cpp b/src/diffpy/srreal/PeakWidthModel.cpp index 0418d9e1..a9bb766c 100644 --- a/src/diffpy/srreal/PeakWidthModel.cpp +++ b/src/diffpy/srreal/PeakWidthModel.cpp @@ -27,7 +27,7 @@ using diffpy::validators::ensureNonNull; namespace diffpy { // Unique instantiation of the template registry base class. -template class HasClassRegistry; +template class DLL_EXPORT HasClassRegistry; namespace srreal { diff --git a/src/diffpy/srreal/PeakWidthModel.hpp b/src/diffpy/srreal/PeakWidthModel.hpp index 25a589bf..3e917d12 100644 --- a/src/diffpy/srreal/PeakWidthModel.hpp +++ b/src/diffpy/srreal/PeakWidthModel.hpp @@ -35,10 +35,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class PeakWidthModel : +class DLL_EXPORT PeakWidthModel : public diffpy::Attributes, public diffpy::HasClassRegistry { @@ -71,7 +73,7 @@ class PeakWidthModel : typedef PeakWidthModel::SharedPtr PeakWidthModelPtr; -class PeakWidthModelOwner +class DLL_EXPORT PeakWidthModelOwner { public: diff --git a/src/diffpy/srreal/PeriodicStructureAdapter.hpp b/src/diffpy/srreal/PeriodicStructureAdapter.hpp index d3082e0e..365f632b 100644 --- a/src/diffpy/srreal/PeriodicStructureAdapter.hpp +++ b/src/diffpy/srreal/PeriodicStructureAdapter.hpp @@ -23,14 +23,17 @@ #define PERIODICSTRUCTUREADAPTER_HPP_INCLUDED #include +#include #include +#include + namespace diffpy { namespace srreal { class PointsInSphere; -class PeriodicStructureAdapter : public AtomicStructureAdapter +class DLL_EXPORT PeriodicStructureAdapter : public AtomicStructureAdapter { public: @@ -68,8 +71,8 @@ typedef boost::shared_ptr PeriodicStructureAdapterPtr; // Comparison functions -bool operator==(const PeriodicStructureAdapter&, const PeriodicStructureAdapter&); -bool operator!=(const PeriodicStructureAdapter&, const PeriodicStructureAdapter&); +DLL_EXPORT bool operator==(const PeriodicStructureAdapter&, const PeriodicStructureAdapter&); +DLL_EXPORT bool operator!=(const PeriodicStructureAdapter&, const PeriodicStructureAdapter&); class PeriodicStructureBondGenerator : public BaseBondGenerator diff --git a/src/diffpy/srreal/QResolutionEnvelope.hpp b/src/diffpy/srreal/QResolutionEnvelope.hpp index dccb3b37..f7d33ae6 100644 --- a/src/diffpy/srreal/QResolutionEnvelope.hpp +++ b/src/diffpy/srreal/QResolutionEnvelope.hpp @@ -21,13 +21,15 @@ #include +#include + namespace diffpy { namespace srreal { /// @class QResolutionEnvelope /// @brief wide Gaussian PDF scaling envelope caused by finite Q resolution -class QResolutionEnvelope : public PDFEnvelope +class DLL_EXPORT QResolutionEnvelope : public PDFEnvelope { public: diff --git a/src/diffpy/srreal/QuantityType.hpp b/src/diffpy/srreal/QuantityType.hpp index 11a1f678..c625ec5e 100644 --- a/src/diffpy/srreal/QuantityType.hpp +++ b/src/diffpy/srreal/QuantityType.hpp @@ -26,10 +26,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class QuantityType : public std::vector +class DLL_EXPORT QuantityType : public std::vector { private: diff --git a/src/diffpy/srreal/R3linalg.cpp b/src/diffpy/srreal/R3linalg.cpp index 19a70cc7..15a32814 100644 --- a/src/diffpy/srreal/R3linalg.cpp +++ b/src/diffpy/srreal/R3linalg.cpp @@ -25,6 +25,10 @@ namespace diffpy { namespace srreal { namespace R3 { +// Constants +DLL_EXPORT const int Ndim = 3; + +// Functions const Matrix& identity() { static Matrix mx = ublas::identity_matrix(Ndim); diff --git a/src/diffpy/srreal/R3linalg.hpp b/src/diffpy/srreal/R3linalg.hpp index bffd5c7c..69916aad 100644 --- a/src/diffpy/srreal/R3linalg.hpp +++ b/src/diffpy/srreal/R3linalg.hpp @@ -26,6 +26,8 @@ #include #include +#include + namespace diffpy { namespace srreal { namespace R3 { @@ -40,13 +42,13 @@ using ublas::trans; // Constants -const int Ndim = 3; +extern DLL_EXPORT const int Ndim; using ::diffpy::mathutils::SQRT_DOUBLE_EPS; const ublas::zero_vector zerovector(Ndim); // Classes -class Vector : public ublas::vector > +class DLL_EXPORT Vector : public ublas::vector > { typedef ublas::vector > BaseVector; @@ -94,7 +96,7 @@ class Vector : public ublas::vector > }; -class Matrix : public ublas::matrix > { typedef ublas::matrix #include +#include + namespace diffpy { namespace srreal { -class SFTElectron : public ScatteringFactorTable +class DLL_EXPORT SFTElectron : public ScatteringFactorTable { public: diff --git a/src/diffpy/srreal/SFTElectronNumber.hpp b/src/diffpy/srreal/SFTElectronNumber.hpp index 3736861b..d3da0981 100644 --- a/src/diffpy/srreal/SFTElectronNumber.hpp +++ b/src/diffpy/srreal/SFTElectronNumber.hpp @@ -24,10 +24,12 @@ #include +#include + namespace diffpy { namespace srreal { -class SFTElectronNumber : public ScatteringFactorTable +class DLL_EXPORT SFTElectronNumber : public ScatteringFactorTable { public: diff --git a/src/diffpy/srreal/SFTNeutron.hpp b/src/diffpy/srreal/SFTNeutron.hpp index d2264dc6..a1a17427 100644 --- a/src/diffpy/srreal/SFTNeutron.hpp +++ b/src/diffpy/srreal/SFTNeutron.hpp @@ -24,10 +24,12 @@ #include +#include + namespace diffpy { namespace srreal { -class SFTNeutron : public ScatteringFactorTable +class DLL_EXPORT SFTNeutron : public ScatteringFactorTable { public: diff --git a/src/diffpy/srreal/SFTXray.hpp b/src/diffpy/srreal/SFTXray.hpp index 833ff611..8a9fc362 100644 --- a/src/diffpy/srreal/SFTXray.hpp +++ b/src/diffpy/srreal/SFTXray.hpp @@ -23,10 +23,12 @@ #include +#include + namespace diffpy { namespace srreal { -class SFTXray : public ScatteringFactorTable +class DLL_EXPORT SFTXray : public ScatteringFactorTable { public: diff --git a/src/diffpy/srreal/ScaleEnvelope.hpp b/src/diffpy/srreal/ScaleEnvelope.hpp index a01bb462..97b927e0 100644 --- a/src/diffpy/srreal/ScaleEnvelope.hpp +++ b/src/diffpy/srreal/ScaleEnvelope.hpp @@ -21,13 +21,15 @@ #include +#include + namespace diffpy { namespace srreal { /// @class ScaleEnvelope /// @brief constant PDF scaling factor -class ScaleEnvelope : public PDFEnvelope +class DLL_EXPORT ScaleEnvelope : public PDFEnvelope { public: diff --git a/src/diffpy/srreal/ScatteringFactorTable.cpp b/src/diffpy/srreal/ScatteringFactorTable.cpp index b5c4872a..07727d62 100644 --- a/src/diffpy/srreal/ScatteringFactorTable.cpp +++ b/src/diffpy/srreal/ScatteringFactorTable.cpp @@ -27,7 +27,7 @@ using diffpy::validators::ensureNonNull; namespace diffpy { // Unique instantiation of the template registry base class. -template class HasClassRegistry; +template class DLL_EXPORT HasClassRegistry; namespace srreal { diff --git a/src/diffpy/srreal/ScatteringFactorTable.hpp b/src/diffpy/srreal/ScatteringFactorTable.hpp index e876748d..1f798438 100644 --- a/src/diffpy/srreal/ScatteringFactorTable.hpp +++ b/src/diffpy/srreal/ScatteringFactorTable.hpp @@ -33,10 +33,12 @@ #include #include +#include + namespace diffpy { namespace srreal { -class ScatteringFactorTable : +class DLL_EXPORT ScatteringFactorTable : public diffpy::HasClassRegistry { public: @@ -79,7 +81,7 @@ class ScatteringFactorTable : typedef ScatteringFactorTable::SharedPtr ScatteringFactorTablePtr; -class ScatteringFactorTableOwner +class DLL_EXPORT ScatteringFactorTableOwner { public: diff --git a/src/diffpy/srreal/SphericalShapeEnvelope.hpp b/src/diffpy/srreal/SphericalShapeEnvelope.hpp index 67ba9740..e6e95bb5 100644 --- a/src/diffpy/srreal/SphericalShapeEnvelope.hpp +++ b/src/diffpy/srreal/SphericalShapeEnvelope.hpp @@ -21,6 +21,8 @@ #include +#include + namespace diffpy { namespace srreal { @@ -29,7 +31,7 @@ namespace srreal { /// Spherical shape envelope is not applied for spherical particle /// diameter, spdiameter, smaller or equal to zero. -class SphericalShapeEnvelope : public PDFEnvelope +class DLL_EXPORT SphericalShapeEnvelope : public PDFEnvelope { public: diff --git a/src/diffpy/srreal/StepCutEnvelope.hpp b/src/diffpy/srreal/StepCutEnvelope.hpp index 597b5a64..4460d874 100644 --- a/src/diffpy/srreal/StepCutEnvelope.hpp +++ b/src/diffpy/srreal/StepCutEnvelope.hpp @@ -21,6 +21,8 @@ #include +#include + namespace diffpy { namespace srreal { @@ -28,7 +30,7 @@ namespace srreal { /// @brief empirical step-function PDF envelope. The envelope is not /// applied when the cutoff radius stepcut is smaller or equal zero. -class StepCutEnvelope : public PDFEnvelope +class DLL_EXPORT StepCutEnvelope : public PDFEnvelope { public: diff --git a/src/diffpy/srreal/StructureAdapter.hpp b/src/diffpy/srreal/StructureAdapter.hpp index 1ff4218d..2b707129 100644 --- a/src/diffpy/srreal/StructureAdapter.hpp +++ b/src/diffpy/srreal/StructureAdapter.hpp @@ -32,6 +32,14 @@ #include #include +#include + +#ifdef _MSC_VER + #define DEPRECATED __declspec(deprecated) +#else + #define DEPRECATED __attribute__((deprecated)) +#endif + namespace diffpy { namespace srreal { @@ -43,7 +51,7 @@ class StructureDifference; /// @brief abstract adaptor to structure data needed by /// PairQuantity calculator -class StructureAdapter : +class DLL_EXPORT StructureAdapter : public boost::enable_shared_from_this { public: @@ -89,9 +97,7 @@ class StructureAdapter : /// this method allows custom special configuration for a concrete /// pair of StructureAdapter and PairQuantity objects. - virtual void customPQConfig(PairQuantity* pq) const - __attribute__ ((deprecated)) - { } + virtual DEPRECATED void customPQConfig(PairQuantity* pq) const { } /// Return difference from the other StructureAdapter virtual StructureDifference diff(StructureAdapterConstPtr) const; @@ -108,7 +114,7 @@ class StructureAdapter : // Routines ------------------------------------------------------------------ /// Return a singleton instance of an empty StructureAdapter -StructureAdapterPtr emptyStructureAdapter(); +DLL_EXPORT StructureAdapterPtr emptyStructureAdapter(); /// Calculate MSD along specified direction in Cartesian space. double meanSquareDisplacement(const R3::Matrix& Uijcartn, const R3::Vector& s, diff --git a/src/diffpy/srreal/StructureDifference.hpp b/src/diffpy/srreal/StructureDifference.hpp index 4be27e58..47bddd5b 100644 --- a/src/diffpy/srreal/StructureDifference.hpp +++ b/src/diffpy/srreal/StructureDifference.hpp @@ -24,10 +24,12 @@ #include +#include + namespace diffpy { namespace srreal { -class StructureDifference { +class DLL_EXPORT StructureDifference { public: diff --git a/src/diffpy/srreal/ZeroBaseline.hpp b/src/diffpy/srreal/ZeroBaseline.hpp index 06ba3978..a863b3e0 100644 --- a/src/diffpy/srreal/ZeroBaseline.hpp +++ b/src/diffpy/srreal/ZeroBaseline.hpp @@ -21,13 +21,15 @@ #include +#include + namespace diffpy { namespace srreal { /// @class ZeroBaseline /// @brief trivial zero baseline -class ZeroBaseline : public PDFBaseline +class DLL_EXPORT ZeroBaseline : public PDFBaseline { public: diff --git a/src/diffpy/version.tpl b/src/diffpy/version.tpl index 548fb3ab..6edf3327 100644 --- a/src/diffpy/version.tpl +++ b/src/diffpy/version.tpl @@ -64,7 +64,9 @@ // libdiffpy_version_info will hold runtime version data, which may be // different from client compile-time values. -struct libdiffpy_version_info { +#include + +struct DLL_EXPORT libdiffpy_version_info { static const long long version; static const char* version_str; From 601959fc179ce357215db5b5442c7194d0b379ac Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 1 Feb 2025 18:22:10 -0500 Subject: [PATCH 3/4] fix build scripts for Windows --- SConstruct | 65 ++++++++++++---- src/SConscript | 161 +++++++++++++++++++++++++++------------ src/SConscript.configure | 62 ++++++--------- src/diffpy/SConscript | 5 +- 4 files changed, 188 insertions(+), 105 deletions(-) diff --git a/SConstruct b/SConstruct index 5179bba5..1bca2b36 100644 --- a/SConstruct +++ b/SConstruct @@ -21,7 +21,8 @@ SCons construction environment can be customized in sconscript.local script. """ import os -import platform +from os.path import join as pjoin +from SCons.Script import * def subdictionary(d, keyset): return dict(kv for kv in d.items() if kv[0] in keyset) @@ -37,32 +38,63 @@ DefaultEnvironment(ENV=subdictionary(os.environ, ''' # Create construction environment env = DefaultEnvironment().Clone() -# Variables definitions below work only with 0.98.1 or later. +# Variables definitions below work only with 0.98.1 or later env.EnsureSConsVersion(0, 98, 1) # Customizable compile variables vars = Variables('sconsvars.py') -vars.Add(PathVariable( - 'prefix', - 'installation prefix directory', - '/usr/local')) -vars.Update(env) +# Set PATHs +if 'PREFIX' in os.environ: + vars.Add(PathVariable( + 'prefix', + 'installation prefix directory', + os.environ['prefix'])) + vars.Update(env) +elif 'CONDA_PREFIX' in os.environ: + vars.Add(PathVariable( + 'prefix', + 'installation prefix directory', + os.environ['CONDA_PREFIX'])) + vars.Update(env) +else: + vars.Add(PathVariable( + 'prefix', + 'installation prefix directory', + '/usr/local')) + vars.Update(env) + +if env['PLATFORM'] == "win32": + include_path = pjoin(env['prefix'], 'Library', 'include') + lib_path = pjoin(env['prefix'], 'Library', 'lib') + shared_path = pjoin(env['prefix'], 'Library', 'share') + + env['ENV']['TMP'] = os.environ['TMP'] +else: + include_path = pjoin(env['prefix'], 'include') + lib_path = pjoin(env['prefix'], 'lib') + shared_path = pjoin(env['prefix'], 'share') + vars.Add(PathVariable( 'libdir', - 'installation directory for compiled library [prefix/lib]', - env['prefix'] + '/lib', + 'installation directory for compiled programs', + lib_path, PathVariable.PathAccept)) vars.Add(PathVariable( 'includedir', - 'installation directory for C++ header files [prefix/include]', - env['prefix'] + '/include', + 'installation directory for C++ header files', + include_path, PathVariable.PathAccept)) vars.Add(PathVariable( 'datadir', - 'installation directory for architecture independent data [prefix/share]', - env['prefix'] + '/share', + 'installation directory for architecture independent data', + shared_path, PathVariable.PathAccept)) + +env.AppendUnique(CPPPATH=[include_path]) +env.AppendUnique(LIBPATH=[lib_path]) + +# Customizable build variables vars.Add(EnumVariable( 'build', 'compiler settings', @@ -70,7 +102,7 @@ vars.Add(EnumVariable( vars.Add(EnumVariable( 'tool', 'C++ compiler toolkit to be used', - 'default', allowed_values=('default', 'intelc'))) + 'default', allowed_values=('default', 'clang', 'gcc', 'intelc'))) vars.Add(BoolVariable( 'enable_objcryst', 'enable objcryst support, when installed', None)) @@ -83,11 +115,14 @@ vars.Add( vars.Add(BoolVariable( 'test_installed', 'build tests using the installed library.', False)) + vars.Update(env) + env.Help(MY_SCONS_HELP % vars.GenerateHelpText(env)) env['has_objcryst'] = None -btags = [env['build'], platform.machine()] + +btags = [env['build'], env['PLATFORM']] if env['profile']: btags.append('profile') builddir = env.Dir('build/' + '-'.join(btags)) diff --git a/src/SConscript b/src/SConscript index fce570ec..6bc5cc38 100644 --- a/src/SConscript +++ b/src/SConscript @@ -1,66 +1,104 @@ import os +from SCons.Script import * +from os.path import join as pjoin Import('env') # Build environment configuration -------------------------------------------- -# Insert LIBRARY_PATH explicitly because some compilers -# ignore it in the system environment. -env.PrependUnique(LIBPATH=env['ENV'].get('LIBRARY_PATH', '').split(':')) - -# Use Intel C++ compiler if requested by the user. -icpc = None +# Use C++ compiler specified by the 'tool' option. +# Intel C++ compiler if env['tool'] == 'intelc': icpc = env.WhereIs('icpc') if not icpc: print("Cannot find the Intel C/C++ compiler 'icpc'.") Exit(1) env.Tool('intelc', topdir=icpc[:icpc.rfind('/bin')]) + env=env.Clone() -fast_linkflags = ['-s'] +# Clang++ compiler +if env['tool'] == 'clang': + llvm = env.WhereIs('clang++') + if not llvm: + print("Cannot find the clang++ compiler.") + Exit(1) + env=env.Clone(tools=['clangxx']) -# 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) +# g++ compiler +if env['tool'] == 'gcc': + gcc = env.WhereIs('g++') + if not gcc: + print("Cannot find the g++ compiler.") + Exit(1) + env=env.Clone(tools=['mingw']) + +# Default use scons auto found compiler # Platform specific intricacies. +fast_linkflags = ['-s'] + +# macOS specific options if env['PLATFORM'] == 'darwin': env.AppendUnique(CXXFLAGS='-ftemplate-depth-256') - env.Append(SHLINKFLAGS=['-install_name', '$TARGET.abspath']) + env.AppendUnique(SHLINKFLAGS=['-install_name', '$TARGET.abspath']) env.AppendUnique(SHLINKFLAGS='-headerpad_max_install_names') fast_linkflags[:] = [] # Compiler specific options -if icpc: - # options for Intel C++ compiler on hpc dev-intel07 - env.PrependUnique(CCFLAGS=['-w1', '-fp-model', 'precise']) - env.PrependUnique(LIBS=['imf']) - fast_optimflags = ['-fast', '-no-ipo'] -else: - # g++ options - env.PrependUnique(CCFLAGS=['-Wall']) - fast_optimflags = ['-ffast-math'] - -# Configure build variants -if env['build'] == 'debug': - env.Append(CCFLAGS='-g') -elif env['build'] == 'coverage': - env.CacheDir(None) - env.Append(CCFLAGS=['-g', '--coverage', '-O0']) - env.Append(LINKFLAGS='--coverage') -elif env['build'] == 'fast': - env.AppendUnique(CCFLAGS=['-O3'] + fast_optimflags) - env.AppendUnique(CPPDEFINES={'NDEBUG' : None}) - env.AppendUnique(LINKFLAGS=fast_linkflags) - -if env['profile']: - env.AppendUnique(CCFLAGS='-pg') - env.AppendUnique(LINKFLAGS='-pg') +if env['PLATFORM'] == "win32": + if env['tool'] == 'clang': + # clang++ on Windows + env['CC'] = 'clang' + env['CCFLAGS'] = ['-O3', '-ffast-math', '-std=c++14', '-m64', '-DBUILD_DLL'] + env.PrependUnique(CPPDEFINES='_USE_MATH_DEFINES') + env['LINKFLAGS']= ['-fuse-ld=lld-link', '-m64', '-lstdc++'] + + elif env['tool'] == 'gcc': + # MinGW + env.PrependUnique(CCFLAGS=['-O3', '-std=c++14', '-m64', '-DBUILD_DLL']) + env.PrependUnique(CPPDEFINES='_USE_MATH_DEFINES') + env.AppendUnique(LINKFLAGS='-m64') + + else: + # Visual c++ + env.PrependUnique(CCFLAGS=['/Ox', '/EHsc', '/MD', '/std:c++14', '/Wall', '/DBUILD_DLL']) + env.AppendUnique(CPPDEFINES=[{'NDEBUG': None}, '_USE_MATH_DEFINES']) + env.AppendUnique(LINKFLAGS=['/OPT:NOREF', '/OPT:NOICF']) + +else: + env.PrependUnique(CXXFLAGS='-std=c++11') + if icpc: + # options for Intel C++ compiler on hpc dev-intel07 + env.PrependUnique(CCFLAGS=['-w1', '-fp-model', 'precise']) + env.PrependUnique(LIBS=['imf']) + fast_optimflags = ['-fast', '-no-ipo'] + else: + # g++ options + env.PrependUnique(CCFLAGS=['-Wall']) + fast_optimflags = ['-ffast-math'] + + # Configure build variants + if env['build'] == 'debug': + env.Append(CCFLAGS='-g') + elif env['build'] == 'coverage': + env.CacheDir(None) + env.Append(CCFLAGS=['-g', '--coverage', '-O0']) + env.Append(LINKFLAGS='--coverage') + elif env['build'] == 'fast': + env.AppendUnique(CCFLAGS=['-O3'] + fast_optimflags) + env.AppendUnique(CPPDEFINES={'NDEBUG' : None}) + env.AppendUnique(LINKFLAGS=fast_linkflags) + + if env['profile']: + env.AppendUnique(CCFLAGS='-pg') + env.AppendUnique(LINKFLAGS='-pg') # configure boost and ObjCryst libraries unless non-relevant. skip_configure = (GetOption('clean') or GetOption('help') or (['sdist'] == list(COMMAND_LINE_TARGETS))) + +# Check dependencies if not skip_configure: SConscript('SConscript.configure') @@ -117,11 +155,15 @@ if 'sdist' in COMMAND_LINE_TARGETS: # use new environment with extra libraries needed for libdiffpy. env_lib = env.Clone() # Setup GSL, the GNU Scientific library. -env_lib.ParseConfig("gsl-config --cflags --libs") -# The dladdr call in runtimepath.cpp requires the dl library. -env_lib.AppendUnique(LIBS=['dl']) +# The dladdr call in runtimepath.cpp requires the dl library for Windows. +if env['has_objcryst'] == True: + env_lib.AppendUnique(LIBS=['dl', 'gsl', 'gslcblas','boost_serialization', 'libobjcryst']) +else: + env_lib.AppendUnique(LIBS=['dl', 'gsl', 'gslcblas','boost_serialization']) + libdiffpy = env_lib.SharedLibrary('diffpy', env['lib_sources']) + # Clean up .gcda and .gcno files from coverage analysis. env_lib.Clean(libdiffpy, Glob('diffpy/*.gc??')) env_lib.Clean(libdiffpy, Glob('diffpy/srreal/*.gc??')) @@ -141,17 +183,36 @@ if targets_that_test.intersection(COMMAND_LINE_TARGETS): prefix = env['prefix'] # install-lib -install_lib = env.Install(env['libdir'], libdiffpy) -if env['PLATFORM'] == 'darwin': - # DARWIN_INSTALL_NAME can be pre-set in sconscript.local - env.SetDefault(DARWIN_INSTALL_NAME='$TARGET.abspath') - env.AddPostAction(install_lib, - 'install_name_tool -id $DARWIN_INSTALL_NAME $TARGET') -if env['PLATFORM'] == 'posix' and WhereIs('ldconfig'): - opts = '' if os.getuid() == 0 else '-n' - env.AddPostAction(install_lib, - 'ldconfig %s $TARGET.dir' % opts) -Alias('install-lib', install_lib) +if env['PLATFORM'] in ['darwin', 'posix']: + install_lib = env.Install(env['libdir'], libdiffpy) + if env['PLATFORM'] == 'darwin': + # DARWIN_INSTALL_NAME can be pre-set in sconscript.local + env.SetDefault(DARWIN_INSTALL_NAME='$TARGET.abspath') + env.AddPostAction(install_lib, + 'install_name_tool -id $DARWIN_INSTALL_NAME $TARGET') + if env['PLATFORM'] == 'posix' and WhereIs('ldconfig'): + opts = '' if os.getuid() == 0 else '-n' + env.AddPostAction(install_lib, + 'ldconfig %s $TARGET.dir' % opts) + Alias('install-lib', install_lib) + +if env['PLATFORM'] == 'win32': + bindir = pjoin(prefix, 'Library', 'bin') + for node in libdiffpy: + ext = os.path.splitext(str(node))[1].lower() + if ext == '.dll': + dll_node = node + elif ext == '.lib': + lib_node = node + + if dll_node is None: + print("Warning: DLL file not found in build outputs.") + if lib_node is None: + print("Warning: LIB file not found in build outputs.") + + install_dll = env.Install(bindir, dll_node) + install_lib = env.Install(env['libdir'], lib_node) + Alias('install-lib', [install_dll, install_lib]) # install-include ninc = len(Dir('.').path) + 1 diff --git a/src/SConscript.configure b/src/SConscript.configure index 3bc0568c..e834089f 100644 --- a/src/SConscript.configure +++ b/src/SConscript.configure @@ -19,61 +19,45 @@ def CheckBoostVersion(context, version): context.Result(rv) return rv -# Helper functions ----------------------------------------------------------- - -boostlibtags = ['', '-mt'] -def configure_boost_library(libname): - '''Add a boost library to the configured environment allowing for any - of the boostlibtags name extensions. - - libname -- boost library name without any extension - - Note: CheckLib function automatically adds library to the environment. +def CheckObjCrystVersion(context, version): + '''Check if ObjCryst Library is at least of specified version ''' - # using global conf defined below - for t in boostlibtags: - libnamefull = libname + t - if conf.CheckLib(libnamefull, language='C++'): - boostlibtags[:] = [t] - return - # library not found here - print('This program requires %r library' % libname) - Exit(1) + # Boost versions are in format major.minor.subminor + v_arr = [int(n) for n in version.split(".")] + version_n = str(int(sum([(v * n) for v, n in zip(v_arr, (1e9, 1e6, 1e3))])))+"LL" + context.Message('Checking for ObjCryst version >= %s... ' % (version)) + rv = context.TryCompile('\n'.join([ + '#include ', + '#if LIBOBJCRYST_VERSION < %s', + '#error Installed ObjCryst is too old!', + '#endif', + 'int main() { return 0; }', + '', ]) % version_n, '.cpp') + context.Result(rv) + return rv # Start configuration -------------------------------------------------------- conf = Configure(env, custom_tests={ 'CheckBoostVersion' : CheckBoostVersion, + 'CheckObjCrystVersion' : CheckObjCrystVersion, }) -# Add Conda include and library paths -import os -conda_prefix = Environment(ENV=os.environ)['ENV'].get('CONDA_PREFIX') -if conda_prefix: - env.Append(CPPPATH=[os.path.join(conda_prefix, 'include')]) - env.Append(LIBPATH=[os.path.join(conda_prefix, 'lib')]) - # serialization of unordered_map requires boost 1.56.0 boost_required = '1.56.0' if not conf.CheckBoostVersion(boost_required): print('This software requires Boost %s or later.' % boost_required) Exit(1) -# boost_serialization -configure_boost_library('boost_serialization') - -# ObjCryst - assume a no-objcryst fallback configuration. -conf.env['has_objcryst'] = False -# Detect ObjCryst and exit with error if requested and not found. -# By default conf.env does not contain the 'enable_objcryst' key. +# Check for ObjCryst library if conf.env.get('enable_objcryst', True): - conf.env['has_objcryst'] = conf.CheckLibWithHeader( - 'ObjCryst', 'ObjCryst/ObjCryst/Crystal.h', - language='C++', autoadd=True) - objcryst_requested = conf.env.get('enable_objcryst', False) - if objcryst_requested and not conf.env['has_objcryst']: - print("Adjust compiler paths or build with 'enable_objcryst=False'.") + if not conf.CheckObjCrystVersion('2017.2.1'): + print('ObjCryst library not found. Please install it or disable it.') Exit(1) + else: + conf.env['has_objcryst'] = True +else: + conf.env['has_objcryst'] = False env = conf.Finish() diff --git a/src/diffpy/SConscript b/src/diffpy/SConscript index 8e3c07d8..f8b8ad6f 100644 --- a/src/diffpy/SConscript +++ b/src/diffpy/SConscript @@ -4,9 +4,12 @@ Import('env', 'GlobSources') env['lib_includes'] += GlobSources('*.[hi]pp') env['lib_sources'] += [f for f in GlobSources('*.cpp') - if str(f) != 'runtimepath.cpp'] + if str(f) != 'runtimepath.cpp'] rtrp = os.path.relpath(env['runtimepath'], env['libdir']) +if env['PLATFORM'] == "win32": + rtrp = rtrp.replace('\\', '/') + env_rt = env.Clone() env_rt.AppendUnique(CPPDEFINES=dict(DIFFPYRUNTIMERELPATH=rtrp)) rtso = env_rt.SharedObject('runtimepath', 'runtimepath.cpp') From 28c0622d7ded9e531c55592221563a4d0cf79021 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 1 Feb 2025 19:26:41 -0500 Subject: [PATCH 4/4] small fix --- src/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SConscript b/src/SConscript index 6bc5cc38..af19b4f3 100644 --- a/src/SConscript +++ b/src/SConscript @@ -67,7 +67,7 @@ if env['PLATFORM'] == "win32": else: env.PrependUnique(CXXFLAGS='-std=c++11') - if icpc: + if env['tool'] == 'intelc': # options for Intel C++ compiler on hpc dev-intel07 env.PrependUnique(CCFLAGS=['-w1', '-fp-model', 'precise']) env.PrependUnique(LIBS=['imf'])