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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
# - Try to find SCOTCH
# Once done this will define
#
# SCOTCH_FOUND - system has found SCOTCH
# SCOTCH_INCLUDE_DIRS - include directories for SCOTCH
# SCOTCH_LIBARIES - libraries for SCOTCH
# SCOTCH_VERSION - version for SCOTCH
#
# Variables used by this module, they can change the default behaviour and
# need to be set before calling find_package:
#
# SCOTCH_DEBUG - Set this to TRUE to enable debugging output
# of FindScotchPT.cmake if you are having problems.
# Please enable this before filing any bug reports.
#=============================================================================
# Copyright (C) 2010-2011 Garth N. Wells, Johannes Ring and Anders Logg
# 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.
#=============================================================================
set(SCOTCH_FOUND FALSE)
message(STATUS "Checking for package 'SCOTCH-PT'")
# Check for header file
find_path(SCOTCH_INCLUDE_DIRS ptscotch.h
HINTS ${SCOTCH_DIR}/include $ENV{SCOTCH_DIR}/include ${PETSC_INCLUDE_DIRS}
PATH_SUFFIXES scotch
DOC "Directory where the SCOTCH-PT header is located"
)
# Check for scotch
find_library(SCOTCH_LIBRARY
NAMES scotch
HINTS ${SCOTCH_DIR}/lib $ENV{SCOTCH_DIR}/lib ${PETSC_LIBRARY_DIRS}
NO_DEFAULT_PATH
DOC "The SCOTCH library"
)
find_library(SCOTCH_LIBRARY
NAMES scotch
DOC "The SCOTCH library"
)
# Check for scotcherr
find_library(SCOTCHERR_LIBRARY
NAMES scotcherr
HINTS ${SCOTCH_DIR}/lib $ENV{SCOTCH_DIR}/lib
NO_DEFAULT_PATH
DOC "The SCOTCH-ERROR library"
)
find_library(SCOTCHERR_LIBRARY
NAMES scotcherr
DOC "The SCOTCH-ERROR library"
)
# Check for ptscotch
find_library(PTSCOTCH_LIBRARY
NAMES ptscotch
HINTS ${SCOTCH_DIR}/lib $ENV{SCOTCH_DIR}/lib ${PETSC_LIBRARY_DIRS}
NO_DEFAULT_PATH
DOC "The PTSCOTCH library"
)
find_library(PTSCOTCH_LIBRARY
NAMES ptscotch
DOC "The PTSCOTCH library"
)
# Check for ptesmumps
find_library(PTESMUMPS_LIBRARY
NAMES ptesmumps esmumps
HINTS ${SCOTCH_DIR}/lib $ENV{SCOTCH_DIR}/lib ${PETSC_LIBRARY_DIRS}
NO_DEFAULT_PATH
DOC "The PTSCOTCH-ESMUMPS library"
)
find_library(PTESMUMPS_LIBRARY
NAMES ptesmumps esmumps
DOC "The PTSCOTCH-ESMUMPS library"
)
# Check for ptscotcherr
find_library(PTSCOTCHERR_LIBRARY
NAMES ptscotcherr
HINTS ${SCOTCH_DIR}/lib $ENV{SCOTCH_DIR}/lib ${PETSC_LIBRARY_DIRS}
NO_DEFAULT_PATH
DOC "The PTSCOTCH-ERROR library"
)
find_library(PTSCOTCHERR_LIBRARY
NAMES ptscotcherr
DOC "The PTSCOTCH-ERROR library"
)
set(SCOTCH_LIBRARIES ${PTSCOTCH_LIBRARY})
if (PTESMUMPS_LIBRARY)
set(SCOTCH_LIBRARIES ${SCOTCH_LIBRARIES} ${PTESMUMPS_LIBRARY})
endif()
set(SCOTCH_LIBRARIES ${SCOTCH_LIBRARIES} ${PTSCOTCHERR_LIBRARY})
# Basic check of SCOTCH_VERSION which does not require compilation
if (SCOTCH_INCLUDE_DIRS)
file(STRINGS "${SCOTCH_INCLUDE_DIRS}/ptscotch.h" PTSCOTCH_H)
string(REGEX MATCH "SCOTCH_VERSION [0-9]+" SCOTCH_VERSION "${PTSCOTCH_H}")
string(REGEX MATCH "[0-9]+" SCOTCH_VERSION "${SCOTCH_VERSION}")
endif()
# If SCOTCH_VERSION was not found in ptscotch.h, look in scotch.h
if (SCOTCH_INCLUDE_DIRS AND NOT SCOTCH_VERSION)
file(STRINGS "${SCOTCH_INCLUDE_DIRS}/scotch.h" SCOTCH_H)
string(REGEX MATCH "SCOTCH_VERSION [0-9]+" SCOTCH_VERSION "${SCOTCH_H}")
string(REGEX MATCH "[0-9]+" SCOTCH_VERSION "${SCOTCH_VERSION}")
endif()
# For SCOTCH version > 6, need to add libraries scotch and ptscotch
if (NOT "${SCOTCH_VERSION}" VERSION_LESS "6")
set(SCOTCH_LIBRARIES ${PTSCOTCH_LIBRARY} ${SCOTCH_LIBRARY} ${PTSCOTCHERR_LIBRARY})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${SCOTCH_LIBRARY})
endif()
# Try compiling and running test program
if (DOLFIN_SKIP_BUILD_TESTS)
message(STATUS "Found SCOTCH (version ${SCOTCH_VERSION})")
set(SCOTCH_TEST_RUNS TRUE)
elseif (SCOTCH_INCLUDE_DIRS AND SCOTCH_LIBRARIES)
if (SCOTCH_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"location of ptscotch.h: ${SCOTCH_INCLUDE_DIRS}/ptscotch.h")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"location of libscotch: ${SCOTCH_LIBRARY}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"location of libptscotch: ${PTSCOTCH_LIBRARY}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"location of libptscotcherr: ${PTSCOTCHERR_LIBRARY}")
endif()
# Set flags for building test program
set(CMAKE_REQUIRED_INCLUDES ${SCOTCH_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${SCOTCH_LIBRARIES})
#set(CMAKE_REQUIRED_LIBRARIES ${SCOTCH_LIBRARY} ${SCOTCHERR_LIBRARY})
# Add MPI variables if MPI has been found
if (MPI_CXX_FOUND)
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}")
endif()
set(SCOTCH_CONFIG_TEST_VERSION_CPP
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/scotch_config_test_version.cpp")
file(WRITE ${SCOTCH_CONFIG_TEST_VERSION_CPP} "
#define MPICH_IGNORE_CXX_SEEK 1
#include <stdint.h>
#include <stdio.h>
#include <mpi.h>
#include <ptscotch.h>
#include <iostream>
int main() {
std::cout << SCOTCH_VERSION << \".\"
<< SCOTCH_RELEASE << \".\"
<< SCOTCH_PATCHLEVEL;
return 0;
}
")
try_run(
SCOTCH_CONFIG_TEST_VERSION_EXITCODE
SCOTCH_CONFIG_TEST_VERSION_COMPILED
${CMAKE_CURRENT_BINARY_DIR}
${SCOTCH_CONFIG_TEST_VERSION_CPP}
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
RUN_OUTPUT_VARIABLE OUTPUT
)
# Set version number
if (SCOTCH_CONFIG_TEST_VERSION_EXITCODE EQUAL 0)
set(SCOTCH_VERSION ${OUTPUT} CACHE TYPE STRING)
message(STATUS "Found SCOTCH (version ${SCOTCH_VERSION})")
endif()
# PT-SCOTCH was first introduced in SCOTCH version 5.0
# FIXME: parallel graph partitioning features in PT-SCOTCH was first
# introduced in 5.1. Do we require version 5.1?
if (NOT ${SCOTCH_VERSION} VERSION_LESS "5.0")
set(SCOTCH_TEST_LIB_CPP
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/scotch_test_lib.cpp")
file(WRITE ${SCOTCH_TEST_LIB_CPP} "
#define MPICH_IGNORE_CXX_SEEK 1
#include <stdint.h>
#include <stdio.h>
#include <mpi.h>
#include <ptscotch.h>
#include <iostream>
#include <cstdlib>
int main() {
int provided;
SCOTCH_Dgraph dgrafdat;
MPI_Init_thread(0, 0, MPI_THREAD_MULTIPLE, &provided);
if (SCOTCH_dgraphInit(&dgrafdat, MPI_COMM_WORLD) != 0) {
if (MPI_THREAD_MULTIPLE > provided) {
std::cout << \"MPI implementation is not thread-safe:\" << std::endl;
std::cout << \"SCOTCH should be compiled without SCOTCH_PTHREAD\" << std::endl;
exit(1);
}
else {
std::cout << \"libptscotch linked to libscotch or other unknown error\" << std::endl;
exit(2);
}
}
else {
SCOTCH_dgraphExit(&dgrafdat);
}
MPI_Finalize();
return 0;
}
")
message(STATUS "Performing test SCOTCH_TEST_RUNS")
try_run(
SCOTCH_TEST_LIB_EXITCODE
SCOTCH_TEST_LIB_COMPILED
${CMAKE_CURRENT_BINARY_DIR}
${SCOTCH_TEST_LIB_CPP}
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
COMPILE_OUTPUT_VARIABLE SCOTCH_TEST_LIB_COMPILE_OUTPUT
RUN_OUTPUT_VARIABLE SCOTCH_TEST_LIB_OUTPUT
)
if (SCOTCH_TEST_LIB_COMPILED AND SCOTCH_TEST_LIB_EXITCODE EQUAL 0)
message(STATUS "Performing test SCOTCH_TEST_RUNS - Success")
set(SCOTCH_TEST_RUNS TRUE)
else()
message(STATUS "Performing test SCOTCH_TEST_RUNS - Failed")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Failed to run SCOTCH test:\n"
"CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}\n"
"CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}\n"
"CMAKE_REQUIRED_FLAGS: ${CMAKE_REQUIRED_FLAGS}\n"
"SCOTCH_TEST_LIB_EXITCODE: ${SCOTCH_TEST_LIB_EXITCODE}\n"
"SCOTCH_TEST_LIB_COMPILED: ${SCOTCH_TEST_LIB_COMPILED}\n"
"SCOTCH_TEST_LIB_COMPILE_OUTPUT: ${SCOTCH_TEST_LIB_COMPILE_OUTPUT}\n"
"SCOTCH_TEST_LIB_OUTPUT: ${SCOTCH_TEST_LIB_OUTPUT}\n\n")
if (SCOTCH_DEBUG)
# Output some variables
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"SCOTCH_TEST_LIB_COMPILED = ${SCOTCH_TEST_LIB_COMPILED}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"SCOTCH_TEST_LIB_COMPILE_OUTPUT = ${SCOTCH_TEST_LIB_COMPILE_OUTPUT}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"SCOTCH_TEST_LIB_EXITCODE = ${SCOTCH_TEST_LIB_EXITCODE}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"SCOTCH_TEST_LIB_OUTPUT = ${SCOTCH_TEST_LIB_OUTPUT}")
endif()
endif()
# If program does not run, try adding zlib library and test again
if(NOT SCOTCH_TEST_RUNS)
if (NOT ZLIB_FOUND)
find_package(ZLIB)
endif()
if (ZLIB_INCLUDE_DIRS AND ZLIB_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${ZLIB_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${ZLIB_LIBRARIES})
message(STATUS "Performing test SCOTCH_ZLIB_TEST_RUNS")
try_run(
SCOTCH_ZLIB_TEST_LIB_EXITCODE
SCOTCH_ZLIB_TEST_LIB_COMPILED
${CMAKE_CURRENT_BINARY_DIR}
${SCOTCH_TEST_LIB_CPP}
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}"
COMPILE_OUTPUT_VARIABLE SCOTCH_ZLIB_TEST_LIB_COMPILE_OUTPUT
RUN_OUTPUT_VARIABLE SCOTCH_ZLIB_TEST_LIB_OUTPUT
)
# Add zlib flags if required and set test run to 'true'
if (SCOTCH_ZLIB_TEST_LIB_COMPILED AND SCOTCH_ZLIB_TEST_LIB_EXITCODE EQUAL 0)
message(STATUS "Performing test SCOTCH_ZLIB_TEST_RUNS - Success")
set(SCOTCH_INCLUDE_DIRS ${SCOTCH_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
set(SCOTCH_LIBRARIES ${SCOTCH_LIBRARIES} ${ZLIB_LIBRARIES})
set(SCOTCH_TEST_RUNS TRUE)
else()
message(STATUS "Performing test SCOTCH_ZLIB_TEST_RUNS - Failed")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Failed to run SCOTCH test with zlib:\n"
"CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}\n"
"CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}\n"
"CMAKE_REQUIRED_FLAGS: ${CMAKE_REQUIRED_FLAGS}\n"
"SCOTCH_ZLIB_TEST_LIB_EXITCODE: ${SCOTCH_ZLIB_TEST_LIB_EXITCODE}\n"
"SCOTCH_ZLIB_TEST_LIB_COMPILED: ${SCOTCH_ZLIB_TEST_LIB_COMPILED}\n"
"SCOTCH_ZLIB_TEST_LIB_COMPILE_OUTPUT: ${SCOTCH_ZLIB_TEST_LIB_COMPILE_OUTPUT}\n"
"SCOTCH_ZLIB_TEST_LIB_OUTPUT: ${SCOTCH_ZLIB_TEST_LIB_OUTPUT}\n\n")
if (SCOTCH_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"SCOTCH_ZLIB_TEST_LIB_COMPILED = ${SCOTCH_ZLIB_TEST_LIB_COMPILED}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"SCOTCH_ZLIB_TEST_LIB_COMPILE_OUTPUT = ${SCOTCH_ZLIB_TEST_LIB_COMPILE_OUTPUT}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"SCOTCH_TEST_LIB_EXITCODE = ${SCOTCH_TEST_LIB_EXITCODE}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"SCOTCH_TEST_LIB_OUTPUT = ${SCOTCH_TEST_LIB_OUTPUT}")
endif()
endif()
endif()
endif()
endif()
endif()
# Standard package handling
find_package_handle_standard_args(SCOTCH
"SCOTCH could not be found. Be sure to set SCOTCH_DIR."
SCOTCH_LIBRARIES
SCOTCH_INCLUDE_DIRS
SCOTCH_TEST_RUNS)
|