OpenMC/CMakeLists.txt

428 lines
15 KiB
Text
Raw Normal View History

cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(openmc C CXX)
2013-11-29 13:36:06 -05:00
# Setup output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Set module path
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
# Allow user to specify <project>_ROOT variables
if (NOT (CMAKE_VERSION VERSION_LESS 3.12))
cmake_policy(SET CMP0074 NEW)
endif()
2013-11-29 13:36:06 -05:00
#===============================================================================
# Command line options
#===============================================================================
2017-04-10 07:32:51 -05:00
option(openmp "Enable shared-memory parallelism with OpenMP" ON)
2013-11-29 13:36:06 -05:00
option(profile "Compile with profiling flags" OFF)
option(debug "Compile with debug flags" OFF)
option(optimize "Turn on all compiler optimization flags" OFF)
option(coverage "Compile with coverage analysis flags" OFF)
option(dagmc "Enable support for DAGMC (CAD) geometry" OFF)
2013-11-29 13:36:06 -05:00
#===============================================================================
# MPI for distributed-memory parallelism
2013-11-29 13:36:06 -05:00
#===============================================================================
set(MPI_ENABLED FALSE)
if(${CMAKE_CXX_COMPILER} MATCHES "(mpi[^/]*|CC)$")
message(STATUS "Detected MPI wrapper: ${CMAKE_CXX_COMPILER}")
set(MPI_ENABLED TRUE)
2013-11-29 13:36:06 -05:00
endif()
#===============================================================================
# DAGMC Geometry Support - need DAGMC/MOAB
#===============================================================================
if(dagmc)
find_package(DAGMC REQUIRED PATH_SUFFIXES lib/cmake)
if (${DAGMC_VERSION} VERSION_LESS 3.2.0)
message(FATAL_ERROR "Discovered DAGMC Version: ${DAGMC_VERSION}. \
Please update DAGMC to version 3.2.0 or greater.")
endif()
endif()
#===============================================================================
# HDF5 for binary output
#===============================================================================
# Unfortunately FindHDF5.cmake will always prefer a serial HDF5 installation
# over a parallel installation if both appear on the user's PATH. To get around
# this, we check for the environment variable HDF5_ROOT and if it exists, use it
# to check whether its a parallel version.
if(NOT DEFINED HDF5_PREFER_PARALLEL)
if(DEFINED ENV{HDF5_ROOT} AND EXISTS $ENV{HDF5_ROOT}/bin/h5pcc)
set(HDF5_PREFER_PARALLEL TRUE)
else()
set(HDF5_PREFER_PARALLEL FALSE)
endif()
endif()
find_package(HDF5 REQUIRED COMPONENTS C HL)
if(HDF5_IS_PARALLEL)
if(NOT MPI_ENABLED)
message(FATAL_ERROR "Parallel HDF5 must be used with MPI.")
endif()
message(STATUS "Using parallel HDF5")
endif()
# Version 1.12 of HDF5 deprecates the H5Oget_info_by_idx() interface.
# Thus, we give these flags to allow usage of the old interface in newer
# versions of HDF5.
if(NOT (${HDF5_VERSION} VERSION_LESS 1.12.0))
list(APPEND cxxflags -DH5Oget_info_by_idx_vers=1 -DH5O_info_t_vers=1)
endif()
2013-11-29 13:36:06 -05:00
#===============================================================================
# Set compile/link flags based on which compiler is being used
#===============================================================================
# Skip for Visual Stduio which has its own configurations through GUI
if(NOT MSVC)
if(openmp)
# Requires CMake 3.1+
find_package(OpenMP)
if(OPENMP_FOUND)
list(APPEND cxxflags ${OpenMP_CXX_FLAGS})
list(APPEND ldflags ${OpenMP_CXX_FLAGS})
endif()
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
list(APPEND cxxflags -O2)
2017-12-01 16:45:28 -05:00
if(debug)
list(REMOVE_ITEM cxxflags -O2)
list(APPEND cxxflags -g -O0)
endif()
if(profile)
2019-03-25 21:55:22 -05:00
list(APPEND cxxflags -g -fno-omit-frame-pointer)
2017-12-01 16:45:28 -05:00
endif()
if(optimize)
list(REMOVE_ITEM cxxflags -O2)
list(APPEND cxxflags -O3)
endif()
if(coverage)
list(APPEND cxxflags --coverage)
list(APPEND ldflags --coverage)
endif()
2017-12-01 16:45:28 -05:00
2017-04-10 07:26:48 -05:00
# Show flags being used
2019-03-25 21:55:22 -05:00
message(STATUS "OpenMC C++ flags: ${cxxflags}")
message(STATUS "OpenMC Linker flags: ${ldflags}")
2017-04-10 07:26:48 -05:00
endif()
#===============================================================================
# Update git submodules as needed
#===============================================================================
find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL 0)
message(FATAL_ERROR "git submodule update --init failed with \
${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
# Check to see if submodules exist (by checking one)
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vendor/pugixml/CMakeLists.txt")
message(FATAL_ERROR "The git submodules were not downloaded! GIT_SUBMODULE was \
turned off or failed. Please update submodules and try again.")
endif()
2013-11-29 13:36:06 -05:00
#===============================================================================
2017-02-24 15:19:31 -06:00
# pugixml library
2013-11-29 13:36:06 -05:00
#===============================================================================
2020-01-12 16:22:49 -06:00
add_subdirectory(vendor/pugixml)
2013-11-29 13:36:06 -05:00
#===============================================================================
# {fmt} library
#===============================================================================
set(FMT_INSTALL ON CACHE BOOL "Generate the install target.")
add_subdirectory(vendor/fmt)
#===============================================================================
# xtensor header-only library
#===============================================================================
# CMake 3.13+ will complain about policy CMP0079 unless it is set explicitly
if (NOT (CMAKE_VERSION VERSION_LESS 3.13))
cmake_policy(SET CMP0079 NEW)
endif()
add_subdirectory(vendor/xtl)
set(xtl_DIR ${CMAKE_CURRENT_BINARY_DIR}/vendor/xtl)
add_subdirectory(vendor/xtensor)
#===============================================================================
# GSL header-only library
#===============================================================================
set(GSL_LITE_OPT_INSTALL_COMPAT_HEADER ON CACHE BOOL
"Install MS-GSL compatibility header <gsl/gsl>")
2020-01-12 16:35:27 -06:00
add_subdirectory(vendor/gsl-lite)
# Make sure contract violations throw exceptions
2020-01-12 23:23:55 -06:00
target_compile_definitions(gsl-lite-v1 INTERFACE GSL_THROW_ON_CONTRACT_VIOLATION)
target_compile_definitions(gsl-lite-v1 INTERFACE gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON=1)
#===============================================================================
# RPATH information
#===============================================================================
2019-11-20 15:45:26 -06:00
# 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()
2016-02-01 12:27:51 -06:00
#===============================================================================
# faddeeva library
2016-02-01 12:27:51 -06:00
#===============================================================================
add_library(faddeeva STATIC vendor/faddeeva/Faddeeva.cc)
2019-10-30 16:01:31 -05:00
target_include_directories(faddeeva
PUBLIC
$<INSTALL_INTERFACE:include/faddeeva>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vendor/faddeeva>
)
target_compile_options(faddeeva PRIVATE ${cxxflags})
2016-02-01 12:27:51 -06:00
2013-11-29 13:36:06 -05:00
#===============================================================================
# libopenmc
2013-11-29 13:36:06 -05:00
#===============================================================================
list(APPEND libopenmc_SOURCES
2018-11-15 08:13:14 -06:00
src/bank.cpp
src/boundary_condition.cpp
src/bremsstrahlung.cpp
src/dagmc.cpp
src/cell.cpp
2018-11-10 12:11:42 -05:00
src/cmfd_solver.cpp
src/cross_sections.cpp
src/distribution.cpp
2018-07-09 17:04:48 -05:00
src/distribution_angle.cpp
2018-07-09 14:47:08 -05:00
src/distribution_energy.cpp
src/distribution_multi.cpp
src/distribution_spatial.cpp
2018-08-30 14:22:55 -05:00
src/eigenvalue.cpp
src/endf.cpp
2018-10-10 07:50:30 -05:00
src/error.cpp
src/event.cpp
2018-04-20 06:38:16 -05:00
src/initialize.cpp
2018-04-26 07:03:40 -05:00
src/finalize.cpp
2018-08-14 16:22:40 -04:00
src/geometry.cpp
2018-05-11 17:20:25 -04:00
src/geometry_aux.cpp
src/hdf5_interface.cpp
2018-02-04 23:15:32 -05:00
src/lattice.cpp
2018-08-15 16:08:32 -04:00
src/material.cpp
src/math_functions.cpp
2018-08-28 06:59:39 -05:00
src/mesh.cpp
src/message_passing.cpp
src/mgxs.cpp
src/mgxs_interface.cpp
2018-07-17 06:43:35 -05:00
src/nuclide.cpp
2018-08-14 19:04:05 -04:00
src/output.cpp
src/particle.cpp
2019-02-14 12:43:05 -06:00
src/particle_restart.cpp
2018-11-15 15:55:05 -06:00
src/photon.cpp
2018-11-17 09:24:31 -06:00
src/physics.cpp
2018-10-07 07:18:29 -04:00
src/physics_common.cpp
src/physics_mg.cpp
src/plot.cpp
src/position.cpp
2018-10-29 18:02:00 -05:00
src/progress_bar.cpp
src/random_lcg.cpp
2018-07-11 07:01:54 -05:00
src/reaction.cpp
2018-07-10 22:49:37 -05:00
src/reaction_product.cpp
src/scattdata.cpp
2018-07-10 15:32:18 -05:00
src/secondary_correlated.cpp
2018-07-10 07:36:46 -05:00
src/secondary_kalbach.cpp
2018-07-09 23:26:05 -05:00
src/secondary_nbody.cpp
src/secondary_thermal.cpp
2018-07-09 23:02:27 -05:00
src/secondary_uncorrelated.cpp
2018-08-06 21:31:30 -05:00
src/settings.cpp
2018-04-12 07:45:47 -05:00
src/simulation.cpp
2018-07-17 06:43:35 -05:00
src/source.cpp
src/state_point.cpp
src/string_utils.cpp
src/summary.cpp
2018-01-23 22:26:48 -05:00
src/surface.cpp
2019-01-26 12:10:18 -05:00
src/tallies/derivative.cpp
src/tallies/filter.cpp
src/tallies/filter_azimuthal.cpp
src/tallies/filter_cellborn.cpp
src/tallies/filter_cellfrom.cpp
src/tallies/filter_cell.cpp
2019-11-05 08:13:25 -05:00
src/tallies/filter_cell_instance.cpp
2018-10-28 15:52:01 -04:00
src/tallies/filter_delayedgroup.cpp
src/tallies/filter_distribcell.cpp
src/tallies/filter_energyfunc.cpp
src/tallies/filter_energy.cpp
src/tallies/filter_legendre.cpp
src/tallies/filter_material.cpp
src/tallies/filter_mesh.cpp
src/tallies/filter_meshsurface.cpp
src/tallies/filter_mu.cpp
2018-10-28 16:26:22 -04:00
src/tallies/filter_particle.cpp
src/tallies/filter_polar.cpp
src/tallies/filter_sph_harm.cpp
src/tallies/filter_sptl_legendre.cpp
src/tallies/filter_surface.cpp
src/tallies/filter_universe.cpp
src/tallies/filter_zernike.cpp
src/tallies/tally.cpp
src/tallies/tally_scoring.cpp
src/tallies/trigger.cpp
src/timer.cpp
src/thermal.cpp
2019-02-19 22:06:20 -06:00
src/track_output.cpp
src/urr.cpp
2019-02-06 21:47:08 -06:00
src/volume_calc.cpp
2018-12-26 07:24:21 -06:00
src/wmp.cpp
src/xml_interface.cpp
2018-12-26 07:24:21 -06:00
src/xsdata.cpp)
# For Visual Studio compilers
if(MSVC)
# Use static library (otherwise explicit symbol portings are needed)
add_library(libopenmc STATIC ${libopenmc_SOURCES})
# To use the shared HDF5 libraries on Windows, the H5_BUILT_AS_DYNAMIC_LIB
# compile definition must be specified.
target_compile_definitions(libopenmc PRIVATE -DH5_BUILT_AS_DYNAMIC_LIB)
else()
add_library(libopenmc SHARED ${libopenmc_SOURCES})
endif()
2020-07-01 15:20:55 +08:00
# Avoid vs error lnk1149 :output filename matches input filename
if(NOT MSVC)
2018-04-24 06:42:43 -05:00
set_target_properties(libopenmc PROPERTIES
OUTPUT_NAME openmc)
2020-07-01 15:20:55 +08:00
endif()
target_include_directories(libopenmc
2019-10-30 16:01:31 -05:00
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${HDF5_INCLUDE_DIRS}
)
2019-02-21 15:49:58 -06:00
# Set compile flags
target_compile_options(libopenmc PRIVATE ${cxxflags})
2017-12-01 16:45:28 -05:00
if (HDF5_IS_PARALLEL)
target_compile_definitions(libopenmc PRIVATE -DPHDF5)
endif()
if (MPI_ENABLED)
target_compile_definitions(libopenmc PUBLIC -DOPENMC_MPI)
endif()
# Set git SHA1 hash as a compile definition
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SHA1_SUCCESS
OUTPUT_VARIABLE GIT_SHA1
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(GIT_SHA1_SUCCESS EQUAL 0)
target_compile_definitions(libopenmc PRIVATE -DGIT_SHA1="${GIT_SHA1}")
endif()
endif()
# target_link_libraries treats any arguments starting with - but not -l as
# linker flags. Thus, we can pass both linker flags and libraries together.
target_link_libraries(libopenmc ${ldflags} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES}
pugixml faddeeva xtensor gsl-lite-v1 fmt::fmt)
if(dagmc)
target_compile_definitions(libopenmc PRIVATE DAGMC)
2020-04-08 09:39:56 -05:00
target_link_libraries(libopenmc dagmc-shared uwuw-shared)
endif()
#===============================================================================
# openmc executable
#===============================================================================
add_executable(openmc src/main.cpp)
target_compile_options(openmc PRIVATE ${cxxflags})
target_link_libraries(openmc libopenmc)
# Ensure C++14 standard is used. Starting with CMake 3.8, another way this could
# be done is using the cxx_std_14 compiler feature.
set_target_properties(
openmc libopenmc faddeeva pugixml
PROPERTIES CXX_STANDARD 14 CXX_EXTENSIONS OFF)
#===============================================================================
# Python package
#===============================================================================
add_custom_command(TARGET libopenmc POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:libopenmc>
2019-09-05 07:31:13 -05:00
${CMAKE_CURRENT_SOURCE_DIR}/openmc/lib/$<TARGET_FILE_NAME:libopenmc>
COMMENT "Copying libopenmc to Python module directory")
#===============================================================================
# Install executable, scripts, manpage, license
#===============================================================================
configure_file(cmake/OpenMCConfig.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" @ONLY)
2019-10-30 16:01:31 -05:00
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/OpenMC)
install(TARGETS openmc libopenmc faddeeva
2019-10-30 16:01:31 -05:00
EXPORT openmc-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(EXPORT openmc-targets
FILE OpenMCTargets.cmake
NAMESPACE OpenMC::
DESTINATION ${INSTALL_CONFIGDIR})
install(DIRECTORY src/relaxng DESTINATION ${CMAKE_INSTALL_DATADIR}/openmc)
install(FILES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" DESTINATION ${INSTALL_CONFIGDIR})
2019-10-30 16:01:31 -05:00
install(FILES man/man1/openmc.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(FILES LICENSE DESTINATION "${CMAKE_INSTALL_DOCDIR}" RENAME copyright)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
2020-01-12 16:41:32 -06:00
# Copy headers for vendored dependencies (note that all except faddeeva are handled
2019-10-30 16:01:31 -05:00
# separately since they are managed by CMake)
install(DIRECTORY vendor/faddeeva DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})