diff --git a/.github/workflows/linux_build_test.yml b/.github/workflows/linux_build_test.yml index 2aaf9ec29..ca90b76ff 100644 --- a/.github/workflows/linux_build_test.yml +++ b/.github/workflows/linux_build_test.yml @@ -50,6 +50,9 @@ jobs: 5.4.1, 5.5.1, ] + pull_install_moab : [ + off, + ] geant4_version : [ 10.7.4, 11.1.2 @@ -58,6 +61,14 @@ jobs: off, v1.1.0, ] + include: + - ubuntu_version: 22.04 + compiler: gcc + hdf5_version: 1.14.3 + moab_version: 5.4.1 + pull_install_moab: on + geant4_version: off + double_down_version: off container: image: ghcr.io/svalinn/dagmc-ci-ubuntu-${{ @@ -88,6 +99,7 @@ jobs: cmake ../ \ -DMOAB_DIR=${moab_install_dir} \ -DBUILD_GEANT4=$([ "${{ matrix.geant4_version }}" != "off" ] && echo "ON" || echo "OFF") \ + -DPULL_INSTALL_MOAB=$([ "${{ matrix.pull_install_moab }}" != "on" ] && echo "OFF" || echo "ON -DHDF5_ROOT=${hdf5_install_dir}") \ -DGEANT4_DIR=${geant4_install_dir} \ -DBUILD_CI_TESTS=ON \ -DBUILD_MW_REG_TESTS=OFF \ diff --git a/CMakeLists.txt b/CMakeLists.txt index cd6c24fcf..f4fe4c4f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,18 @@ if(BUILD_MCNP5 OR BUILD_MCNP6) enable_language(Fortran) endif() -find_package(MOAB REQUIRED) +# Dealing with MOAB +if (PULL_INSTALL_MOAB) + # Ensure MOAB_VERSION + if(NOT DEFINED MOAB_VERSION) + set(MOAB_VERSION "5.5.1") + endif() + include(MOAB_PullAndMake) + moab_pull_make(${MOAB_VERSION}) +else() + find_package(MOAB REQUIRED) +endif() + find_package(OpenMP) dagmc_setup_flags() diff --git a/cmake/DAGMC_macros.cmake b/cmake/DAGMC_macros.cmake index d5b2cd04e..bd34eb1e4 100644 --- a/cmake/DAGMC_macros.cmake +++ b/cmake/DAGMC_macros.cmake @@ -73,6 +73,8 @@ macro (dagmc_setup_options) option(DOUBLE_DOWN "Enable ray tracing with Embree via double down" OFF) + option(PULL_INSTALL_MOAB "Enable automatic downloading of MOAB dependency" OFF) + if (BUILD_ALL) set(BUILD_MCNP5 ON) set(BUILD_MCNP6 ON) @@ -253,6 +255,11 @@ macro (dagmc_install_library lib_name) EXPORT DAGMCTargets LIBRARY DESTINATION ${INSTALL_LIB_DIR} PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR}) + # Required to ensure that MOAB is built before DAGMC and to properly link against MOAB + if(PULL_INSTALL_MOAB) + add_dependencies(${lib_name}-shared MOAB) + target_link_libraries(${lib_name}-shared PUBLIC ${MOAB_LIBRARY_DIRS}/libMOAB${CMAKE_SHARED_LIBRARY_SUFFIX}) + endif() endif () if (BUILD_STATIC_LIBS) diff --git a/cmake/FindMOAB.cmake b/cmake/FindMOAB.cmake index 92602c891..04a968f44 100644 --- a/cmake/FindMOAB.cmake +++ b/cmake/FindMOAB.cmake @@ -1,3 +1,5 @@ +# This leverage HDF5_macro.cmake in order to find HDF5 libraries. + message("") # Find MOAB cmake config file @@ -19,27 +21,9 @@ endif () # Find HDF5 include(${MOAB_CMAKE_CONFIG}) -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(HDF5_macro) +find_set_HDF5() -include_directories(${HDF5_INCLUDE_DIRS}) if(MSVC) set(BUILD_STATIC_LIBS TRUE) set(BUILD_SHARED_LIBS OFF) diff --git a/cmake/HDF5_macro.cmake b/cmake/HDF5_macro.cmake new file mode 100644 index 000000000..9f6f0849f --- /dev/null +++ b/cmake/HDF5_macro.cmake @@ -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) diff --git a/cmake/MOAB_PullAndMake.cmake b/cmake/MOAB_PullAndMake.cmake new file mode 100644 index 000000000..c6825a2e4 --- /dev/null +++ b/cmake/MOAB_PullAndMake.cmake @@ -0,0 +1,88 @@ +# 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") + + # Ensure STATIC LIBS Build + IF(DAGMC_BUILD_STATIC_LIBS) + MESSAGE(FATAL_ERROR "PULL_INSTALL_MOAB is ONLY compatible with shared libraries.") + 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= + -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}") + +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) + MESSAGE(FATAL_ERROR "HDF5_ROOT is required to build MOAB") + ENDIF() + + IF (DEFINED ${EIGEN3_DIR}) + SET(OPTION_FLAG "-DEIGEN3_DIR=${EIGEN3_DIR}") + ENDIF() + +ENDIF () + +ENDMACRO (moab_autobuild_check_deps) \ No newline at end of file diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 2480d32ef..0f288e580 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -7,6 +7,9 @@ DAGMC Changelog Next version ==================== +**Added:** + * Allow download from cmake and compilation at build time of MOAB (#969) + v3.2.4 ==================== diff --git a/src/mcnp/CMakeLists.txt b/src/mcnp/CMakeLists.txt index c4fe94750..118d1e958 100644 --- a/src/mcnp/CMakeLists.txt +++ b/src/mcnp/CMakeLists.txt @@ -18,6 +18,11 @@ add_library(mcnp_funcs OBJECT mcnp_funcs.cpp) message(STATUS "Building object library: meshtal_funcs") add_library(meshtal_funcs OBJECT meshtal_funcs.cpp) +if(PULL_INSTALL_MOAB) + add_dependencies(mcnp_funcs MOAB) + add_dependencies(meshtal_funcs MOAB) +endif() + if (BUILD_MCNP5) add_subdirectory(mcnp5) endif ()