diff --git a/CMakeLists.txt b/CMakeLists.txt index e983a6566c..292f8b0a8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,13 @@ cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(openmc C CXX) +# Set version numbers +set(OPENMC_VERSION_MAJOR 0) +set(OPENMC_VERSION_MINOR 12) +set(OPENMC_VERSION_RELEASE 1) +set(OPENMC_VERSION ${OPENMC_VERSION_MAJOR}.${OPENMC_VERSION_MINOR}.${OPENMC_VERSION_RELEASE}) +configure_file(include/openmc/version.h.in "${CMAKE_BINARY_DIR}/include/openmc/version.h" @ONLY) + # Setup output directories set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) @@ -40,10 +47,6 @@ endif() #=============================================================================== 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() #=============================================================================== @@ -346,6 +349,9 @@ target_include_directories(libopenmc # Set compile flags target_compile_options(libopenmc PRIVATE ${cxxflags}) +# Add include directory for configured version file +target_include_directories(libopenmc PRIVATE ${CMAKE_BINARY_DIR}/include) + if (HDF5_IS_PARALLEL) target_compile_definitions(libopenmc PRIVATE -DPHDF5) endif() @@ -380,6 +386,7 @@ endif() #=============================================================================== add_executable(openmc src/main.cpp) target_compile_options(openmc PRIVATE ${cxxflags}) +target_include_directories(openmc PRIVATE ${CMAKE_BINARY_DIR}/include) target_link_libraries(openmc libopenmc) # Ensure C++14 standard is used. Starting with CMake 3.8, another way this could @@ -403,6 +410,7 @@ add_custom_command(TARGET libopenmc POST_BUILD #=============================================================================== configure_file(cmake/OpenMCConfig.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" @ONLY) +configure_file(cmake/OpenMCConfigVersion.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" @ONLY) set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/OpenMC) install(TARGETS openmc libopenmc faddeeva @@ -417,10 +425,14 @@ install(EXPORT openmc-targets 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}) +install(FILES + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfig.cmake" + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/OpenMCConfigVersion.cmake" + DESTINATION ${INSTALL_CONFIGDIR}) 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}) +install(FILES "${CMAKE_BINARY_DIR}/include/openmc/version.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openmc) # Copy headers for vendored dependencies (note that all except faddeeva are handled # separately since they are managed by CMake) diff --git a/cmake/OpenMCConfigVersion.cmake.in b/cmake/OpenMCConfigVersion.cmake.in new file mode 100644 index 0000000000..90d345de44 --- /dev/null +++ b/cmake/OpenMCConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@OPENMC_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() diff --git a/include/openmc/constants.h b/include/openmc/constants.h index 24d60b92c4..60aa4544d3 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -9,6 +9,8 @@ #include #include +#include "openmc/version.h" + namespace openmc { using double_2dvec = std::vector>; @@ -18,13 +20,6 @@ using double_4dvec = std::vector>>>; // ============================================================================ // VERSIONING NUMBERS -// OpenMC major, minor, and release numbers -constexpr int VERSION_MAJOR {0}; -constexpr int VERSION_MINOR {12}; -constexpr int VERSION_RELEASE {1}; -constexpr bool VERSION_DEV {true}; -constexpr std::array VERSION {VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE}; - // HDF5 data format constexpr int HDF5_VERSION[] {3, 0}; diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in new file mode 100644 index 0000000000..a7cf51d048 --- /dev/null +++ b/include/openmc/version.h.in @@ -0,0 +1,12 @@ +#include + +namespace openmc { + +// OpenMC major, minor, and release numbers +constexpr int VERSION_MAJOR {@OPENMC_VERSION_MAJOR@}; +constexpr int VERSION_MINOR {@OPENMC_VERSION_MINOR@}; +constexpr int VERSION_RELEASE {@OPENMC_VERSION_RELEASE@}; +constexpr bool VERSION_DEV {true}; +constexpr std::array VERSION {VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE}; + +}