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

Fixed compilation errors on Windows

parent 59b69776
......@@ -29,6 +29,9 @@
* 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/internal/ContextImpl.h"
#include "openmm/internal/NonbondedForceImpl.h"
......@@ -37,10 +40,6 @@
#include <map>
#include <sstream>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
using namespace OpenMM;
using namespace std;
......
......@@ -29,6 +29,7 @@
#include "openmm/Platform.h"
#include "openmm/System.h"
#include "windowsExportCuda.h"
namespace OpenMM {
......@@ -38,7 +39,7 @@ class CudaContext;
* This Platform subclass uses CUDA implementations of the OpenMM kernels.
*/
class OPENMM_EXPORT CudaPlatform : public Platform {
class OPENMM_EXPORT_CUDA CudaPlatform : public Platform {
public:
class PlatformData;
CudaPlatform();
......@@ -91,7 +92,7 @@ public:
}
};
class OPENMM_EXPORT CudaPlatform::PlatformData {
class OPENMM_EXPORT_CUDA CudaPlatform::PlatformData {
public:
PlatformData(const System& system, const std::string& deviceIndexProperty, const std::string& blockingProperty, const std::string& precisionProperty,
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)
SET(MAIN_OPENMM_LIB ${OPENMM_LIBRARY_NAME})
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
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})
......@@ -28,7 +28,7 @@
* -------------------------------------------------------------------------- */
#include "openmm/OpenMMException.h"
#include "openmm/internal/windowsExport.h"
#include "windowsExportCuda.h"
#include <cuda.h>
#include <iostream>
#include <sstream>
......@@ -43,7 +43,7 @@ class CudaContext;
* for working with it and for copying data to and from device memory.
*/
class OPENMM_EXPORT CudaArray {
class OPENMM_EXPORT_CUDA CudaArray {
public:
/**
* Create a CudaArray object. The object is allocated on the heap with the "new" operator.
......
......@@ -78,7 +78,7 @@ namespace OpenMM {
* from your interaction code.
*/
class OPENMM_EXPORT CudaBondedUtilities {
class OPENMM_EXPORT_CUDA CudaBondedUtilities {
public:
CudaBondedUtilities(CudaContext& context);
~CudaBondedUtilities();
......
......@@ -39,7 +39,7 @@
#include <cuda.h>
#include <builtin_types.h>
#include <vector_functions.h>
#include "openmm/internal/windowsExport.h"
#include "windowsExportCuda.h"
#include "CudaPlatform.h"
namespace OpenMM {
......@@ -63,7 +63,7 @@ class System;
* thread is not used and calculations are performed on the main application thread.
*/
class OPENMM_EXPORT CudaContext {
class OPENMM_EXPORT_CUDA CudaContext {
public:
class WorkTask;
class WorkThread;
......
......@@ -43,7 +43,7 @@ namespace OpenMM {
* user defined mathematical expressions.
*/
class OPENMM_EXPORT CudaExpressionUtilities {
class OPENMM_EXPORT_CUDA CudaExpressionUtilities {
public:
CudaExpressionUtilities(CudaContext& context) : context(context) {
}
......
......@@ -27,7 +27,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExport.h"
#include "windowsExportCuda.h"
#include <vector>
namespace OpenMM {
......@@ -37,7 +37,7 @@ namespace OpenMM {
* about the behavior and requirements of that force.
*/
class OPENMM_EXPORT CudaForceInfo {
class OPENMM_EXPORT_CUDA CudaForceInfo {
public:
CudaForceInfo() {
}
......
......@@ -29,7 +29,7 @@
#include "openmm/System.h"
#include "CudaContext.h"
#include "openmm/internal/windowsExport.h"
#include "windowsExportCuda.h"
#include <iosfwd>
namespace OpenMM {
......@@ -39,7 +39,7 @@ namespace OpenMM {
* common workspace arrays, random number generation, and enforcing constraints.
*/
class OPENMM_EXPORT CudaIntegrationUtilities {
class OPENMM_EXPORT_CUDA CudaIntegrationUtilities {
public:
CudaIntegrationUtilities(CudaContext& context, const System& system);
~CudaIntegrationUtilities();
......
......@@ -27,7 +27,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExport.h"
#include "windowsExportCuda.h"
#include <string>
namespace OpenMM {
......@@ -38,7 +38,7 @@ namespace OpenMM {
* kernels subfolder.
*/
class OPENMM_EXPORT CudaKernelSources {
class OPENMM_EXPORT_CUDA CudaKernelSources {
public:
@CUDA_FILE_DECLARATIONS@
};
......
......@@ -61,7 +61,7 @@ namespace OpenMM {
* by ForceImpls during calcForcesAndEnergy().
*/
class OPENMM_EXPORT CudaNonbondedUtilities {
class OPENMM_EXPORT_CUDA CudaNonbondedUtilities {
public:
class ParameterInfo;
CudaNonbondedUtilities(CudaContext& context);
......
......@@ -40,7 +40,7 @@ class CudaNonbondedUtilities;
* on the number of parameters required.
*/
class OPENMM_EXPORT CudaParameterSet {
class OPENMM_EXPORT_CUDA CudaParameterSet {
public:
/**
* Create an CudaParameterSet.
......
......@@ -42,7 +42,7 @@
using namespace OpenMM;
using namespace std;
extern "C" OPENMM_EXPORT void registerPlatforms() {
extern "C" OPENMM_EXPORT_CUDA void registerPlatforms() {
Platform::registerPlatform(new CudaPlatform());
}
......
......@@ -28,7 +28,7 @@
* -------------------------------------------------------------------------- */
#include "CudaArray.h"
#include "openmm/internal/windowsExport.h"
#include "windowsExportCuda.h"
#include "CudaContext.h"
namespace OpenMM {
......@@ -66,7 +66,7 @@ namespace OpenMM {
* elements).
*/
class OPENMM_EXPORT CudaSort {
class OPENMM_EXPORT_CUDA CudaSort {
public:
class SortTrait;
/**
......
......@@ -128,7 +128,7 @@ void testRandomVelocities() {
ke += 0.5*system.getParticleMass(i)*v.dot(v);
}
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[]) {
......
......@@ -29,7 +29,7 @@
#include "openmm/Platform.h"
#include "openmm/System.h"
#include "windowsExportOpenCL.h"
namespace OpenMM {
class OpenCLContext;
......@@ -38,7 +38,7 @@ class OpenCLContext;
* This Platform subclass uses OpenCL implementations of the OpenMM kernels.
*/
class OPENMM_EXPORT OpenCLPlatform : public Platform {
class OPENMM_EXPORT_OPENCL OpenCLPlatform : public Platform {
public:
class PlatformData;
OpenCLPlatform();
......@@ -77,7 +77,7 @@ public:
}
};
class OPENMM_EXPORT OpenCLPlatform::PlatformData {
class OPENMM_EXPORT_OPENCL OpenCLPlatform::PlatformData {
public:
PlatformData(const System& system, const std::string& platformPropValue, const std::string& deviceIndexProperty, const std::string& precisionProperty);
~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)
SET(MAIN_OPENMM_LIB ${OPENMM_LIBRARY_NAME})
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
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})
......@@ -29,7 +29,7 @@
#include "OpenCLContext.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/windowsExport.h"
#include "windowsExportOpenCL.h"
#include <iostream>
#include <sstream>
#include <vector>
......@@ -41,7 +41,7 @@ namespace OpenMM {
* and for copying data to and from the OpenCL Buffer.
*/
class OPENMM_EXPORT OpenCLArray {
class OPENMM_EXPORT_OPENCL OpenCLArray {
public:
/**
* 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