diff --git a/CHANGELOG.md b/CHANGELOG.md index f0f58fe01900a6267b772186b11ef6177425e84e..61d48aaebd50731104612da10f4c3d35864c9d5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- Close logging down in destructor so linked device server can be restarted. + +### Changed + +- Build system correctly produces a major version shared object +- Removed Clang path from build (CMake checks PATH) +- Corrected static library build +- Install now places header in include/hdb++/ + ## [0.9.1] - 2019-07-18 ### Added -- Google benchmark submodule for micro benchmarking. This will enabled future optimisation +- Google benchmark sub-module for micro benchmarking. This will enabled future optimisation - Benchmark tests for QueryBuilder ### Fixed @@ -25,4 +36,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Pre v1 release of the library. - This is an almost complete version of the library. - - Next couple of versions will complete the library before a v1 release. \ No newline at end of file + - Next couple of versions will complete the library before a v1 release. diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fe382feb53ab51daed3dc5f957af5f49606684e..0602e9b62a08f2c4cc10f82dbc4d76520437c5b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,10 +20,15 @@ set(LIBHDBPP_TIMESCALE_NAME "libhdb++timescale") # Versioning set(VERSION_MAJOR "0") set(VERSION_MINOR "9") -set(VERSION_PATCH "1") +set(VERSION_PATCH "2") set(VERSION_METADATA "") set(VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) +# Add any include paths from the command line +list(APPEND INCLUDE_PATHS ${CMAKE_INCLUDE_PATH}) +list(APPEND INCLUDE_PATHS ${CMAKE_SOURCE_DIR}) +list(APPEND LIBRARY_PATHS ${CMAKE_LIBRARY_PATH}) + # Start the project project(libhdbpp_timescale VERSION ${VERSION_STRING} LANGUAGES CXX) @@ -80,10 +85,10 @@ find_package(Threads REQUIRED) # build google benchmark (target: benchmark) # do not build tests of benchmarking lib set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Suppressing benchmark's tests" FORCE) -add_subdirectory(thirdparty/google/benchmark) +add_subdirectory(thirdparty/google/benchmark EXCLUDE_FROM_ALL) # build tests (targets: gtest_main, gtest) -add_subdirectory(thirdparty/google/googletest/googletest) +add_subdirectory(thirdparty/google/googletest/googletest EXCLUDE_FROM_ALL) # Include the thirdparty projects add_subdirectory(thirdparty/libhdbpp EXCLUDE_FROM_ALL) @@ -107,9 +112,11 @@ set_target_properties(pqxx_static if(ENABLE_CLANG) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + # To find clang, find_program will search your PATH environment variable. + # Ensure if you have a non-standard clang install, that it has been added + # to your path. find_program(CLANG_TIDY_EXE NAMES "clang-tidy" - HINTS "/users/sjames/workspace/tools/clang/bin" DOC "Path to clang-tidy executable") if(NOT CLANG_TIDY_EXE) @@ -120,6 +127,8 @@ if(ENABLE_CLANG) endif(NOT CLANG_TIDY_EXE) endif(ENABLE_CLANG) +# Source ----------------------------------- + add_subdirectory(src) # Build Targets ----------------------------------- @@ -146,7 +155,7 @@ set_target_properties(libhdbpp_timescale_shared_library CXX_STANDARD 14 POSITION_INDEPENDENT_CODE 1 VERSION ${VERSION_STRING} - SOVERSION ${VERSION_STRING}) + SOVERSION ${VERSION_MAJOR}) if(DO_CLANG_TIDY) set_target_properties(libhdbpp_timescale_shared_library @@ -157,16 +166,25 @@ endif(DO_CLANG_TIDY) target_compile_options(libhdbpp_timescale_shared_library PRIVATE "$<$<CONFIG:DEBUG>:-g>") -# Libhdbpp shared library -------- -add_library(libhdbpp_timescale_static_library STATIC ${SRC_FILES}) +# Static library -------- +add_library(libhdbpp_timescale_static_library STATIC EXCLUDE_FROM_ALL ${SRC_FILES}) target_link_libraries(libhdbpp_timescale_static_library - PUBLIC ${TDB_FOUND_LIBRARIES} + PUBLIC ${TDB_FOUND_LIBRARIES} pqxx_static libhdbpp_headers spdlog Threads::Threads PRIVATE TangoInterfaceLibrary) +target_include_directories(libhdbpp_timescale_static_library + PUBLIC + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> + PRIVATE + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src> + ${INCLUDE_PATHS} + "${PROJECT_BINARY_DIR}") + + set_target_properties(libhdbpp_timescale_static_library PROPERTIES - OUTPUT_NAME hdb++ + OUTPUT_NAME hdb++timescale LINK_FLAGS "-Wl,--no-undefined" CXX_STANDARD 14 EXCLUDE_FROM_ALL 1) @@ -183,7 +201,7 @@ install( install( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hdb++ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN HdbppTimescaleDb.hpp) diff --git a/doc/build.md b/doc/build.md index 5b0a64efa30f0f2ba714ae56df5cbb65894e20e4..451825abc5dc9cc27cc5f2635f809c9715e26d21 100644 --- a/doc/build.md +++ b/doc/build.md @@ -35,8 +35,6 @@ To compile this library, first ensure it has been recursively cloned so all subm export PKG_CONFIG_PATH=/non/standard/tango/install/location ``` -CMake is also set to search any paths added to CMAKE_PREFIX_PATH. This can be set and passed into CMake instead. - Then to build just the library: ```bash @@ -46,6 +44,14 @@ cmake .. make ``` +The pkg-config path can also be set with the cmake argument CMAKE_PREFIX_PATH. This can be set on the command line at configuration time, i.e.: + +```bash +... +cmake -DCMAKE_PREFIX_PATH=/non/standard/tango/install/location .. +... +``` + ## Build Flags The following build flags are available diff --git a/doc/db-schema-config.md b/doc/db-schema-config.md index 726fb4a022562be89f136374454921084124c144..8c0e6ea16fb90fa02b8894ae24dc1ea3aa8314c6 100644 --- a/doc/db-schema-config.md +++ b/doc/db-schema-config.md @@ -35,6 +35,7 @@ Rather than create and manage the tables via a superuser, we create and admin us ```sql CREATE ROLE hdb_admin WITH LOGIN PASSWORD 'hdbpp'; ALTER USER hdb_admin CREATEDB; +ALTER USER hdb_admin CREATEROLE; ALTER USER hdb_admin SUPERUSER; ``` diff --git a/include/HdbppTimescaleDb.hpp b/include/hdb++/HdbppTimescaleDb.hpp similarity index 100% rename from include/HdbppTimescaleDb.hpp rename to include/hdb++/HdbppTimescaleDb.hpp diff --git a/src/DbConnection.cpp b/src/DbConnection.cpp index 34197f31cbbfc230297eae204abfc3c2214ad62c..00af4f9876e7270ee9cc3af79f46936678c9fc93 100644 --- a/src/DbConnection.cpp +++ b/src/DbConnection.cpp @@ -58,7 +58,8 @@ namespace pqxx_conn } catch (const pqxx::broken_connection &ex) { - string msg {"Failed to connect to database. Ensure parameters are correct and database is running"}; + string msg {"Failed to connect to database. Exception: "}; + msg += ex.what(); _logger->error("Error: Connecting to postgres database with connect string: \"{}\"", connect_string); _logger->error("Caught error: \"{}\"", ex.what()); @@ -622,7 +623,7 @@ namespace pqxx_conn "] does not exist in the database. Unable to work with this attribute until it is added."}; _logger->error("Error: The attribute does not exist in the database, add it first."); - _logger->error("Attribute details. Name: {} traits: {}", full_attr_name); + _logger->error("Attribute details. Name: {}", full_attr_name); _logger->error("Throwing consistency error with message: \"{}\"", msg); Tango::Except::throw_exception("Consistency Error", msg, location); } diff --git a/src/HdbppTimescaleDb.cpp b/src/HdbppTimescaleDb.cpp index 5c1177f697397c9741b852b0717df6783fb8c518..164a99b041eecc698fd7b77204ff04dded38e277 100644 --- a/src/HdbppTimescaleDb.cpp +++ b/src/HdbppTimescaleDb.cpp @@ -17,7 +17,7 @@ You should have received a copy of the Lesser GNU General Public License along with libhdb++timescale. If not, see <http://www.gnu.org/licenses/>. */ -#include "HdbppTimescaleDb.hpp" +#include "hdb++/HdbppTimescaleDb.hpp" #include "DbConnection.hpp" #include "HdbppTxDataEvent.hpp" @@ -148,6 +148,8 @@ HdbppTimescaleDb::~HdbppTimescaleDb() { if (Conn->isOpen()) Conn->disconnect(); + + LogConfigurator::shutdownLogging(); } //============================================================================= @@ -163,7 +165,7 @@ void HdbppTimescaleDb::insert_Attr(Tango::EventData *event_data, HdbEventDataTyp { spdlog::trace("Event type is error for attribute: {}", event_data->attr_name); - // now time data is passed for errors, so make something up + // no time data is passed for errors, so make something up struct timeval tv {}; @@ -269,5 +271,5 @@ AbstractDB *HdbppTimescaleDbFactory::create_db(vector<string> configuration) DBFactory *getDBFactory() { auto *factory = new hdbpp::HdbppTimescaleDbFactory(); - return static_cast<DBFactory *>(factory); + return static_cast<DBFactory*>(factory); } diff --git a/src/HdbppTxDataEventError.hpp b/src/HdbppTxDataEventError.hpp index 1e7ae35d27b3351eff2e40f10f275f2b1503393b..b4274d99a8c01282de39177f28ec9a9e572f79a1 100644 --- a/src/HdbppTxDataEventError.hpp +++ b/src/HdbppTxDataEventError.hpp @@ -38,7 +38,7 @@ public: HdbppTxDataEventError(Conn &conn) : HdbppTxDataEventBase<Conn, HdbppTxDataEventError>(conn) {} virtual ~HdbppTxDataEventError() {} - HdbppTxDataEventError<Conn> &withError(const string &error_msg) + HdbppTxDataEventError<Conn> &withError(const std::string &error_msg) { _error_msg = error_msg; return *this; diff --git a/src/LibUtils.hpp b/src/LibUtils.hpp index 23beb84824afe40bb006717fca2441345ffbbc0c..266c7e0c7e11d1ad5248f04a526ddd59ad9cffc1 100644 --- a/src/LibUtils.hpp +++ b/src/LibUtils.hpp @@ -59,7 +59,7 @@ std::ostream &operator<<(std::ostream &os, Tango::CmdArgType type); std::ostream &operator<<(std::ostream &os, Tango::AttrQuality quality); // SPDLOG config and setup -const string LibLoggerName = "hdbpp"; +const std::string LibLoggerName = "hdbpp"; struct LogConfigurator { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 80deb9ec9a4ec0089d13ab1597c633df7bd03182..353a4276193140c384f27b8b4fea3a2d87a45d48 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,11 +28,13 @@ target_link_libraries(unit-tests target_include_directories(unit-tests PRIVATE ${CMAKE_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}) -target_compile_definitions(unit-tests - PRIVATE -DDEBUG_ENABLED) - set_target_properties(unit-tests PROPERTIES LINK_FLAGS "-Wl,--no-undefined" - CXX_CLANG_TIDY ${DO_CLANG_TIDY} - CXX_STANDARD 14) \ No newline at end of file + CXX_STANDARD 14) + +if(DO_CLANG_TIDY) + set_target_properties(unit-tests + PROPERTIES + CXX_CLANG_TIDY ${DO_CLANG_TIDY}) +endif(DO_CLANG_TIDY) \ No newline at end of file diff --git a/test/HdbppTxDataEventTests.cpp b/test/HdbppTxDataEventTests.cpp index 9ff6112a8b1c00b0ccb7eee4d40b15fd0ec167d0..8861eab72ed71e67a8d91444cf8ddc332b119607 100644 --- a/test/HdbppTxDataEventTests.cpp +++ b/test/HdbppTxDataEventTests.cpp @@ -106,7 +106,7 @@ Tango::DeviceAttribute createDeviceAttribute(const AttributeTraits &traits) }; // hack hack hack.... this mess of forced public (!) variable setting actually - // sets up the consitions for valid extracts inside the HdbppTxDataEvent class. + // sets up the conditions for valid extracts inside the HdbppTxDataEvent class. // Should the Tango API ever be improved then this hack is doomed. auto attr = attr_gen(select_size(traits.hasReadData(), 1), select_size(traits.hasWriteData(), 1)); attr.dim_x = select_size(traits.hasReadData(), 1);