-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
167 lines (145 loc) · 5.09 KB
/
Copy pathCMakeLists.txt
File metadata and controls
167 lines (145 loc) · 5.09 KB
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
cmake_minimum_required (VERSION 3.1)
project(pde1d)
SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
cmake_policy(SET CMP0008 NEW)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
set(PSE "Octave" CACHE STRING "Problem solving environment")
set_property(CACHE PSE PROPERTY STRINGS Octave MATLAB)
#message(STATUS "CMAKE_CXX_COMPILER_ID=" ${CMAKE_CXX_COMPILER_ID})
if(MSVC)
add_compile_options("/wd4996")
add_compile_options("/wd4477")
add_definitions(-DNOMINMAX)
elseif(UNIX OR MINGW)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
add_compile_options(-Wunused-variable)
#add_compile_options(-Wall)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Want to find Eigen and check version even if it hasn't been formally "installed".
# In Eigen 3.3 this requires find_package in module mode for the un-installed case and
# config mode for the installed case.
if(EIGEN_ROOT)
set(CMAKE_MODULE_PATH ${EIGEN_ROOT} ; ${EIGEN_ROOT}/cmake)
set(CMAKE_PREFIX_PATH ${EIGEN_ROOT}/share) # config mode
set(EIGEN3_INCLUDE_DIR ${EIGEN_ROOT})
set(Eigen3_FIND_VERSION 3.3)
endif() # EIGEN_ROOT
find_package(Eigen3 ${Eigen3_FIND_VERSION} REQUIRED)
if(NOT EIGEN3_FOUND)
message(SEND_ERROR "Eigen matrix library not found.")
endif()
# Eigen 3.3 FindEigen3.cmake not issuing error for wrong version
if(EIGEN3_VERSION AND EIGEN3_VERSION VERSION_LESS Eigen3_FIND_VERSION)
message(SEND_ERROR "Eigen version must be at least " ${Eigen3_FIND_VERSION})
endif()
message(STATUS "EIGEN3_INCLUDE_DIR=" ${EIGEN3_INCLUDE_DIR})
include_directories(${EIGEN3_INCLUDE_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
set(LINEAR_SOLVER "Eigen" CACHE STRING "Sparse Linear Solver")
set_property(CACHE LINEAR_SOLVER PROPERTY STRINGS Eigen KLU)
message(STATUS "LINEAR_SOLVER=" ${LINEAR_SOLVER})
string(TOLOWER ${LINEAR_SOLVER} LSL)
if(${LSL} STREQUAL klu)
# suitesparse to get KLU for sundials ida
set(SUITESPARSE_COMP_NAMES suitesparseconfig; KLU; AMD; COLAMD; BTF)
#set(SuiteSparse_VERBOSE ON)
set(SUITESPARSE_ROOT SUITESPARSE_ROOT-NOTFOUND CACHE PATH "Path to SuiteSparse solver")
set(SuiteSparse_DIR ${SUITESPARSE_ROOT})
find_package(SuiteSparse REQUIRED
COMPONENTS ${SUITESPARSE_COMP_NAMES})
foreach(cn IN LISTS SUITESPARSE_COMP_NAMES)
string(TOUPPER ${cn} cnUC)
include_directories(${SuiteSparse_${cnUC}_INCLUDE_DIR})
list(APPEND SUITESPARSE_LIBS_RELEASE ${SuiteSparse_${cnUC}_LIBRARY_RELEASE})
list(APPEND SUITESPARSE_LIBS_DEBUG ${SuiteSparse_${cnUC}_LIBRARY_DEBUG})
endforeach()
set(USE_KLU TRUE)
elseif(${LSL} STREQUAL eigen)
add_definitions(-DUSE_EIGEN_LU)
else()
message(SEND_ERROR "Unsupported linear solver: " ${LINEAR_SOLVER})
endif() # LINEAR_SOLVER
#
# find sundials includes and libs
#
set(SUNDIALS_LIBS_NAMES sundials_ida sundials_nvecserial)
if(USE_KLU)
set(SUNDIALS_LIBS_NAMES ${SUNDIALS_LIBS_NAMES} sundials_sunlinsolklu)
endif()
# sundials version must be > 3
# If solver is KLU, sundials must be configured with SuiteSparse.
# This combination may have to be built in a local directory so we
# link to the sundials libs statically to avoid having to set
# LD_LIBRARY_PATH when running the PSE
set(SUNDIALS_USE_STATIC_LIBRARIES TRUE)
find_package(SUNDIALS 3.1 REQUIRED COMPONENTS ${SUNDIALS_LIBS_NAMES})
include_directories(${SUNDIALS_INCLUDE_DIR}/../)
find_package( Boost 1.55 REQUIRED )
include_directories(${Boost_INCLUDE_DIRS})
string(TOLOWER ${PSE} PSEL)
if(${PSEL} STREQUAL octave)
find_package(Octave 5.0 REQUIRED COMPONENTS Development)
include_directories(${Octave_INCLUDE_DIRS})
set(MEX_LIBS ${Octave_OCTAVE_LIBRARY} ${Octave_INTERP_LIBRARY})
message(STATUS "Path to Octave include files: " ${Octave_INCLUDE_DIRS})
elseif(${PSEL} STREQUAL matlab)
find_package( Matlab REQUIRED COMPONENTS MX_LIBRARY)
include_directories(${Matlab_INCLUDE_DIRS})
set(MEX_LIBS
${Matlab_MEX_LIBRARY}
${Matlab_MX_LIBRARY}
)
else()
message(SEND_ERROR "Invalid PSE: " ${PSE})
endif()
FILE(GLOB PDE_LIB_SRC pde1dlib/*.cpp)
FILE(GLOB PDE_H_FILES pde1dlib/*.h)
FILE(GLOB PDE_MEX_SRC pde1dmex/*.cpp)
FILE(GLOB PDE_MEX_H_FILES pde1dmex/*.h)
FILE(GLOB PDE_JAC_SRC FDJacobian/*.cpp)
FILE(GLOB PDE_JAC_H_FILES FDJacobian/*.h)
include_directories(./util)
include_directories(./pde1dlib)
include_directories(./FDJacobian)
add_library(pde1dLib
${PDE_LIB_SRC}
${PDE_H_FILES}
${PDE_JAC_SRC}
${PDE_JAC_H_FILES}
util/util.h
util/util.cpp
)
add_library (pde1d SHARED
${PDE_MEX_SRC}
${PDE_MEX_H_FILES}
)
target_compile_features(pde1d PUBLIC cxx_std_11)
if(MSVC)
target_sources (pde1d PUBLIC ${CMAKE_SOURCE_DIR}/mexFunction.def)
endif()
target_link_libraries(pde1d PRIVATE
pde1dLib
debug "${SUNDIALS_LIBS_DEBUG}"
optimized "${SUNDIALS_LIBS_RELEASE}"
${MEX_LIBS}
)
if(USE_KLU)
target_link_libraries(pde1d PRIVATE
debug "${SUITESPARSE_LIBS_DEBUG}"
optimized "${SUITESPARSE_LIBS_RELEASE}"
)
endif()
string(TOLOWER ${PSE} PSEL)
if(${PSEL} STREQUAL matlab)
set(mexext ${Matlab_MEX_EXTENSION})
else()
set(mexext mex)
endif()
add_custom_command(TARGET pde1d POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
$<TARGET_FILE:pde1d>
"${CMAKE_INSTALL_PREFIX}/pde1d.${mexext}")
add_subdirectory (tests)