Commit 32f1c09f authored by Michael Sherman's avatar Michael Sherman
Browse files

Top level CMakeLists: got rid of "if hell is frozen over" code; eliminated some CMake warnings.

Examples: now builds CWrappers as a library; modified C builds to use it; added visual studio project to build Argon example in Fortran.
System.h: addForce() wasn't returning the index.
parent 38e8a8b4
......@@ -17,6 +17,12 @@
# On Linux it appears that cmake 2.4 does not work with Cuda cmake rules
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0005 NEW)
cmake_policy(SET CMP0011 NEW)
endif(COMMAND cmake_policy)
# Don't create a new project name if this is part of a mega-build from the
# parent directory
IF( NOT PROJECT_NAME )
......@@ -273,77 +279,6 @@ INSTALL_FILES(/include/openmm FILES ${TOP_HEADERS})
INSTALL_FILES(/include/openmm/internal FILES ${INTERNAL_HEADERS})
IF(HELL_IS_FROZEN_OVER)
# Set the build flags to link statically to the microsoft runtime library, unless
# the user tells us otherwise, via the variable "USE_MSVC_RUNTIME_DLL"
# It is a sore defect of cmake that makes these gymnastics necessary
IF(CMAKE_GENERATOR MATCHES "Visual Studio")
IF (CMAKE_BUILD_TYPE MATCHES Debug)
# STRING_APPEND( CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:\"LIBCMT.lib\"")
# STRING_APPEND( CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:\"LIBCMT.lib\"")
SET(CMAKE_EXE_LINKER_FLAGS /NODEFAULTLIB:LIBCMT)
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)
# First notice whether the user wants static or dll linkage to runtime library
SET(USE_MSVC_RUNTIME_DLL 0 CACHE BOOL "Link to DLL version of microsoft runtime library")
IF (USE_MSVC_RUNTIME_DLL)
# The same replacement strings will be used to replace "/MD" with "/MT", and "/MDd" with "/MTd"
SET(RT_FLAG_WE_WANT "/MD")
SET(RT_FLAG_WE_HATE "/MT")
IF (CMAKE_BUILD_TYPE MATCHES Debug)
SET(RT_FLAG_WE_WANT "/MDd")
SET(RT_FLAG_WE_HATE "/MTd")
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)
ELSE (USE_MSVC_RUNTIME_DLL)
SET(RT_FLAG_WE_WANT "/MT")
SET(RT_FLAG_WE_HATE "/MD")
IF (CMAKE_BUILD_TYPE MATCHES Debug)
SET(RT_FLAG_WE_WANT "/MTd")
SET(RT_FLAG_WE_HATE "/MDd")
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)
ENDIF(USE_MSVC_RUNTIME_DLL)
# Next, set the compiler flags using the "FORCE" option, which seems to be required for setting these
# C flags
STRING(REPLACE ${RT_FLAG_WE_HATE} ${RT_FLAG_WE_WANT} CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
STRING(REPLACE ${RT_FLAG_WE_HATE} ${RT_FLAG_WE_WANT} CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
STRING(REPLACE ${RT_FLAG_WE_HATE} ${RT_FLAG_WE_WANT} CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO})
SET(CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO} CACHE STRING "" FORCE)
STRING(REPLACE ${RT_FLAG_WE_HATE} ${RT_FLAG_WE_WANT} CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL})
SET(CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL} CACHE STRING "" FORCE)
# C++ flags
STRING(REPLACE ${RT_FLAG_WE_HATE} ${RT_FLAG_WE_WANT} CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
STRING(REPLACE ${RT_FLAG_WE_HATE} ${RT_FLAG_WE_WANT} CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
STRING(REPLACE ${RT_FLAG_WE_HATE} ${RT_FLAG_WE_WANT} CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} CACHE STRING "" FORCE)
STRING(REPLACE ${RT_FLAG_WE_HATE} ${RT_FLAG_WE_WANT} CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
SET(CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL} CACHE STRING "" FORCE)
ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio")
ENDIF(HELL_IS_FROZEN_OVER)
#
# Allow automated build and dashboard.
#
......
......@@ -16,6 +16,18 @@
SET(OpenMM_CWRAPPER "OpenMM_CWrapper")
SET(OpenMM_FMODULE "OpenMM_Module")
# CWrapper is always a static library but you need a different
# one if you want to link with the OpenMM static library.
SET(CWRAPPER_FOR_SHARED ${OpenMM_CWRAPPER})
SET(CWRAPPER_FOR_STATIC ${OpenMM_CWRAPPER}_static)
# Visual Studio will add "_d" to target names automatically
# but on Unix or Cygwin we have to add the suffix manually
IF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET(CWRAPPER_FOR_SHARED ${CWRAPPER_FOR_SHARED}_d)
SET(CWRAPPER_FOR_STATIC ${CWRAPPER_FOR_STATIC}_d)
ENDIF (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET(CPP_EXAMPLES HelloArgon HelloSodiumChloride HelloEthane HelloWaterBox)
SET(C_EXAMPLES HelloArgonInC HelloSodiumChlorideInC)
SET(F_EXAMPLES HelloArgonInFortran HelloSodiumChlorideInFortran)
......@@ -23,6 +35,22 @@ SET(F_EXAMPLES HelloArgonInFortran HelloSodiumChlorideInFortran)
SET(BUILD_TESTING_SHARED 1)
SET(BUILD_TESTING_STATIC 1)
ADD_LIBRARY(${CWRAPPER_FOR_SHARED} ${OpenMM_CWRAPPER}.cpp ${OpenMM_CWRAPPER}.h)
SET_TARGET_PROPERTIES(${CWRAPPER_FOR_SHARED}
PROPERTIES
PROJECT_LABEL "C Bindings")
TARGET_LINK_LIBRARIES(${CWRAPPER_FOR_SHARED} ${SHARED_TARGET})
ADD_LIBRARY(${CWRAPPER_FOR_STATIC} ${OpenMM_CWRAPPER}.cpp ${OpenMM_CWRAPPER}.h)
SET_TARGET_PROPERTIES(${CWRAPPER_FOR_STATIC}
PROPERTIES
COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
PROJECT_LABEL "C Bindings for static OpenMM")
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${CWRAPPER_FOR_SHARED})
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${CWRAPPER_FOR_STATIC})
FOREACH(EX_ROOT ${CPP_EXAMPLES})
IF (BUILD_TESTING_SHARED)
# Link with shared library
......@@ -51,22 +79,22 @@ ENDFOREACH(EX_ROOT ${CPP_EXAMPLES})
FOREACH(EX_ROOT ${C_EXAMPLES})
IF (BUILD_TESTING_SHARED)
# Link with shared library
ADD_EXECUTABLE(${EX_ROOT} ${EX_ROOT}.c ${OpenMM_CWRAPPER}.cpp)
ADD_EXECUTABLE(${EX_ROOT} ${EX_ROOT}.c)
SET_TARGET_PROPERTIES(${EX_ROOT}
PROPERTIES
PROJECT_LABEL "Example C - ${EX_ROOT}")
TARGET_LINK_LIBRARIES(${EX_ROOT} ${SHARED_TARGET})
TARGET_LINK_LIBRARIES(${EX_ROOT} ${CWRAPPER_FOR_SHARED} ${SHARED_TARGET})
ENDIF (BUILD_TESTING_SHARED)
IF (BUILD_TESTING_STATIC)
# Link with static library
SET(EX_STATIC ${EX_ROOT}Static)
ADD_EXECUTABLE(${EX_STATIC} ${EX_ROOT}.c ${OpenMM_CWRAPPER}.cpp)
ADD_EXECUTABLE(${EX_STATIC} ${EX_ROOT}.c)
SET_TARGET_PROPERTIES(${EX_STATIC}
PROPERTIES
COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
PROJECT_LABEL "Example C - ${EX_STATIC}")
TARGET_LINK_LIBRARIES(${EX_STATIC} ${STATIC_TARGET})
TARGET_LINK_LIBRARIES(${EX_STATIC} ${CWRAPPER_FOR_STATIC} ${STATIC_TARGET})
ENDIF (BUILD_TESTING_STATIC)
INSTALL(FILES ${EX_ROOT}.c DESTINATION examples)
......

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "HelloArgonInFortran", "HelloArgonInFortran.vfproj", "{06661778-659C-45A6-8396-AE3567241AD9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{06661778-659C-45A6-8396-AE3567241AD9}.Debug|Win32.ActiveCfg = Debug|Win32
{06661778-659C-45A6-8396-AE3567241AD9}.Debug|Win32.Build.0 = Debug|Win32
{06661778-659C-45A6-8396-AE3567241AD9}.Release|Win32.ActiveCfg = Release|Win32
{06661778-659C-45A6-8396-AE3567241AD9}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject ProjectCreator="Intel Fortran" Keyword="Console Application" Version="11.0" ProjectIdGuid="{06661778-659C-45A6-8396-AE3567241AD9}">
<Platforms>
<Platform Name="Win32"/></Platforms>
<Configurations>
<Configuration Name="Debug|Win32">
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" DebugInformationFormat="debugEnabled" Optimization="optimizeDisabled" Interfaces="true" WarnInterfaces="true" Traceback="true" BoundsCheck="true" RuntimeLibrary="rtMultiThreadedDebugDLL"/>
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" AdditionalLibraryDirectories="C:\Program Files\OpenMM\lib" GenerateDebugInformation="true" SubSystem="subSystemConsole" AdditionalDependencies="OpenMM_CWrapper_d.lib OpenMM_d.lib"/>
<Tool Name="VFResourceCompilerTool"/>
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
<Tool Name="VFCustomBuildTool"/>
<Tool Name="VFPreLinkEventTool"/>
<Tool Name="VFPreBuildEventTool"/>
<Tool Name="VFPostBuildEventTool"/>
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
<Configuration Name="Release|Win32">
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" RuntimeLibrary="rtMultiThreadedDLL"/>
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" AdditionalLibraryDirectories="C:\Program Files\OpenMM\lib" SubSystem="subSystemConsole" AdditionalDependencies="OpenMM_CWrapper.lib OpenMM.lib"/>
<Tool Name="VFResourceCompilerTool"/>
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
<Tool Name="VFCustomBuildTool"/>
<Tool Name="VFPreLinkEventTool"/>
<Tool Name="VFPreBuildEventTool"/>
<Tool Name="VFPostBuildEventTool"/>
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration></Configurations>
<Files>
<Filter Name="Header Files" Filter="fi;fd"/>
<Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"/>
<Filter Name="Source Files" Filter="f90;for;f;fpp;ftn;def;odl;idl">
<File RelativePath="..\HelloArgonInFortran.f90"/>
<File RelativePath="..\OpenMM_Module.f90"/></Filter></Files>
<Globals/></VisualStudioProject>
......@@ -132,9 +132,13 @@ public:
* Add a Force to the System. The Force should have been created on the heap with the
* "new" operator. The System takes over ownership of it, and deletes the Force when the
* System itself is deleted.
*
* @param force a pointer to the Force object to be added
* @return the index within the System of the Force that was added
*/
void addForce(Force* force) {
int addForce(Force* force) {
forces.push_back(force);
return forces.size()-1;
}
/**
* Get the number of Force objects that have been added to the System.
......@@ -143,7 +147,7 @@ public:
return forces.size();
}
/**
* Get a reference to one of the Forces in this System.
* Get a const reference to one of the Forces in this System.
*
* @param index the index of the Force to get
*/
......@@ -151,7 +155,7 @@ public:
return *forces[index];
}
/**
* Get a reference to one of the Forces in this System.
* Get a writable reference to one of the Forces in this System.
*
* @param index the index of the Force to get
*/
......
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