From 9968da9cf94fd3df0209c1f87753f4ca5e0710ac Mon Sep 17 00:00:00 2001 From: bergmann Date: Thu, 1 Aug 2019 20:32:30 +0200 Subject: [PATCH] * Updated project structure --- .gitmodules | 4 +- CMakeLists.txt | 2 +- cmake/cppmicrohttpd-config.cmake | 5 +-- cmake/cppmicrohttpd-options.cmake | 6 +++ cmake/cppmicrohttpd-var.cmake | 65 +++++++++++++++++------------ test/CMakeLists.txt | 68 +++++++++++++++++++------------ 6 files changed, 91 insertions(+), 59 deletions(-) diff --git a/.gitmodules b/.gitmodules index 914806d..a89889c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "/home/bergmann/projects/dnpnode/projects/cppmicrohttpd/cmake/modules"] - path = /home/bergmann/projects/dnpnode/projects/cppmicrohttpd/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 5d31d1c..c0b0a19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,8 +20,8 @@ EndIf ( ) # Project ######################################################################################### -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppmicrohttpd-var.cmake ) Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppmicrohttpd-options.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppmicrohttpd-var.cmake ) Project ( cppmicrohttpd DESCRIPTION "A simple library" VERSION "${CPPMICROHTTPD_VERSION}" ) diff --git a/cmake/cppmicrohttpd-config.cmake b/cmake/cppmicrohttpd-config.cmake index 04d4c73..b69b68e 100644 --- a/cmake/cppmicrohttpd-config.cmake +++ b/cmake/cppmicrohttpd-config.cmake @@ -1,8 +1,7 @@ # cppmicrohttpd-config.cmake - package configuration file -Message ( WARNING "Please configure the dependencies of this package!" ) -# Include ( CMakeFindDependencyMacro ) -# Find_Dependency ( ) +Include ( CMakeFindDependencyMacro ) +Find_Dependency ( cppcore libmicrohttpd ) Include ( FindPackageHandleStandardArgs ) Set ( ${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE} ) diff --git a/cmake/cppmicrohttpd-options.cmake b/cmake/cppmicrohttpd-options.cmake index 2d10276..f2727a0 100644 --- a/cmake/cppmicrohttpd-options.cmake +++ b/cmake/cppmicrohttpd-options.cmake @@ -10,6 +10,12 @@ Option ( CPPMICROHTTPD_INSTALL_SHARED Option ( CPPMICROHTTPD_INSTALL_DEBUG "Install the stripped debug informations of cppmicrohttpd." OFF ) +Option ( CPPMICROHTTPD_NO_STRIP + "Do not strip debug symbols from binary." + OFF ) +Option ( CPPMICROHTTPD_USE_GIT_VERSION + "Read the git tags to get the version of cppmicrohttpd" + ON ) If ( NOT CPPMICROHTTPD_LOGGING ) Set ( CPPMICROHTTPD_LOGGING none CACHE STRING "Specify how cppmicrohttpd should write log entries." ) diff --git a/cmake/cppmicrohttpd-var.cmake b/cmake/cppmicrohttpd-var.cmake index 6b8a2f6..6675c89 100644 --- a/cmake/cppmicrohttpd-var.cmake +++ b/cmake/cppmicrohttpd-var.cmake @@ -1,31 +1,44 @@ # Version -Set ( CPPMICROHTTPD_VERSION_MAJOR 1 ) -Set ( CPPMICROHTTPD_VERSION_MINOR 0 ) -Set ( CPPMICROHTTPD_VERSION_PATCH 0 ) -Set ( CPPMICROHTTPD_VERSION_BUILD 0 ) -Set ( CPPMICROHTTPD_VERSION_SHORT "${CPPMICROHTTPD_VERSION_MAJOR}.${CPPMICROHTTPD_VERSION_MINOR}" ) -Set ( CPPMICROHTTPD_VERSION "${CPPMICROHTTPD_VERSION_SHORT}.${CPPMICROHTTPD_VERSION_PATCH}.${CPPMICROHTTPD_VERSION_BUILD}" ) -Set ( CPPMICROHTTPD_NAME "cppmicrohttpd-${CPPMICROHTTPD_VERSION_SHORT}" ) -Set ( CPPMICROHTTPD_OUTPUTNAME "cppmicrohttpd" ) +Set ( CPPMICROHTTPD_VERSION_MAJOR 1 ) +Set ( CPPMICROHTTPD_VERSION_MINOR 0 ) +Set ( CPPMICROHTTPD_VERSION_PATCH 0 ) +Set ( CPPMICROHTTPD_VERSION_BUILD 0 ) +Set ( CPPMICROHTTPD_VERSION_HASH "" ) +Set ( CPPMICROHTTPD_VERSION_BEHIND 0 ) +Set ( CPPMICROHTTPD_VERSION_DIRTY 0 ) + +# Git Version +If ( CPPMICROHTTPD_USE_GIT_VERSION ) + Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) + If ( HAS_GIT_HELPER ) + GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/.. + CPPMICROHTTPD_VERSION_MAJOR + CPPMICROHTTPD_VERSION_MINOR + CPPMICROHTTPD_VERSION_PATCH + CPPMICROHTTPD_VERSION_BUILD + CPPMICROHTTPD_VERSION_HASH + CPPMICROHTTPD_VERSION_BEHIND + CPPMICROHTTPD_VERSION_DIRTY ) + EndIf ( ) +EndIf ( ) + +# Strings +Set ( CPPMICROHTTPD_VERSION_SHORT "${CPPMICROHTTPD_VERSION_MAJOR}.${CPPMICROHTTPD_VERSION_MINOR}" ) +Set ( CPPMICROHTTPD_VERSION "${CPPMICROHTTPD_VERSION_SHORT}.${CPPMICROHTTPD_VERSION_PATCH}.${CPPMICROHTTPD_VERSION_BUILD}" ) +Set ( CPPMICROHTTPD_VERSION_COMPLETE "${CPPMICROHTTPD_VERSION}" ) +Set ( CPPMICROHTTPD_NAME "cppmicrohttpd-${CPPMICROHTTPD_VERSION_SHORT}" ) +Set ( CPPMICROHTTPD_OUTPUTNAME "cppmicrohttpd" ) +If ( CPPMICROHTTPD_VERSION_BEHIND ) + Set ( CPPMICROHTTPD_VERSION_COMPLETE "${CPPMICROHTTPD_VERSION_COMPLETE}+${CPPMICROHTTPD_VERSION_BEHIND}" ) +EndIf ( ) # Install directories -Set ( CPPMICROHTTPD_INSTALL_DIR_INCLUDE "include/${CPPMICROHTTPD_NAME}" ) -Set ( CPPMICROHTTPD_INSTALL_DIR_LIB "lib" ) -Set ( CPPMICROHTTPD_INSTALL_DIR_SHARE "share/${CPPMICROHTTPD_NAME}" ) +Set ( CPPMICROHTTPD_INSTALL_DIR_INCLUDE "include/${CPPMICROHTTPD_NAME}" ) +Set ( CPPMICROHTTPD_INSTALL_DIR_LIB "lib" ) +Set ( CPPMICROHTTPD_INSTALL_DIR_SHARE "share/${CPPMICROHTTPD_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}/.. - CPPMICROHTTPD_VERSION_MAJOR - CPPMICROHTTPD_VERSION_MINOR - CPPMICROHTTPD_VERSION_PATCH - CPPMICROHTTPD_VERSION_BUILD - CPPMICROHTTPD_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/test/CMakeLists.txt b/test/CMakeLists.txt index 4986603..1c9d275 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,33 +27,47 @@ Target_Link_Libraries ( cppmicrohttpd-test-helper # Test ############################################################################################ -File ( GLOB_RECURSE CPPMICROHTTPD_TEST_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cppmicrohttpd/*.h ) -File ( GLOB_RECURSE CPPMICROHTTPD_TEST_INLINE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cppmicrohttpd/*.inl ) -File ( GLOB_RECURSE CPPMICROHTTPD_TEST_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cppmicrohttpd/*.cpp ) - -Add_Executable ( cppmicrohttpd-test - EXCLUDE_FROM_ALL - ${CPPMICROHTTPD_TEST_HEADER_FILES} - ${CPPMICROHTTPD_TEST_INLINE_FILES} - ${CPPMICROHTTPD_TEST_SOURCE_FILES} ) -Target_Link_Libraries ( cppmicrohttpd-test - PUBLIC - cppmicrohttpd-test-helper - GTest::Main ) +File ( GLOB_RECURSE CPPMICROHTTPD_TEST_HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) +File ( GLOB_RECURSE CPPMICROHTTPD_TEST_INLINE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) +File ( GLOB_RECURSE CPPMICROHTTPD_TEST_SOURCE_FILES + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/cppmicrohttpd/*.cpp ) -# pedantic -If ( HAS_PEDANTIC ) - Pedantic_Apply_Flags_Target ( cppmicrohttpd-test ALL ) -EndIf ( ) +ForEach ( FILE IN LISTS CPPMICROHTTPD_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 + ${CPPMICROHTTPD_TEST_HEADER_FILES} + ${CPPMICROHTTPD_TEST_INLINE_FILES} + ${FILE} ) + Target_Link_Libraries ( ${TEST_NAME} + PUBLIC + cppmicrohttpd-test-helper + GMock::Main ) -# optimization -If ( HAS_COTIRE ) - Cotire ( cppmicrohttpd-test ) -EndIf ( ) + # pedantic + If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) + EndIf ( ) -# test -If ( HAS_CMAKE_TESTS ) - Add_CMake_Test ( NAME cppmicrohttpd TARGET cppmicrohttpd-test ) -Else ( ) - Add_Test ( NAME cppmicrohttpd COMMAND cppmicrohttpd-test ) -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 ( )