-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
executable file
·232 lines (187 loc) · 8.68 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
project( LTMDOpenMM )
cmake_minimum_required(VERSION 2.8)
include_directories( "include" )
# Profiling
option( BUILD_PROFILE "Build Profiling code" Off )
if( BUILD_PROFILE )
option( BUILD_PROFILE_INTEGRATOR "Build Integrator Profiling code" Off )
if( BUILD_PROFILE_INTEGRATOR )
add_definitions( "-DPROFILE_INTEGRATOR" )
endif( BUILD_PROFILE_INTEGRATOR )
option( BUILD_PROFILE_ANALYSIS "Build Analysis Profiling code" Off )
if( BUILD_PROFILE_ANALYSIS )
add_definitions( "-DPROFILE_ANALYSIS" )
endif( BUILD_PROFILE_ANALYSIS )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pg")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
endif( BUILD_PROFILE )
# Validation
option( BUILD_VALIDATION "Build Validation Code" Off )
if( BUILD_VALIDATION )
add_definitions( "-DVALIDATION" )
endif( BUILD_VALIDATION )
option( BUILD_KERNEL_VALIDATION "Build Kernel Validation Code" Off )
if( BUILD_KERNEL_VALIDATION )
add_definitions( "-DKERNEL_VALIDATION" )
endif( BUILD_KERNEL_VALIDATION )
# MKL
option( BUILD_MKL "Build with Intel MKL code" Off )
if( BUILD_MKL )
add_definitions( "-DINTEL_MKL" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mkl=parallel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mkl=parallel")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mkl=parallel")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -mkl=parallel")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -mkl=parallel")
else( BUILD_MKL )
find_library( LIB_BLAS "blas" HINTS "${BLAS_LIBPATH}" )
find_library( LIB_LAPACK "lapack" HINTS "${LAPACK_LIBPATH}" )
if( NOT ${LIB_BLAS} MATCHES "LIB_BLAS-NOTFOUND" AND NOT ${LIB_LAPACK} MATCHES "LIB_LAPACK-NOTFOUND" )
set( LIBS ${LIBS} ${LIB_BLAS} ${LIB_LAPACK} )
else()
if( ${LIB_BLAS} MATCHES "LIB_BLAS-NOTFOUND" )
set( BLAS_INCPATH "" CACHE PATH "Blas include directory" )
set( BLAS_LIBPATH "" CACHE PATH "Blas library directory" )
endif()
if( ${LIB_LAPACK} MATCHES "LIB_LAPACK-NOTFOUND" )
set( LAPACK_INCPATH "" CACHE PATH "Lapack include directory" )
set( LAPACK_LIBPATH "" CACHE PATH "Lapack library directory" )
endif()
endif()
endif( BUILD_MKL )
# OpenMP
option( BUILD_OPENMP "Build with openmp support" Off )
if( BUILD_OPENMP )
# Intel
if( ${CMAKE_CXX_COMPILER} MATCHES "icpc.*$" OR ${CMAKE_CXX_COMPILER} MATCHES "icc.*$" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -openmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -openmp")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -openmp")
else()
# Other
include( FindOpenMP )
if( OPENMP_FOUND )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif( OPENMP_FOUND )
endif()
endif( BUILD_OPENMP )
# OpenMM
set( OPENMM_DIR "$ENV{OPENMM_HOME}" CACHE PATH "OpenMM Install Directory")
if( OPENMM_DIR )
link_directories( "${OPENMM_DIR}/lib/" )
include_directories( "${OPENMM_DIR}/include/" )
endif()
set( OPENMM_SOURCE_DIR "$ENV{OPENMM_SOURCE}" CACHE PATH "OpenMM Source Directory")
if( OPENMM_SOURCE_DIR )
# JAMA
include_directories( "${OPENMM_SOURCE_DIR}/libraries/jama/include/" )
# SFMT
include_directories( "${OPENMM_SOURCE_DIR}/libraries/sfmt/include/" )
# Reference
include_directories( "${OPENMM_SOURCE_DIR}/platforms/reference/src/" )
include_directories( "${OPENMM_SOURCE_DIR}/platforms/reference/include/" )
# CUDA
include_directories( "${OPENMM_SOURCE_DIR}/platforms/cuda/src/" )
include_directories( "${OPENMM_SOURCE_DIR}/platforms/cuda/include/" )
include_directories( "${OPENMM_SOURCE_DIR}/libraries/lepton/include" )
endif()
find_library( OPENMM_LIB "OpenMM" HINT ${OPENMM_DIR}/lib )
set( LIBS ${OPENMM_LIB} ${LIBS} )
# First Order
option( BUILD_FIRST_ORDER "Build with first order perterb" Off )
if( BUILD_FIRST_ORDER )
add_definitions( "-DFIRST_ORDER" )
endif( BUILD_FIRST_ORDER )
# LTMD Library
file( GLOB LTMD_HEADERS include/LTMD/*.h )
source_group( "include\\LTMD" FILES ${LTMD_HEADERS} )
file( GLOB LTMD_SOURCES src/LTMD/*.cpp )
source_group( "src\\LTMD" FILES ${LTMD_SOURCES} )
add_library( OpenMMLTMD SHARED ${LTMD_HEADERS} ${LTMD_SOURCES})
target_link_libraries( OpenMMLTMD ${LIBS} )
# LTMD Reference Plugin
file( GLOB LTMD_REFERENCE_HEADERS include/LTMD/Reference/*.h )
source_group( "include\\LTMD\\Reference" FILES ${LTMD_REFERENCE_HEADERS} )
file( GLOB LTMD_REFERENCE_SOURCES src/LTMD/Reference/*.cpp )
source_group( "src\\LTMD\\Reference" FILES ${LTMD_REFERENCE_SOURCES} )
add_library( LTMDReference SHARED ${LTMD_REFERENCE_HEADERS} ${LTMD_REFERENCE_SOURCES})
set_target_properties( LTMDReference PROPERTIES COMPILE_FLAGS "-DNMLOPENMM_REFERENCE_BUILDING_SHARED_LIBRARY -DNMLOPENMM_BUILDING_SHARED_LIBRARY")
target_link_libraries( LTMDReference OpenMMLTMD )
option( BUILD_GPU "Build GPU code" Off )
if( BUILD_GPU )
option( BUILD_FAST_NOISE "Build Fast Noise code" On )
if( BUILD_FAST_NOISE )
add_definitions( "-DFAST_NOISE" )
endif( BUILD_FAST_NOISE )
option( BUILD_GPU_CUDA "Build Cuda GPU code" Off )
if( BUILD_GPU_CUDA )
find_package( CUDA REQUIRED )
find_library( OPENMM_CUDA_LIB "OpenMMCUDA" HINT "${OPENMM_DIR}/lib/plugins")
file( GLOB LTMD_CUDA_HEADERS include/LTMD/CUDA/*.h )
source_group( "include\\LTMD\\CUDA" FILES ${LTMD_CUDA_HEADERS} )
include_directories( "include/LTMD/CUDA/" )
file( GLOB LTMD_CUDA_SOURCES src/LTMD/CUDA/*.cpp )
source_group( "src\\LTMD\\CUDA" FILES ${LTMD_CUDA_SOURCES} )
file( GLOB LTMD_CUDA_KERNELS src/LTMD/CUDA/kernels/*.cpp )
source_group( "Kernels\\LTMD" FILES ${LTMD_CUDA_KERNELS} )
# Fast Math
option( BUILD_GPU_CUDA_FAST_MATH "Build with fast math" Off )
if( BUILD_GPU_CUDA_FAST_MATH )
list( APPEND CUDA_NVCC_FLAGS "-use_fast_math" )
endif( BUILD_GPU_CUDA_FAST_MATH )
# Intel
if( ${CMAKE_CXX_COMPILER} MATCHES "icpc.*$" OR ${CMAKE_CXX_COMPILER} MATCHES "icc.*$" )
list( APPEND CUDA_NVCC_FLAGS "-ccbin=icc" )
endif()
# Encode Cuda Files
FILE(GLOB CUDA_KERNELS src/LTMD/CUDA/kernels/*_kernel.cu)
SET(CUDA_FILE_DECLARATIONS)
SET(CUDA_FILE_DEFINITIONS)
FOREACH(file ${CUDA_KERNELS})
# Load the file contents
FILE(STRINGS ${file} file_content NEWLINE_CONSUME)
# Clean Content
STRING(REGEX REPLACE "\\\\([^;])" "\\\\\\\\\\1" file_content "${file_content}")
STRING(REPLACE "\"" "\\\"" file_content "${file_content}")
STRING(REPLACE "\n" "\\n\"\n\"" file_content "${file_content}")
# Determine a name for the variable that will contain this file's contents
FILE(RELATIVE_PATH filename ${CMAKE_SOURCE_DIR}/src/LTMD/CUDA/kernels ${file})
STRING(LENGTH ${filename} filename_length)
MATH(EXPR filename_length ${filename_length}-10)
STRING(SUBSTRING ${filename} 0 ${filename_length} variable_name)
# Record the variable declaration and definition.
SET(CUDA_FILE_DECLARATIONS ${CUDA_FILE_DECLARATIONS}static\ const\ std::string\ ${variable_name};\n\t\t)
SET(CUDA_FILE_DEFINITIONS ${CUDA_FILE_DEFINITIONS}const\ std::string\ KernelSources::${variable_name}\ =\ \"${file_content}\"\;\n\n\t)
ENDFOREACH(file)
STRING(REGEX REPLACE "(\r?\n)+\t+$" "" CUDA_FILE_DEFINITIONS "${CUDA_FILE_DEFINITIONS}")
STRING(REGEX REPLACE "(\r?\n)+\t+$" "" CUDA_FILE_DECLARATIONS "${CUDA_FILE_DECLARATIONS}")
CONFIGURE_FILE(src/LTMD/CUDA/KernelSources.cpp.in ${PROJECT_BINARY_DIR}/src/LTMD/CUDA/KernelSources.cpp)
CONFIGURE_FILE(include/LTMD/CUDA/KernelSources.h.in ${PROJECT_BINARY_DIR}/include/LTMD/CUDA/KernelSources.h)
include_directories("${PROJECT_BINARY_DIR}/include")
CUDA_ADD_LIBRARY( LTMDCuda SHARED ${LTMD_CUDA_HEADERS} ${LTMD_CUDA_SOURCES} "${PROJECT_BINARY_DIR}/src/LTMD/CUDA/KernelSources.cpp" ${LTMD_CUDA_KERNELS} )
set_target_properties( LTMDCuda PROPERTIES COMPILE_FLAGS "-DNMLOPENMM_CUDA_BUILDING_SHARED_LIBRARY -DNMLOPENMM_BUILDING_SHARED_LIBRARY")
target_link_libraries( LTMDCuda OpenMMLTMD ${OPENMM_CUDA_LIB} )
install( TARGETS LTMDCuda LIBRARY DESTINATION "lib/plugins" )
endif( BUILD_GPU_CUDA )
endif( BUILD_GPU )
# Testing
option( BUILD_TESTING "Build test code" Off )
if( BUILD_TESTING )
add_subdirectory( "test" )
endif( BUILD_TESTING )
# Installation
install(
DIRECTORY "include/"
DESTINATION "include"
PATTERN "*.h"
PATTERN ".*" EXCLUDE
PATTERN "include/LTMD/CUDA" EXCLUDE
PATTERN "include/LTMD/Reference" EXCLUDE
)
install( TARGETS OpenMMLTMD LIBRARY DESTINATION "lib" ARCHIVE DESTINATION "lib" )
install( TARGETS LTMDReference LIBRARY DESTINATION "lib/plugins" )