Debian Codegraph @

cmake/modules/FindSUNDIALS.cmake

raw
1 # - Try to find SUNDIALS
2 # Once done this will define
3 #
4 # SUNDIALS_FOUND - system has SUNDIALS
5 # SUNDIALS_INCLUDE_DIRS - include directories for SUNDIALS
6 # SUNDIALS_LIBRARIES - libraries for SUNDIALS
7 # SUNDIALS_VERSION - version for SUNDIALS
8
9 #=============================================================================
10 # Copyright (C) 2010 Garth N. Wells, Anders Logg and Johannes Ring
11 # All rights reserved.
12 #
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are permitted provided that the following conditions
15 # are met:
16 #
17 # 1. Redistributions of source code must retain the above copyright
18 # notice, this list of conditions and the following disclaimer.
19 # 2. Redistributions in binary form must reproduce the above copyright
20 # notice, this list of conditions and the following disclaimer in
21 # the documentation and/or other materials provided with the
22 # distribution.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 # POSSIBILITY OF SUCH DAMAGE.
36 #=============================================================================
37
38 if (MPI_CXX_FOUND)
39 find_path(SUNDIALS_INCLUDE_DIRS
40 NAMES cvode/cvode.h
41 HINTS ${SUNDIALS_DIR}/include $ENV{SUNDIALS_DIR}/include ${PETSC_INCLUDE_DIRS}
42 DOC "Directory where the SUNDIALS CVODE header files are located"
43 )
44 find_library(SUNDIALS_LIBRARY
45 NAMES sundials_cvode
46 HINTS ${SUNDIALS_DIR}/lib $ENV{SUNDIALS_DIR}/lib ${PETSC_LIBRARY_DIRS}
47 NO_DEFAULT_PATH
48 DOC "Directory where the SUNDIALS CVODE library is located"
49 )
50 find_library(SUNDIALS_NVECTOR_SERIAL_LIBRARY
51 NAMES sundials_nvecserial
52 HINTS ${SUNDIALS_DIR}/lib $ENV{SUNDIALS_DIR}/lib ${PETSC_LIBRARY_DIRS}
53 NO_DEFAULT_PATH
54 DOC "Directory where the SUNDIALS CVODE library is located"
55 )
56
57 set(SUNDIALS_LIBRARIES ${SUNDIALS_LIBRARY})
58 set(SUNDIALS_LIBRARIES ${SUNDIALS_LIBRARIES} ${SUNDIALS_NVECTOR_PARALLEL_LIBRARY})
59 set(SUNDIALS_LIBRARIES ${SUNDIALS_LIBRARIES} ${SUNDIALS_NVECTOR_SERIAL_LIBRARY})
60
61 # Try compiling and running test program
62 if (DOLFIN_SKIP_BUILD_TESTS)
63 set(SUNDIALS_TEST_RUNS TRUE)
64 set(SUNDIALS_VERSION "UNKNOWN")
65 set(SUNDIALS_VERSION_OK TRUE)
66 elseif (SUNDIALS_INCLUDE_DIRS AND SUNDIALS_LIBRARIES)
67
68 # Set flags for building test program
69 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${MPI_CXX_INCLUDE_PATH})
70 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${MPI_CXX_LIBRARIES})
71 set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${MPI_CXX_COMPILE_FLAGS})
72
73 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${SUNDIALS_INCLUDE_DIRS})
74 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${SUNDIALS_LIBRARIES})
75
76 # Check SUNDIALS version
77 set(SUNDIALS_CONFIG_TEST_VERSION_CPP
78 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/sundials_config_test_version.cpp")
79 file(WRITE ${SUNDIALS_CONFIG_TEST_VERSION_CPP} "
80 #define MPICH_IGNORE_CXX_SEEK 1
81 #include <iostream>
82 #include \"cvode/cvode.h\"
83
84 int main() {
85 #ifdef SUNDIALS_VERSION
86 std::cout << SUNDIALS_VERSION;
87 #elif defined(SUNDIALS_PACKAGE_VERSION)
88 std::cout << SUNDIALS_PACKAGE_VERSION;
89 #else
90 std::cout << SUNDIALS_VERSION_MAJOR << \".\"
91 << SUNDIALS_VERSION_MINOR;
92 #endif
93 return 0;
94 }
95 ")
96
97 try_run(
98 SUNDIALS_CONFIG_TEST_VERSION_EXITCODE
99 SUNDIALS_CONFIG_TEST_VERSION_COMPILED
100 ${CMAKE_CURRENT_BINARY_DIR}
101 ${SUNDIALS_CONFIG_TEST_VERSION_CPP}
102 CMAKE_FLAGS
103 "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
104 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
105 COMPILE_OUTPUT_VARIABLE SUNDIALS_CONFIG_TEST_VERSION_COMPILE_OUTPUT
106 RUN_OUTPUT_VARIABLE SUNDIALS_CONFIG_TEST_VERSION_OUTPUT
107 )
108
109 if (SUNDIALS_CONFIG_TEST_VERSION_EXITCODE EQUAL 0)
110 set(SUNDIALS_VERSION ${SUNDIALS_CONFIG_TEST_VERSION_OUTPUT} CACHE TYPE STRING)
111 mark_as_advanced(SUNDIALS_VERSION)
112 endif()
113
114 if (SUNDIALS_FIND_VERSION)
115 string(REPLACE "." ";" VERSION_LIST ${SUNDIALS_VERSION})
116 list(GET VERSION_LIST 0 SUNDIALS_VERSION_MAJOR)
117 list(GET VERSION_LIST 1 SUNDIALS_VERSION_MINOR)
118 # Check if version found is >= required version
119 if (NOT "${SUNDIALS_VERSION_MAJOR}" VERSION_LESS "3")
120 set(SUNDIALS_VERSION_OK TRUE)
121 endif()
122 else()
123 # No specific version requested
124 set(SUNDIALS_VERSION_OK TRUE)
125 endif()
126 mark_as_advanced(SUNDIALS_VERSION_OK)
127
128 # Build and run test program
129 set(SUNDIALS_TEST_LIB_CPP "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/sundials_test_lib.cpp")
130 file(WRITE ${SUNDIALS_TEST_LIB_CPP} "
131 #define MPICH_IGNORE_CXX_SEEK 1
132 #define NEQ 10
133 #include <iostream>
134 #include <nvector/nvector_serial.h>
135 #include <cvode/cvode.h>
136
137 int main(int argc, char** argv)
138 {
139 int my_pe, npes;
140 long int local_N, nperpe, nrem;
141 N_Vector u;
142
143 u = N_VNew_Serial(NEQ);
144 N_VDestroy_Serial(u);
145
146 return 0;
147 }")
148
149
150
151 message(STATUS "Performing test SUNDIALS_TEST_RUNS")
152 try_run(
153 SUNDIALS_TEST_LIB_EXITCODE
154 SUNDIALS_TEST_LIB_COMPILED
155 ${CMAKE_CURRENT_BINARY_DIR}
156 ${SUNDIALS_TEST_LIB_CPP}
157 CMAKE_FLAGS
158 "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
159 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
160 COMPILE_OUTPUT_VARIABLE SUNDIALS_TEST_LIB_COMPILE_OUTPUT
161 RUN_OUTPUT_VARIABLE SUNDIALS_TEST_LIB_OUTPUT
162 )
163
164 if (SUNDIALS_TEST_LIB_COMPILED AND SUNDIALS_TEST_LIB_EXITCODE EQUAL 0)
165 message(STATUS "Performing test SUNDIALS_TEST_RUNS - Success")
166 set(SUNDIALS_TEST_RUNS TRUE)
167 else()
168 message(STATUS "Performing test SUNDIALS_TEST_RUNS - Failed")
169 if (SUNDIALS_DEBUG)
170 # Output some variables
171 message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
172 "SUNDIALS_TEST_LIB_COMPILED = ${SUNDIALS_TEST_LIB_COMPILED}")
173 message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
174 "SUNDIALS_TEST_LIB_COMPILE_OUTPUT = ${SUNDIALS_TEST_LIB_COMPILE_OUTPUT}")
175 message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
176 "SUNDIALS_TEST_LIB_EXITCODE = ${SUNDIALS_TEST_LIB_EXITCODE}")
177 message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
178 "SUNDIALS_TEST_LIB_OUTPUT = ${SUNDIALS_TEST_LIB_OUTPUT}")
179 endif()
180 endif()
181 endif()
182 endif()
183 # Standard package handling
184 find_package_handle_standard_args(SUNDIALS
185 "SUNDIALS could not be found/configured."
186 SUNDIALS_LIBRARIES
187 SUNDIALS_TEST_RUNS
188 SUNDIALS_INCLUDE_DIRS
189 SUNDIALS_VERSION
190 SUNDIALS_VERSION_OK)