Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 2 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project(DAGMC)
cmake_minimum_required(VERSION 3.18)
project(DAGMC)
enable_language(CXX)

# Set DAGMC version
Expand Down Expand Up @@ -45,20 +45,7 @@ if(BUILD_MCNP5 OR BUILD_MCNP6)
endif()

# 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()
include(ExternalProjects)

find_package(OpenMP)

Expand Down
48 changes: 42 additions & 6 deletions cmake/DAGMC_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ 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)
option(DOWNLOAD_HDF5 "Enable automatic downloading of HDF5 dependency" ON)
option(DOWNLOAD_MOAB "Enable automatic downloading of MOAB dependency" ON)
option(DOWNLOAD_EIGEN3 "Enable automatic downloading of Eigen3 dependency" ON)

if (BUILD_ALL)
set(BUILD_MCNP5 ON)
Expand Down Expand Up @@ -243,22 +245,21 @@ macro (dagmc_install_library lib_name)
INSTALL_RPATH_USE_LINK_PATH TRUE)

endif ()
list(APPEND LINK_LIBS_SHARED MOAB)
message(STATUS "LINK LIBS: ${LINK_LIBS_SHARED}")
target_link_libraries(${lib_name}-shared PUBLIC ${LINK_LIBS_SHARED})
if (DOUBLE_DOWN)
target_compile_definitions(${lib_name}-shared PRIVATE DOUBLE_DOWN)
target_link_libraries(${lib_name}-shared PUBLIC dd)
endif()
target_include_directories(${lib_name}-shared INTERFACE $<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>
${MOAB_INCLUDE_DIRS})
target_include_directories(${lib_name}-shared INTERFACE $<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>)
install(TARGETS ${lib_name}-shared
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)
if(DOWNLOAD_MOAB)
add_dependencies(${lib_name}-shared moab-project)
endif()
endif ()

Expand Down Expand Up @@ -361,3 +362,38 @@ macro (dagmc_install_test_file filename)
install(FILES ${filename} DESTINATION ${INSTALL_TESTS_DIR})
configure_file(${CMAKE_CURRENT_LIST_DIR}/${filename} ${CMAKE_CURRENT_BINARY_DIR}/${filename} COPYONLY)
endmacro ()

# Install dependent library via ExternalProject
macro(install_dependent_library _library _folder)
if(APPLE)
add_custom_target(fix-${_library} ALL
COMMAND find ${_folder} -type l -delete
COMMAND for lib_file in *${CMAKE_SHARED_LIBRARY_SUFFIX}* \; do
install_name_tool -add_rpath @loader_path "$$lib_file" \;
identifier_file=`otool -D "$$lib_file" | sed -n 's/.*\\///p'` \;
if [ "$$lib_file" != "$$identifier_file" ] \; then
mv "$$lib_file" "$$identifier_file" \;
fi \;
done
WORKING_DIRECTORY ${_folder}
DEPENDS dagmc-shared
)
elseif(UNIX)
add_custom_target(fix-${_library} ALL
COMMAND find ${_folder} -type l -delete
COMMAND for lib_file in *${CMAKE_SHARED_LIBRARY_SUFFIX}* \; do
patchelf --set-rpath '$$ORIGIN/' "$$lib_file" \;
identifier_file=`objdump -p "$$lib_file" | grep SONAME | awk '{print $$2}'` \;
if [ "$$lib_file" != "$$identifier_file" ] \; then
mv "$$lib_file" "$$identifier_file" \;
fi \;
done
WORKING_DIRECTORY ${_folder}
DEPENDS dagmc-shared
)
endif()
install(DIRECTORY ${_folder}/
DESTINATION ${INSTALL_LIB_DIR}
FILES_MATCHING PATTERN "*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
)
endmacro()
162 changes: 162 additions & 0 deletions cmake/ExternalProjects.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Include the ExternalProject module
# This module handles downloading and building external projects
include(ExternalProject)

############################################################
# Setup HDF5 #
############################################################

# If HDF5 is installed in a non-standard location, set HDF5_DIR
# to the cmake directory of the HDF5 installation.
# For example: export HDF5_DIR=/path/to/hdf5/cmake
# If HDF5 is not installed, set DOWNLOAD_HDF5 to ON.
# PyNE will download and build HDF5 if DOWNLOAD_HDF5 is ON.
if(NOT DOWNLOAD_HDF5)
find_package(HDF5 REQUIRED)
else()
message(STATUS "HDF5 will be downloaded and installed")

# Configure HDF5
if(NOT HDF5_VERSION)
set(HDF5_VERSION "1.14.3")
endif()

# Replace the dots with semicolons to create a list
string(REPLACE "." ";" HDF5_VERSION_LIST ${HDF5_VERSION})

# Convert the list into individual variables
list(GET HDF5_VERSION_LIST 0 HDF5_VERSION_MAJOR)
list(GET HDF5_VERSION_LIST 1 HDF5_VERSION_MINOR)
list(GET HDF5_VERSION_LIST 2 HDF5_VERSION_PATCH)
set(HDF5_ROOT "${CMAKE_BINARY_DIR}/hdf5")
set(HDF5_INCLUDE_DIRS "${HDF5_ROOT}/include")
set(HDF5_LIBRARY_DIRS "${HDF5_ROOT}/lib")
ExternalProject_Add(hdf5-project
PREFIX ${HDF5_ROOT}
URL https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-${HDF5_VERSION_MAJOR}.${HDF5_VERSION_MINOR}/hdf5-${HDF5_VERSION}/src/hdf5-${HDF5_VERSION}.tar.gz
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DBUILD_SHARED_LIBS:BOOL=ON
-DBUILD_STATIC_LIBS:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
-DHDF5_BUILD_TOOLS:BOOL=OFF
-DHDF5_BUILD_EXAMPLES:BOOL=OFF
DOWNLOAD_EXTRACT_TIMESTAMP true
BUILD_BYPRODUCTS "${HDF5_LIBRARY_DIRS}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
)

# HDF5 is a shared library, so we need to install it
install_dependent_library(hdf5 ${HDF5_LIBRARY_DIRS})
endif()

# Include the HDF5 libraries
include_directories(${HDF5_INCLUDE_DIRS})
message(STATUS "HDF5 include dirs: ${HDF5_INCLUDE_DIRS}")

link_directories(${HDF5_LIBRARY_DIRS})
message(STATUS "HDF5 library dirs: ${HDF5_LIBRARY_DIRS}")

# Set up shared and static versions of the HDF5 libraries
set(HDF5_LIBRARIES_SHARED ${HDF5_LIBRARIES})
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()

# Print out some more information about the HDF5 setup
message(STATUS "HDF5 libraries shared: ${HDF5_LIBRARIES_SHARED}")
message(STATUS "HDF5 libraries static: ${HDF5_LIBRARIES_STATIC}")


############################################################
# Setup Eigen3 #
############################################################

# If Eigen3 is installed in a non-standard location, set EIGEN3_DIR
# to the cmake directory of the Eigen3 installation.
# For example: export EIGEN3_ROOT=/path/to/eigen3/cmake
# If Eigen is not installed, set DOWNLOAD_EIGEN3 to ON.
# PyNE will download Eigen3 if DOWNLOAD_EIGEN3 is ON. (Recommended)
if(NOT DOWNLOAD_EIGEN3)
find_package(Eigen3 REQUIRED)
else()
message(STATUS "Eigen3 will be downloaded")

# Configure Eigen3
if(NOT EIGEN3_VERSION)
set(EIGEN3_VERSION "3.4.0")
endif()
set(EIGEN3_ROOT "${CMAKE_BINARY_DIR}/eigen3")
set(EIGEN3_INCLUDE_DIRS "${EIGEN3_ROOT}/include/eigen3")
ExternalProject_Add(eigen3-project
PREFIX ${EIGEN3_ROOT}
URL https://gitlab.com/libeigen/eigen/-/archive/${EIGEN3_VERSION}/eigen-${EIGEN3_VERSION}.tar.bz2
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
DOWNLOAD_EXTRACT_TIMESTAMP true
)
endif()

# Include the Eigen3 libraries
include_directories("${EIGEN3_INCLUDE_DIRS}")
message(STATUS "Eigen3 include dirs: ${EIGEN3_INCLUDE_DIRS}")


############################################################
# Setup MOAB #
############################################################

# If MOAB is installed in a non-standard location, set MOAB_DIR
# to the cmake directory of the MOAB installation.
# For example: export MOAB_ROOT=/path/to/moab/cmake
# If MOAB is not installed, set DOWNLOAD_MOAB to ON.
# PyNE will download and build MOAB if DOWNLOAD_MOAB is ON. (Recommended)
if(NOT DOWNLOAD_MOAB)
find_package(MOAB REQUIRED)
else()
message(STATUS "MOAB will be downloaded and built")

# Configure MOAB
if(NOT MOAB_VERSION)
set(MOAB_VERSION "5.6.0")
endif()
set(MOAB_ROOT "${CMAKE_BINARY_DIR}/moab")
set(MOAB_INCLUDE_DIRS "${MOAB_ROOT}/include")
set(MOAB_LIBRARY_DIRS "${MOAB_ROOT}/${CMAKE_INSTALL_LIBDIR}")
ExternalProject_Add(moab-project
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}
-DENABLE_BLASLAPACK:BOOL=OFF
-DENABLE_FORTRAN:BOOL=OFF
-DCMAKE_MACOSX_RPATH:BOOL=ON
DOWNLOAD_EXTRACT_TIMESTAMP true
BUILD_BYPRODUCTS "${MOAB_LIBRARY_DIRS}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*"
)

# HDF5 is needed to be build before MOAB
if(DOWNLOAD_HDF5)
add_dependencies(moab-project hdf5-project)
endif()

# EIGEN3 is needed to be build before MOAB
if(DOWNLOAD_EIGEN3)
add_dependencies(moab-project eigen3-project)
endif()

# MOAB is a shared library, so we need to install it
install_dependent_library(MOAB ${MOAB_LIBRARY_DIRS})
endif()
include_directories(${MOAB_INCLUDE_DIRS})
link_directories(${MOAB_LIBRARY_DIRS})
message(STATUS "MOAB include dirs: ${MOAB_INCLUDE_DIRS}")
message(STATUS "MOAB library dirs: ${MOAB_LIBRARY_DIRS}")
65 changes: 0 additions & 65 deletions cmake/FindMOAB.cmake

This file was deleted.

25 changes: 0 additions & 25 deletions cmake/HDF5_macro.cmake

This file was deleted.

Loading
Loading