Commit ea84748d authored by Praetorius, Simon's avatar Praetorius, Simon

find-boost, find-petsc and find-umfpack packed into separate files, like targt_enable_xxx

parent 73772d03
......@@ -82,7 +82,8 @@ endif (NOT BOOST_ROOT)
if (NOT BOOST_LIBRARYDIR)
set(BOOST_LIBRARYDIR @BOOST_LIBRARYDIR@)
endif (NOT BOOST_LIBRARYDIR)
include(find_boost)
include(target_enable_boost)
target_enable_boost(amdis_base INTERFACE ON)
# umfpack library
# --------------------
......@@ -90,7 +91,8 @@ if (AMDIS_NEED_UMFPACK)
set(AMDIS_SuiteSparse_DIR @SuiteSparse_DIR@)
set(AMDIS_UMFPACK_INCLUDE_DIR @UMFPACK_INCLUDE_DIRS@)
set(AMDIS_UMFPACK_LIB_DIR ${AMDIS_UMFPACK_INCLUDE_DIR}/../include)
include(find_umfpack)
include(target_enable_umfpack)
target_enable_umfpack(amdis_base INTERFACE ON)
endif (AMDIS_NEED_UMFPACK)
......
......@@ -9,6 +9,7 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
endif ()
include(FindPkgConfig)
# ------------------------------------------------------------------------------
#some options to control the build process
......@@ -58,10 +59,15 @@ endif (ENABLE_CXX11)
include(find_mtl4) # -> target mtl4
install(FILES ${BASE_DIR}/cmake3/find_mtl4.cmake DESTINATION share/amdis/)
include(find_umfpack)
if (ENABLE_UMFPACK)
include(target_enable_umfpack) # -> target boost
target_enable_umfpack(amdis_base INTERFACE)
install(FILES ${BASE_DIR}/cmake3/target_enable_umfpack.cmake DESTINATION share/amdis/)
endif (ENABLE_UMFPACK)
include(find_boost) # -> target boost
install(FILES ${BASE_DIR}/cmake3/find_boost.cmake DESTINATION share/amdis/)
include(target_enable_boost) # -> target boost
target_enable_boost(amdis_base INTERFACE)
install(FILES ${BASE_DIR}/cmake3/target_enable_boost.cmake DESTINATION share/amdis/)
# ------------------------------------------------------------------------------
......
if (BOOST_ROOT)
file(TO_CMAKE_PATH ${BOOST_ROOT} BOOST_ROOT)
endif (BOOST_ROOT)
if (BOOST_LIBRARYDIR)
file(TO_CMAKE_PATH ${BOOST_LIBRARYDIR} BOOST_LIBRARYDIR)
endif (BOOST_LIBRARYDIR)
set(BOOST_VERSION "1.48")
set(BOOST_LIBS_REQUIRED system iostreams filesystem program_options date_time)
if (WIN32)
list(APPEND BOOST_LIBS_REQUIRED zlib)
if (ENABLE_COMPRESSION OR AMDIS_NEED_COMPRESSION)
list(APPEND BOOST_LIBS_REQUIRED bzip2)
endif (ENABLE_COMPRESSION OR AMDIS_NEED_COMPRESSION)
endif (WIN32)
if (NOT BUILD_SHARED_LIBS)
set(Boost_USE_STATIC_LIBS ON)
endif (NOT BUILD_SHARED_LIBS)
find_package(Boost ${BOOST_VERSION} REQUIRED ${BOOST_LIBS_REQUIRED})
if (Boost_FOUND)
add_library(boost INTERFACE)
target_include_directories(boost INTERFACE ${Boost_INCLUDE_DIR})
target_link_libraries(boost INTERFACE ${Boost_LIBRARIES})
target_link_libraries(amdis_base INTERFACE boost)
if (MSVC_SHARED_LIBS)
link_directories(${Boost_LIBRARY_DIRS})
target_compile_definitions(amdis_base INTERFACE ${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
endif (MSVC_SHARED_LIBS)
endif (Boost_FOUND)
macro(target_enable_boost _TARGET_ _SCOPE_)
if (${ARGC} GREATER 2)
set(LINK_EXECUTABLE ON)
else ()
set(LINK_EXECUTABLE OFF)
endif ()
if (BOOST_ROOT)
file(TO_CMAKE_PATH ${BOOST_ROOT} BOOST_ROOT)
endif (BOOST_ROOT)
if (BOOST_LIBRARYDIR)
file(TO_CMAKE_PATH ${BOOST_LIBRARYDIR} BOOST_LIBRARYDIR)
endif (BOOST_LIBRARYDIR)
set(BOOST_VERSION "1.48")
set(BOOST_LIBS_REQUIRED system iostreams filesystem program_options date_time)
if (WIN32)
list(APPEND BOOST_LIBS_REQUIRED zlib)
if (ENABLE_COMPRESSION OR AMDIS_NEED_COMPRESSION)
list(APPEND BOOST_LIBS_REQUIRED bzip2)
endif (ENABLE_COMPRESSION OR AMDIS_NEED_COMPRESSION)
endif (WIN32)
if (NOT BUILD_SHARED_LIBS)
set(Boost_USE_STATIC_LIBS ON)
endif (NOT BUILD_SHARED_LIBS)
find_package(Boost ${BOOST_VERSION} REQUIRED ${BOOST_LIBS_REQUIRED})
if (Boost_FOUND)
add_library(boost INTERFACE)
target_include_directories(boost INTERFACE ${Boost_INCLUDE_DIR})
if (LINK_EXECUTABLE)
target_link_libraries(boost INTERFACE ${Boost_LIBRARIES})
endif (LINK_EXECUTABLE)
target_link_libraries(${_TARGET_} ${_SCOPE_} boost)
if (MSVC_SHARED_LIBS AND LINK_EXECUTABLE)
link_directories(${Boost_LIBRARY_DIRS})
target_compile_definitions(${_TARGET_} ${_SCOPE_} ${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
endif (MSVC_SHARED_LIBS AND LINK_EXECUTABLE)
endif (Boost_FOUND)
endmacro(target_enable_boost)
......@@ -27,29 +27,35 @@ macro(target_enable_petsc _TARGET_ _SCOPE_)
endif ()
# PETSc library is required
find_package(PETSc QUIET)
if (PETSc_FOUND)
set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDES})
set(PETSC_LIBRARY_DIRS ${PETSC_LIB_DIR})
message(STATUS " Found PETSc, version ${PETSC_VERSION}")
else (PETSc_FOUND)
include(FindPkgConfig)
find_file(PETSC_PKG_CONFIG "PETSc.pc"
HINTS ${PETSC_DIR}/lib/pkgconfig
${PETSC_ROOT}/lib/pkgconfig
/usr/lib/petsc/lib/pkgconfig
/usr/lib/petsc/linux-gnu-cxx-opt/lib/pkgconfig
/usr/lib/petsc/linux-gnu-c-opt/lib/pkgconfig)
if (PETSC_PKG_CONFIG-NOTFOUND)
message(FATAL_ERROR "PETSc PKG-Config file 'PETSc.pc' could not be found. Set variable PETSC_DIR to the directory where this file is located!")
endif (PETSC_PKG_CONFIG-NOTFOUND)
find_file(PETSC_PKG_CONFIG "PETSc.pc"
HINTS ${PETSC_DIR}/lib/pkgconfig
$ENV{PETSC_DIR}/lib/pkgconfig
${PETSC_ROOT}/lib/pkgconfig
$ENV{PETSC_ROOT}/lib/pkgconfig
/usr/lib/petsc/lib/pkgconfig
/usr/lib/petsc/linux-gnu-cxx-opt/lib/pkgconfig
/usr/lib/petsc/linux-gnu-c-opt/lib/pkgconfig)
if (PETSC_PKG_CONFIG)
get_filename_component(PETSC_PKG_CONFIG_PATH "${PETSC_PKG_CONFIG}" PATH CACHE)
set(ENV{PKG_CONFIG_PATH} ${PETSC_PKG_CONFIG_PATH})
pkg_check_modules(PETSC REQUIRED PETSc>=3.3)
set(PETSC_DEFINITIONS ${PETSC_CFLAGS} ${PETSC_CFLAGS_OTHER})
endif (PETSc_FOUND)
endif (PETSC_PKG_CONFIG)
# check whether PETSc installation and configuration is valid
if (NOT PETSC_INCLUDE_DIRS)
set(PETSC_HEADER_FILE-NOTFOUND ON)
else ()
find_file(PETSC_HEADER_FILE "petsc.h" PATHS ${PETSC_INCLUDE_DIRS} NO_DEFAULT_PATH)
endif (NOT PETSC_INCLUDE_DIRS)
# if not valid, search again
if (PETSC_HEADER_FILE-NOTFOUND)
find_package(PETSc REQUIRED)
set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDES})
set(PETSC_LIBRARY_DIRS ${PETSC_LIB_DIR})
message(STATUS " Found PETSc, version ${PETSC_VERSION}")
endif (PETSC_HEADER_FILE-NOTFOUND)
target_include_directories(${_TARGET_} ${_SCOPE_} ${PETSC_INCLUDE_DIRS})
target_compile_definitions(${_TARGET_} ${_SCOPE_}
......
if (ENABLE_UMFPACK OR AMDIS_NEED_UMFPACK)
macro(target_enable_umfpack _TARGET_ _SCOPE_)
if (${ARGC} GREATER 2)
set(LINK_EXECUTABLE ON)
else ()
set(LINK_EXECUTABLE OFF)
endif ()
if (WIN32)
set(SuiteSparse_USE_LAPACK_BLAS ON)
endif (WIN32)
......@@ -12,8 +18,10 @@ if (ENABLE_UMFPACK OR AMDIS_NEED_UMFPACK)
if (SuiteSparse_FOUND)
message(STATUS "Found SuiteSparse CMake-library")
include(${USE_SuiteSparse})
target_link_libraries(amdis_base INTERFACE ${SuiteSparse_LIBRARIES})
target_include_directories(amdis_base INTERFACE ${SuiteSparse_INCLUDE_DIR} ${SuiteSparse_METIS_INCLUDE_DIR})
if (LINK_EXECUTABLE)
target_link_libraries(${_TARGET_} ${_SCOPE_} ${SuiteSparse_LIBRARIES})
endif (LINK_EXECUTABLE)
target_include_directories(${_TARGET_} ${_SCOPE_} ${SuiteSparse_INCLUDE_DIR} ${SuiteSparse_METIS_INCLUDE_DIR})
set(FOUND_SUITESPARSE_LIBS ${SuiteSparse_LIBRARIES})
else (SuiteSparse_FOUND)
# find umfpack manually by searching for umfpack.h header file
......@@ -48,8 +56,10 @@ if (ENABLE_UMFPACK OR AMDIS_NEED_UMFPACK)
list(APPEND FOUND_SUITESPARSE_LIBS ${SUITESPARSECONFIG_LIBRARY})
endif (SUITESPARSECONFIG_LIBRARY)
target_include_directories(amdis_base INTERFACE ${UMFPACK_PATH})
target_link_libraries(amdis_base INTERFACE ${FOUND_SUITESPARSE_LIBS})
target_include_directories(${_TARGET_} ${_SCOPE_} ${UMFPACK_PATH})
if (LINK_EXECUTABLE)
target_link_libraries(${_TARGET_} ${_SCOPE_} ${FOUND_SUITESPARSE_LIBS})
endif (LINK_EXECUTABLE)
else()
message(FATAL_ERROR "Could not find the UMFPACK header umfpack.h.")
endif (UMFPACK_H AND UMFPACK_LIBRARY)
......@@ -57,37 +67,36 @@ if (ENABLE_UMFPACK OR AMDIS_NEED_UMFPACK)
# Check for clock_gettime in librt
if (NOT WIN32)
include(CheckLibraryExists)
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
if (HAVE_CLOCK_GETTIME)
target_link_libraries(amdis_base INTERFACE rt)
else ()
check_library_exists(c clock_gettime "" HAVE_CLOCK_GETTIME)
endif (HAVE_CLOCK_GETTIME)
endif (NOT WIN32)
if (NOT WIN32 AND LINK_EXECUTABLE)
include(CheckLibraryExists)
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
if (HAVE_CLOCK_GETTIME)
target_link_libraries(${_TARGET_} ${_SCOPE_} rt)
else ()
check_library_exists(c clock_gettime "" HAVE_CLOCK_GETTIME)
endif (HAVE_CLOCK_GETTIME)
endif (NOT WIN32 AND LINK_EXECUTABLE)
# collect informations about umfpack version and found libraries
if (FOUND_SUITESPARSE_LIBS)
find_file(_UMFPACK_H umfpack.h HINTS ${SuiteSparse_INCLUDE_DIR} ${UMFPACK_PATH})
find_file(_UMFPACK_H umfpack.h PATHS ${SuiteSparse_INCLUDE_DIR} ${UMFPACK_PATH} NO_DEFAULT_PATH)
file(STRINGS ${_UMFPACK_H} UMFPACK_VERSION_LINE REGEX "#define UMFPACK_VERSION")
string(REGEX MATCH "\"UMFPACK V?([^\"]+)\"" UMFPACK_VERSION_REGEX ${UMFPACK_VERSION_LINE})
set(UMFPACK_VERSION ${CMAKE_MATCH_1})
unset(_UMFPACK_H CACHE)
message(STATUS "UMFPACK version: ${UMFPACK_VERSION}")
message(STATUS "Found the following SuiteSparse libraries:")
foreach (lib ${FOUND_SUITESPARSE_LIBS})
message(STATUS " ${lib}")
endforeach ()
if (LINK_EXECUTABLE)
message(STATUS "Found the following SuiteSparse libraries:")
foreach (lib ${FOUND_SUITESPARSE_LIBS})
message(STATUS " ${lib}")
endforeach ()
endif (LINK_EXECUTABLE)
endif (FOUND_SUITESPARSE_LIBS)
target_compile_definitions(amdis_base INTERFACE
target_compile_definitions(${_TARGET_} ${_SCOPE_}
HAVE_UMFPACK=1
MTL_HAS_UMFPACK=1)
if (NOT IS_AMDISCONFIG)
install(FILES ${BASE_DIR}/cmake3/find_umfpack.cmake DESTINATION share/amdis/)
endif ()
endif (ENABLE_UMFPACK OR AMDIS_NEED_UMFPACK)
\ No newline at end of file
endmacro(target_enable_umfpack)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment