-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
96 lines (80 loc) · 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
# Specify cmake version needed
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
# Set project name, language and c++ std
project(A2D LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Make sure a build type is set explicitly
if(NOT CMAKE_BUILD_TYPE)
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be set explicitly: cmake ... -DCMAKE_BUILD_TYPE={Release,Debug}")
endif()
IF(CMAKE_BUILD_TYPE MATCHES Debug)
message("This is a Debug build.")
ELSEIF(CMAKE_BUILD_TYPE MATCHES Release)
message("This is a Release build.")
ELSE()
message(FATAL_ERROR "Unknown build type CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}, should be Release or Debug")
ENDIF()
# save A2D root directory
set(A2D_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Dependencies
if(NOT DEFINED A2D_KOKKOS_DIR)
set(A2D_KOKKOS_DIR ${A2D_ROOT_DIR}/installs/kokkos)
endif()
if(NOT DEFINED A2D_METIS_DIR)
set(A2D_METIS_DIR ${A2D_ROOT_DIR}/installs/metis)
endif()
# if(NOT DEFINED KOKKOS_KERNELS_INSTALL_DIR)
# set(KOKKOS_KERNELS_INSTALL_DIR ${A2D_ROOT_DIR}/installs/kokkos-kernels)
# endif()
set(Kokkos_ROOT ${A2D_KOKKOS_DIR}) # CMake needs this to locate Kokkos package
set(KOKKOS_INSTALL_DIR ${A2D_KOKKOS_DIR}) # CMake needs this to locate Kokkos package
# Set options
option(A2D_BUILD_EXAMPLES "Compile the a2d examples" ON)
option(A2D_BUILD_UNIT_TESTS "Compile the unit test executables" OFF)
# option(A2D_BUILD_EXTENSION "Compile the pybind11 extension" OFF)
# option(A2D_BUILD_EXAMPLES_AMGX "build amgx examples that requires AMGX and CUDA" OFF)
# Set warning flags
add_compile_options(
-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-sign-compare
)
# Require Lapack and OpenMP
find_package(LAPACK REQUIRED)
find_package(OpenMP REQUIRED)
find_package(Kokkos REQUIRED)
# Build amgx examples
# if(A2D_BUILD_EXAMPLES_AMGX)
# # If use AMGX, the following directories should be valid
# set(AMGX_INCLUDE_DIR ${A2D_ROOT_DIR}/extern/amgx/include)
# set(AMGX_LIB_DIR ${A2D_ROOT_DIR}/extern/amgx/lib/)
# if(NOT EXISTS ${AMGX_INCLUDE_DIR})
# message(WARNING "${AMGX_INCLUDE_DIR} does not exist, can't build with AMGX")
# elseif(NOT EXISTS ${AMGX_LIB_DIR})
# message(WARNING "${AMGX_LIB_DIR} does not exist, please build AMGX first")
# else()
# add_subdirectory(${A2D_ROOT_DIR}/examples/amgx)
# endif()
# endif()
# Build pybind11 extension
# if(A2D_BUILD_EXTENSION)
# execute_process(COMMAND python3 -m pybind11 --cmakedir OUTPUT_VARIABLE
# pybind11_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
# find_package(pybind11 REQUIRED)
# add_subdirectory(${A2D_ROOT_DIR}/pybind11)
# endif()
# Build unit tests
if(A2D_BUILD_UNIT_TESTS)
# Download google test (git tag needs to be updated frequently)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release-1.10.0
)
FetchContent_MakeAvailable(googletest)
add_subdirectory(${A2D_ROOT_DIR}/tests)
endif()
# Build a2d examples
if(A2D_BUILD_EXAMPLES)
add_subdirectory(${A2D_ROOT_DIR}/examples)
endif()