From ccc81c1796d1e0d8e85fce1bdedf5208895883de Mon Sep 17 00:00:00 2001 From: bergmann Date: Thu, 1 Aug 2019 19:34:17 +0200 Subject: [PATCH] * Updated project structure --- CMakeFiles/cmake.check_cache | 1 + CMakeLists.txt | 12 ++-- cmake/cppcore-config.cmake | 6 +- cmake/cppcore-options.cmake | 6 ++ cmake/cppcore-var.cmake | 54 +++++++++++----- cmake/modules | 2 +- include/cppcore/misc/vector_streambuf.inl | 6 +- src/CMakeLists.txt | 16 ++--- test/CMakeLists.txt | 75 +++++++++++++---------- 9 files changed, 115 insertions(+), 63 deletions(-) create mode 100644 CMakeFiles/cmake.check_cache create mode 100644 cmake/cppcore-options.cmake diff --git a/CMakeFiles/cmake.check_cache b/CMakeFiles/cmake.check_cache new file mode 100644 index 0000000..3dccd73 --- /dev/null +++ b/CMakeFiles/cmake.check_cache @@ -0,0 +1 @@ +# This file is generated by cmake for dependency checking of the CMakeCache.txt file diff --git a/CMakeLists.txt b/CMakeLists.txt index 63abecf..99708d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,8 @@ EndIf ( ) # Project ######################################################################################### -Include ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppcore-var.cmake" ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppcore-options.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppcore-var.cmake ) Project ( cppcore DESCRIPTION "A simple library" VERSION "${CPPCORE_VERSION}" ) @@ -41,9 +42,12 @@ Configure_File ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppcore-c @ONLY ) Set ( ConfigPackageLocation "${CPPCORE_INSTALL_DIR_SHARE}/cmake" ) -Install ( EXPORT cppcore - NAMESPACE cppcore:: - DESTINATION ${ConfigPackageLocation} ) +Install ( EXPORT + cppcore + NAMESPACE + cppcore:: + DESTINATION + ${ConfigPackageLocation} ) Install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/cppcore-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake/cppcore-config-version.cmake" diff --git a/cmake/cppcore-config.cmake b/cmake/cppcore-config.cmake index 52f697e..b0d1d61 100644 --- a/cmake/cppcore-config.cmake +++ b/cmake/cppcore-config.cmake @@ -1,4 +1,6 @@ # cppcore-config.cmake - package configuration file -Get_Filename_Component ( CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH ) -Include ( ${CURRENT_DIR}/cppcore.cmake ) +Include ( FindPackageHandleStandardArgs ) +Set ( ${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE} ) +Find_Package_Handle_Standard_Args ( cppcore CONFIG_MODE ) +Include ( "${CMAKE_CURRENT_LIST_DIR}/cppcore.cmake") diff --git a/cmake/cppcore-options.cmake b/cmake/cppcore-options.cmake new file mode 100644 index 0000000..f86a19d --- /dev/null +++ b/cmake/cppcore-options.cmake @@ -0,0 +1,6 @@ +Option ( CPPCORE_INSTALL_HEADER + "Install headers of cppcore." + ON ) +Option ( CPPCORE_USE_GIT_VERSION + "Read the git tags to get the version of cppcore" + ON ) diff --git a/cmake/cppcore-var.cmake b/cmake/cppcore-var.cmake index 70b75e6..98af065 100644 --- a/cmake/cppcore-var.cmake +++ b/cmake/cppcore-var.cmake @@ -1,20 +1,44 @@ # Version -Set ( CPPCORE_VERSION_MAJOR 1 ) -Set ( CPPCORE_VERSION_MINOR 0 ) -Set ( CPPCORE_VERSION_PATCH 0 ) -Set ( CPPCORE_VERSION_BUILD 0 ) -Set ( CPPCORE_VERSION_SHORT "${CPPCORE_VERSION_MAJOR}.${CPPCORE_VERSION_MINOR}" ) -Set ( CPPCORE_VERSION "${CPPCORE_VERSION_SHORT}.${CPPCORE_VERSION_PATCH}.${CPPCORE_VERSION_BUILD}" ) -Set ( CPPCORE_NAME "cppcore-${CPPCORE_VERSION_SHORT}" ) -Set ( CPPCORE_OUTPUTNAME "helloworld" ) +Set ( CPPCORE_VERSION_MAJOR 1 ) +Set ( CPPCORE_VERSION_MINOR 0 ) +Set ( CPPCORE_VERSION_PATCH 0 ) +Set ( CPPCORE_VERSION_BUILD 0 ) +Set ( CPPCORE_VERSION_HASH "" ) +Set ( CPPCORE_VERSION_BEHIND 0 ) +Set ( CPPCORE_VERSION_DIRTY 0 ) + +# Git Version +If ( CPPCORE_USE_GIT_VERSION ) + Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) + If ( HAS_GIT_HELPER ) + GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/.. + CPPCORE_VERSION_MAJOR + CPPCORE_VERSION_MINOR + CPPCORE_VERSION_PATCH + CPPCORE_VERSION_BUILD + CPPCORE_VERSION_HASH + CPPCORE_VERSION_BEHIND + CPPCORE_VERSION_DIRTY ) + EndIf ( ) +EndIf ( ) + +# Strings +Set ( CPPCORE_VERSION_SHORT "${CPPCORE_VERSION_MAJOR}.${CPPCORE_VERSION_MINOR}" ) +Set ( CPPCORE_VERSION "${CPPCORE_VERSION_SHORT}.${CPPCORE_VERSION_PATCH}.${CPPCORE_VERSION_BUILD}" ) +Set ( CPPCORE_VERSION_COMPLETE "${CPPCORE_VERSION}" ) +Set ( CPPCORE_NAME "cppcore-${CPPCORE_VERSION_SHORT}" ) +Set ( CPPCORE_OUTPUTNAME "cppcore" ) +If ( CPPCORE_VERSION_BEHIND ) + Set ( CPPCORE_VERSION_COMPLETE "${CPPCORE_VERSION_COMPLETE}+${CPPCORE_VERSION_BEHIND}" ) +EndIf ( ) # Install directories -Set ( CPPCORE_INSTALL_DIR_INCLUDE "include/${CPPCORE_NAME}" ) -Set ( CPPCORE_INSTALL_DIR_LIB "lib" ) -Set ( CPPCORE_INSTALL_DIR_SHARE "share/${CPPCORE_NAME}" ) +Set ( CPPCORE_INSTALL_DIR_INCLUDE "include/${CPPCORE_NAME}" ) +Set ( CPPCORE_INSTALL_DIR_LIB "lib" ) +Set ( CPPCORE_INSTALL_DIR_SHARE "share/${CPPCORE_NAME}" ) # C Standard -Set ( CMAKE_C_STANDARD 11 ) -Set ( CMAKE_CXX_STANDARD 17 ) -Set ( CMAKE_C_STANDARD_REQUIRED ON ) -Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) +Set ( CMAKE_C_STANDARD 11 ) +Set ( CMAKE_CXX_STANDARD 17 ) +Set ( CMAKE_C_STANDARD_REQUIRED ON ) +Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) diff --git a/cmake/modules b/cmake/modules index 1a32531..4953cd4 160000 --- a/cmake/modules +++ b/cmake/modules @@ -1 +1 @@ -Subproject commit 1a32531aef2deeebd5637b1873bc4e976628801c +Subproject commit 4953cd4cc849afdfa02a6057b5a2011fb62e91a6 diff --git a/include/cppcore/misc/vector_streambuf.inl b/include/cppcore/misc/vector_streambuf.inl index 19890cf..356a2ce 100644 --- a/include/cppcore/misc/vector_streambuf.inl +++ b/include/cppcore/misc/vector_streambuf.inl @@ -31,7 +31,7 @@ namespace cppcore _buffer = std::forward(v); auto beg = reinterpret_cast(&_buffer.front()); auto end = beg + _buffer.size(); - this->setp(beg, end); + this->setp(end, end); this->setg(beg, beg, end); } @@ -53,8 +53,8 @@ namespace cppcore ::underflow() { auto gpos = static_cast(this->gptr() - this->eback()); - this->setg(this->pbase(), this->pbase() + gpos, this->pptr()); - if (this->gptr() == this->pptr()) + this->setg(this->eback(), this->eback() + gpos, this->pptr()); + if (this->gptr() == this->egptr()) return traits_type::eof(); auto ret = static_cast(*this->gptr()); return ret; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 350bf52..0a68ef3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,10 +16,12 @@ Target_Include_Directories ( cppcore # Install ######################################################################################### # Header -Install ( FILES ${CPPCORE_INCLUDE_DIR}/cppcore.h - DESTINATION ${CPPCORE_INSTALL_DIR_INCLUDE} ) -Install ( DIRECTORY ${CPPCORE_INCLUDE_DIR}/cppcore - DESTINATION ${CPPCORE_INSTALL_DIR_INCLUDE} ) -Install ( TARGETS cppcore - EXPORT cppcore - DESTINATION ${CPPCORE_INSTALL_DIR_INCLUDE} ) +If ( CPPCORE_INSTALL_HEADER ) + Install ( FILES ${CPPCORE_INCLUDE_DIR}/cppcore.h + DESTINATION ${CPPCORE_INSTALL_DIR_INCLUDE} ) + Install ( DIRECTORY ${CPPCORE_INCLUDE_DIR}/cppcore + DESTINATION ${CPPCORE_INSTALL_DIR_INCLUDE} ) + Install ( TARGETS cppcore + EXPORT cppcore + DESTINATION ${CPPCORE_INSTALL_DIR_INCLUDE} ) +EndIf ( ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ec69fff..36702e5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,34 +11,47 @@ If ( NOT "${GTest_FOUND}" ) Return ( ) EndIf ( ) -File ( GLOB_RECURSE CPPCORE_TEST_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) -File ( GLOB_RECURSE CPPCORE_TEST_INLINE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) -File ( GLOB_RECURSE CPPCORE_TEST_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) - -Add_Executable ( cppcore-test - EXCLUDE_FROM_ALL - ${CPPCORE_TEST_HEADER_FILES} - ${CPPCORE_TEST_INLINE_FILES} - ${CPPCORE_TEST_SOURCE_FILES} ) -Target_Link_Libraries ( cppcore-test - PUBLIC - cppcore - GTest::Main ) - -# optimization -If ( HAS_COTIRE ) - Cotire ( cppcore-test ) -EndIf ( ) - -# pedantic -If ( HAS_PEDANTIC ) - Pedantic_Apply_Flags_Target ( cppcore-test - ALL ) -EndIf ( ) - -# test -If ( HAS_CMAKE_TESTS ) - Add_CMake_Test ( NAME cppcore TARGET cppcore-test ) -Else ( ) - Add_Test ( NAME cppcore COMMAND cppcore-test ) -EndIf ( ) +File ( GLOB_RECURSE CPPCORE_TEST_HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) +File ( GLOB_RECURSE CPPCORE_TEST_INLINE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) +File ( GLOB_RECURSE CPPCORE_TEST_SOURCE_FILES + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) + +ForEach ( FILE IN LISTS CPPCORE_TEST_SOURCE_FILES ) + # add test + Get_Filename_Component ( TEST_DIR ${FILE} DIRECTORY ) + Get_Filename_Component ( TEST_NAME ${FILE} NAME_WE ) + Set ( TEST_NAME "${TEST_DIR}/${TEST_NAME}" ) + String ( REPLACE "\\" "-" TEST_NAME "${TEST_NAME}" ) + String ( REPLACE "/" "-" TEST_NAME "${TEST_NAME}" ) + String ( REPLACE "_" "-" TEST_NAME "${TEST_NAME}" ) + Set ( TEST_NAME "test-${TEST_NAME}" ) + Add_Executable ( ${TEST_NAME} + EXCLUDE_FROM_ALL + ${CPPCORE_TEST_HEADER_FILES} + ${CPPCORE_TEST_INLINE_FILES} + ${FILE} ) + Target_Link_Libraries ( ${TEST_NAME} + PUBLIC + cppcore + GTest::Main ) + + # pedantic + If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) + EndIf ( ) + + # optimization + If ( HAS_COTIRE ) + Cotire ( ${TEST_NAME} ) + EndIf ( ) + + # test + If ( HAS_CMAKE_TESTS ) + Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} ) + Else ( ) + Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + EndIf ( ) +EndForEach ( )