diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ccb0d79..6717f280 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.22) # Adds version settings and set variable CMAKE_PROJECT_VERSION -project(ReSolve VERSION "0.1.0") +project(ReSolve VERSION "0.99.1") set(CMAKE_CXX_STANDARD 11) diff --git a/resolve/CMakeLists.txt b/resolve/CMakeLists.txt index 078bb4d6..a02ffdb6 100644 --- a/resolve/CMakeLists.txt +++ b/resolve/CMakeLists.txt @@ -116,6 +116,7 @@ target_include_directories(ReSolve INTERFACE # TODO: Make this PRIVATE dependency (requires refactoring ReSolve code) target_link_libraries(ReSolve PUBLIC ${ReSolve_Targets_List}) +target_link_libraries(ReSolve PRIVATE resolve_version) # Install targets install(TARGETS ReSolve diff --git a/resolve/SystemSolver.cpp b/resolve/SystemSolver.cpp index 59d160bb..467217e1 100644 --- a/resolve/SystemSolver.cpp +++ b/resolve/SystemSolver.cpp @@ -1,3 +1,5 @@ +#include + #include #include @@ -94,10 +96,13 @@ namespace ReSolve delete resVector_; delete factorizationSolver_; delete refactorizationSolver_; + +#if defined(RESOLVE_USE_HIP) || defined(RESOLVE_USE_CUDA) if (irMethod_ != "none") { delete iterativeSolver_; delete gs_; } +#endif delete matrixHandler_; delete vectorHandler_; @@ -364,6 +369,7 @@ namespace ReSolve void SystemSolver::setRefinementMethod(std::string method, std::string gsMethod) { +#if defined(RESOLVE_USE_HIP) || defined(RESOLVE_USE_CUDA) if (iterativeSolver_ != nullptr) delete iterativeSolver_; @@ -375,7 +381,6 @@ namespace ReSolve gsMethod_ = gsMethod; -#if defined(RESOLVE_USE_HIP) || defined(RESOLVE_USE_CUDA) if (method == "fgmres") { if (gsMethod == "cgs2") { gs_ = new GramSchmidt(vectorHandler_, GramSchmidt::cgs2); diff --git a/resolve/resolve_defs.hpp.in b/resolve/resolve_defs.hpp.in index 15cd5791..49a39203 100644 --- a/resolve/resolve_defs.hpp.in +++ b/resolve/resolve_defs.hpp.in @@ -11,9 +11,10 @@ #cmakedefine RESOLVE_USE_EIGEN #cmakedefine RESOLVE_USE_KLU #define RESOLVE_VERSION "@PROJECT_VERSION@" -// #define RESOLVE_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ -// #define RESOLVE_VERSION_MINOR @PROJECT_VERSION_MINOR@ -// #define RESOLVE_VERSION_PATCH @PROJECT_VERSION_PATCH@ + +#define RESOLVE_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@" +#define RESOLVE_VERSION_MINOR "@PROJECT_VERSION_MINOR@" +#define RESOLVE_VERSION_PATCH "@PROJECT_VERSION_PATCH@" // /// Date of build with the format "%Y-%m-%d" // #define RESOLVE_RELEASE_DATE "@RESOLVE_RELEASE_DATE@" diff --git a/resolve/utilities/CMakeLists.txt b/resolve/utilities/CMakeLists.txt index b66ae0eb..c866713d 100644 --- a/resolve/utilities/CMakeLists.txt +++ b/resolve/utilities/CMakeLists.txt @@ -7,3 +7,4 @@ ]] add_subdirectory(logger) +add_subdirectory(version) diff --git a/resolve/utilities/version/CMakeLists.txt b/resolve/utilities/version/CMakeLists.txt new file mode 100644 index 00000000..457c7bc5 --- /dev/null +++ b/resolve/utilities/version/CMakeLists.txt @@ -0,0 +1,27 @@ +#[[ + +@brief Build ReSolve function that returns version at runtime + +@author Slaven Peles + +]] + +set(Logger_SRC + version.cpp +) + +set(Logger_HEADER_INSTALL + version.hpp +) + +# Build shared library ReSolve +add_library(resolve_version OBJECT ${Logger_SRC}) +set_property(TARGET resolve_version PROPERTY POSITION_INDEPENDENT_CODE ON) + +target_include_directories(resolve_version PUBLIC + $ + $ + $ +) + +install(FILES ${Logger_HEADER_INSTALL} DESTINATION include/resolve/utilities/version) diff --git a/resolve/utilities/version/version.cpp b/resolve/utilities/version/version.cpp new file mode 100644 index 00000000..33033f58 --- /dev/null +++ b/resolve/utilities/version/version.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include "version.hpp" +#include + +namespace ReSolve +{ + // Function that splits the verison in major minor and patch ints + int VersionGetVersion(int* major, int* minor, int* patch) + { + *major = atoi(RESOLVE_VERSION_MAJOR); + *minor = atoi(RESOLVE_VERSION_MINOR); + *patch = atoi(RESOLVE_VERSION_PATCH); + return 0; + } + + // Function that grabs ReSolves Version as a string + int VersionGetVersionStr(std::string &str) + { + str = RESOLVE_VERSION; + return 0; + } + +} diff --git a/resolve/utilities/version/version.hpp b/resolve/utilities/version/version.hpp new file mode 100644 index 00000000..9ce8ccd6 --- /dev/null +++ b/resolve/utilities/version/version.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace ReSolve +{ + + /** + * Sets major, minor, and patch versions for current ReSolve build. The user is + * responsible for free'ing this memory. + */ + int VersionGetVersion(int *, int *, int *); + + /** + * Sets string with build version for current ExaGO build in format + * "major.minor.patch". The user is responsible for free'ing this memory. + */ + int VersionGetVersionStr(std::string &); + +} diff --git a/tests/functionality/CMakeLists.txt b/tests/functionality/CMakeLists.txt index 5fae41cd..c606d5ff 100644 --- a/tests/functionality/CMakeLists.txt +++ b/tests/functionality/CMakeLists.txt @@ -6,6 +6,10 @@ ]] +# Build basic version test +add_executable(version.exe testVersion.cpp) +target_link_libraries(version.exe PRIVATE ReSolve) + # Build KLU+KLU test add_executable(klu_klu_test.exe testKLU.cpp) target_link_libraries(klu_klu_test.exe PRIVATE ReSolve) @@ -56,7 +60,7 @@ if(RESOLVE_USE_HIP) endif(RESOLVE_USE_HIP) # Install tests -set(installable_tests klu_klu_test.exe) +set(installable_tests klu_klu_test.exe version.exe) if(RESOLVE_USE_CUDA) set(installable_tests ${installable_tests} @@ -81,6 +85,7 @@ install(DIRECTORY data DESTINATION bin/resolve/tests/functionality) set(test_data_dir ${CMAKE_SOURCE_DIR}/tests/functionality/) +add_test(NAME version COMMAND $ "${test_data_dir}") add_test(NAME klu_klu_test COMMAND $ "${test_data_dir}") if(RESOLVE_USE_CUDA) add_test(NAME klu_rf_test COMMAND $ "${test_data_dir}") diff --git a/tests/functionality/testVersion.cpp b/tests/functionality/testVersion.cpp new file mode 100644 index 00000000..38402fd1 --- /dev/null +++ b/tests/functionality/testVersion.cpp @@ -0,0 +1,32 @@ +#include +#include + + +#include + +//author: RD +//version test to check to make sure ReSolve's version can be printed + +/** + * @brief Test ReSolve version + * + * The purpose of this mildly annoying test is to force developers + * to change version at two different places. The hope is this test + * will fail if the version is changed accidentally. + * + * @return int If test was successful return zero + */ +int main() +{ + std::string answer("0.99.1"); + std::string versionstr; + ReSolve::VersionGetVersionStr(versionstr); + std::cout << "ReSolveVersionGetVersionStr Test: " << versionstr << std::endl << std::endl; + + if (versionstr != answer) { + std::cout << "ReSolve version set incorrectly!\n"; + return 1; + } + + return 0; +} \ No newline at end of file