Skip to content

Commit

Permalink
moving this up one level
Browse files Browse the repository at this point in the history
  • Loading branch information
bam241 committed Jan 10, 2025
1 parent 6675cef commit 19da17b
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 81 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project(DAGMC)
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.18)
enable_language(CXX)

# Set DAGMC version
Expand Down Expand Up @@ -44,7 +44,14 @@ if(BUILD_MCNP5 OR BUILD_MCNP6)
enable_language(Fortran)
endif()

find_package(MOAB REQUIRED)
# Dealing with MOAB
if (PULL_INSTALL_MOAB)
include(MOAB_PullAndMake)
moab_pull_make(${MOAB_VERSION}
else()
find_package(MOAB REQUIRED)
endif()

find_package(OpenMP)

dagmc_setup_flags()
Expand Down
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
25 changes: 25 additions & 0 deletions cmake/HDF5_macro.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
MACRO (find_set_HDF5)
# 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_directories(${HDF5_INCLUDE_DIRS})

ENDMACRO (find_set_HDF5)
136 changes: 95 additions & 41 deletions cmake/MOAB_PullAndMake.cmake
Original file line number Diff line number Diff line change
@@ -1,45 +1,99 @@
# this Macro sets up the download and build of MOAB using ExternalProject
# few tweak are done in src/dagmc/CMakeLists.txt and src/PyNE/CMakelists.txt
# This Macro sets up the download and build of MOAB using ExternalProject
# few tweak are done in src/dagmc/CMakeLists.txt and src/PyNE/CMakeists.txt
# to make sure that MOAB is built before DAGMC.
MACRO (moab_pull_make moab_version)
message(STATUS "MOAB will be downloaded and built")
include(ExternalProject)
message("HDF5_ROOT: ${HDF5_ROOT}")
set(MOAB_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/moab")
set(MOAB_ROOT "${CMAKE_BINARY_DIR}/moab")
set(MOAB_INCLUDE_DIRS "${MOAB_INSTALL_PREFIX}/include")
set(MOAB_LIBRARY_DIRS "${MOAB_INSTALL_PREFIX}/lib")
message("MOAB_LIBRARY_DIRS: ${MOAB_LIBRARY_DIRS}")
message("CMAKE_SHARED_LIBRARY_SUFFIX: ${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(MOAB_LIBRARIES_SHARED "")
ExternalProject_Add(MOAB_ep
PREFIX ${MOAB_ROOT}
GIT_REPOSITORY https://bitbucket.org/fathomteam/moab.git
GIT_TAG ${moab_version}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DBUILD_SHARED_LIBS:BOOL=ON
-DENABLE_HDF5:BOOL=ON
-DHDF5_ROOT:PATH=${HDF5_ROOT}
-DCMAKE_INSTALL_RPATH=${HDF5_ROOT}/lib:${MOAB_INSTALL_PREFIX}/lib
-DENABLE_BLASLAPACK:BOOL=OFF
-DENABLE_FORTRAN:BOOL=OFF
-DENABLE_PYMOAB:BOOL=OFF
DOWNLOAD_EXTRACT_TIMESTAMP true
BUILD_BYPRODUCTS "${MOAB_LIBRARY_DIRS}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
INSTALL_DIR "${MOAB_INSTALL_PREFIX}"
)
# Setup a interface library for MOAB based on ExternalProoject MOAB_EP
add_library(MOAB INTERFACE)

target_include_directories(MOAB SYSTEM INTERFACE ${MOAB_INCLUDE_DIRS})
target_link_libraries(MOAB INTERFACE ${MOAB_LIBRARY_DIRS}/libMOAB${CMAKE_SHARED_LIBRARY_SUFFIX})
add_dependencies(MOAB MOAB_ep)
install(TARGETS MOAB LIBRARY DESTINATION ${MOAB_LIBRARY_DIRS}
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})
MESSAGE(STATUS "MOAB will be downloaded and built")

# Ensure STATIC LIBS Build
IF(DAGMC_BUILD_STATIC_LIBS)
MESSAGE(FATAL_ERROR "PULL_INSTALL_MOAB is ONLY compatible with shared libraries.")
endIF()

# Ensure MOAB_VERSION
IF(NOT MOAB_VERSION)
SET(MOAB_VERSION "5.5.1")
endIF()

# Ensure we have the right variables to build MOAB
moab_autobuild_check_deps()


INCLUDE(ExternalProject)
MESSAGE("HDF5_ROOT: ${HDF5_ROOT}")
SET(MOAB_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/moab")
SET(MOAB_ROOT "${CMAKE_BINARY_DIR}/moab")
SET(MOAB_INCLUDE_DIRS "${MOAB_INSTALL_PREFIX}/INCLUDE")
SET(MOAB_LIBRARY_DIRS "${MOAB_INSTALL_PREFIX}/lib")
MESSAGE("MOAB_LIBRARY_DIRS: ${MOAB_LIBRARY_DIRS}")
MESSAGE("CMAKE_SHARED_LIBRARY_SUFFIX: ${CMAKE_SHARED_LIBRARY_SUFFIX}")
SET(MOAB_LIBRARIES_SHARED "")
ExternalProject_Add(MOAB_ep
PREFIX ${MOAB_ROOT}
GIT_REPOSITORY https://bitbucket.org/fathomteam/moab.git
GIT_TAG ${moab_version}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DBUILD_SHARED_LIBS:BOOL=ON
-DENABLE_HDF5:BOOL=ON
-DHDF5_ROOT:PATH=${HDF5_ROOT}
-DCMAKE_INSTALL_RPATH=${HDF5_ROOT}/lib:${MOAB_INSTALL_PREFIX}/lib
-DENABLE_BLASLAPACK:BOOL=OFF
-DENABLE_FORTRAN:BOOL=OFF
-DENABLE_PYMOAB:BOOL=OFF
${OPTION_FLAG}
DOWNLOAD_EXTRACT_TIMESTAMP true
BUILD_BYPRODUCTS "${MOAB_LIBRARY_DIRS}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
INSTALL_DIR "${MOAB_INSTALL_PREFIX}"
)
# SETup a interface library for MOAB based on ExternalProoject MOAB_EP
ADD_LIBRARY(MOAB INTERFACE)

TARGET_INCLUDE_DIRECTORIES(MOAB SYSTEM INTERFACE ${MOAB_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(MOAB INTERFACE ${MOAB_LIBRARY_DIRS}/libMOAB${CMAKE_SHARED_LIBRARY_SUFFIX})
ADD_DEPENDENCIES(MOAB MOAB_ep)
INSTALL(TARGETS MOAB LIBRARY DESTINATION ${MOAB_LIBRARY_DIRS}
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 HDF5
INCLUDE(HDF5_macro)
find_SET_HDF5()

SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
FIND_LIBRARY(MOAB_LIBRARIES_SHARED
NAMES MOAB
HINTS ${MOAB_LIBRARY_DIRS}
NO_DEFAULT_PATH
)
LIST(APPEND MOAB_LIBRARIES_SHARED)
MESSAGE(STATUS "MOAB_INCLUDE_DIRS: ${MOAB_INCLUDE_DIRS}")
MESSAGE(STATUS "MOAB_LIBRARY_DIRS: ${MOAB_LIBRARY_DIRS}")
MESSAGE(STATUS "MOAB_LIBRARIES_SHARED: ${MOAB_LIBRARIES_SHARED}")

INCLUDE_DIRECTORIES(${MOAB_INCLUDE_DIRS})
IF (MOAB_INCLUDE_DIRS AND (MOAB_LIBRARIES_SHARED))
MESSAGE(STATUS "MOAB Will be installed.")
ELSE ()
MESSAGE(FATAL_ERROR "Could not set MOAB for installation and compilation.")
ENDIF ()

ENDMACRO(moab_pull_make)


MACRO (moab_autobuild_check_deps)
# First check IF we are forcing the download of MOAB
IF (PULL_INSTALL_MOAB)
IF (NOT DEFINED HDF5_ROOT or not DEFINED ${HDF5_ROOT})
MESSAGE(FATAL_ERROR "HDF5_ROOT is required to build MOAB")
ENDIF()

IF (DEFINED ${EIGEN3_DIR})
OPTION_FLAG = "-DEIGEN3_DIR=${EIGEN3_DIR}"
ENDIF()

ENDIF ()

ENDMACRO (moab_autobuild_check_deps)

0 comments on commit 19da17b

Please sign in to comment.