forked from prism-em/prismatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
233 lines (202 loc) · 7.75 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
233
cmake_minimum_required(VERSION 3.5)
project(PRISM)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE RELEASE)
# set warning level
if ( CMAKE_COMPILER_IS_GNUCC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -O3 -fPIC")
endif ( CMAKE_COMPILER_IS_GNUCC )
if ( MSVC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0 /utf-8 /Ox")
endif ( MSVC )
# PRISM custom options
set(PRISMATIC_ENABLE_GUI 0 CACHE BOOL PRISMATIC_ENABLE_GUI)
set(PRISMATIC_ENABLE_GPU 0 CACHE BOOL PRISMATIC_ENABLE_GPU)
set(PRISMATIC_ENABLE_CLI 1 CACHE BOOL PRISMATIC_ENABLE_GPU)
set(PRISMATIC_ENABLE_PYTHON_GPU 0 CACHE BOOL PRISMATIC_ENABLE_PYTHON_GPU)
set(PRISMATIC_ENABLE_DOUBLE_PRECISION 0 CACHE BOOL PRISMATIC_ENABLE_DOUBLE_PRECISION)
#set (CMAKE_BUILD_TYPE DEBUG)
if (PRISMATIC_ENABLE_GPU)
set(NVCC_FLAGS_EXTRA "-arch=sm_30 -std=c++11 -Xcompiler -fPIC")
endif (PRISMATIC_ENABLE_GPU)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
if (UNIX)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/lib)
link_directories(${CMAKE_LIBRARY_PATH})
endif (UNIX)
# create variables with various bundles of source files
set(SOURCE_FILES
src/configure.cpp
src/WorkDispatcher.cpp
src/Multislice_calcOutput.cpp
src/PRISM01_calcPotential.cpp
src/PRISM02_calcSMatrix.cpp
src/PRISM03_calcOutput.cpp
src/PRISM_entry.cpp
src/Multislice_entry.cpp
src/projectedPotential.cpp
src/parseInput.cpp
src/utility.cpp
src/atom.cpp
src/go.cpp)
if (PRISMATIC_ENABLE_GUI)
set(GUI_SOURCE_FILES
Qt/main.cpp
Qt/prismmainwindow.cpp
Qt/prism_qthreads.cpp
Qt/prism_progressbar.cpp
Qt/saveatomiccoordinatesdialog.cpp
Qt/prism_colormapper.cpp
Qt/prism_resources.qrc)
endif (PRISMATIC_ENABLE_GUI)
if (PRISMATIC_ENABLE_GPU)
set(CUDA_SOURCE_FILES
src/Multislice_calcOutput.cu
src/PRISM02_calcSMatrix.cu
src/PRISM03_calcOutput.cu
src/utility.cu)
endif (PRISMATIC_ENABLE_GPU)
# find core packages
find_package (Threads REQUIRED)
find_package (Boost REQUIRED)
find_package(FFTW3 REQUIRED)
message("Boost dir " ${Boost_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/include
${Boost_INCLUDE_DIRS}
${FFTW_INCLUDE_DIR})
# find CUDA package, if building for GPU
if (PRISMATIC_ENABLE_GPU)
message("GPU support enabled")
find_package(CUDA REQUIRED)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA})
endif(PRISMATIC_ENABLE_GPU)
# find Qt modules, if building GUI
if (PRISMATIC_ENABLE_GUI)
find_package(Qt5Widgets REQUIRED)
message(Qt5Widgets_DIR = ${Qt5Widgets_DIR})
endif (PRISMATIC_ENABLE_GUI)
# add preprocessor directives based on configuration
if (PRISMATIC_ENABLE_DOUBLE_PRECISION)
add_definitions(-DPRISMATIC_ENABLE_DOUBLE_PRECISION)
endif (PRISMATIC_ENABLE_DOUBLE_PRECISION)
if (PRISMATIC_ENABLE_GUI)
add_definitions(-DPRISMATIC_ENABLE_GUI)
endif (PRISMATIC_ENABLE_GUI)
if (PRISMATIC_ENABLE_GPU)
add_definitions(-DPRISMATIC_ENABLE_GPU)
endif (PRISMATIC_ENABLE_GPU)
if (PRISMATIC_ENABLE_CLI)
add_definitions(-DPRISMATIC_ENABLE_CLI)
endif (PRISMATIC_ENABLE_CLI)
# setup FFTW based on desired precision
if (NOT PRISMATIC_ENABLE_DOUBLE_PRECISION)
message("Single precision enabled")
if (UNIX)
message(UNIX)
set(FFTW_LIBRARIES ${FFTW_EXECUTABLE_LIBRARIES})
set(FFTW_LIBRARIES fftw3f fftw3f_threads)
set(FFTW_LIBRARY ${FFTW_EXECUTABLE_LIBRARIES})
message("FFTW_EXECUTABLE_LIBRARIES = " ${FFTW_EXECUTABLE_LIBRARIES})
message("FFTW_LIBRARY = " ${FFTW_LIBRARY})
endif (UNIX)
else(NOT PRISMATIC_ENABLE_DOUBLE_PRECISION)
message("Double precision enabled")
add_definitions(-DPRISMATIC_ENABLE_DOUBLE_PRECISION)
if (FFTW_THREADS_LIBRARY)
set(FFTW_LIBRARIES ${FFTW_LIBRARY} ${FFTW_THREADS_LIBRARY})
endif(FFTW_THREADS_LIBRARY)
endif(NOT PRISMATIC_ENABLE_DOUBLE_PRECISION)
if (PRISMATIC_ENABLE_CLI)
# build CLI
if (PRISMATIC_ENABLE_GPU)
cuda_add_executable(prismatic
src/driver.cpp
${SOURCE_FILES}
${CUDA_SOURCE_FILES})
cuda_add_cufft_to_target(prismatic)
else(PRISMATIC_ENABLE_GPU)
add_executable(prismatic
src/driver.cpp
${SOURCE_FILES})
endif (PRISMATIC_ENABLE_GPU)
target_link_libraries(prismatic
${CMAKE_THREAD_LIBS_INIT}
# ${Boost_LIBRARY_DIRS}
${FFTW_LIBRARIES})
endif (PRISMATIC_ENABLE_CLI)
if(APPLE)
list(APPEND GUI_SOURCE_FILES ../Qt/icons/prismatic-icon.icns)
set(MACOSX_BUNDLE_ICON_FILE prismatic-icon.icns)
set(MACOSX_BUNDLE_BUNDLE_VERSION 0.1)
set_source_files_properties(../Qt/icons/prismatic-icon.icns PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
elseif(WIN32)
list(APPEND GUI_SOURCE_FILES ../Qt/icons/prismatic.ico)
endif()
if (PRISMATIC_ENABLE_GUI)
# build GUI
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR on)
include_directories(${CMAKE_SOURCE_DIR}/Qt ${CMAKE_SOURCE_DIR}/include)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
if (PRISMATIC_ENABLE_GPU)
# build the shared CUDA library used by the GUI
#cuda_add_library(prism_shared
# ${SOURCE_FILES}
# ${CUDA_SOURCE_FILES}
# #${GUI_SOURCE_FILES}
# SHARED)
#target_link_libraries(prism_shared
# ${CMAKE_THREAD_LIBS_INIT}
# ${Boost_LIBRARY_DIRS}
# ${FFTW_LIBRARIES})
#cuda_add_cufft_to_target(prism_shared)
# add_definitions(-DPRISMATIC_BUILDING_GUI)
# add_definitions(-DHEY)
#
cuda_add_executable(prismatic-gui
${SOURCE_FILES}
${GUI_SOURCE_FILES}
${CUDA_SOURCE_FILES}
OPTIONS -DPRISMATIC_BUILDING_GUI)
target_link_libraries(prismatic-gui
Qt5::Widgets
${CMAKE_THREAD_LIBS_INIT}
# ${Boost_LIBRARY_DIRS}
${FFTW_LIBRARIES})
cuda_add_cufft_to_target(prismatic-gui)
else (PRISMATIC_ENABLE_GPU)
add_executable(prismatic-gui
WIN32 MACOSX_BUNDLE
${SOURCE_FILES}
${GUI_SOURCE_FILES})
target_link_libraries(prismatic-gui
Qt5::Widgets
${CMAKE_THREAD_LIBS_INIT}
# ${Boost_LIBRARY_DIRS}
${FFTW_LIBRARIES})
endif (PRISMATIC_ENABLE_GPU)
target_compile_definitions(prismatic-gui PRIVATE PRISMATIC_BUILDING_GUI=1)
if(APPLE)
install(TARGETS prismatic-gui DESTINATION Applications COMPONENT runtime)
else(APPLE)
install(TARGETS prismatic-gui RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif(APPLE)
endif (PRISMATIC_ENABLE_GUI)
if (PRISMATIC_ENABLE_CLI)
install(TARGETS prismatic RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif(PRISMATIC_ENABLE_CLI)
if (PRISMATIC_ENABLE_PYTHON_GPU AND PRISMATIC_ENABLE_GPU)
cuda_add_library(cuprismatic SHARED
${SOURCE_FILES}
${CUDA_SOURCE_FILES})
cuda_add_cufft_to_target(cuprismatic)
target_link_libraries(cuprismatic
${FFTW_LIBRARIES})
target_compile_definitions(cuprismatic PRIVATE PRISMATIC_ENABLE_GPU=1 BUILDING_CUPRISMATIC=1 CUPRISMATIC_EXPORT=1)
install(TARGETS cuprismatic
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif(PRISMATIC_ENABLE_PYTHON_GPU AND PRISMATIC_ENABLE_GPU)