-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
103 lines (87 loc) · 3.73 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
cmake_minimum_required(VERSION 3.19.3)
project(tf-diffusion)
# Use C++14 standard to make it compatible with BioDynaMo later on.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
## ------------------------------ CNPY -----------------------------------------
## Since there is not support for the AAA algorithm, we use python to compute
## the expansion coefficients c_\inf, c_k, and d_k. We export them in the `npy`
## format and use CNPY to read them from the CPP part or the program.
set(CNPY_PATH "/usr/local/include") # PATH to source directore, e.g. cloned git
set(CNPY_LIB "/usr/local/lib") # PATH to installed directory
if(APPLE)
set(CNPY_LIB_NAME "libcnpy.dylib")
else()
set(CNPY_LIB_NAME "libcnpy.so")
endif(APPLE)
include_directories(${CNPY_PATH})
add_library(cnpy SHARED IMPORTED)
set_target_properties(cnpy PROPERTIES
IMPORTED_LOCATION "${CNPY_LIB}/${CNPY_LIB_NAME}"
INTERFACE_INCLUDE_DIRECTORIES "${CNPY_PATH}"
)
## -------------------------- USE MFEM -----------------------------------------
## MFEM is used for the finite element discretization, computation of mass and
## stiffness matrix, and general sparse matrix-vector operations. The cmake
## code of this section was provided by MFEM / LLNL directly.
# Use MFEM in this project.
# Import MFEM. The following variables can be used to help CMake find MFEM:
# * MFEM_DIR - absolute path to the MFEM build or install prefix.
# * mfem_DIR - absolute path to where MFEMConfig.cmake is.
message(STATUS "Looking for mfem ...")
set(MFEM_DIR "" CACHE PATH "Path to the MFEM build or install prefix.")
if (MFEM_DIR)
find_package(mfem REQUIRED NAMES MFEM HINTS "${MFEM_DIR}"
"${MFEM_DIR}/lib/cmake/mfem" NO_DEFAULT_PATH)
else()
find_package(mfem REQUIRED NAMES MFEM)
endif()
message(STATUS "Found mfem config in: ${mfem_DIR} (version ${MFEM_VERSION})")
# Use the same C++ compiler as MFEM. This is needed when MFEM was built using
# an MPI wrapper and we do not have explicitly the MPI compile and link flags.
message(STATUS "Mfem compiler is: ${MFEM_CXX_COMPILER}")
if (NOT CMAKE_CXX_COMPILER AND MFEM_CXX_COMPILER)
set(CMAKE_CXX_COMPILER "${MFEM_CXX_COMPILER}")
endif()
message(STATUS "Mfem include dir is: ${MFEM_INCLUDE_DIRS}")
include_directories(${MFEM_INCLUDE_DIRS})
message(STATUS "Mfem library is: ${MFEM_LIBRARIES}")
## --------------------------- Compile Main ----------------------------------
# Consider all files in src/ for diffusion simulation.
include_directories("src")
file(GLOB_RECURSE PROJECT_HEADERS src/*.h)
file(GLOB_RECURSE PROJECT_SOURCES src/*.cc)
message(STATUS "Building diffusion simulation. Considering the follwing: \n"
" .cc: ${PROJECT_SOURCES} \n" " .h: ${PROJECT_HEADERS}")
# define target executable for diffusion simulation
add_executable(
${CMAKE_PROJECT_NAME}
${PROJECT_HEADERS} ${PROJECT_SOURCES}
)
# Link executable against mfem
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${MFEM_LIBRARIES} cnpy)
## -------------------------- USE GOOGLETEST -----------------------------------
# Fetch googletest from their gitrepository
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# Make google test available
FetchContent_MakeAvailable(googletest)
## -------------------------- Compile Test -------------------------------------
# Get all .cc files from test directory
include_directories("test")
file(GLOB_RECURSE TEST_SOURCES test/*.cc)
# Define an executable for the tests and link against gtest
enable_testing()
add_executable(
${CMAKE_PROJECT_NAME}-test
${TEST_SOURCES} "src/util.cc"
)
target_link_libraries(
${CMAKE_PROJECT_NAME}-test
gtest_main cnpy
)
include(GoogleTest)
gtest_discover_tests(${CMAKE_PROJECT_NAME}-test)