-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathCMakeLists.txt
160 lines (134 loc) · 5.04 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
cmake_minimum_required(VERSION 3.10)
project(
PVFMM
VERSION 1.2
LANGUAGES CXX C)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
include(GNUInstallDirs)
# compiler flags
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# using Clang
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
# using intel
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -qno-offload")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
endif()
# Add all the SCTL relevant flags
add_compile_options(-DHAVE_CONFIG_H -DSCTL_QUAD_T=__float128 -DSCTL_HAVE_BLAS -DSCTL_HAVE_LAPACK -DSCTL_HAVE_FFTW)
set(MPI_CXX_SKIP_MPICXX
true
CACHE BOOL
"If true, the MPI-2 C++ bindings are disabled using definitions.")
# required compiler features
find_package(MPI REQUIRED)
find_package(OpenMP REQUIRED)
# library
find_package(MKL)
if(MKL_FOUND)
set(DEP_INC ${MKL_FFTW_INCLUDE_DIR} ${MKL_INCLUDE_DIR})
set(DEP_LIB ${MKL_SDL_LIBRARY})
else()
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
find_package(FFTW REQUIRED)
set(DEP_INC ${FFTW_INCLUDE_DIRS})
set(DEP_LIB ${FFTW_FLOAT_OPENMP_LIB} ${FFTW_FLOAT_LIB}
${FFTW_DOUBLE_OPENMP_LIB} ${FFTW_DOUBLE_LIB}
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES})
endif()
find_file(SYS_STAT sys/stat.h OPTIONAL)
# generate pvfmm_config.h
# switch for periodic boundary condition
option(PVFMM_EXTENDED_BC "PVFMM_EXTENDED_BC" ON)
if(MKL_FOUND)
option(PVFMM_FFTW3_MKL "PVFMM_FFTW3_MKL" ON)
option(PVFMM_HAVE_FFTW "PVFMM_HAVE_FFTW" ON)
option(PVFMM_HAVE_FFTWF "PVFMM_HAVE_FFTWF" ON)
endif()
if(FFTW_DOUBLE_LIB_FOUND)
option(PVFMM_HAVE_FFTW "PVFMM_HAVE_FFTW" ON)
endif()
if(FFTW_FLOAT_LIB_FOUND)
option(PVFMM_HAVE_FFTWF "PVFMM_HAVE_FFTWF" ON)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
option(PVFMM_HAVE_INTEL_SVML "PVFMM_HAVE_INTEL_SVML" ON)
endif()
if(SYS_STAT)
option(PVFMM_HAVE_SYS_STAT_H "PVFMM_HAVE_SYS_STAT_H" ON)
endif()
option(PVFMM_ENABLE_CUDA "PVFMM_ENABLE_CUDA" OFF)
if (PVFMM_ENABLE_CUDA)
enable_language(CUDA)
option(PVFMM_HAVE_CUDA "PVFMM_HAVE_CUDA" ON)
file(GLOB pvfmm_SRC_CUDA "src/*.cu")
set(DEP_LIB_CUDA "${CUDA_CUBLAS_LIBRARIES}")
list(APPEND PVFMM_DEFINES "SCTL_HAVE_CUDA")
else()
option(PVFMM_HAVE_CUDA "PVFMM_HAVE_CUDA" OFF)
endif()
configure_file(pvfmm_config.h.in pvfmm_config.h @ONLY)
# part 1, core library
file(GLOB pvfmm_SRC "src/*.cpp")
# shared lib
add_library(pvfmm SHARED ${pvfmm_SRC} ${pvfmm_SRC_CUDA})
set_target_properties(pvfmm PROPERTIES OUTPUT_NAME pvfmm)
target_include_directories(
pvfmm
PUBLIC $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/SCTL/include/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
${CMAKE_CURRENT_BINARY_DIR} ${DEP_INC})
target_link_libraries(pvfmm PUBLIC ${DEP_LIB} ${DEP_LIB_CUDA} OpenMP::OpenMP_CXX MPI::MPI_CXX)
target_compile_definitions(pvfmm PUBLIC "${PVFMM_DEFINES}")
# static lib
add_library(pvfmmStatic STATIC ${pvfmm_SRC} ${pvfmm_SRC_CUDA})
set_target_properties(pvfmmStatic PROPERTIES OUTPUT_NAME pvfmm)
target_include_directories(
pvfmmStatic
PUBLIC $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/SCTL/include/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
${CMAKE_CURRENT_BINARY_DIR} ${DEP_INC})
target_link_libraries(pvfmmStatic PUBLIC ${DEP_LIB} ${DEP_LIB_CUDA} OpenMP::OpenMP_CXX MPI::MPI_CXX)
target_compile_definitions(pvfmmStatic PUBLIC "${PVFMM_DEFINES}")
# Config.cmake files
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/pvfmmConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
get_target_property(PVFMM_SHARED_NAME pvfmm OUTPUT_NAME)
get_target_property(PVFMM_STATIC_NAME pvfmmStatic OUTPUT_NAME)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/pvfmmConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/pvfmmConfig.cmake INSTALL_DESTINATION
${CMAKE_INSTALL_PREFIX}/share/pvfmm)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pvfmmConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/pvfmmConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pvfmm)
# install core library and headers
include(GNUInstallDirs)
install(
TARGETS pvfmm
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(
TARGETS pvfmmStatic
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pvfmm/)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/SCTL/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pvfmm/)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pvfmm_config.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pvfmm/)
add_subdirectory(examples)