-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
135 lines (116 loc) · 4.3 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
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
project(nlcglib LANGUAGES CXX VERSION 0.8)
set(CMAKE_CXX_STANDARD 17)
# user variables
set(USE_OPENMP On CACHE BOOL "use OpenMP")
set(USE_CUDA Off CACHE BOOL "use cuda")
set(USE_ROCM Off CACHE BOOL "use amd gpus")
set(USE_MAGMA Off CACHE BOOL "use magma eigensolver for amd gpus")
set(USE_GPU_DIRECT Off CACHE BOOL "use gpu direct")
set(BUILD_TESTS OFF CACHE BOOL "build tests")
set(LAPACK_VENDOR "OpenBLAS" CACHE STRING "lapack vendor")
set_property(CACHE LAPACK_VENDOR PROPERTY STRINGS "OpenBLAS" "MKL" "MKLONEAPI")
find_package(MPI REQUIRED)
if(USE_OPENMP)
find_package(OpenMP REQUIRED)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS "YES")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
include(cmake/nlcglib_macros.cmake)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
if(USE_CUDA)
find_package(CUDAToolkit REQUIRED)
include(cmake/cudalibs_target.cmake)
endif()
if(USE_ROCM)
include(cmake/rocmlibs_target.cmake)
endif()
find_package(Kokkos)
if(USE_MAGMA)
find_package(MAGMA REQUIRED)
endif()
find_package(MPI REQUIRED)
if(LAPACK_VENDOR MATCHES OpenBLAS)
message("find package openblas")
find_package(OpenBLAS REQUIRED)
if(NOT TARGET nlcg::cpu_lapack)
add_library(nlcg::cpu_lapack INTERFACE IMPORTED)
set_target_properties(nlcg::cpu_lapack PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OpenBLAS_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${OpenBLAS_LIBRARIES}")
endif()
elseif(LAPACK_VENDOR STREQUAL MKLONEAPI)
message("LAPACK VENDOR MKL")
set(MKL_INTERFACE "lp64" CACHE STRING "")
set(MKL_THREADING "sequential" CACHE STRING "")
set(MKL_MPI "mpich" CACHE STRING "")
find_package(MKL CONFIG REQUIRED)
if(NOT TARGET nlcg::cpu_lapack)
add_library(nlcg::cpu_lapack INTERFACE IMPORTED)
target_link_libraries(nlcg::cpu_lapack INTERFACE MKL::MKL)
target_compile_definitions(nlcg::cpu_lapack INTERFACE __USE_MKL)
endif()
elseif(LAPACK_VENDOR STREQUAL MKL)
find_package(MKL REQUIRED NO_MODULE)
if(NOT TARGET nlcg::cpu_lapack)
add_library(nlcg::cpu_lapack INTERFACE IMPORTED)
target_link_libraries(nlcg::cpu_lapack INTERFACE mkl::mkl_intel_32bit_omp_dyn)
target_compile_definitions(nlcg::cpu_lapack INTERFACE __USE_MKL)
endif()
elseif(LAPACK_VENDOR STREQUAL CRAY_LIBSCI)
message("LAPACK VENDOR Cray Libsci")
find_package(SCI REQUIRED)
if(NOT TARGET nlcg::cpu_lapack)
add_library(nlcg::cpu_lapack INTERFACE IMPORTED)
set_target_properties(nlcg::cpu_lapack PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SCI_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${SCI_LIBRARIES}")
endif()
else()
message(FATAL_ERROR "must specify a LAPACK_VENDOR")
endif()
find_package(nlohmann_json 3.2.0 REQUIRED)
add_subdirectory(src)
if(BUILD_TESTS)
add_subdirectory(test)
add_subdirectory(unit_tests)
endif()
# preserve rpaths when installing and make the install folder relocatable
# use `CMAKE_SKIP_INSTALL_RPATH` to skip this
# https://spack.readthedocs.io/en/latest/workflows.html#write-the-cmake-build
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
# skip RPATH if nlcglib is installed to system directories
if(isSystemDir STREQUAL "-1")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if(APPLE)
set(basePoint @loader_path)
else()
set(basePoint $ORIGIN)
endif()
file(RELATIVE_PATH relDir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_RPATH ${basePoint} ${basePoint}/${relDir})
endif()
include(CMakePackageConfigHelpers)
install(EXPORT nlcglib_targets
FILE nlcglib-targets.cmake
NAMESPACE nlcglib::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/nlcglib")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/nlcglib/nlcglibConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
cmake/nlcglib-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/nlcglib-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nlcglib
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/nlcglib-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/nlcglib/nlcglibConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/nlcglib)