From dccf48d3f48f2ffd09f4d1ffa154addcf074a080 Mon Sep 17 00:00:00 2001 From: Stian Skjelstad Date: Fri, 21 Dec 2018 02:27:05 +0100 Subject: [PATCH] On my Ubuntu setup, compilation failes when using med.h, since libmedc is built with openMPI, while freeCAD selects hdf5-serial. libmed declares functions prototypes which has MPI parameters if built for openMPI, causing compilation errors. Doing some online searches reveals that some users manually changes the include-paths to hdf5-openmpi if this error happens. This patch tries to autodetect this situation. --- CMakeLists.txt | 12 ++++++++++-- cMake/FindMEDFile.cmake | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44781c3fcc..7743128eaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -703,12 +703,21 @@ endif() list(REMOVE_ITEM VTK_LIBRARIES "optimized" "debug") if(NOT FREECAD_USE_EXTERNAL_SMESH) + find_package(MEDFile REQUIRED) # See https://www.hdfgroup.org/HDF5/release/cmakebuild.html if (WIN32) find_package(HDF5 COMPONENTS NO_MODULE REQUIRED static) else() find_package(PkgConfig) - pkg_search_module(HDF5 hdf5-serial) + FILE(READ ${meddotH} TMPTXT) + STRING(FIND "${TMPTXT}" "#define MED_HAVE_MPI" matchres) + if(${matchres} EQUAL -1) + message(STATUS "We guess that libmed was built using hdf5-serial version") + pkg_search_module(HDF5 hdf5-serial) + else() + message(STATUS "We guess that libmed was built using hdf5-openmpi version") + pkg_search_module(HDF5 hdf5-openmpi) + endif() if(NOT HDF5_FOUND) find_package(HDF5 REQUIRED) else() @@ -735,7 +744,6 @@ endif() message( WARNING "mpi.h was not found. Check for error above.") endif() endif() - find_package(MEDFile REQUIRED) set(SMESH_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/3rdParty/salomesmesh/inc) else(NOT FREECAD_USE_EXTERNAL_SMESH) diff --git a/cMake/FindMEDFile.cmake b/cMake/FindMEDFile.cmake index 1aeaea4eb4..db550b2e65 100644 --- a/cMake/FindMEDFile.cmake +++ b/cMake/FindMEDFile.cmake @@ -41,6 +41,10 @@ IF(MEDFILE_ROOT_DIR) ENDIF(MEDFILE_ROOT_DIR) FIND_PATH(MEDFILE_INCLUDE_DIRS med.h PATH_SUFFIXES med) +find_file(meddotH med.h PATHS ${MEDFILE_INCLUDE_DIRS} NO_DEFAULT_PATH) +if(NOT meddotH) + message( FATAL_ERROR "med.h not found in an error message above.") +endif() #FIND_PROGRAM(MDUMP mdump) FIND_LIBRARY(MEDFILE_C_LIBRARIES NAMES medC) FIND_LIBRARY(MEDFILE_F_LIBRARIES NAMES med)