Commit b256555e authored by Peter Eastman's avatar Peter Eastman
Browse files

Fixed compilation errors on Windows

parent 59b69776
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#ifdef WIN32
#define _USE_MATH_DEFINES // Needed to get M_PI
#endif
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h" #include "openmm/internal/ContextImpl.h"
#include "openmm/internal/NonbondedForceImpl.h" #include "openmm/internal/NonbondedForceImpl.h"
...@@ -37,10 +40,6 @@ ...@@ -37,10 +40,6 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "openmm/Platform.h" #include "openmm/Platform.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "windowsExportCuda.h"
namespace OpenMM { namespace OpenMM {
...@@ -38,7 +39,7 @@ class CudaContext; ...@@ -38,7 +39,7 @@ class CudaContext;
* This Platform subclass uses CUDA implementations of the OpenMM kernels. * This Platform subclass uses CUDA implementations of the OpenMM kernels.
*/ */
class OPENMM_EXPORT CudaPlatform : public Platform { class OPENMM_EXPORT_CUDA CudaPlatform : public Platform {
public: public:
class PlatformData; class PlatformData;
CudaPlatform(); CudaPlatform();
...@@ -91,7 +92,7 @@ public: ...@@ -91,7 +92,7 @@ public:
} }
}; };
class OPENMM_EXPORT CudaPlatform::PlatformData { class OPENMM_EXPORT_CUDA CudaPlatform::PlatformData {
public: public:
PlatformData(const System& system, const std::string& deviceIndexProperty, const std::string& blockingProperty, const std::string& precisionProperty, PlatformData(const System& system, const std::string& deviceIndexProperty, const std::string& blockingProperty, const std::string& precisionProperty,
const std::string& compilerProperty, const std::string& tempProperty); const std::string& compilerProperty, const std::string& tempProperty);
......
#ifndef OPENMM_WINDOWSEXPORTCUDA_H_
#define OPENMM_WINDOWSEXPORTCUDA_H_
/*
* Shared libraries are messy in Visual Studio. We have to distinguish three
* cases:
* (1) this header is being used to build the OpenMM shared library
* (dllexport)
* (2) this header is being used by a *client* of the OpenMM shared
* library (dllimport)
* (3) we are building the OpenMM static library, or the client is
* being compiled with the expectation of linking with the
* OpenMM static library (nothing special needed)
* In the CMake script for building this library, we define one of the symbols
* OPENMM_CUDA_BUILDING_{SHARED|STATIC}_LIBRARY
* Client code normally has no special symbol defined, in which case we'll
* assume it wants to use the shared library. However, if the client defines
* the symbol OPENMM_USE_STATIC_LIBRARIES we'll suppress the dllimport so
* that the client code can be linked with static libraries. Note that
* the client symbol is not library dependent, while the library symbols
* affect only the OpenMM library, meaning that other libraries can
* be clients of this one. However, we are assuming all-static or all-shared.
*/
#ifdef _MSC_VER
// We don't want to hear about how sprintf is "unsafe".
#pragma warning(disable:4996)
// Keep MS VC++ quiet about lack of dll export of private members.
#pragma warning(disable:4251)
#if defined(OPENMM_CUDA_BUILDING_SHARED_LIBRARY)
#define OPENMM_EXPORT_CUDA __declspec(dllexport)
#elif defined(OPENMM_CUDA_BUILDING_STATIC_LIBRARY) || defined(OPENMM_CUDA_USE_STATIC_LIBRARIES)
#define OPENMM_EXPORT_CUDA
#else
#define OPENMM_EXPORT_CUDA __declspec(dllimport) // i.e., a client of a shared library
#endif
#else
#define OPENMM_EXPORT_CUDA // Linux, Mac
#endif
#endif // OPENMM_WINDOWSEXPORTCUDA_H_
...@@ -19,6 +19,6 @@ ELSE (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug) ...@@ -19,6 +19,6 @@ ELSE (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET(MAIN_OPENMM_LIB ${OPENMM_LIBRARY_NAME}) SET(MAIN_OPENMM_LIB ${OPENMM_LIBRARY_NAME})
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug) ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${MAIN_OPENMM_LIB} ${CUDA_CUDA_LIBRARY} ${CUDA_cufft_LIBRARY} ${PTHREADS_LIB}) TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${MAIN_OPENMM_LIB} ${CUDA_CUDA_LIBRARY} ${CUDA_cufft_LIBRARY} ${PTHREADS_LIB})
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES COMPILE_FLAGS "-DOPENMM_BUILDING_SHARED_LIBRARY") SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES COMPILE_FLAGS "-DOPENMM_CUDA_BUILDING_SHARED_LIBRARY")
INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${SHARED_TARGET}) INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${SHARED_TARGET})
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/internal/windowsExport.h" #include "windowsExportCuda.h"
#include <cuda.h> #include <cuda.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
...@@ -43,7 +43,7 @@ class CudaContext; ...@@ -43,7 +43,7 @@ class CudaContext;
* for working with it and for copying data to and from device memory. * for working with it and for copying data to and from device memory.
*/ */
class OPENMM_EXPORT CudaArray { class OPENMM_EXPORT_CUDA CudaArray {
public: public:
/** /**
* Create a CudaArray object. The object is allocated on the heap with the "new" operator. * Create a CudaArray object. The object is allocated on the heap with the "new" operator.
......
...@@ -78,7 +78,7 @@ namespace OpenMM { ...@@ -78,7 +78,7 @@ namespace OpenMM {
* from your interaction code. * from your interaction code.
*/ */
class OPENMM_EXPORT CudaBondedUtilities { class OPENMM_EXPORT_CUDA CudaBondedUtilities {
public: public:
CudaBondedUtilities(CudaContext& context); CudaBondedUtilities(CudaContext& context);
~CudaBondedUtilities(); ~CudaBondedUtilities();
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include <cuda.h> #include <cuda.h>
#include <builtin_types.h> #include <builtin_types.h>
#include <vector_functions.h> #include <vector_functions.h>
#include "openmm/internal/windowsExport.h" #include "windowsExportCuda.h"
#include "CudaPlatform.h" #include "CudaPlatform.h"
namespace OpenMM { namespace OpenMM {
...@@ -63,7 +63,7 @@ class System; ...@@ -63,7 +63,7 @@ class System;
* thread is not used and calculations are performed on the main application thread. * thread is not used and calculations are performed on the main application thread.
*/ */
class OPENMM_EXPORT CudaContext { class OPENMM_EXPORT_CUDA CudaContext {
public: public:
class WorkTask; class WorkTask;
class WorkThread; class WorkThread;
......
...@@ -43,7 +43,7 @@ namespace OpenMM { ...@@ -43,7 +43,7 @@ namespace OpenMM {
* user defined mathematical expressions. * user defined mathematical expressions.
*/ */
class OPENMM_EXPORT CudaExpressionUtilities { class OPENMM_EXPORT_CUDA CudaExpressionUtilities {
public: public:
CudaExpressionUtilities(CudaContext& context) : context(context) { CudaExpressionUtilities(CudaContext& context) : context(context) {
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExport.h" #include "windowsExportCuda.h"
#include <vector> #include <vector>
namespace OpenMM { namespace OpenMM {
...@@ -37,7 +37,7 @@ namespace OpenMM { ...@@ -37,7 +37,7 @@ namespace OpenMM {
* about the behavior and requirements of that force. * about the behavior and requirements of that force.
*/ */
class OPENMM_EXPORT CudaForceInfo { class OPENMM_EXPORT_CUDA CudaForceInfo {
public: public:
CudaForceInfo() { CudaForceInfo() {
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "openmm/System.h" #include "openmm/System.h"
#include "CudaContext.h" #include "CudaContext.h"
#include "openmm/internal/windowsExport.h" #include "windowsExportCuda.h"
#include <iosfwd> #include <iosfwd>
namespace OpenMM { namespace OpenMM {
...@@ -39,7 +39,7 @@ namespace OpenMM { ...@@ -39,7 +39,7 @@ namespace OpenMM {
* common workspace arrays, random number generation, and enforcing constraints. * common workspace arrays, random number generation, and enforcing constraints.
*/ */
class OPENMM_EXPORT CudaIntegrationUtilities { class OPENMM_EXPORT_CUDA CudaIntegrationUtilities {
public: public:
CudaIntegrationUtilities(CudaContext& context, const System& system); CudaIntegrationUtilities(CudaContext& context, const System& system);
~CudaIntegrationUtilities(); ~CudaIntegrationUtilities();
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExport.h" #include "windowsExportCuda.h"
#include <string> #include <string>
namespace OpenMM { namespace OpenMM {
...@@ -38,7 +38,7 @@ namespace OpenMM { ...@@ -38,7 +38,7 @@ namespace OpenMM {
* kernels subfolder. * kernels subfolder.
*/ */
class OPENMM_EXPORT CudaKernelSources { class OPENMM_EXPORT_CUDA CudaKernelSources {
public: public:
@CUDA_FILE_DECLARATIONS@ @CUDA_FILE_DECLARATIONS@
}; };
......
...@@ -61,7 +61,7 @@ namespace OpenMM { ...@@ -61,7 +61,7 @@ namespace OpenMM {
* by ForceImpls during calcForcesAndEnergy(). * by ForceImpls during calcForcesAndEnergy().
*/ */
class OPENMM_EXPORT CudaNonbondedUtilities { class OPENMM_EXPORT_CUDA CudaNonbondedUtilities {
public: public:
class ParameterInfo; class ParameterInfo;
CudaNonbondedUtilities(CudaContext& context); CudaNonbondedUtilities(CudaContext& context);
......
...@@ -40,7 +40,7 @@ class CudaNonbondedUtilities; ...@@ -40,7 +40,7 @@ class CudaNonbondedUtilities;
* on the number of parameters required. * on the number of parameters required.
*/ */
class OPENMM_EXPORT CudaParameterSet { class OPENMM_EXPORT_CUDA CudaParameterSet {
public: public:
/** /**
* Create an CudaParameterSet. * Create an CudaParameterSet.
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
extern "C" OPENMM_EXPORT void registerPlatforms() { extern "C" OPENMM_EXPORT_CUDA void registerPlatforms() {
Platform::registerPlatform(new CudaPlatform()); Platform::registerPlatform(new CudaPlatform());
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "CudaArray.h" #include "CudaArray.h"
#include "openmm/internal/windowsExport.h" #include "windowsExportCuda.h"
#include "CudaContext.h" #include "CudaContext.h"
namespace OpenMM { namespace OpenMM {
...@@ -66,7 +66,7 @@ namespace OpenMM { ...@@ -66,7 +66,7 @@ namespace OpenMM {
* elements). * elements).
*/ */
class OPENMM_EXPORT CudaSort { class OPENMM_EXPORT_CUDA CudaSort {
public: public:
class SortTrait; class SortTrait;
/** /**
......
...@@ -128,7 +128,7 @@ void testRandomVelocities() { ...@@ -128,7 +128,7 @@ void testRandomVelocities() {
ke += 0.5*system.getParticleMass(i)*v.dot(v); ke += 0.5*system.getParticleMass(i)*v.dot(v);
} }
double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temperture; double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temperture;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 4/sqrt(numParticles)); ASSERT_USUALLY_EQUAL_TOL(expected, ke, 4/sqrt((double) numParticles));
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "openmm/Platform.h" #include "openmm/Platform.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "windowsExportOpenCL.h"
namespace OpenMM { namespace OpenMM {
class OpenCLContext; class OpenCLContext;
...@@ -38,7 +38,7 @@ class OpenCLContext; ...@@ -38,7 +38,7 @@ class OpenCLContext;
* This Platform subclass uses OpenCL implementations of the OpenMM kernels. * This Platform subclass uses OpenCL implementations of the OpenMM kernels.
*/ */
class OPENMM_EXPORT OpenCLPlatform : public Platform { class OPENMM_EXPORT_OPENCL OpenCLPlatform : public Platform {
public: public:
class PlatformData; class PlatformData;
OpenCLPlatform(); OpenCLPlatform();
...@@ -77,7 +77,7 @@ public: ...@@ -77,7 +77,7 @@ public:
} }
}; };
class OPENMM_EXPORT OpenCLPlatform::PlatformData { class OPENMM_EXPORT_OPENCL OpenCLPlatform::PlatformData {
public: public:
PlatformData(const System& system, const std::string& platformPropValue, const std::string& deviceIndexProperty, const std::string& precisionProperty); PlatformData(const System& system, const std::string& platformPropValue, const std::string& deviceIndexProperty, const std::string& precisionProperty);
~PlatformData(); ~PlatformData();
......
#ifndef OPENMM_WINDOWSEXPORTOPENCL_H_
#define OPENMM_WINDOWSEXPORTOPENCL_H_
/*
* Shared libraries are messy in Visual Studio. We have to distinguish three
* cases:
* (1) this header is being used to build the OpenMM shared library
* (dllexport)
* (2) this header is being used by a *client* of the OpenMM shared
* library (dllimport)
* (3) we are building the OpenMM static library, or the client is
* being compiled with the expectation of linking with the
* OpenMM static library (nothing special needed)
* In the CMake script for building this library, we define one of the symbols
* OPENMM_OPENCL_BUILDING_{SHARED|STATIC}_LIBRARY
* Client code normally has no special symbol defined, in which case we'll
* assume it wants to use the shared library. However, if the client defines
* the symbol OPENMM_USE_STATIC_LIBRARIES we'll suppress the dllimport so
* that the client code can be linked with static libraries. Note that
* the client symbol is not library dependent, while the library symbols
* affect only the OpenMM library, meaning that other libraries can
* be clients of this one. However, we are assuming all-static or all-shared.
*/
#ifdef _MSC_VER
// We don't want to hear about how sprintf is "unsafe".
#pragma warning(disable:4996)
// Keep MS VC++ quiet about lack of dll export of private members.
#pragma warning(disable:4251)
#if defined(OPENMM_OPENCL_BUILDING_SHARED_LIBRARY)
#define OPENMM_EXPORT_OPENCL __declspec(dllexport)
#elif defined(OPENMM_OPENCL_BUILDING_STATIC_LIBRARY) || defined(OPENMM_OPENCL_USE_STATIC_LIBRARIES)
#define OPENMM_EXPORT_OPENCL
#else
#define OPENMM_EXPORT_OPENCL __declspec(dllimport) // i.e., a client of a shared library
#endif
#else
#define OPENMM_EXPORT_OPENCL // Linux, Mac
#endif
#endif // OPENMM_WINDOWSEXPORTOPENCL_H_
...@@ -19,6 +19,6 @@ ELSE (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug) ...@@ -19,6 +19,6 @@ ELSE (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET(MAIN_OPENMM_LIB ${OPENMM_LIBRARY_NAME}) SET(MAIN_OPENMM_LIB ${OPENMM_LIBRARY_NAME})
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug) ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${MAIN_OPENMM_LIB} ${OPENCL_LIBRARIES} ${PTHREADS_LIB}) TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${MAIN_OPENMM_LIB} ${OPENCL_LIBRARIES} ${PTHREADS_LIB})
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES COMPILE_FLAGS "-DOPENMM_BUILDING_SHARED_LIBRARY") SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES COMPILE_FLAGS "-DOPENMM_OPENCL_BUILDING_SHARED_LIBRARY")
INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${SHARED_TARGET}) INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${SHARED_TARGET})
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "OpenCLContext.h" #include "OpenCLContext.h"
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/internal/windowsExport.h" #include "windowsExportOpenCL.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
...@@ -41,7 +41,7 @@ namespace OpenMM { ...@@ -41,7 +41,7 @@ namespace OpenMM {
* and for copying data to and from the OpenCL Buffer. * and for copying data to and from the OpenCL Buffer.
*/ */
class OPENMM_EXPORT OpenCLArray { class OPENMM_EXPORT_OPENCL OpenCLArray {
public: public:
/** /**
* Create an OpenCLArray object. The object is allocated on the heap with the "new" operator. * Create an OpenCLArray object. The object is allocated on the heap with the "new" operator.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment