Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic download and build of MOAB #969

Merged
merged 33 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3e50508
first attempt to auto-install MOAB
bam241 Dec 3, 2024
61b67f7
Update cmake/FindMOAB.cmake
bam241 Dec 5, 2024
5a1d673
Update cmake/FindMOAB.cmake
bam241 Dec 5, 2024
4d68614
reformating + changelog + tests
bam241 Dec 6, 2024
0939975
add missing indent
bam241 Dec 6, 2024
d3a417e
generalyze shared lib extention
bam241 Dec 6, 2024
ac418e0
temporary change to master
bam241 Dec 6, 2024
22aaf91
back to 5.5.1
bam241 Dec 6, 2024
9f96331
adding DDL_INSTALL_DEPS as an option with default to OFF
bam241 Dec 12, 2024
27ce0d9
keeping jon changes
bam241 Dec 12, 2024
4bee370
trying MOAB master
bam241 Dec 12, 2024
53d3065
reverting to 5.5.1 as default version for MOAB
bam241 Dec 12, 2024
d808d08
cleaning variable name
bam241 Dec 12, 2024
8d3f466
moving this up one level
bam241 Jan 10, 2025
cb7ed61
missing a )
bam241 Jan 10, 2025
11853a2
cmake likes set to define variables
bam241 Jan 10, 2025
306b751
no need for MOAB_VERSION
bam241 Jan 10, 2025
87fbdd2
how about now ?
bam241 Jan 10, 2025
3a71b29
how about now ?
bam241 Jan 10, 2025
e97037e
no caps for include folder
bam241 Jan 10, 2025
9db848d
revamping find_MOAB
bam241 Jan 10, 2025
cff6cdc
adressing @gonuke comments
bam241 Jan 13, 2025
1d38753
removing unnecessary commented lines
bam241 Jan 23, 2025
af0e850
Adding and re-ordering cmake args for MOAB to match the Dockerfile one.
bam241 Jan 24, 2025
5667457
making PULL_INSTALL_MOAB a boolean with value, so it can be ON and OF…
bam241 Jan 24, 2025
4e71015
Update MOAB_PullAndMake.cmake
bam241 Jan 24, 2025
e022d74
Apply suggestions from code review
bam241 Feb 4, 2025
b070148
fixing MOAB version
bam241 Feb 4, 2025
814933e
fixing regex to only accept number shaped as X.Y.Z
bam241 Feb 4, 2025
383ddb2
english
bam241 Feb 4, 2025
4d22c95
some improvement
bam241 Feb 4, 2025
141bb0b
Update CMakeLists.txt
bam241 Feb 4, 2025
56e8c13
restoring indent
bam241 Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/linux_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
5.4.1,
5.5.1,
]
pull_install_moab : [
off,
]
geant4_version : [
10.7.4,
11.1.2
Expand All @@ -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-${{
Expand Down Expand Up @@ -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 \
Expand Down
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,22 @@ if(BUILD_MCNP5 OR BUILD_MCNP6)
enable_language(Fortran)
endif()

find_package(MOAB REQUIRED)
# Dealing with MOAB
if (PULL_INSTALL_MOAB)
set(MOAB_VERSION ${PULL_INSTALL_MOAB})

# Ensure MOAB_VERSION
if(NOT ${MOAB_VERSION} MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+")
MESSAGE("MOAB_VERSION: ${MOAB_VERSION} not recognized. Defaulting to 5.5.1")
set(MOAB_VERSION "5.5.1")
endif()
MESSAGE("MOAB_VERSION to be installed: ${MOAB_VERSION}")
include(MOAB_PullAndMake)
moab_pull_make(${MOAB_VERSION})
else()
find_package(MOAB REQUIRED)
endif()

find_package(OpenMP)

dagmc_setup_flags()
Expand Down
7 changes: 7 additions & 0 deletions cmake/DAGMC_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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, provide a MOAB TAG version" OFF)

if (BUILD_ALL)
set(BUILD_MCNP5 ON)
set(BUILD_MCNP6 ON)
Expand Down Expand Up @@ -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)
target_link_libraries(${lib_name}-shared PUBLIC ${MOAB_LIBRARY_DIRS}/libMOAB${CMAKE_SHARED_LIBRARY_SUFFIX})
add_dependencies(${lib_name}-shared MOAB)
endif()
endif ()

if (BUILD_STATIC_LIBS)
Expand Down
24 changes: 4 additions & 20 deletions cmake/FindMOAB.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This leverages HDF5_macro.cmake in order to find HDF5 libraries.

message("")

# Find MOAB cmake config file
Expand All @@ -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)
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)
95 changes: 95 additions & 0 deletions cmake/MOAB_PullAndMake.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# 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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems MOAB is going to be installed in a custom path, which means only DAGMC will have access to it, as it will use the rpath. This is a good approach, and we can apply the same strategy for HDF5 as well. However, I think we can use the same CMAKE_INSTALL_PREFIX for both DAGMC and MOAB instead of CMAKE_INSTALL_PREFIX}/moab, as there are no conflicts having the same file name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did put the MOAB installation there, because I though about scenarii where users would already have MOAB installed on it computer but would try an installation of DAGMC against a different version of MOAB.
To avoid conflict, I rather have MOAB installed in the DAGMC install dir, as it is installed through DAGMC.
Also if one would come to uninstall DAGMC by removing the install dir, it would make sense to remove MOAB at the same time.

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}")
MESSAGE("MOAB_Version: ${MOAB_Version}")
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>
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DENABLE_HDF5:BOOL=ON
-DHDF5_ROOT:PATH=${HDF5_ROOT}
-DCMAKE_INSTALL_RPATH=${HDF5_ROOT}/lib:${MOAB_INSTALL_PREFIX}/lib
-DENABLE_BLASLAPACK:BOOL=OFF
-DBUILD_SHARED_LIBS:BOOL=ON
-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})
SET_SOURCE_FILES_PROPERTIES(
${MOAB_LIBRARY_DIRS}/libMOAB${CMAKE_SHARED_LIBRARY_SUFFIX} PROPERTIES
EXTERNAL_OBJECT TRUE # Identifies this as an object file
GENERATED TRUE # Avoids need for file to exist at configure-time
)
INCLUDE_DIRECTORIES(${MOAB_INCLUDE_DIRS})
LINK_DIRECTORIES(${MOAB_LIBRARY_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}")
ELSE()
FIND_PACKAGE(Eigen3 REQUIRED NO_MODULE)
INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIRS})
ENDIF()

ENDIF ()

ENDMACRO (moab_autobuild_check_deps)
3 changes: 3 additions & 0 deletions doc/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Next version
**Changed:**
* Update formating of few files to comply with clang-format (#937)

**Added:**
* Allow download & build of MOAB from cmake at build time (#969)

v3.2.4
====================

Expand Down
5 changes: 5 additions & 0 deletions doc/install/cmake_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ Note that unless set, all boolean options default to ``OFF``.
* ``-DBUILD_PIC=ON`` Build with position-independent code. (Default: OFF)

* ``-DBUILD_RPATH=ON`` Build with RPATH functionality. (Default: ON)

* ``-DPULL_INSTALL_MOAB=MOAB_version`` Enables automatic downloading of MOAB
dependency, provide a MOAB TAG version, (default: OFF). When using this
option, it is required to provide the path to HDF5 location, using
``-DHDF5_ROOT``.
11 changes: 11 additions & 0 deletions doc/install/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ To build moab using the default packages:
$ make check
$ make install

If you whish to avoid building MOAB from source, it is possible to build it at
the same time as DAGMC by setting the ``PULL_INSTALL_MOAB`` option to the
desired MOAB version. This will automatically download and build MOAB as a
dependency of DAGMC. When using this option it is assumed that HDF5 is properly
installed on your computer and you will need to provide its location for the
MOAB installation. For example, to build MOAB version 5.5.1, you would add the
following flag to the cmake command when building DAGMC:
::

$ cmake ../dagmc -DPULL_INSTALL_MOAB=5.5.1 -DHDF5_ROOT=PATH_TO_HDF5

Making sure the dependencies were installed correctly
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 5 additions & 0 deletions src/mcnp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down