From 84ea5dcfb93e8cf7c465e177ce3ce53292b202da Mon Sep 17 00:00:00 2001 From: bergmann Date: Thu, 1 Aug 2019 19:45:25 +0200 Subject: [PATCH] * Updated project structure --- .gitignore | 1 + .gitmodules | 4 +- CMakeLists.txt | 2 +- cmake/cppcurl-config.cmake | 5 +- cmake/cppcurl-options.cmake | 3 + cmake/cppcurl-var.cmake | 65 +++++++++------- cmake/modules | 2 +- include/cppcurl/exception.inl | 2 +- test/CMakeLists.txt | 74 +++++++++++-------- .../{cppcurl-tests.cpp => cppcurl_tests.cpp} | 2 +- 10 files changed, 95 insertions(+), 65 deletions(-) create mode 100644 .gitignore rename test/cppcurl/{cppcurl-tests.cpp => cppcurl_tests.cpp} (79%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f65519e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/** diff --git a/.gitmodules b/.gitmodules index bd7cbfa..a89889c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "/home/bergmann/projects/dnpnode/projects/cppcurl/cmake/modules"] - path = /home/bergmann/projects/dnpnode/projects/cppcurl/cmake/modules +[submodule "cmake/modules"] + path = cmake/modules url = b3rgmann@git.bergmann89.de:cpp/CmakeModules.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 983444d..0141ffa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,8 +20,8 @@ EndIf ( ) # Project ######################################################################################### -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppcurl-var.cmake ) Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppcurl-options.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppcurl-var.cmake ) Project ( cppcurl DESCRIPTION "A simple library" VERSION "${CPPCURL_VERSION}" ) diff --git a/cmake/cppcurl-config.cmake b/cmake/cppcurl-config.cmake index ad9c6d9..5602dcf 100644 --- a/cmake/cppcurl-config.cmake +++ b/cmake/cppcurl-config.cmake @@ -1,8 +1,7 @@ # cppcurl-config.cmake - package configuration file -Message ( WARNING "Please configure the dependencies of this package!" ) -# Include ( CMakeFindDependencyMacro ) -# Find_Dependency ( ) +Include ( CMakeFindDependencyMacro ) +Find_Dependency ( CURL ) Include ( FindPackageHandleStandardArgs ) Set ( ${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE} ) diff --git a/cmake/cppcurl-options.cmake b/cmake/cppcurl-options.cmake index 0e5f1a8..c4db833 100644 --- a/cmake/cppcurl-options.cmake +++ b/cmake/cppcurl-options.cmake @@ -13,3 +13,6 @@ Option ( CPPCURL_INSTALL_DEBUG Option ( CPPCURL_NO_STRIP "Do not strip debug symbols from binary." OFF ) +Option ( CPPCURL_USE_GIT_VERSION + "Read the git tags to get the version of cppcurl" + ON ) diff --git a/cmake/cppcurl-var.cmake b/cmake/cppcurl-var.cmake index 44bb3c2..490f1f2 100644 --- a/cmake/cppcurl-var.cmake +++ b/cmake/cppcurl-var.cmake @@ -1,31 +1,44 @@ # Version -Set ( CPPCURL_VERSION_MAJOR 1 ) -Set ( CPPCURL_VERSION_MINOR 0 ) -Set ( CPPCURL_VERSION_PATCH 0 ) -Set ( CPPCURL_VERSION_BUILD 0 ) -Set ( CPPCURL_VERSION_SHORT "${CPPCURL_VERSION_MAJOR}.${CPPCURL_VERSION_MINOR}" ) -Set ( CPPCURL_VERSION "${CPPCURL_VERSION_SHORT}.${CPPCURL_VERSION_PATCH}.${CPPCURL_VERSION_BUILD}" ) -Set ( CPPCURL_NAME "cppcurl-${CPPCURL_VERSION_SHORT}" ) -Set ( CPPCURL_OUTPUTNAME "cppcurl" ) +Set ( CPPCURL_VERSION_MAJOR 1 ) +Set ( CPPCURL_VERSION_MINOR 0 ) +Set ( CPPCURL_VERSION_PATCH 0 ) +Set ( CPPCURL_VERSION_BUILD 0 ) +Set ( CPPCURL_VERSION_HASH "" ) +Set ( CPPCURL_VERSION_BEHIND 0 ) +Set ( CPPCURL_VERSION_DIRTY 0 ) + +# Git Version +If ( CPPCURL_USE_GIT_VERSION ) + Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) + If ( HAS_GIT_HELPER ) + GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/.. + CPPCURL_VERSION_MAJOR + CPPCURL_VERSION_MINOR + CPPCURL_VERSION_PATCH + CPPCURL_VERSION_BUILD + CPPCURL_VERSION_HASH + CPPCURL_VERSION_BEHIND + CPPCURL_VERSION_DIRTY ) + EndIf ( ) +EndIf ( ) + +# Strings +Set ( CPPCURL_VERSION_SHORT "${CPPCURL_VERSION_MAJOR}.${CPPCURL_VERSION_MINOR}" ) +Set ( CPPCURL_VERSION "${CPPCURL_VERSION_SHORT}.${CPPCURL_VERSION_PATCH}.${CPPCURL_VERSION_BUILD}" ) +Set ( CPPCURL_VERSION_COMPLETE "${CPPCURL_VERSION}" ) +Set ( CPPCURL_NAME "cppcurl-${CPPCURL_VERSION_SHORT}" ) +Set ( CPPCURL_OUTPUTNAME "cppcurl" ) +If ( CPPCURL_VERSION_BEHIND ) + Set ( CPPCURL_VERSION_COMPLETE "${CPPCURL_VERSION_COMPLETE}+${CPPCURL_VERSION_BEHIND}" ) +EndIf ( ) # Install directories -Set ( CPPCURL_INSTALL_DIR_INCLUDE "include/${CPPCURL_NAME}" ) -Set ( CPPCURL_INSTALL_DIR_LIB "lib" ) -Set ( CPPCURL_INSTALL_DIR_SHARE "share/${CPPCURL_NAME}" ) +Set ( CPPCURL_INSTALL_DIR_INCLUDE "include/${CPPCURL_NAME}" ) +Set ( CPPCURL_INSTALL_DIR_LIB "lib" ) +Set ( CPPCURL_INSTALL_DIR_SHARE "share/${CPPCURL_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 ) - -# Git Version -Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) -If ( HAS_GIT_HELPER ) - GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/.. - CPPCURL_VERSION_MAJOR - CPPCURL_VERSION_MINOR - CPPCURL_VERSION_PATCH - CPPCURL_VERSION_BUILD - CPPCURL_VERSION_HASH ) -EndIf ( ) +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 a50f650..4953cd4 160000 --- a/cmake/modules +++ b/cmake/modules @@ -1 +1 @@ -Subproject commit a50f6505f4989b1d96449ba7cd498f8bf2880427 +Subproject commit 4953cd4cc849afdfa02a6057b5a2011fb62e91a6 diff --git a/include/cppcurl/exception.inl b/include/cppcurl/exception.inl index a0b537f..0bc8d49 100644 --- a/include/cppcurl/exception.inl +++ b/include/cppcurl/exception.inl @@ -65,7 +65,7 @@ namespace cppcurl ::exception(T_error err, const std::string& msg) : _what (__impl::get_error_str()(err) + "(" + std::to_string(static_cast(err)) + "): " + msg) , error (err) - , error_str (get_error_str()(err)) + , error_str (__impl::get_error_str()(err)) { } template diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 85d0848..ad6c3ab 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,33 +11,47 @@ If ( NOT "${GTest_FOUND}" ) Return ( ) EndIf ( ) -File ( GLOB_RECURSE CPPCURL_TEST_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) -File ( GLOB_RECURSE CPPCURL_TEST_INLINE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) -File ( GLOB_RECURSE CPPCURL_TEST_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) - -Add_Executable ( cppcurl-test - EXCLUDE_FROM_ALL - ${CPPCURL_TEST_HEADER_FILES} - ${CPPCURL_TEST_INLINE_FILES} - ${CPPCURL_TEST_SOURCE_FILES} ) -Target_Link_Libraries ( cppcurl-test - PUBLIC - cppcurl - GTest::Main ) - -# pedantic -If ( HAS_PEDANTIC ) - Pedantic_Apply_Flags_Target ( cppcurl-test ALL ) -EndIf ( ) - -# optimization -If ( HAS_COTIRE ) - Cotire ( cppcurl-test ) -EndIf ( ) - -# test -If ( HAS_CMAKE_TESTS ) - Add_CMake_Test ( NAME cppcurl TARGET cppcurl-test ) -Else ( ) - Add_Test ( NAME cppcurl COMMAND cppcurl-test ) -EndIf ( ) +File ( GLOB_RECURSE CPPCURL_TEST_HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) +File ( GLOB_RECURSE CPPCURL_TEST_INLINE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) +File ( GLOB_RECURSE CPPCURL_TEST_SOURCE_FILES + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) + +ForEach ( FILE IN LISTS CPPCURL_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 + ${CPPCURL_TEST_HEADER_FILES} + ${CPPCURL_TEST_INLINE_FILES} + ${FILE} ) + Target_Link_Libraries ( ${TEST_NAME} + PUBLIC + cppcurl + 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 ( ) diff --git a/test/cppcurl/cppcurl-tests.cpp b/test/cppcurl/cppcurl_tests.cpp similarity index 79% rename from test/cppcurl/cppcurl-tests.cpp rename to test/cppcurl/cppcurl_tests.cpp index 0f3a5ae..283969d 100644 --- a/test/cppcurl/cppcurl-tests.cpp +++ b/test/cppcurl/cppcurl_tests.cpp @@ -5,6 +5,6 @@ using namespace ::testing; using namespace ::cppcurl; -TEST(cppcurl, dummy) +TEST(cppcurl_tests, dummy) { }