Skip to content

Commit

Permalink
revamping find_MOAB
Browse files Browse the repository at this point in the history
  • Loading branch information
bam241 committed Jan 10, 2025
1 parent 9d4ccc0 commit 445aab9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 42 deletions.
43 changes: 5 additions & 38 deletions cmake/FindMOAB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,18 @@ find_path(MOAB_CMAKE_CONFIG
PATHS ${MOAB_SEARCH_DIRS}
NO_DEFAULT_PATH
)

# First check if we are forcing the download of MOAB
if (PULL_INSTALL_MOAB)
if(DAGMC_BUILD_STATIC_LIBS)
message(FATAL_ERROR "PULL_INSTALL_MOAB is ONLY compatible with shared libraries.")
endif()
if(NOT MOAB_VERSION)
set(MOAB_VERSION "5.5.1")
endif()
include(MOAB_PullAndMake)
moab_pull_make(${MOAB_VERSION})

# Back to normal behavior
elseif (MOAB_CMAKE_CONFIG)
if (MOAB_CMAKE_CONFIG)
set(MOAB_CMAKE_CONFIG ${MOAB_CMAKE_CONFIG}/MOABConfig.cmake)
include(${MOAB_CMAKE_CONFIG})
message(STATUS "MOAB_CMAKE_CONFIG: ${MOAB_CMAKE_CONFIG}")
else ()
message(FATAL_ERROR "Could not find MOAB. Set -DMOAB_DIR=<MOAB_DIR> when running cmake or use the $MOAB_DIR environment variable.")
endif ()

# Find HDF5
set(ENV{PATH} "${HDF5_DIR}:$ENV{PATH}")
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
find_package(HDF5 REQUIRED)
# Remove HDF5 transitive dependencies that are system libraries
list(FILTER HDF5_LIBRARIES EXCLUDE REGEX ".*lib(pthread|dl|m).*")
set(HDF5_LIBRARIES_SHARED ${HDF5_LIBRARIES})
# CMake doesn't let you find_package(HDF5) twice so we have to do this instead
if (BUILD_STATIC_LIBS)
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX}
HDF5_LIBRARIES_STATIC "${HDF5_LIBRARIES_SHARED}")
endif ()
if (NOT BUILD_SHARED_LIBS)
set(HDF5_LIBRARIES_SHARED)
endif ()
set(HDF5_LIBRARIES)

message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}")
message(STATUS "HDF5_LIBRARIES_SHARED: ${HDF5_LIBRARIES_SHARED}")
message(STATUS "HDF5_LIBRARIES_STATIC: ${HDF5_LIBRARIES_STATIC}")
include(${MOAB_CMAKE_CONFIG})
include(HDF5_macro)
find_set_HDF5()

include_directories(${HDF5_INCLUDE_DIRS})
if(MSVC)
set(BUILD_STATIC_LIBS TRUE)
set(BUILD_SHARED_LIBS OFF)
Expand Down Expand Up @@ -84,9 +53,7 @@ message(STATUS "MOAB_LIBRARY_DIRS: ${MOAB_LIBRARY_DIRS}")
message(STATUS "MOAB_LIBRARIES_SHARED: ${MOAB_LIBRARIES_SHARED}")
message(STATUS "MOAB_LIBRARIES_STATIC: ${MOAB_LIBRARIES_STATIC}")

if(PULL_INSTALL_MOAB)
message(STATUS "MOAB will be downloaded and built at make time")
elseif (MOAB_INCLUDE_DIRS AND (MOAB_LIBRARIES_SHARED OR NOT BUILD_SHARED_LIBS) AND
if (MOAB_INCLUDE_DIRS AND (MOAB_LIBRARIES_SHARED OR NOT BUILD_SHARED_LIBS) AND
(MOAB_LIBRARIES_STATIC OR NOT BUILD_STATIC_LIBS))
message(STATUS "Found MOAB")
else ()
Expand Down
7 changes: 3 additions & 4 deletions cmake/MOAB_PullAndMake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ MACRO (moab_pull_make)
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${MOAB_INCLUDE_DIRS})
LINK_DIRECTORIES(${MOAB_LIBRARY_DIRS})
FIND_PACKAGE(Eigen3 REQUIRED NO_MODULE)
INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIRS})

# FIND_PACKAGE(Eigen3 REQUIRED NO_MODULE)
# INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIRS})

# Find HDF5
INCLUDE(HDF5_macro)
Expand All @@ -73,8 +74,6 @@ MACRO (moab_pull_make)
MESSAGE(STATUS "MOAB_LIBRARY_DIRS: ${MOAB_LIBRARY_DIRS}")
MESSAGE(STATUS "MOAB_LIBRARIES_SHARED: ${MOAB_LIBRARIES_SHARED}")

INCLUDE_DIRECTORIES(${MOAB_INCLUDE_DIRS})

ENDMACRO(moab_pull_make)


Expand Down

0 comments on commit 445aab9

Please sign in to comment.