File: FindSUNDIALS.cmake

package info (click to toggle)
dolfin 2018.1.0.post1-16
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 28,764 kB
  • sloc: xml: 104,040; cpp: 98,856; python: 22,511; makefile: 204; sh: 182
file content (190 lines) | stat: -rw-r--r-- 7,439 bytes parent folder | download | duplicates (5)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# - Try to find SUNDIALS
# Once done this will define
#
#  SUNDIALS_FOUND        - system has SUNDIALS
#  SUNDIALS_INCLUDE_DIRS - include directories for SUNDIALS
#  SUNDIALS_LIBRARIES    - libraries for SUNDIALS
#  SUNDIALS_VERSION      - version for SUNDIALS

#=============================================================================
# Copyright (C) 2010 Garth N. Wells, Anders Logg and Johannes Ring
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

if (MPI_CXX_FOUND)
  find_path(SUNDIALS_INCLUDE_DIRS
    NAMES cvode/cvode.h
    HINTS ${SUNDIALS_DIR}/include $ENV{SUNDIALS_DIR}/include ${PETSC_INCLUDE_DIRS}
    DOC "Directory where the SUNDIALS CVODE header files are located"
  )
  find_library(SUNDIALS_LIBRARY 
    NAMES sundials_cvode
    HINTS ${SUNDIALS_DIR}/lib $ENV{SUNDIALS_DIR}/lib ${PETSC_LIBRARY_DIRS}
    NO_DEFAULT_PATH
    DOC "Directory where the SUNDIALS CVODE library is located"
  )
  find_library(SUNDIALS_NVECTOR_SERIAL_LIBRARY
    NAMES sundials_nvecserial
    HINTS ${SUNDIALS_DIR}/lib $ENV{SUNDIALS_DIR}/lib ${PETSC_LIBRARY_DIRS}
    NO_DEFAULT_PATH
    DOC "Directory where the SUNDIALS CVODE library is located"
  )

  set(SUNDIALS_LIBRARIES ${SUNDIALS_LIBRARY})
  set(SUNDIALS_LIBRARIES ${SUNDIALS_LIBRARIES} ${SUNDIALS_NVECTOR_PARALLEL_LIBRARY})
  set(SUNDIALS_LIBRARIES ${SUNDIALS_LIBRARIES} ${SUNDIALS_NVECTOR_SERIAL_LIBRARY})

  # Try compiling and running test program
  if (DOLFIN_SKIP_BUILD_TESTS)
    set(SUNDIALS_TEST_RUNS TRUE)
    set(SUNDIALS_VERSION "UNKNOWN")
    set(SUNDIALS_VERSION_OK TRUE)
  elseif (SUNDIALS_INCLUDE_DIRS AND SUNDIALS_LIBRARIES)

  # Set flags for building test program
  set(CMAKE_REQUIRED_INCLUDES  ${CMAKE_REQUIRED_INCLUDES} ${MPI_CXX_INCLUDE_PATH})
  set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}    ${MPI_CXX_LIBRARIES})
  set(CMAKE_REQUIRED_FLAGS     ${CMAKE_REQUIRED_FLAGS}  ${MPI_CXX_COMPILE_FLAGS})

  set(CMAKE_REQUIRED_INCLUDES  ${CMAKE_REQUIRED_INCLUDES} ${SUNDIALS_INCLUDE_DIRS})
  set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${SUNDIALS_LIBRARIES})

  # Check SUNDIALS version
  set(SUNDIALS_CONFIG_TEST_VERSION_CPP
    "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/sundials_config_test_version.cpp")
  file(WRITE ${SUNDIALS_CONFIG_TEST_VERSION_CPP} "
#define MPICH_IGNORE_CXX_SEEK 1
#include <iostream>
#include \"cvode/cvode.h\"

int main() {
#ifdef SUNDIALS_VERSION
  std::cout << SUNDIALS_VERSION;
#elif defined(SUNDIALS_PACKAGE_VERSION)
  std::cout << SUNDIALS_PACKAGE_VERSION;
#else
  std::cout << SUNDIALS_VERSION_MAJOR << \".\"
  << SUNDIALS_VERSION_MINOR;
#endif
  return 0;
}
")

    try_run(
      SUNDIALS_CONFIG_TEST_VERSION_EXITCODE
      SUNDIALS_CONFIG_TEST_VERSION_COMPILED
      ${CMAKE_CURRENT_BINARY_DIR}
      ${SUNDIALS_CONFIG_TEST_VERSION_CPP}
      CMAKE_FLAGS
        "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
      	"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
      COMPILE_OUTPUT_VARIABLE SUNDIALS_CONFIG_TEST_VERSION_COMPILE_OUTPUT
      RUN_OUTPUT_VARIABLE SUNDIALS_CONFIG_TEST_VERSION_OUTPUT
      )

    if (SUNDIALS_CONFIG_TEST_VERSION_EXITCODE EQUAL 0)
      set(SUNDIALS_VERSION ${SUNDIALS_CONFIG_TEST_VERSION_OUTPUT} CACHE TYPE STRING)
      mark_as_advanced(SUNDIALS_VERSION)
    endif()

    if (SUNDIALS_FIND_VERSION)
      string(REPLACE "." ";" VERSION_LIST ${SUNDIALS_VERSION})
      list(GET VERSION_LIST 0 SUNDIALS_VERSION_MAJOR)
      list(GET VERSION_LIST 1 SUNDIALS_VERSION_MINOR)
      # Check if version found is >= required version
      if (NOT "${SUNDIALS_VERSION_MAJOR}" VERSION_LESS "3")
      	set(SUNDIALS_VERSION_OK TRUE)
      endif()
    else()
      # No specific version requested
      set(SUNDIALS_VERSION_OK TRUE)
    endif()
    mark_as_advanced(SUNDIALS_VERSION_OK)

    # Build and run test program
    set(SUNDIALS_TEST_LIB_CPP "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/sundials_test_lib.cpp")
    file(WRITE ${SUNDIALS_TEST_LIB_CPP} "
#define MPICH_IGNORE_CXX_SEEK 1
#define NEQ 10
#include <iostream>
#include <nvector/nvector_serial.h>
#include <cvode/cvode.h>

int main(int argc, char** argv)
{
  int my_pe, npes;
  long int local_N, nperpe, nrem;
  N_Vector u;  

  u = N_VNew_Serial(NEQ);
  N_VDestroy_Serial(u);

  return 0;
}") 



    message(STATUS "Performing test SUNDIALS_TEST_RUNS")
    try_run(
      SUNDIALS_TEST_LIB_EXITCODE
      SUNDIALS_TEST_LIB_COMPILED
      ${CMAKE_CURRENT_BINARY_DIR}
      ${SUNDIALS_TEST_LIB_CPP}
      CMAKE_FLAGS
        "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
      COMPILE_OUTPUT_VARIABLE SUNDIALS_TEST_LIB_COMPILE_OUTPUT
      RUN_OUTPUT_VARIABLE SUNDIALS_TEST_LIB_OUTPUT
      )

    if (SUNDIALS_TEST_LIB_COMPILED AND SUNDIALS_TEST_LIB_EXITCODE EQUAL 0)
      message(STATUS "Performing test SUNDIALS_TEST_RUNS - Success")
      set(SUNDIALS_TEST_RUNS TRUE)
    else()
      message(STATUS "Performing test SUNDIALS_TEST_RUNS - Failed")
      if (SUNDIALS_DEBUG)
        # Output some variables
        message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
                       "SUNDIALS_TEST_LIB_COMPILED = ${SUNDIALS_TEST_LIB_COMPILED}")
        message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
                       "SUNDIALS_TEST_LIB_COMPILE_OUTPUT = ${SUNDIALS_TEST_LIB_COMPILE_OUTPUT}")
        message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
                       "SUNDIALS_TEST_LIB_EXITCODE = ${SUNDIALS_TEST_LIB_EXITCODE}")
        message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
                       "SUNDIALS_TEST_LIB_OUTPUT = ${SUNDIALS_TEST_LIB_OUTPUT}")
      endif()
    endif()
  endif()
endif()
# Standard package handling
find_package_handle_standard_args(SUNDIALS
                                  "SUNDIALS could not be found/configured."
                                  SUNDIALS_LIBRARIES
				  SUNDIALS_TEST_RUNS
                                  SUNDIALS_INCLUDE_DIRS
				  SUNDIALS_VERSION
				  SUNDIALS_VERSION_OK)