From b94d89dea7410189a50826a5d5c0634df53e70c9 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 18 Jan 2021 12:37:18 -0600 Subject: [PATCH 1/3] Moving version numbers into a configured HEADER. Adding version numbers to CMake and including a version file. --- CMakeLists.txt | 23 ++++++++++++++++++----- cmake/OpenMCConfigVersion.cmake.in | 12 ++++++++++++ include/openmc/constants.h | 9 ++------- include/openmc/version.h.in | 11 +++++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 cmake/OpenMCConfigVersion.cmake.in create mode 100644 include/openmc/version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e983a6566c..a7bf646da2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,14 @@ 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 +48,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 +350,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 +387,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 +411,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 +426,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..8cde634e8b --- /dev/null +++ b/cmake/OpenMCConfigVersion.cmake.in @@ -0,0 +1,12 @@ + +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..79e7f34bb6 --- /dev/null +++ b/include/openmc/version.h.in @@ -0,0 +1,11 @@ + +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}; + +} \ No newline at end of file From ee44b0c9c3ea2111e8a7f4cb92ea79642b8caf76 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 18 Jan 2021 22:27:33 -0600 Subject: [PATCH 2/3] Update include/openmc/version.h.in Co-authored-by: Paul Romano --- include/openmc/version.h.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in index 79e7f34bb6..48c4f8c08f 100644 --- a/include/openmc/version.h.in +++ b/include/openmc/version.h.in @@ -1,3 +1,4 @@ +#include namespace openmc { @@ -8,4 +9,4 @@ namespace openmc { constexpr bool VERSION_DEV {true}; constexpr std::array VERSION {VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE}; -} \ No newline at end of file +} From 60cfe907b17d993b3f092696312a3a41aa9d05f2 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 18 Jan 2021 22:27:58 -0600 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Paul Romano --- CMakeLists.txt | 1 - cmake/OpenMCConfigVersion.cmake.in | 1 - include/openmc/version.h.in | 12 ++++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7bf646da2..292f8b0a8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,6 @@ 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) diff --git a/cmake/OpenMCConfigVersion.cmake.in b/cmake/OpenMCConfigVersion.cmake.in index 8cde634e8b..90d345de44 100644 --- a/cmake/OpenMCConfigVersion.cmake.in +++ b/cmake/OpenMCConfigVersion.cmake.in @@ -1,4 +1,3 @@ - set(PACKAGE_VERSION "@OPENMC_VERSION@") # Check whether the requested PACKAGE_FIND_VERSION is compatible diff --git a/include/openmc/version.h.in b/include/openmc/version.h.in index 48c4f8c08f..a7cf51d048 100644 --- a/include/openmc/version.h.in +++ b/include/openmc/version.h.in @@ -2,11 +2,11 @@ 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}; +// 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}; }