-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
169 lines (137 loc) · 6.09 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#---------------------------------------------------
# OpenMM NonbondedSlicing Plugin
#----------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 3.17)
PROJECT(OpenMMNonbondedSlicing VERSION 0.2.2)
IF(DEFINED ENV{CONDA_PREFIX})
SET(OPENMM_DIR $ENV{CONDA_PREFIX} CACHE PATH "Where OpenMM is installed")
EXECUTE_PROCESS(
COMMAND conda list ^openmm\\b
OUTPUT_VARIABLE CONDA_OPENMM_VERSION
)
IF (NOT CONDA_OPENMM_VERSION)
MESSAGE(FATAL_ERROR "OpenMM conda package not found. Please install OpenMM with conda.")
ENDIF(NOT CONDA_OPENMM_VERSION)
STRING(REGEX REPLACE "[^\\.]+([0-9]+\\.[0-9]+).*" "\\1" CONDA_OPENMM_VERSION "${CONDA_OPENMM_VERSION}")
SET(OPENMM_VERSION ${CONDA_OPENMM_VERSION} CACHE STRING "OpenMM version")
ELSE(DEFINED ENV{CONDA_PREFIX})
ENDIF(DEFINED ENV{CONDA_PREFIX})
MESSAGE(STATUS "OpenMM version: ${OPENMM_VERSION}")
STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" OPENMM_VERSION_MAJOR "${OPENMM_VERSION}")
STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" OPENMM_VERSION_MINOR "${OPENMM_VERSION}")
MESSAGE(STATUS "OpenMM major version: ${OPENMM_VERSION_MAJOR}")
MESSAGE(STATUS "OpenMM minor version: ${OPENMM_VERSION_MINOR}")
ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MAJOR=${OPENMM_VERSION_MAJOR})
ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MINOR=${OPENMM_VERSION_MINOR})
INCLUDE_DIRECTORIES("${OPENMM_DIR}/include")
LINK_DIRECTORIES("${OPENMM_DIR}/lib" "${OPENMM_DIR}/lib/plugins")
# Specify the C++ version we are building for.
SET (CMAKE_CXX_STANDARD 11)
# Set flags for linking on mac
IF(APPLE)
SET(CMAKE_INSTALL_NAME_DIR "@rpath")
SET(EXTRA_COMPILE_FLAGS "-msse2 -stdlib=libc++")
ENDIF(APPLE)
# Select where to install
IF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
IF(WIN32)
SET(CMAKE_INSTALL_PREFIX "$ENV{ProgramFiles}/OpenMM" CACHE PATH "Where to install the plugin" FORCE)
ELSE(WIN32)
SET(CMAKE_INSTALL_PREFIX $ENV{CONDA_PREFIX} CACHE PATH "Where to install the plugin" FORCE)
ENDIF(WIN32)
ENDIF(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT})
# The source is organized into subdirectories, but we handle them all from
# this CMakeLists file rather than letting CMake visit them as SUBDIRS.
SET(PLUGIN_SOURCE_SUBDIRS openmmapi serialization)
# Set the library name
SET(PLUGIN_LIBRARY_NAME NonbondedSlicing)
SET(SHARED_NONBONDED_SLICING_TARGET ${PLUGIN_LIBRARY_NAME})
# These are all the places to search for header files which are to be part of the API.
SET(API_INCLUDE_DIRS "openmmapi/include")
# Locate header files.
SET(API_INCLUDE_FILES)
FOREACH(dir ${API_INCLUDE_DIRS})
FILE(GLOB fullpaths ${dir}/*.h)
SET(API_INCLUDE_FILES ${API_INCLUDE_FILES} ${fullpaths})
ENDFOREACH(dir)
# Collect up source files
SET(SOURCE_FILES) # empty
SET(SOURCE_INCLUDE_FILES)
FOREACH(subdir ${PLUGIN_SOURCE_SUBDIRS})
FILE(GLOB src_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.cpp)
FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.h)
SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append
SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
## Make sure we find these locally before looking in OpenMM/include if
## OpenMM was previously installed there.
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
ENDFOREACH(subdir)
# Create the library.
ADD_LIBRARY(${SHARED_NONBONDED_SLICING_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES})
SET_TARGET_PROPERTIES(${SHARED_NONBONDED_SLICING_TARGET}
PROPERTIES COMPILE_FLAGS "-DPLUGIN_BUILDING_SHARED_LIBRARY ${EXTRA_COMPILE_FLAGS}"
LINK_FLAGS "${EXTRA_COMPILE_FLAGS}")
TARGET_LINK_LIBRARIES(${SHARED_NONBONDED_SLICING_TARGET} OpenMM)
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${SHARED_NONBONDED_SLICING_TARGET})
# install headers
FILE(GLOB API_ONLY_INCLUDE_FILES "openmmapi/include/*.h")
INSTALL (FILES ${API_ONLY_INCLUDE_FILES} DESTINATION include)
FILE(GLOB API_ONLY_INCLUDE_FILES_INTERNAL "openmmapi/include/internal/*.h")
INSTALL (FILES ${API_ONLY_INCLUDE_FILES_INTERNAL} DESTINATION include/internal)
# Enable testing
ENABLE_TESTING()
ADD_SUBDIRECTORY(serialization/tests)
INCLUDE(CTest)
# Build the implementations for different platforms
ADD_SUBDIRECTORY(platforms/reference)
ADD_SUBDIRECTORY(platforms/common)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
FIND_PACKAGE(OPENCL QUIET)
IF(OPENCL_FOUND)
MESSAGE("Found OpenCL: TRUE")
SET(PLUGIN_BUILD_OPENCL_LIB ON CACHE BOOL "Build implementation for OpenCL")
ELSE(OPENCL_FOUND)
MESSAGE("Found OpenCL: FALSE")
SET(PLUGIN_BUILD_OPENCL_LIB OFF CACHE BOOL "Build implementation for OpenCL")
ENDIF(OPENCL_FOUND)
IF(PLUGIN_BUILD_OPENCL_LIB)
ADD_SUBDIRECTORY(platforms/opencl)
ENDIF(PLUGIN_BUILD_OPENCL_LIB)
FIND_PACKAGE(CUDA QUIET)
IF(CUDA_FOUND)
MESSAGE("Found CUDA: TRUE")
SET(PLUGIN_BUILD_CUDA_LIB ON CACHE BOOL "Build implementation for CUDA")
ELSE(CUDA_FOUND)
MESSAGE("Found CUDA: FALSE")
SET(PLUGIN_BUILD_CUDA_LIB OFF CACHE BOOL "Build implementation for CUDA")
ENDIF(CUDA_FOUND)
IF(PLUGIN_BUILD_CUDA_LIB)
GET_FILENAME_COMPONENT(CUDA_LIB_DIR "${CUDA_cufft_LIBRARY}" PATH)
SET(CUDA_nvrtc_LIBRARY "${CUDA_LIB_DIR}/libnvrtc.so")
ADD_SUBDIRECTORY(platforms/cuda)
ENDIF(PLUGIN_BUILD_CUDA_LIB)
# Fetch VkFFT
IF(OPENCL_FOUND OR CUDA_FOUND)
include(FetchContent)
FetchContent_Declare(
VkFFT
GIT_REPOSITORY https://github.com/DTolm/VkFFT
GIT_TAG v1.3.2
CMAKE_ARGS -DVKFFT_BACKEND=3
)
FetchContent_Populate(vkFFT)
ENDIF(OPENCL_FOUND OR CUDA_FOUND)
# Build the Python API
FIND_PROGRAM(DOXYGEN_EXECUTABLE doxygen)
FIND_PROGRAM(PYTHON_EXECUTABLE python REQUIRED)
FIND_PROGRAM(SWIG_EXECUTABLE swig REQUIRED)
SET(PLUGIN_BUILD_PYTHON_WRAPPERS ON CACHE BOOL "Build wrappers for Python")
IF(PLUGIN_BUILD_PYTHON_WRAPPERS)
ADD_SUBDIRECTORY(python)
ENDIF(PLUGIN_BUILD_PYTHON_WRAPPERS)
# Build the documentation
ADD_SUBDIRECTORY(docs)
# Find required packages
SET(CMAKE_THREAD_PREFER_PTHREAD ON CACHE BOOL "Prefer pthread lib")
SET(THREADS_PREFER_PTHREAD_FLAG ON CACHE BOOL "Prefer pthread flag")
FIND_PACKAGE(Threads REQUIRED)