From 2e12ef9b3bf4096384b0a920192d8d9afba15bb1 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Thu, 15 May 2014 20:06:30 +0000 Subject: [PATCH] CMake: Port MPI, BZIP2 and ZLIB to new find mechanism git-svn-id: https://svn.dealii.org/trunk@32911 0785d39b-7218-0410-832d-ea1e28bc413d --- .../cmake/configure/configure_1_bzip2.cmake | 14 -- deal.II/cmake/configure/configure_1_mpi.cmake | 141 --------------- .../cmake/configure/configure_1_zlib.cmake | 7 +- .../macros/macro_deal_ii_package_handle.cmake | 6 +- deal.II/cmake/modules/FindBZIP2.cmake | 46 +++++ deal.II/cmake/modules/FindMPI.cmake | 163 ++++++++++++++++++ deal.II/cmake/modules/FindZLIB.cmake | 51 ++++++ 7 files changed, 264 insertions(+), 164 deletions(-) create mode 100644 deal.II/cmake/modules/FindBZIP2.cmake create mode 100644 deal.II/cmake/modules/FindMPI.cmake create mode 100644 deal.II/cmake/modules/FindZLIB.cmake diff --git a/deal.II/cmake/configure/configure_1_bzip2.cmake b/deal.II/cmake/configure/configure_1_bzip2.cmake index 37a0f81305..42f3915ea9 100644 --- a/deal.II/cmake/configure/configure_1_bzip2.cmake +++ b/deal.II/cmake/configure/configure_1_bzip2.cmake @@ -18,18 +18,4 @@ # Configuration for the bzip2 library: # -MACRO(FEATURE_BZIP2_FIND_EXTERNAL var) - FIND_PACKAGE(BZip2) - - IF(BZIP2_FOUND) - # - # Rename variables: - # - SET(BZIP2_VERSION ${BZIP2_VERSION_STRING}) - SET(BZIP2_INCLUDE_DIRS ${BZIP2_INCLUDE_DIR}) - - SET(${var} TRUE) - ENDIF() -ENDMACRO() - CONFIGURE_FEATURE(BZIP2) diff --git a/deal.II/cmake/configure/configure_1_mpi.cmake b/deal.II/cmake/configure/configure_1_mpi.cmake index 1fd25d1bf0..8001da4318 100644 --- a/deal.II/cmake/configure/configure_1_mpi.cmake +++ b/deal.II/cmake/configure/configure_1_mpi.cmake @@ -17,141 +17,6 @@ # # Configuration for mpi support: # -# We look for the C and Fortran libraries as well because they are needed -# by some external libraries for the link interface: -# - -MACRO(FEATURE_MPI_FIND_EXTERNAL var) - # - # Obey a manual user override: If MPI_CXX_FOUND is set to true in the - # cache, we skip the FIND_PACKAGE calls: - # - IF(MPI_CXX_FOUND) - SET(MPI_FOUND TRUE) - ENDIF() - - # - # If CMAKE_CXX_COMPILER is already an MPI wrapper, use it to determine - # the mpi implementation. If MPI_CXX_COMPILER is defined use the value - # directly. - # - SET_IF_EMPTY(MPI_CXX_COMPILER ${CMAKE_CXX_COMPILER}) - IF(CMAKE_C_COMPILER_WORKS) - SET_IF_EMPTY(MPI_C_COMPILER ${CMAKE_C_COMPILER}) # for good measure - ELSE() - MESSAGE(STATUS - "No suitable C compiler was found! MPI C interface can not be " - "autodetected" - ) - ENDIF() - IF(CMAKE_Fortran_COMPILER_WORKS) - SET_IF_EMPTY(MPI_Fortran_COMPILER ${CMAKE_Fortran_COMPILER}) # for good measure - ELSE() - MESSAGE(STATUS - "No suitable Fortran compiler was found! MPI Fortran interface can " - "not be autodetected" - ) - ENDIF() - - FIND_PACKAGE(MPI) - - IF(NOT MPI_CXX_FOUND AND DEAL_II_WITH_MPI) - # - # CMAKE_CXX_COMPILER is apparently not an mpi wrapper. - # So, let's be a bit more aggressive in finding MPI (and if - # DEAL_II_WITH_MPI is set). - # - MESSAGE(STATUS - "MPI not found but DEAL_II_WITH_MPI is set to TRUE." - " Try again with more aggressive search paths:" - ) - SET(MPI_FOUND) # clear this value so that FIND_PACKAGE runs again. - UNSET(MPI_CXX_COMPILER CACHE) - UNSET(MPI_C_COMPILER CACHE) - UNSET(MPI_Fortran_COMPILER CACHE) - FIND_PACKAGE(MPI) - ENDIF() - - # - # Manually clean up variables: - # - FOREACH(_lang C CXX Fortran) - IF(MPI_${_lang}_LIBRARIES MATCHES "-NOTFOUND") - SET(MPI_${_lang}_LIBRARIES) - ENDIF() - ENDFOREACH() - - IF(MPI_CXX_FOUND) - # - # Manually assemble some version information: - # - FIND_FILE(MPI_MPI_H NAMES mpi.h - HINTS ${MPI_INCLUDE_PATH} - ) - - IF(NOT MPI_MPI_H MATCHES "-NOTFOUND" AND NOT DEFINED MPI_VERSION) - FILE(STRINGS "${MPI_MPI_H}" MPI_VERSION_MAJOR_STRING - REGEX "#define.*MPI_VERSION") - STRING(REGEX REPLACE "^.*MPI_VERSION.*([0-9]+).*" "\\1" - MPI_VERSION_MAJOR "${MPI_VERSION_MAJOR_STRING}" - ) - FILE(STRINGS ${MPI_MPI_H} MPI_VERSION_MINOR_STRING - REGEX "#define.*MPI_SUBVERSION") - STRING(REGEX REPLACE "^.*MPI_SUBVERSION.*([0-9]+).*" "\\1" - MPI_VERSION_MINOR "${MPI_VERSION_MINOR_STRING}" - ) - SET(MPI_VERSION "${MPI_VERSION_MAJOR}.${MPI_VERSION_MINOR}") - IF("${MPI_VERSION}" STREQUAL ".") - SET(MPI_VERSION) - SET(MPI_VERSION_MAJOR) - SET(MPI_VERSION_MINOR) - ENDIF() - - # OMPI specific version number: - FILE(STRINGS ${MPI_MPI_H} OMPI_VERSION_MAJOR_STRING - REGEX "#define.*OMPI_MAJOR_VERSION") - STRING(REGEX REPLACE "^.*OMPI_MAJOR_VERSION.*([0-9]+).*" "\\1" - OMPI_VERSION_MAJOR "${OMPI_VERSION_MAJOR_STRING}" - ) - FILE(STRINGS ${MPI_MPI_H} OMPI_VERSION_MINOR_STRING - REGEX "#define.*OMPI_MINOR_VERSION") - STRING(REGEX REPLACE "^.*OMPI_MINOR_VERSION.*([0-9]+).*" "\\1" - OMPI_VERSION_MINOR "${OMPI_VERSION_MINOR_STRING}" - ) - FILE(STRINGS ${MPI_MPI_H} OMPI_VERSION_RELEASE_STRING - REGEX "#define.*OMPI_RELEASE_VERSION") - STRING(REGEX REPLACE "^.*OMPI_RELEASE_VERSION.*([0-9]+).*" "\\1" - OMPI_VERSION_SUBMINOR "${OMPI_VERSION_RELEASE_STRING}" - ) - SET(OMPI_VERSION - "${OMPI_VERSION_MAJOR}.${OMPI_VERSION_MINOR}.${OMPI_VERSION_SUBMINOR}" - ) - IF("${OMPI_VERSION}" STREQUAL "..") - SET(OMPI_VERSION) - SET(OMPI_VERSION_MAJOR) - SET(OMPI_VERSION_MINOR) - SET(OMPI_VERSION_SUBMINOR) - ENDIF() - ENDIF() - - SET(${var} TRUE) - ENDIF() - - # Hide some variables: - MARK_AS_ADVANCED(MPI_EXTRA_LIBRARY MPI_LIBRARY MPI_MPI_H) - - # - # Populate correct variables: - # - SET(MPI_LIBRARIES - ${MPI_CXX_LIBRARIES} ${MPI_Fortran_LIBRARIES} ${MPI_C_LIBRARIES} - ) - SET(MPI_INCLUDE_DIRS ${MPI_CXX_INCLUDE_PATH}) - SET(MPI_CXX_FLAGS ${MPI_CXX_COMPILE_FLAGS}) - SET(MPI_LINKER_FLAGS "${MPI_CXX_LINK_FLAGS}") - -ENDMACRO() - MACRO(FEATURE_MPI_ERROR_MESSAGE) MESSAGE(FATAL_ERROR "\n" @@ -169,10 +34,4 @@ MACRO(FEATURE_MPI_ERROR_MESSAGE) ) ENDMACRO() - CONFIGURE_FEATURE(MPI) - -# -# The user has to know the location of the mpi headers as well: -# -SET(MPI_USER_INCLUDE_DIRS ${MPI_INCLUDE_DIRS}) diff --git a/deal.II/cmake/configure/configure_1_zlib.cmake b/deal.II/cmake/configure/configure_1_zlib.cmake index 772f66acbc..5058a7195c 100644 --- a/deal.II/cmake/configure/configure_1_zlib.cmake +++ b/deal.II/cmake/configure/configure_1_zlib.cmake @@ -1,7 +1,7 @@ ## --------------------------------------------------------------------- ## $Id$ ## -## Copyright (C) 2012 - 2013 by the deal.II authors +## Copyright (C) 2012 - 2014 by the deal.II authors ## ## This file is part of the deal.II library. ## @@ -19,8 +19,3 @@ # CONFIGURE_FEATURE(ZLIB) - -# Export ZLIB_VERSION: -IF(DEFINED ZLIB_VERSION_STRING) - SET(ZLIB_VERSION ${ZLIB_VERSION_STRING}) -ENDIF() diff --git a/deal.II/cmake/macros/macro_deal_ii_package_handle.cmake b/deal.II/cmake/macros/macro_deal_ii_package_handle.cmake index 8fa5e6142d..f0deef241d 100644 --- a/deal.II/cmake/macros/macro_deal_ii_package_handle.cmake +++ b/deal.II/cmake/macros/macro_deal_ii_package_handle.cmake @@ -104,11 +104,11 @@ MACRO(DEAL_II_PACKAGE_HANDLE _feature _var) LIST(APPEND _clear ${_arg}) ENDIF() ELSE() - IF(NOT DEFINED ${_arg} OR ${_arg} MATCHES "-NOTFOUND") + IF("${_arg}" STREQUAL "" OR ${_arg} MATCHES "-NOTFOUND") IF(_required AND _fine) - IF(NOT DEFINED ${_arg}) + IF("${_arg}" STREQUAL "") MESSAGE(STATUS - " ${_feature}_${_variable}: *** Required variable \"${_arg}\" undefined ***" + " ${_feature}_${_variable}: *** Required variable \"${_arg}\" empty ***" ) ELSE() MESSAGE(STATUS diff --git a/deal.II/cmake/modules/FindBZIP2.cmake b/deal.II/cmake/modules/FindBZIP2.cmake new file mode 100644 index 0000000000..e6f7cbded2 --- /dev/null +++ b/deal.II/cmake/modules/FindBZIP2.cmake @@ -0,0 +1,46 @@ +## --------------------------------------------------------------------- +## $Id$ +## +## Copyright (C) 2014 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# Try to find the BZIP2 library +# +# This module exports +# +# BZIP2_LIBRARIES +# BZIP2_INCLUDE_DIRS +# BZIP2_VERSION +# + +# +# Houston, we have a problem: CMake ships its own FindBZip2.cmake module. +# Unfortunately we want to call DEAL_II_PACKAGE_HANDLE. Therefore, use the +# original find module and do a dummy call to DEAL_II_PACKAGE_HANDLE: +# + +LIST(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/) +FIND_PACKAGE(BZip2) +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/) + +SET(BZIP2_VERSION ${BZIP2_VERSION_STRING}) +SET(_bzip2_libraries ${BZIP2_LIBRARIES}) + +DEAL_II_PACKAGE_HANDLE(BZIP2 + LIBRARIES REQUIRED _bzip2_libraries + INCLUDE_DIRS REQUIRED BZIP2_INCLUDE_DIR + CLEAR + BZIP2_INCLUDE_DIR BZIP2_LIBRARY_DEBUG BZIP2_LIBRARY_RELEASE + BZIP2_NEED_PREFIX + ) diff --git a/deal.II/cmake/modules/FindMPI.cmake b/deal.II/cmake/modules/FindMPI.cmake new file mode 100644 index 0000000000..111c75a58e --- /dev/null +++ b/deal.II/cmake/modules/FindMPI.cmake @@ -0,0 +1,163 @@ +## --------------------------------------------------------------------- +## $Id$ +## +## Copyright (C) 2012 - 2014 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# Find MPI +# +# This module exports: +# MPI_LIBRARIES +# MPI_INCLUDE_DIRS +# MPI_CXX_FLAGS +# MPI_LINKER_FLAGS +# MPI_VERSION +# OMPI_VERSION +# + +# +# Configuration for mpi support: +# +# We look for the C and Fortran libraries as well because they are needed +# by some external libraries for the link interface. +# + +IF(MPI_CXX_FOUND) + SET(MPI_FOUND TRUE) +ENDIF() + +# +# If CMAKE_CXX_COMPILER is already an MPI wrapper, use it to determine +# the mpi implementation. If MPI_CXX_COMPILER is defined use the value +# directly. +# +SET_IF_EMPTY(MPI_CXX_COMPILER ${CMAKE_CXX_COMPILER}) +IF(CMAKE_C_COMPILER_WORKS) + SET_IF_EMPTY(MPI_C_COMPILER ${CMAKE_C_COMPILER}) # for good measure +ELSE() + MESSAGE(STATUS + "No suitable C compiler was found! MPI C interface can not be " + "autodetected" + ) +ENDIF() +IF(CMAKE_Fortran_COMPILER_WORKS) + SET_IF_EMPTY(MPI_Fortran_COMPILER ${CMAKE_Fortran_COMPILER}) # for good measure +ELSE() + MESSAGE(STATUS + "No suitable Fortran compiler was found! MPI Fortran interface can " + "not be autodetected" + ) +ENDIF() + +# +# Call the system FindMPI.cmake module: +# +LIST(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/) +FIND_PACKAGE(MPI) + +IF(NOT MPI_CXX_FOUND AND DEAL_II_WITH_MPI) + # + # CMAKE_CXX_COMPILER is apparently not an mpi wrapper. + # So, let's be a bit more aggressive in finding MPI (and if + # DEAL_II_WITH_MPI is set). + # + MESSAGE(STATUS + "MPI not found but DEAL_II_WITH_MPI is set to TRUE." + " Try again with more aggressive search paths:" + ) + # Clear variables so that FIND_PACKAGE runs again: + SET(MPI_FOUND) + UNSET(MPI_CXX_COMPILER CACHE) + UNSET(MPI_C_COMPILER CACHE) + UNSET(MPI_Fortran_COMPILER CACHE) + FIND_PACKAGE(MPI) +ENDIF() +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/) + + +# +# Manually assemble some version information: +# + +DEAL_II_FIND_FILE(MPI_MPI_H + NAMES mpi.h + HINTS ${MPI_CXX_INCLUDE_PATH} ${MPI_C_INCLUDE_PATH} + ) +IF(NOT MPI_MPI_H MATCHES "-NOTFOUND" AND NOT DEFINED MPI_VERSION) + FILE(STRINGS "${MPI_MPI_H}" MPI_VERSION_MAJOR_STRING + REGEX "#define.*MPI_VERSION") + STRING(REGEX REPLACE "^.*MPI_VERSION.*([0-9]+).*" "\\1" + MPI_VERSION_MAJOR "${MPI_VERSION_MAJOR_STRING}" + ) + FILE(STRINGS ${MPI_MPI_H} MPI_VERSION_MINOR_STRING + REGEX "#define.*MPI_SUBVERSION") + STRING(REGEX REPLACE "^.*MPI_SUBVERSION.*([0-9]+).*" "\\1" + MPI_VERSION_MINOR "${MPI_VERSION_MINOR_STRING}" + ) + SET(MPI_VERSION "${MPI_VERSION_MAJOR}.${MPI_VERSION_MINOR}") + IF("${MPI_VERSION}" STREQUAL ".") + SET(MPI_VERSION) + SET(MPI_VERSION_MAJOR) + SET(MPI_VERSION_MINOR) + ENDIF() + + # OMPI specific version number: + FILE(STRINGS ${MPI_MPI_H} OMPI_VERSION_MAJOR_STRING + REGEX "#define.*OMPI_MAJOR_VERSION") + STRING(REGEX REPLACE "^.*OMPI_MAJOR_VERSION.*([0-9]+).*" "\\1" + OMPI_VERSION_MAJOR "${OMPI_VERSION_MAJOR_STRING}" + ) + FILE(STRINGS ${MPI_MPI_H} OMPI_VERSION_MINOR_STRING + REGEX "#define.*OMPI_MINOR_VERSION") + STRING(REGEX REPLACE "^.*OMPI_MINOR_VERSION.*([0-9]+).*" "\\1" + OMPI_VERSION_MINOR "${OMPI_VERSION_MINOR_STRING}" + ) + FILE(STRINGS ${MPI_MPI_H} OMPI_VERSION_RELEASE_STRING + REGEX "#define.*OMPI_RELEASE_VERSION") + STRING(REGEX REPLACE "^.*OMPI_RELEASE_VERSION.*([0-9]+).*" "\\1" + OMPI_VERSION_SUBMINOR "${OMPI_VERSION_RELEASE_STRING}" + ) + SET(OMPI_VERSION + "${OMPI_VERSION_MAJOR}.${OMPI_VERSION_MINOR}.${OMPI_VERSION_SUBMINOR}" + ) + IF("${OMPI_VERSION}" STREQUAL "..") + SET(OMPI_VERSION) + SET(OMPI_VERSION_MAJOR) + SET(OMPI_VERSION_MINOR) + SET(OMPI_VERSION_SUBMINOR) + ENDIF() +ENDIF() + +DEAL_II_PACKAGE_HANDLE(MPI + LIBRARIES + REQUIRED MPI_CXX_LIBRARIES + OPTIONAL MPI_Fortran_LIBRARIES MPI_C_LIBRARIES + INCLUDE_DIRS + REQUIRED MPI_CXX_INCLUDE_PATH + OPTIONAL MPI_C_INCLUDE_PATH + USER_INCLUDE_DIRS + REQUIRED MPI_CXX_INCLUDE_PATH + OPTIONAL MPI_C_INCLUDE_PATH + CXX_FLAGS OPTIONAL MPI_CXX_COMPILE_FLAGS + LINKER_FLAGS OPTIONAL MPI_CXX_LINK_FLAGS + CLEAR + MPI_MPI_H + MPI_HEADER_PATH + MPI_LIB + MPIEXEC + MPI_CXX_COMPILER + MPI_C_COMPILER + MPI_Fortran_COMPILER + ) + diff --git a/deal.II/cmake/modules/FindZLIB.cmake b/deal.II/cmake/modules/FindZLIB.cmake new file mode 100644 index 0000000000..d9022891b8 --- /dev/null +++ b/deal.II/cmake/modules/FindZLIB.cmake @@ -0,0 +1,51 @@ +## --------------------------------------------------------------------- +## $Id$ +## +## Copyright (C) 2014 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# Try to find the ZLIB library +# +# This module exports +# +# ZLIB_LIBRARIES +# ZLIB_INCLUDE_DIRS +# ZLIB_VERSION +# + +SET(ZLIB_DIR "" CACHE PATH "An optional hint to a ZLIB installation") +SET_IF_EMPTY(ZLIB_DIR "$ENV{ZLIB_DIR}") + +# +# Houston, we have a problem: CMake ships its own FindZLIB.cmake module. +# Unfortunately we want to call DEAL_II_PACKAGE_HANDLE. Therefore, use the +# original find module and do a dummy call to DEAL_II_PACKAGE_HANDLE: +# + +IF(NOT "${ZLIB_DIR}" STREQUAL "") + SET(ZLIB_ROOT ${ZLIB_DIR}) +ENDIF() +LIST(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/) +FIND_PACKAGE(ZLIB) +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/) + +SET(ZLIB_VERSION ${ZLIB_VERSION_STRING}) +SET(_zlib_libraries ${ZLIB_LIBRARIES}) +SET(_zlib_include_dirs ${ZLIB_INCLUDE_DIRS}) + +DEAL_II_PACKAGE_HANDLE(ZLIB + LIBRARIES REQUIRED _zlib_libraries + INCLUDE_DIRS REQUIRED _zlib_include_dirs + CLEAR ZLIB_INCLUDE_DIR ZLIB_LIBRARY + ) -- 2.39.5