Merge pull request #2008 from kkiesling/build_types

Replace custom configure options with default build types
This commit is contained in:
Paul Romano 2022-03-23 16:55:51 -05:00 committed by GitHub
commit fe8892cebc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 61 deletions

View file

@ -25,13 +25,20 @@ endif()
# Command line options
#===============================================================================
option(openmp "Enable shared-memory parallelism with OpenMP" ON)
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)
option(libmesh "Enable support for libMesh unstructured mesh tallies" OFF)
option(OPENMC_USE_OPENMP "Enable shared-memory parallelism with OpenMP" ON)
option(OPENMC_ENABLE_PROFILE "Compile with profiling flags" OFF)
option(OPENMC_ENABLE_COVERAGE "Compile with coverage analysis flags" OFF)
option(OPENMC_USE_DAGMC "Enable support for DAGMC (CAD) geometry" OFF)
option(OPENMC_USE_LIBMESH "Enable support for libMesh unstructured mesh tallies" OFF)
#===============================================================================
# Set a default build configuration if not explicitly specified
#===============================================================================
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, defaulting to RelWithDebInfo")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build" FORCE)
endif()
#===============================================================================
# MPI for distributed-memory parallelism
@ -60,7 +67,7 @@ endmacro()
# DAGMC Geometry Support - need DAGMC/MOAB
#===============================================================================
if(dagmc)
if(OPENMC_USE_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}. \
@ -72,7 +79,7 @@ endif()
# libMesh Unstructured Mesh Support
#===============================================================================
if(libmesh)
if(OPENMC_USE_LIBMESH)
find_package(LIBMESH REQUIRED)
endif()
@ -123,7 +130,7 @@ endif()
# Skip for Visual Studio which has its own configurations through GUI
if(NOT MSVC)
if(openmp)
if(OPENMC_USE_OPENMP)
find_package(OpenMP)
if(OPENMP_FOUND)
# In CMake 3.9+, can use the OpenMP::OpenMP_CXX imported target
@ -134,19 +141,10 @@ endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
list(APPEND cxxflags -O2)
if(debug)
list(REMOVE_ITEM cxxflags -O2)
list(APPEND cxxflags -g -O0)
endif()
if(profile)
if(OPENMC_ENABLE_PROFILE)
list(APPEND cxxflags -g -fno-omit-frame-pointer)
endif()
if(optimize)
list(REMOVE_ITEM cxxflags -O2)
list(APPEND cxxflags -O3)
endif()
if(coverage)
if(OPENMC_ENABLE_COVERAGE)
list(APPEND cxxflags --coverage)
list(APPEND ldflags --coverage)
endif()
@ -436,12 +434,12 @@ else()
target_link_libraries(libopenmc pugixml)
endif()
if(dagmc)
if(OPENMC_USE_DAGMC)
target_compile_definitions(libopenmc PRIVATE DAGMC)
target_link_libraries(libopenmc dagmc-shared uwuw-shared)
endif()
if(libmesh)
if(OPENMC_USE_LIBMESH)
target_compile_definitions(libopenmc PRIVATE LIBMESH)
target_link_libraries(libopenmc PkgConfig::LIBMESH)
endif()

View file

@ -179,33 +179,25 @@ RUN mkdir -p ${HOME}/OpenMC && cd ${HOME}/OpenMC \
&& mkdir build && cd build ; \
if [ ${build_dagmc} = "on" ] && [ ${build_libmesh} = "on" ]; then \
cmake ../openmc \
-Doptimize=off \
-Ddebug=off \
-DHDF5_PREFER_PARALLEL=on \
-Ddagmc=on \
-Dlibmesh=on \
-DOPENMC_USE_DAGMC=on \
-DOPENMC_USE_LIBMESH=on \
-DCMAKE_PREFIX_PATH="${DAGMC_INSTALL_DIR};${LIBMESH_INSTALL_DIR}" ; \
fi ; \
if [ ${build_dagmc} = "on" ] && [ ${build_libmesh} = "off" ]; then \
cmake ../openmc \
-Doptimize=off \
-Ddebug=off \
-DHDF5_PREFER_PARALLEL=on \
-Ddagmc=ON \
-DOPENMC_USE_DAGMC=ON \
-DCMAKE_PREFIX_PATH=${DAGMC_INSTALL_DIR} ; \
fi ; \
if [ ${build_dagmc} = "off" ] && [ ${build_libmesh} = "on" ]; then \
cmake ../openmc \
-Doptimize=off \
-Ddebug=off \
-DHDF5_PREFER_PARALLEL=on \
-Dlibmesh=on \
-DOPENMC_USE_LIBMESH=on \
-DCMAKE_PREFIX_PATH=${LIBMESH_INSTALL_DIR} ; \
fi ; \
if [ ${build_dagmc} = "off" ] && [ ${build_libmesh} = "off" ]; then \
cmake ../openmc \
-Doptimize=off \
-Ddebug=off \
-DHDF5_PREFER_PARALLEL=on ; \
fi ; \
make 2>/dev/null -j${compile_cores} install \

View file

@ -5,11 +5,11 @@ find_package(gsl-lite REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../gsl-lite)
find_package(pugixml REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../pugixml)
find_package(xtl REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../xtl)
find_package(xtensor REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../xtensor)
if(@dagmc@)
if(@OPENMC_USE_DAGMC@)
find_package(DAGMC REQUIRED HINTS @DAGMC_DIR@)
endif()
if(@libmesh@)
if(@OPENMC_USE_LIBMESH@)
include(FindPkgConfig)
list(APPEND CMAKE_PREFIX_PATH @LIBMESH_PREFIX@)
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH True)

View file

@ -252,7 +252,7 @@ Prerequisites
In addition to turning this option on, the path to the DAGMC installation
should be specified as part of the ``CMAKE_PREFIX_PATH`` variable::
cmake -Ddagmc=on -DCMAKE_PREFIX_PATH=/path/to/dagmc/installation
cmake -DOPENMC_USE_DAGMC=on -DCMAKE_PREFIX_PATH=/path/to/dagmc/installation
* libMesh_ mesh library framework for numerical simulations of partial differential equations
@ -263,7 +263,7 @@ Prerequisites
installation should be specified as part of the ``CMAKE_PREFIX_PATH``
variable.::
CXX=mpicxx cmake -Dlibmesh=on -DCMAKE_PREFIX_PATH=/path/to/libmesh/installation
CXX=mpicxx cmake -DOPENMC_USE_LIBMESH=on -DCMAKE_PREFIX_PATH=/path/to/libmesh/installation
Note that libMesh is most commonly compiled with MPI support. If that
is the case, then OpenMC should be compiled with MPI support as well.
@ -331,46 +331,59 @@ CMakeLists.txt Options
The following options are available in the CMakeLists.txt file:
debug
Enables debugging when compiling. The flags added are dependent on which
compiler is used.
OPENMC_ENABLE_PROFILE
Enables profiling using the GNU profiler, gprof. (Default: off)
profile
Enables profiling using the GNU profiler, gprof.
optimize
Enables high-optimization using compiler-dependent flags. For gcc and
Intel C++, this compiles with -O3.
openmp
OPENMC_USE_OPENMP
Enables shared-memory parallelism using the OpenMP API. The C++ compiler
being used must support OpenMP. (Default: on)
dagmc
OPENMC_USE_DAGMC
Enables use of CAD-based DAGMC_ geometries and MOAB_ unstructured mesh
tallies. Please see the note about DAGMC in the optional dependencies list
for more information on this feature. The installation directory for DAGMC
should also be defined as `DAGMC_ROOT` in the CMake configuration command.
(Default: off)
libmesh
OPENMC_USE_LIBMESH
Enables the use of unstructured mesh tallies with libMesh_. (Default: off)
coverage
OPENMC_ENABLE_COVERAGE
Compile and link code instrumented for coverage analysis. This is typically
used in conjunction with gcov_.
used in conjunction with gcov_. (Default: off)
To set any of these options (e.g. turning on debug mode), the following form
To set any of these options (e.g., turning on profiling), the following form
should be used:
.. code-block:: sh
cmake -Ddebug=on /path/to/openmc
cmake -DOPENMC_ENABLE_PROFILE=on /path/to/openmc
.. _gcov: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html
.. _usersguide_compile_mpi:
Specifying the Build Type
+++++++++++++++++++++++++
OpenMC can be configured for debug, release, or release with debug info by setting
the `CMAKE_BUILD_TYPE` option.
Debug
Enable debug compiler flags with no optimization `-O0 -g`.
Release
Disable debug and enable optimization `-O3 -DNDEBUG`.
RelWithDebInfo
(Default if no type is specified.) Enable optimization and debug `-O2 -g`.
Example of configuring for Debug mode:
.. code-block:: sh
cmake -DCMAKE_BUILD_TYPE=Debug /path/to/openmc
Compiling with MPI
++++++++++++++++++

View file

@ -26,11 +26,11 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False):
os.chdir('build')
# Build in debug mode by default
cmake_cmd = ['cmake', '-Ddebug=on']
cmake_cmd = ['cmake', '-DCMAKE_BUILD_TYPE=Debug']
# Turn off OpenMP if specified
if not omp:
cmake_cmd.append('-Dopenmp=off')
cmake_cmd.append('-DOPENMC_USE_OPENMP=off')
# Use MPI wrappers when building in parallel
if mpi:
@ -46,16 +46,16 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False):
cmake_cmd.append('-DHDF5_PREFER_PARALLEL=OFF')
if dagmc:
cmake_cmd.append('-Ddagmc=ON')
cmake_cmd.append('-DOPENMC_USE_DAGMC=ON')
cmake_cmd.append('-DCMAKE_PREFIX_PATH=~/DAGMC')
if libmesh:
cmake_cmd.append('-Dlibmesh=ON')
cmake_cmd.append('-DOPENMC_USE_LIBMESH=ON')
libmesh_path = os.environ.get('HOME') + '/LIBMESH'
cmake_cmd.append('-DCMAKE_PREFIX_PATH=' + libmesh_path)
# Build in coverage mode for coverage testing
cmake_cmd.append('-Dcoverage=on')
cmake_cmd.append('-DOPENMC_ENABLE_COVERAGE=on')
# Build and install
cmake_cmd.append('..')