Skip to content

Commit

Permalink
Merge pull request #11 from pshriwise/packaging
Browse files Browse the repository at this point in the history
Installation & Packaging
  • Loading branch information
pshriwise authored Jan 17, 2024
2 parents 21ab369 + 0411a05 commit 22fd238
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 15 deletions.
71 changes: 66 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc C CXX)

option(XDG_ENABLE_MOAB "Enable support for the MOAB mesh library" ON)
option(XDG_ENABLE_MFEM "Enable support for the MFEM mesh library" OFF)
option(XDG_ENABLE_MOAB "Enable support for the MOAB mesh library" ON)
option(XDG_ENABLE_MFEM "Enable support for the MFEM mesh library" OFF)
option(XDG_ENABLE_LIBMESH "Enable support for the libMesh mesh library" OFF)
option(XDG_BUILD_TESTS "Enable C++ unit testing" ON)
option(XDG_BUILD_TESTS "Enable C++ unit testing" ON)

# Set version numbers
set(XDG_VERSION_MAJOR 0)
set(XDG_VERSION_MINOR 14)
set(XDG_VERSION_RELEASE 1)
set(XDG_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE})

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose build type" FORCE)
Expand Down Expand Up @@ -63,8 +69,6 @@ endif()

add_library(xdg SHARED ${xdg_sources})

add_library(xdg::libxdg ALIAS xdg)

# pass precompile definition depending on embree version
if (${EMBREE_VERSION} VERSION_GREATER_EQUAL 4.0.0)
target_compile_definitions(xdg PUBLIC XDG_EMBREE4)
Expand All @@ -87,3 +91,60 @@ target_link_libraries(xdg embree fmt::fmt)
if (XDG_ENABLE_MOAB)
target_link_libraries(xdg MOAB)
endif()

#===============================================================================
# RPATH information (from OpenMC)
#===============================================================================

# Provide install directory variables as defined by GNU coding standards
include(GNUInstallDirs)

# This block of code ensures that dynamic libraries can be found via the RPATH
# whether the executable is the original one from the build directory or the
# installed one in CMAKE_INSTALL_PREFIX. Ref:
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling

# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()

#=================================================================
# Installation & Packaging
#=================================================================
configure_file(cmake/XDGConfig.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XDGConfig.cmake" @ONLY)
configure_file(cmake/XDGConfigVersion.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XDGConfigVersion.cmake" @ONLY)

install(TARGETS xdg
EXPORT xdg-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION include
)

install(EXPORT xdg-targets
FILE XDGTargets.cmake
NAMESPACE xdg::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/xdg
)

install(FILES
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XDGConfig.cmake"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XDGConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/xdg
)

install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
16 changes: 16 additions & 0 deletions cmake/XDGConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
get_filename_component(XDG_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)

find_package(fmt REQUIRED HINTS ${XDG_CMAKE_DIR}/../fmt)
find_package(embree 3.6.1 REQUIRED HINTS @EMBREE_DIR@)

if(@XDG_ENABLE_MOAB@)
find_package(MOAB REQUIRED HINTS @MOAB_DIR@)
endif()

if (NOT TARGET xdg::xdg)
include("${XDG_CMAKE_DIR}/XDGTargets.cmake")
endif()

if (NOT TARGET xdg::xdg)
FATAL_ERROR("XDG Target not found")
endif()
11 changes: 11 additions & 0 deletions cmake/XDGConfigVersion.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(PACKAGE_VERSION "@XDG_VERSION@")

# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
10 changes: 5 additions & 5 deletions include/xdg/xdg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

namespace xdg {

class XDG {

class AcceleratedDiscretizedGeometry {

public:
// Constructors
XDG() = default;
AcceleratedDiscretizedGeometry() = default;

XDG(std::shared_ptr<MeshManager> mesh_manager) :
AcceleratedDiscretizedGeometry(std::shared_ptr<MeshManager> mesh_manager) :
mesh_manager_(mesh_manager) {}


// Methods
void prepare_raytracer() {
ray_tracing_interface_->register_all_volumes(mesh_manager_);
}

// Geometric Measurements
double measure_volume(MeshID volume) const;

double measure_surface_area(MeshID surface) const;
double measure_volume_area(MeshID surface) const;

Expand Down
6 changes: 3 additions & 3 deletions src/xdg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "xdg/geometry/measure.h"
namespace xdg {

double XDG::measure_volume(MeshID volume) const
double AcceleratedDiscretizedGeometry::measure_volume(MeshID volume) const
{
double volume_total {0.0};

Expand All @@ -31,7 +31,7 @@ double XDG::measure_volume(MeshID volume) const
return volume_total / 6.0;
}

double XDG::measure_surface_area(MeshID surface) const
double AcceleratedDiscretizedGeometry::measure_surface_area(MeshID surface) const
{
double area {0.0};
for (auto triangle : mesh_manager()->get_surface_elements(surface)) {
Expand All @@ -40,7 +40,7 @@ double XDG::measure_surface_area(MeshID surface) const
return area;
}

double XDG::measure_volume_area(MeshID volume) const
double AcceleratedDiscretizedGeometry::measure_volume_area(MeshID volume) const
{
double area {0.0};
for (auto surface : mesh_manager()->get_volume_surfaces(volume)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST_CASE("Test Mesh Mock")
std::shared_ptr<MeshManager> mm = std::make_shared<MeshMock>();
mm->init(); // this should do nothing, but its good practice to call it

XDG xdg{mm};
AcceleratedDiscretizedGeometry xdg{mm};

double volume = xdg.measure_volume(mm->volumes()[0]);
REQUIRE_THAT(volume, Catch::Matchers::WithinAbs(693., 1e-6));
Expand Down
2 changes: 1 addition & 1 deletion tests/test_xdg_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace xdg;

TEST_CASE("XDG Interface")
{
std::shared_ptr<XDG> xdg = std::make_shared<XDG>();
std::shared_ptr<AcceleratedDiscretizedGeometry> xdg = std::make_shared<AcceleratedDiscretizedGeometry>();
REQUIRE(xdg->ray_tracing_interface() != nullptr);
REQUIRE(xdg->mesh_manager() == nullptr);
}

0 comments on commit 22fd238

Please sign in to comment.