|
| 1 | +#--------------------------------------------------- |
| 2 | +# OpenMM DMFF Plugin |
| 3 | +#---------------------------------------------------- |
| 4 | + |
| 5 | +CMAKE_MINIMUM_REQUIRED(VERSION 3.5) |
| 6 | +SET(CMAKE_VERBOSE_MAKEFILE OFF) |
| 7 | + |
| 8 | +project(OpenMMDMFF) |
| 9 | + |
| 10 | +# We need to know where OpenMM is installed so we can access the headers and libraries. |
| 11 | +SET(OPENMM_DIR "/usr/local/openmm" CACHE PATH "Where OpenMM is installed") |
| 12 | +INCLUDE_DIRECTORIES("${OPENMM_DIR}/include") |
| 13 | +LINK_DIRECTORIES("${OPENMM_DIR}/lib" "${OPENMM_DIR}/lib/plugins") |
| 14 | + |
| 15 | + |
| 16 | +# Include the cppflow |
| 17 | +SET(CPPFLOW_DIR "/usr/local/cppflow/" CACHE PATH "Where cppflow is installed") |
| 18 | +INCLUDE_DIRECTORIES("${CPPFLOW_DIR}/include") |
| 19 | +LINK_DIRECTORIES("${CPPFLOW_DIR}/lib") |
| 20 | + |
| 21 | +# Include the tensorflow |
| 22 | +SET(TENSORFLOW_DIR "/usr/local/tensorflow/" CACHE PATH "Where libtensorflow is installed") |
| 23 | +INCLUDE_DIRECTORIES("${TENSORFLOW_DIR}/include") |
| 24 | +LINK_DIRECTORIES("${TENSORFLOW_DIR}/lib") |
| 25 | + |
| 26 | +# Specify the C++ version we are building for. |
| 27 | +SET (CMAKE_CXX_STANDARD 17) |
| 28 | + |
| 29 | +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ignored-attributes -Wl,--allow-multiple-definition -Wl,--no-as-needed") |
| 30 | + |
| 31 | +# Set if high precision (double) is used. By default, it is off. |
| 32 | +OPTION(USE_HIGH_PRECISION "Use high precision (double) for calculations" OFF) |
| 33 | + |
| 34 | +IF(USE_HIGH_PRECISION) |
| 35 | + message(STATUS "USE_HIGH_PRECISION is enabled") |
| 36 | + ADD_DEFINITIONS(-DUSE_HIGH_PRECISION) |
| 37 | +endif () |
| 38 | + |
| 39 | +if (USE_HIGH_PRECISION) |
| 40 | + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHIGH_PRECISION") |
| 41 | +else () |
| 42 | + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 43 | +endif () |
| 44 | + |
| 45 | +# Select where to install |
| 46 | +IF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) |
| 47 | + IF(WIN32) |
| 48 | + SET(CMAKE_INSTALL_PREFIX "$ENV{ProgramFiles}/OpenMM" CACHE PATH "Where to install the plugin" FORCE) |
| 49 | + ELSE(WIN32) |
| 50 | + SET(CMAKE_INSTALL_PREFIX "${OPENMM_DIR}" CACHE PATH "Where to install the plugin" FORCE) |
| 51 | + ENDIF(WIN32) |
| 52 | +ENDIF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) |
| 53 | + |
| 54 | +# Put all the tests and libraries in a single output directory. |
| 55 | +IF(NOT EXECUTABLE_OUTPUT_PATH) |
| 56 | + SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR} |
| 57 | + CACHE INTERNAL "Single output directory for building all executables.") |
| 58 | +ENDIF() |
| 59 | +IF(NOT LIBRARY_OUTPUT_PATH) |
| 60 | + SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR} |
| 61 | + CACHE INTERNAL "Single output directory for building all libraries.") |
| 62 | +ENDIF() |
| 63 | +SET(${PROJECT_NAME}_EXECUTABLE_DIR ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}) |
| 64 | +SET(${PROJECT_NAME}_LIBRARY_DIR ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}) |
| 65 | + |
| 66 | +# The source is organized into subdirectories, but we handle them all from |
| 67 | +# this CMakeLists file rather than letting CMake visit them as SUBDIRS. |
| 68 | +SET(DMFF_PLUGIN_SOURCE_SUBDIRS openmmapi serialization) |
| 69 | + |
| 70 | +# Set the library name |
| 71 | +SET(DMFF_LIBRARY_NAME OpenMMDMFF) |
| 72 | +SET(SHARED_DMFF_TARGET ${DMFF_LIBRARY_NAME}) |
| 73 | + |
| 74 | +# These are all the places to search for header files that are to be part of the API. |
| 75 | +SET(API_INCLUDE_DIRS "openmmapi/include" "openmmapi/include/internal") |
| 76 | + |
| 77 | +# Locate header files. |
| 78 | +SET(API_INCLUDE_FILES) |
| 79 | +FOREACH(dir ${API_INCLUDE_DIRS}) |
| 80 | + FILE(GLOB fullpaths ${dir}/*.h) |
| 81 | + SET(API_INCLUDE_FILES ${API_INCLUDE_FILES} ${fullpaths}) |
| 82 | +ENDFOREACH(dir) |
| 83 | + |
| 84 | +# Collect source files |
| 85 | +SET(SOURCE_FILES) # empty |
| 86 | +SET(SOURCE_INCLUDE_FILES) |
| 87 | +FOREACH(subdir ${DMFF_PLUGIN_SOURCE_SUBDIRS}) |
| 88 | + FILE(GLOB src_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.cpp) |
| 89 | + FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.h) |
| 90 | + SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append |
| 91 | + SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files}) |
| 92 | + |
| 93 | + ## Make sure we find these locally before looking in OpenMM/include if |
| 94 | + ## OpenMM was previously installed there. |
| 95 | + INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include) |
| 96 | +ENDFOREACH(subdir) |
| 97 | + |
| 98 | +# Create the library. |
| 99 | + |
| 100 | +ADD_LIBRARY(${SHARED_DMFF_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES}) |
| 101 | +SET_TARGET_PROPERTIES(${SHARED_DMFF_TARGET} |
| 102 | + PROPERTIES COMPILE_FLAGS "-DDMFF_BUILDING_SHARED_LIBRARY ${EXTRA_COMPILE_FLAGS}" |
| 103 | + LINK_FLAGS "${EXTRA_COMPILE_FLAGS}") |
| 104 | +TARGET_LINK_LIBRARIES(${SHARED_DMFF_TARGET} OpenMM) |
| 105 | +TARGET_LINK_LIBRARIES(${SHARED_DMFF_TARGET} tensorflow_cc) |
| 106 | + |
| 107 | +INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${SHARED_DMFF_TARGET}) |
| 108 | + |
| 109 | +# install headers |
| 110 | +FILE(GLOB API_ONLY_INCLUDE_FILES "openmmapi/include/*.h") |
| 111 | +INSTALL (FILES ${API_ONLY_INCLUDE_FILES} DESTINATION include) |
| 112 | +FILE(GLOB API_ONLY_INCLUDE_FILES_INTERNAL "openmmapi/include/internal/*.h") |
| 113 | +INSTALL (FILES ${API_ONLY_INCLUDE_FILES_INTERNAL} DESTINATION include/internal) |
| 114 | + |
| 115 | +# Enable testing |
| 116 | +# Set no testing here. |
| 117 | +ENABLE_TESTING() |
| 118 | +ADD_SUBDIRECTORY(serialization/tests) |
| 119 | + |
| 120 | +# Use reference platform default. |
| 121 | +ADD_SUBDIRECTORY(platforms/reference) |
| 122 | + |
| 123 | +FIND_PACKAGE(CUDA QUIET) |
| 124 | +IF(CUDA_FOUND) |
| 125 | + message(STATUS "CUDA found, building CUDA implementation") |
| 126 | + SET(PLUGIN_BUILD_CUDA_LIB ON CACHE BOOL "Build implementation for CUDA: ON") |
| 127 | +ELSE(CUDA_FOUND) |
| 128 | + message(STATUS "CUDA not found, not building CUDA implementation") |
| 129 | + SET(PLUGIN_BUILD_CUDA_LIB OFF CACHE BOOL "Build implementation for CUDA: OFF") |
| 130 | +ENDIF(CUDA_FOUND) |
| 131 | +IF(PLUGIN_BUILD_CUDA_LIB) |
| 132 | + ADD_SUBDIRECTORY(platforms/cuda) |
| 133 | +ENDIF(PLUGIN_BUILD_CUDA_LIB) |
| 134 | + |
| 135 | + |
| 136 | +# Build the Python API |
| 137 | +FIND_PROGRAM(PYTHON_EXECUTABLE python) |
| 138 | +FIND_PROGRAM(SWIG_EXECUTABLE swig) |
| 139 | +IF(PYTHON_EXECUTABLE AND SWIG_EXECUTABLE) |
| 140 | + message(STATUS "Python and SWIG found, building Python wrappers") |
| 141 | + SET(PLUGIN_BUILD_PYTHON_WRAPPERS ON CACHE BOOL "Build wrappers for Python") |
| 142 | +ELSE(PYTHON_EXECUTABLE AND SWIG_EXECUTABLE) |
| 143 | + message(FATAL_ERROR "Python or SWIG not found, not building Python wrappers") |
| 144 | + SET(PLUGIN_BUILD_PYTHON_WRAPPERS OFF CACHE BOOL "Build wrappers for Python") |
| 145 | +ENDIF(PYTHON_EXECUTABLE AND SWIG_EXECUTABLE) |
| 146 | +IF(PLUGIN_BUILD_PYTHON_WRAPPERS) |
| 147 | + ADD_SUBDIRECTORY(python) |
| 148 | +ENDIF(PLUGIN_BUILD_PYTHON_WRAPPERS) |
| 149 | + |
0 commit comments