diff --git a/CMakeLists.txt b/CMakeLists.txt index 184d2f4..774b6bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,31 @@ # Initialize CMake ################################################################################ -CMake_Minimum_Required ( VERSION 3.12.0 FATAL_ERROR ) +CMake_Minimum_Required ( VERSION 3.12.0 FATAL_ERROR ) -# Set CMAKE_BUILD_TYPE -If ( NOT CMAKE_BUILD_TYPE ) - Set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build!" FORCE ) -EndIf ( NOT CMAKE_BUILD_TYPE ) -Set_Property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel ) +Project ( TestProject ) -# Set CMAKE_MODULE_PATH -If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) - Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) -EndIf ( ) +# CMAKE_BUILD_TYPE +If ( NOT CMAKE_BUILD_TYPE ) + Set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build!" FORCE ) +EndIf ( ) +Set_Property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel ) -If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) - Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) -EndIf ( ) +# CMAKE_MODULE_PATH +If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) + Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) +EndIf ( ) + +If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) + Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) +EndIf ( ) # Includes -Include ( CTest ) -Include ( GNUInstallDirs ) +Include ( CTest ) +Include ( GNUInstallDirs ) # Projects ######################################################################################## -Message ( WARNING "Please configure the subprojects of this project group!" ) -# Find_Package ( ) +Message ( FATAL_ERROR "Please configure the subprojects of this project group!" ) +Find_Package ( helloworld REQUIRED ) +Find_Package ( libhelloworld REQUIRED ) +Find_Package ( libinterface REQUIRED ) diff --git a/README.md b/README.md index b5dac37..fa8562a 100644 --- a/README.md +++ b/README.md @@ -1 +1,57 @@ -TODO: write a docu :) +# New Group + +Create a new project group + +```console +$ tool \ + --verbose \ + --modules \ + --group +``` + +# New Executable + +Add a new executable to an existing project group + +```console +$ tool \ + --verbose \ + --modules \ + --executable +``` + +# New Library + +Add a new library to an existing project group + +```console +$ tool \ + --verbose \ + --modules \ + --library +``` + +# New Interface Library + +Add a new interface library to an existing project group + +```console +$ tool \ + --verbose \ + --modules \ + --interface +``` + +# All in One + +You can generate all in one by specifying multiple project or group arguments + +```console +$ tool \ + --verbose \ + --modules \ + --group /tmp/fuu \ + --executable myexe /tmp/fuu \ + --library mylib /tmp/fuu \ + --interface myintf /tmp/fuu +``` diff --git a/cmake/Findhelloworld.cmake b/cmake/Findhelloworld.cmake new file mode 100644 index 0000000..918bb30 --- /dev/null +++ b/cmake/Findhelloworld.cmake @@ -0,0 +1,6 @@ +Include ( ${CMAKE_CURRENT_LIST_DIR}/modules/cmake/find_local_module.cmake ) +FindLocalModule ( helloworld ${CMAKE_CURRENT_LIST_DIR}/../projects/helloworld ) + +If ( NOT TARGET helloworld::helloworld-objects ) + Add_Library ( helloworld::helloworld-objects ALIAS helloworld-objects ) +EndIf ( ) diff --git a/cmake/Findlibhelloworld.cmake b/cmake/Findlibhelloworld.cmake new file mode 100644 index 0000000..f82525b --- /dev/null +++ b/cmake/Findlibhelloworld.cmake @@ -0,0 +1,10 @@ +Include ( ${CMAKE_CURRENT_LIST_DIR}/modules/cmake/find_local_module.cmake ) +FindLocalModule ( libhelloworld ${CMAKE_CURRENT_LIST_DIR}/../projects/libhelloworld ) + +If ( NOT TARGET libhelloworld::libhelloworld-static ) + Add_Library ( libhelloworld::libhelloworld-static ALIAS libhelloworld-static ) +EndIf ( ) + +If ( NOT TARGET libhelloworld::libhelloworld-shared ) + Add_Library ( libhelloworld::libhelloworld-shared ALIAS libhelloworld-shared ) +EndIf ( ) diff --git a/cmake/Findlibinterface.cmake b/cmake/Findlibinterface.cmake new file mode 100644 index 0000000..4831096 --- /dev/null +++ b/cmake/Findlibinterface.cmake @@ -0,0 +1,6 @@ +Include ( ${CMAKE_CURRENT_LIST_DIR}/modules/cmake/find_local_module.cmake ) +FindLocalModule ( libinterface ${CMAKE_CURRENT_LIST_DIR}/../projects/libinterface ) + +If ( NOT TARGET libinterface::libinterface ) + Add_Library ( libinterface::libinterface ALIAS libinterface ) +EndIf ( ) diff --git a/cmake/modules b/cmake/modules index 94b9877..f1ff5b9 160000 --- a/cmake/modules +++ b/cmake/modules @@ -1 +1 @@ -Subproject commit 94b9877d65e46c9d8169ebc46f163d02e4d9dcf3 +Subproject commit f1ff5b9d65609f2a9e09b9dd3f3e18aac69e02c8 diff --git a/projects/helloworld/CMakeLists.txt b/projects/helloworld/CMakeLists.txt index ba741d5..0e4aa4d 100644 --- a/projects/helloworld/CMakeLists.txt +++ b/projects/helloworld/CMakeLists.txt @@ -1,34 +1,176 @@ # Initialize CMake ################################################################################ -CMake_Minimum_Required ( VERSION 3.12.0 FATAL_ERROR ) - -# Set CMAKE_BUILD_TYPE -If ( NOT CMAKE_BUILD_TYPE ) - Set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build!" FORCE ) -EndIf ( NOT CMAKE_BUILD_TYPE ) -Set_Property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel ) - -# Set CMAKE_MODULE_PATH -If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) - Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) -EndIf ( ) -If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) - Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) -EndIf ( ) +CMake_Minimum_Required ( VERSION 3.12.0 FATAL_ERROR ) + +# CMAKE_BUILD_TYPE +If ( NOT CMAKE_BUILD_TYPE ) + Set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build!" FORCE ) +EndIf ( ) +Set_Property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel ) + +# CMAKE_MODULE_PATH +If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) + Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) +EndIf ( ) + +If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) + Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) +EndIf ( ) # Project ######################################################################################### -Include ( GNUInstallDirs ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/helloworld-options.cmake ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/helloworld-const.cmake ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/helloworld-var.cmake ) -Project ( ${HELLOWORLD_PROJECT_NAME} - DESCRIPTION "${HELLOWORLD_PROJECT_DESCRIPTION}" - VERSION "${HELLOWORLD_VERSION}" ) -Include ( CTest ) - -# Subdirectories -Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/src ) -Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/test ) +Include ( GNUInstallDirs ) + +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/helloworld-options.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/helloworld-const.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/helloworld-var.cmake ) + +Project ( ${HELLOWORLD_PROJECT_NAME} + DESCRIPTION "${HELLOWORLD_PROJECT_DESCRIPTION}" + VERSION "${HELLOWORLD_VERSION}" ) + +Include ( CTest ) + +# Initialize ###################################################################################### + +Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) +Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) +Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) +Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) + +Find_Package ( GTest QUIET ) +Find_Package ( Sanitizers QUIET ) + +Message ( FATAL_ERROR "Please configure the dependencies of this project!" ) +Find_Package ( libhelloworld REQUIRED ${HELLOWORLD_FIND_PACKAGE_EXTRA_ARGS} ) + +# Object Library ################################################################################## + +Set ( HELLOWORLD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" ) +Set ( HELLOWORLD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" ) +Set ( HELLOWORLD_MAIN_FILE "${HELLOWORLD_SOURCE_DIR}/main.cpp" ) + +File ( GLOB_RECURSE HELLOWORLD_HEADER_FILES "${HELLOWORLD_INCLUDE_DIR}/*.h" ) +File ( GLOB_RECURSE HELLOWORLD_INLINE_FILES "${HELLOWORLD_INCLUDE_DIR}/*.inl" ) +File ( GLOB_RECURSE HELLOWORLD_SOURCE_FILES "${HELLOWORLD_SOURCE_DIR}/*.cpp" ) + +File ( GLOB_RECURSE HELLOWORLD_TEST_HEADER_FILES "${HELLOWORLD_INCLUDE_DIR}/*.test.h" ) +File ( GLOB_RECURSE HELLOWORLD_TEST_INLINE_FILES "${HELLOWORLD_INCLUDE_DIR}/*.test.inl" ) +File ( GLOB_RECURSE HELLOWORLD_TEST_SOURCE_FILES "${HELLOWORLD_SOURCE_DIR}/*.test.cpp" ) + +ForEach ( TEST_FILE IN LISTS HELLOWORLD_TEST_HEADER_FILES ) + List ( REMOVE_ITEM HELLOWORLD_HEADER_FILES "${TEST_FILE}" ) +EndForEach ( ) + +ForEach ( TEST_FILE IN LISTS HELLOWORLD_TEST_INLINE_FILES ) + List ( REMOVE_ITEM HELLOWORLD_INLINE_FILES "${TEST_FILE}" ) +EndForEach ( ) + +List ( REMOVE_ITEM HELLOWORLD_SOURCE_FILES "${HELLOWORLD_MAIN_FILE}" ) +ForEach ( TEST_FILE IN LISTS HELLOWORLD_TEST_SOURCE_FILES ) + List ( REMOVE_ITEM HELLOWORLD_SOURCE_FILES "${TEST_FILE}" ) +EndForEach ( ) + +Add_Library ( + helloworld-objects + OBJECT + ${HELLOWORLD_HEADER_FILES} + ${HELLOWORLD_INLINE_FILES} + ${HELLOWORLD_SOURCE_FILES} ) +Target_Include_Directories ( + helloworld-objects + PUBLIC + $ + $ ) +Target_Link_Libraries ( + helloworld-objects + PUBLIC + libhelloworld::libhelloworld-shared ) + +# Executable ###################################################################################### + +Add_Executable ( helloworld "${HELLOWORLD_MAIN_FILE}" ) +Target_Link_Libraries ( + helloworld + PUBLIC + helloworld-objects ) + +# Tests ########################################################################################### + +If ( GTest_FOUND ) + ForEach ( FILE IN LISTS HELLOWORLD_TEST_SOURCE_FILES ) + + # Add Test + File ( RELATIVE_PATH RELFILE "${HELLOWORLD_SOURCE_DIR}" "${FILE}" ) + Get_Filename_Component ( TEST_DIR "${RELFILE}" DIRECTORY ) + Get_Filename_Component ( TEST_NAME "${RELFILE}" NAME_WE ) + Set ( TEST_NAME "${TEST_DIR}/${TEST_NAME}" ) + String ( REPLACE ".test" "" TEST_NAME "${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 + ${HELLOWORLD_TEST_HEADER_FILES} + ${HELLOWORLD_TEST_INLINE_FILES} + ${FILE} ) + Target_Link_Libraries ( ${TEST_NAME} + PUBLIC + helloworld-objects + GTest::Main ) + + # Sanitizers + If ( Sanitizers_FOUND ) + Add_Sanitizers ( ${TEST_NAME} ) + EndIf ( ) + + # pedantic + If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) + EndIf ( ) + + # test + If ( HAS_CMAKE_TESTS ) + Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} GROUP gedt ) + Else ( ) + Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + EndIf ( ) + EndForEach ( ) +EndIf ( ) + +# Optimization #################################################################################### + +# sanitizers +If ( Sanitizers_FOUND ) + Add_Sanitizers ( helloworld-objects ) + Add_Sanitizers ( helloworld ) +EndIf ( ) + +# pedantic +If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( helloworld-objects ALL ) + Pedantic_Apply_Flags_Target ( helloworld ALL ) +EndIf ( ) + +# cotire +If ( HAS_COTIRE ) + Cotire ( helloworld-objects ) + Cotire ( helloworld ) +EndIf ( ) + +# Install ######################################################################################### + +# Executable +Install ( TARGETS helloworld + DESTINATION ${HELLOWORLD_INSTALL_DIR_BIN} ) + +# Debug +If ( HAS_STRIP_SYMBOLS AND NOT HELLOWORLD_NO_STRIP ) + Strip_Symbols ( helloworld HELLOWORLD_DBG_FILE ) + If ( HELLOWORLD_INSTALL_DEBUG ) + Install ( FILES ${HELLOWORLD_DBG_FILE} + DESTINATION ${HELLOWORLD_INSTALL_DIR_LIB} ) + EndIf ( ) +EndIf ( ) diff --git a/projects/helloworld/cmake/helloworld-const.cmake b/projects/helloworld/cmake/helloworld-const.cmake index a0fe12a..58d3183 100644 --- a/projects/helloworld/cmake/helloworld-const.cmake +++ b/projects/helloworld/cmake/helloworld-const.cmake @@ -1,26 +1,27 @@ # This file contains constant variables that are fixed to this project # Version -Set ( HELLOWORLD_VERSION_MAJOR 1 ) -Set ( HELLOWORLD_VERSION_MINOR 0 ) -Set ( HELLOWORLD_VERSION_PATCH 0 ) -Set ( HELLOWORLD_VERSION_BUILD 0 ) -Set ( HELLOWORLD_VERSION_HASH "" ) -Set ( HELLOWORLD_VERSION_BEHIND 0 ) -Set ( HELLOWORLD_VERSION_DIRTY 0 ) +Set ( HELLOWORLD_VERSION_MAJOR 1 ) +Set ( HELLOWORLD_VERSION_MINOR 0 ) +Set ( HELLOWORLD_VERSION_PATCH 0 ) +Set ( HELLOWORLD_VERSION_BUILD 0 ) +Set ( HELLOWORLD_VERSION_BEHIND 0 ) +Set ( HELLOWORLD_VERSION_DIRTY 0 ) +Set ( HELLOWORLD_VERSION_HASH "notgit" ) +Set ( HELLOWORLD_VERSION_HASH_SHORT "notgit" ) # Names -Set ( HELLOWORLD_PROJECT_NAME "helloworld" ) -Set ( HELLOWORLD_PROJECT_DESCRIPTION "A simple hello world project" ) +Set ( HELLOWORLD_PROJECT_NAME "helloworld" ) +Set ( HELLOWORLD_PROJECT_DESCRIPTION "A simple hello world project" ) # Include generated variables for further usage -Include ( ${CMAKE_CURRENT_LIST_DIR}/helloworld-var.cmake ) +Include ( ${CMAKE_CURRENT_LIST_DIR}/helloworld-var.cmake ) # Install directories -Set ( HELLOWORLD_INSTALL_DIR_BIN "${CMAKE_INSTALL_BINDIR}" ) +Set ( HELLOWORLD_INSTALL_DIR_BIN "${CMAKE_INSTALL_BINDIR}" ) # 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 20 ) +Set ( CMAKE_C_STANDARD_REQUIRED ON ) +Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) diff --git a/projects/helloworld/cmake/helloworld-options.cmake b/projects/helloworld/cmake/helloworld-options.cmake index d6c8be9..3aeb5f2 100644 --- a/projects/helloworld/cmake/helloworld-options.cmake +++ b/projects/helloworld/cmake/helloworld-options.cmake @@ -1,11 +1,14 @@ # This file contains options that can be passed to the cmake command -Option ( HELLOWORLD_INSTALL_DEBUG - "Install the stripped debug informations of helloworld." - OFF ) -Option ( HELLOWORLD_NO_STRIP - "Do not strip debug symbols from helloworld binary." - OFF ) -Option ( HELLOWORLD_USE_GIT_VERSION - "Read the git tags to get the version of helloworld" - ON ) +Option ( HELLOWORLD_INSTALL_DEBUG + "Install the stripped debug informations of helloworld." + OFF ) +Option ( HELLOWORLD_NO_STRIP + "Do not strip debug symbols from helloworld binary." + OFF ) +Option ( HELLOWORLD_USE_GIT_VERSION + "Read the git tags to get the version of helloworld" + ON ) +Option ( HELLOWORLD_IGNORE_MODULES + "Use only config mode to find other packages" + OFF ) diff --git a/projects/helloworld/cmake/helloworld-var.cmake b/projects/helloworld/cmake/helloworld-var.cmake index ba937f1..de473ba 100644 --- a/projects/helloworld/cmake/helloworld-var.cmake +++ b/projects/helloworld/cmake/helloworld-var.cmake @@ -1,32 +1,34 @@ # This file contains generated variables that are needed for the project # Git Version -If ( HELLOWORLD_USE_GIT_VERSION ) - Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) - If ( HAS_GIT_HELPER ) - GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/.. - HELLOWORLD_VERSION_MAJOR - HELLOWORLD_VERSION_MINOR - HELLOWORLD_VERSION_PATCH - HELLOWORLD_VERSION_BUILD - HELLOWORLD_VERSION_HASH - HELLOWORLD_VERSION_BEHIND - HELLOWORLD_VERSION_DIRTY ) - EndIf ( ) -EndIf ( ) +If ( HELLOWORLD_USE_GIT_VERSION ) + Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) + If ( HAS_GIT_HELPER ) + GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/../../.. + HELLOWORLD_VERSION_MAJOR + HELLOWORLD_VERSION_MINOR + HELLOWORLD_VERSION_PATCH + HELLOWORLD_VERSION_BUILD + HELLOWORLD_VERSION_HASH + HELLOWORLD_VERSION_BEHIND + HELLOWORLD_VERSION_DIRTY ) + EndIf ( ) +EndIf ( ) # Strings -Set ( HELLOWORLD_VERSION_SHORT - "${HELLOWORLD_VERSION_MAJOR}.${HELLOWORLD_VERSION_MINOR}" ) -Set ( HELLOWORLD_VERSION - "${HELLOWORLD_VERSION_SHORT}.${HELLOWORLD_VERSION_PATCH}.${HELLOWORLD_VERSION_BUILD}" ) -Set ( HELLOWORLD_VERSION_COMPLETE - "${HELLOWORLD_VERSION}" ) -Set ( HELLOWORLD_NAME - "${HELLOWORLD_PROJECT_NAME}-${HELLOWORLD_VERSION_SHORT}" ) -Set ( HELLOWORLD_OUTPUTNAME - "${HELLOWORLD_PROJECT_NAME}" ) -If ( HELLOWORLD_VERSION_BEHIND ) - Set ( HELLOWORLD_VERSION_COMPLETE - "${HELLOWORLD_VERSION_COMPLETE}+${HELLOWORLD_VERSION_BEHIND}" ) -EndIf ( ) +Set ( HELLOWORLD_VERSION "${HELLOWORLD_VERSION_SHORT}.${HELLOWORLD_VERSION_PATCH}.${HELLOWORLD_VERSION_BUILD}" ) +Set ( HELLOWORLD_VERSION_SHORT "${HELLOWORLD_VERSION_MAJOR}.${HELLOWORLD_VERSION_MINOR}" ) +Set ( HELLOWORLD_VERSION_COMPLETE "${HELLOWORLD_VERSION}" ) +If ( HELLOWORLD_VERSION_BEHIND ) + Set ( HELLOWORLD_VERSION_COMPLETE "${HELLOWORLD_VERSION_COMPLETE}+${HELLOWORLD_VERSION_BEHIND}" ) +EndIf ( ) + +Set ( HELLOWORLD_NAME "${HELLOWORLD_PROJECT_NAME}-${HELLOWORLD_VERSION_SHORT}" ) +Set ( HELLOWORLD_OUTPUTNAME "${HELLOWORLD_PROJECT_NAME}" ) + +String ( SUBSTRING "${HELLOWORLD_VERSION_HASH}" 0 8 HELLOWORLD_VERSION_HASH_SHORT ) + +# Extra +If ( HELLOWORLD_IGNORE_MODULES ) + Set ( HELLOWORLD_FIND_PACKAGE_EXTRA_ARGS "CONFIG" ) +EndIf ( ) diff --git a/projects/helloworld/include/helloworld.h b/projects/helloworld/include/helloworld.h deleted file mode 100644 index 28807e7..0000000 --- a/projects/helloworld/include/helloworld.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include diff --git a/projects/helloworld/src/CMakeLists.txt b/projects/helloworld/src/CMakeLists.txt deleted file mode 100644 index d14dff8..0000000 --- a/projects/helloworld/src/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -# Initialize ###################################################################################### - -Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) -Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) -Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) - -Find_Package ( Sanitizers QUIET ) - -Message ( WARNING "Please configure the dependencies of this project!" ) -Find_Package ( libhelloworld REQUIRED ) - -# Object Library ################################################################################## - -Set ( HELLOWORLD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include ) -File ( GLOB_RECURSE HELLOWORLD_HEADER_FILES ${HELLOWORLD_INCLUDE_DIR}/*.h ) -File ( GLOB_RECURSE HELLOWORLD_INLINE_FILES ${HELLOWORLD_INCLUDE_DIR}/*.inl ) -File ( GLOB_RECURSE HELLOWORLD_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) -List ( REMOVE_ITEM HELLOWORLD_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ) -Add_Library ( helloworld-objects - OBJECT - ${HELLOWORLD_HEADER_FILES} - ${HELLOWORLD_INLINE_FILES} - ${HELLOWORLD_SOURCE_FILES} ) -Target_Include_Directories ( helloworld-objects - PUBLIC - $ - $ ) -Target_Link_Libraries ( helloworld-objects - PUBLIC - libhelloworld-shared ) - -# Executable ###################################################################################### - -Set ( HELLOWORLD_MAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ) -Add_Executable ( helloworld ${HELLOWORLD_MAIN_FILE} ) -Target_Link_Libraries ( helloworld - PUBLIC - helloworld-objects ) - -# Optimization #################################################################################### - -# sanitizers -If ( Sanitizers_FOUND ) - Add_Sanitizers ( helloworld-objects ) - Add_Sanitizers ( helloworld ) -EndIf ( ) - -# pedantic -If ( HAS_PEDANTIC ) - Pedantic_Apply_Flags_Target ( helloworld-objects ALL ) - Pedantic_Apply_Flags_Target ( helloworld ALL ) -EndIf ( ) - -# cotire -If ( HAS_COTIRE ) - Cotire ( helloworld-objects ) - Cotire ( helloworld ) -EndIf ( ) - -# Install ######################################################################################### - -# Executable -Install ( TARGETS helloworld - DESTINATION ${HELLOWORLD_INSTALL_DIR_BIN} ) - -# Debug -If ( HAS_STRIP_SYMBOLS AND NOT HELLOWORLD_NO_STRIP ) - Strip_Symbols ( helloworld HELLOWORLD_DBG_FILE ) - If ( HELLOWORLD_INSTALL_DEBUG ) - Install ( FILES ${HELLOWORLD_DBG_FILE} - DESTINATION ${HELLOWORLD_INSTALL_DIR_LIB} ) - EndIf ( ) -EndIf ( ) diff --git a/projects/helloworld/include/helloworld/dummy.h b/projects/helloworld/src/helloworld/dummy.h similarity index 100% rename from projects/helloworld/include/helloworld/dummy.h rename to projects/helloworld/src/helloworld/dummy.h diff --git a/projects/helloworld/test/helloworld/helloworld_tests.cpp b/projects/helloworld/src/helloworld/dummy.test.cpp similarity index 58% rename from projects/helloworld/test/helloworld/helloworld_tests.cpp rename to projects/helloworld/src/helloworld/dummy.test.cpp index ed72d7e..5df3226 100644 --- a/projects/helloworld/test/helloworld/helloworld_tests.cpp +++ b/projects/helloworld/src/helloworld/dummy.test.cpp @@ -1,6 +1,5 @@ -#include - -#include +#include +#include using namespace ::testing; using namespace ::helloworld; diff --git a/projects/helloworld/src/helloworld/dummy.test.h b/projects/helloworld/src/helloworld/dummy.test.h new file mode 100644 index 0000000..8ed389b --- /dev/null +++ b/projects/helloworld/src/helloworld/dummy.test.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/projects/helloworld/src/main.cpp b/projects/helloworld/src/main.cpp index ce628bb..059a3d6 100644 --- a/projects/helloworld/src/main.cpp +++ b/projects/helloworld/src/main.cpp @@ -1,5 +1,6 @@ #include -#include + +#include using namespace ::helloworld; diff --git a/projects/helloworld/test/CMakeLists.txt b/projects/helloworld/test/CMakeLists.txt deleted file mode 100644 index 1c66413..0000000 --- a/projects/helloworld/test/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -# Initialize ###################################################################################### - -Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) -Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) -Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) - -Find_Package ( Sanitizers QUIET ) - -# Test ############################################################################################ - -Find_Package ( GTest QUIET ) -If ( NOT "${GTest_FOUND}" ) - Return ( ) -EndIf ( ) - -File ( GLOB_RECURSE HELLOWORLD_TEST_HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) -File ( GLOB_RECURSE HELLOWORLD_TEST_INLINE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) -File ( GLOB_RECURSE HELLOWORLD_TEST_SOURCE_FILES - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) - -ForEach ( FILE IN LISTS HELLOWORLD_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 - ${HELLOWORLD_TEST_HEADER_FILES} - ${HELLOWORLD_TEST_INLINE_FILES} - ${FILE} ) - Target_Link_Libraries ( ${TEST_NAME} - PUBLIC - helloworld-objects - GTest::Main ) - - # Sanitizers - If ( Sanitizers_FOUND ) - Add_Sanitizers ( ${TEST_NAME} ) - EndIf ( ) - - # pedantic - If ( HAS_PEDANTIC ) - Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) - EndIf ( ) - - # test - If ( HAS_CMAKE_TESTS ) - Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} GROUP helloworld ) - Else ( ) - Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) - EndIf ( ) -EndForEach ( ) diff --git a/projects/libhelloworld/CMakeLists.txt b/projects/libhelloworld/CMakeLists.txt index 57cc37e..4a27e2c 100644 --- a/projects/libhelloworld/CMakeLists.txt +++ b/projects/libhelloworld/CMakeLists.txt @@ -1,63 +1,242 @@ # Initialize CMake ################################################################################ -CMake_Minimum_Required ( VERSION 3.12.0 FATAL_ERROR ) - -# Set CMAKE_BUILD_TYPE -If ( NOT CMAKE_BUILD_TYPE ) - Set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build!" FORCE ) -EndIf ( NOT CMAKE_BUILD_TYPE ) -Set_Property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel ) - -# Set CMAKE_MODULE_PATH -If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) - Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) -EndIf ( ) -If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) - Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) -EndIf ( ) +CMake_Minimum_Required ( VERSION 3.12.0 FATAL_ERROR ) + +# CMAKE_BUILD_TYPE +If ( NOT CMAKE_BUILD_TYPE ) + Set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build!" FORCE ) +EndIf ( NOT CMAKE_BUILD_TYPE ) +Set_Property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel ) + +# CMAKE_MODULE_PATH +If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) + Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) +EndIf ( ) + +If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) + Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) +EndIf ( ) # Project ######################################################################################### -Include ( GNUInstallDirs ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-options.cmake ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-const.cmake ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-var.cmake ) -Project ( ${LIBHELLOWORLD_PROJECT_NAME} - DESCRIPTION "${LIBHELLOWORLD_PROJECT_DESCRIPTION}" - VERSION "${LIBHELLOWORLD_VERSION}" ) -Include ( CTest ) - -# Subdirectories -Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/src ) -Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/test ) - -# Install -If ( NOT LIBHELLOWORLD_HAS_EXPORT - OR NOT LIBHELLOWORLD_INSTALL_PACKAGE ) - Return ( ) -EndIf ( ) - -Include ( CMakePackageConfigHelpers ) -Write_Basic_Package_Version_File ( "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config-version.cmake" - VERSION ${LIBHELLOWORLD_VERSION} - COMPATIBILITY AnyNewerVersion ) -Configure_File ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config.cmake" - @ONLY ) - -Set ( ConfigPackageLocation "${LIBHELLOWORLD_INSTALL_DIR_SHARE}/cmake" ) -Install ( EXPORT - libhelloworld - NAMESPACE - libhelloworld:: - DESTINATION - ${ConfigPackageLocation} ) -Install ( FILES - "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config-version.cmake" - DESTINATION - ${ConfigPackageLocation} - COMPONENT - Devel ) +Include ( GNUInstallDirs ) + +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-options.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-const.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-var.cmake ) + +Project ( ${LIBHELLOWORLD_PROJECT_NAME} + DESCRIPTION "${LIBHELLOWORLD_PROJECT_DESCRIPTION}" + VERSION "${LIBHELLOWORLD_VERSION}" ) + +Include ( CTest ) + +# Initialize ###################################################################################### + +Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) +Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) +Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) +Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) + +Find_Package ( GTest QUIET ) +Find_Package ( Sanitizers QUIET ) + +Message ( FATAL_ERROR "Please configure the dependencies of this project!" ) +# Find_Package ( libhelloworld REQUIRED ${LIBHELLOWORLD_FIND_PACKAGE_EXTRA_ARGS} ) + +# Object Library ################################################################################## + +Set ( CMAKE_POSITION_INDEPENDENT_CODE ON ) + +Set ( LIBHELLOWORLD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" ) +Set ( LIBHELLOWORLD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" ) + +File ( GLOB_RECURSE LIBHELLOWORLD_HEADER_FILES "${LIBHELLOWORLD_INCLUDE_DIR}/*.h" ) +File ( GLOB_RECURSE LIBHELLOWORLD_INLINE_FILES "${LIBHELLOWORLD_INCLUDE_DIR}/*.inl" ) +File ( GLOB_RECURSE LIBHELLOWORLD_SOURCE_FILES "${LIBHELLOWORLD_SOURCE_DIR}/*.cpp" ) + +File ( GLOB_RECURSE LIBHELLOWORLD_TEST_HEADER_FILES "${LIBHELLOWORLD_INCLUDE_DIR}/*.test.h" ) +File ( GLOB_RECURSE LIBHELLOWORLD_TEST_INLINE_FILES "${LIBHELLOWORLD_INCLUDE_DIR}/*.test.inl" ) +File ( GLOB_RECURSE LIBHELLOWORLD_TEST_SOURCE_FILES "${LIBHELLOWORLD_SOURCE_DIR}/*.test.cpp" ) + +ForEach ( TEST_FILE IN LISTS LIBHELLOWORLD_TEST_HEADER_FILES ) + List ( REMOVE_ITEM LIBHELLOWORLD_HEADER_FILES "${TEST_FILE}" ) +EndForEach ( ) + +ForEach ( TEST_FILE IN LISTS LIBHELLOWORLD_TEST_INLINE_FILES ) + List ( REMOVE_ITEM LIBHELLOWORLD_INLINE_FILES "${TEST_FILE}" ) +EndForEach ( ) + +ForEach ( TEST_FILE IN LISTS LIBHELLOWORLD_TEST_SOURCE_FILES ) + List ( REMOVE_ITEM LIBHELLOWORLD_SOURCE_FILES "${TEST_FILE}" ) +EndForEach ( ) + +Add_Library ( + libhelloworld-objects + OBJECT + ${LIBHELLOWORLD_HEADER_FILES} + ${LIBHELLOWORLD_INLINE_FILES} + ${LIBHELLOWORLD_SOURCE_FILES} ) +Target_Include_Directories ( + libhelloworld-objects + PUBLIC + $ + $ ) + +# Static Library ################################################################################## + +Add_Library ( + libhelloworld-static + STATIC + $ ) +Set_Target_Properties ( + libhelloworld-static + PROPERTIES + VERSION "${LIBHELLOWORLD_VERSION}-${LIBHELLOWORLD_VERSION_HASH_SHORT}" + OUTPUT_NAME "${LIBHELLOWORLD_OUTPUTNAME}" ) +Target_Include_Directories ( + libhelloworld-static + PUBLIC + $ + $ ) + +# Shared Library ################################################################################## + +Add_Library ( + libhelloworld-shared + SHARED + $ ) +Set_Target_Properties ( + libhelloworld-shared + PROPERTIES + VERSION "${LIBHELLOWORLD_VERSION}-${LIBHELLOWORLD_VERSION_HASH_SHORT}" + OUTPUT_NAME "${LIBHELLOWORLD_OUTPUTNAME}" ) +Target_Include_Directories ( + libhelloworld-shared + PUBLIC + $ + $ ) + +# Tests ########################################################################################### + +If ( GTest_FOUND ) + ForEach ( FILE IN LISTS LIBHELLOWORLD_TEST_SOURCE_FILES ) + + # Add Test + File ( RELATIVE_PATH RELFILE "${LIBHELLOWORLD_SOURCE_DIR}" "${FILE}" ) + Get_Filename_Component ( TEST_DIR "${RELFILE}" DIRECTORY ) + Get_Filename_Component ( TEST_NAME "${RELFILE}" NAME_WE ) + Set ( TEST_NAME "${TEST_DIR}/${TEST_NAME}" ) + String ( REPLACE ".test" "" TEST_NAME "${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 + ${HELLOWORLD_TEST_HEADER_FILES} + ${HELLOWORLD_TEST_INLINE_FILES} + ${FILE} ) + Target_Link_Libraries ( ${TEST_NAME} + PUBLIC + libhelloworld-objects + GTest::Main ) + + # Sanitizers + If ( Sanitizers_FOUND ) + Add_Sanitizers ( ${TEST_NAME} ) + EndIf ( ) + + # pedantic + If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) + EndIf ( ) + + # test + If ( HAS_CMAKE_TESTS ) + Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} GROUP gedt ) + Else ( ) + Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + EndIf ( ) + EndForEach ( ) +EndIf ( ) + +# Optimization #################################################################################### + +# sanitizers +If ( Sanitizers_FOUND ) + Add_Sanitizers ( libhelloworld-objects ) +EndIf ( ) + +# pedantic +If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( libhelloworld-objects ALL ) + Pedantic_Apply_Flags_Target ( libhelloworld-static ALL ) + Pedantic_Apply_Flags_Target ( libhelloworld-shared ALL ) +EndIf ( ) + +# cotire +If ( HAS_COTIRE ) + Cotire ( libhelloworld-objects ) + Cotire ( libhelloworld-static ) + Cotire ( libhelloworld-shared ) +EndIf ( ) + +# Install ######################################################################################### + +# Header +If ( LIBHELLOWORLD_INSTALL_HEADER ) + Install ( DIRECTORY "${LIBHELLOWORLD_INCLUDE_DIR}/libhelloworld" + DESTINATION "${LIBHELLOWORLD_INSTALL_DIR_INCLUDE}" + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.inl" + PATTERN "*.test.h" EXCLUDE + PATTERN "*.test.inl" EXCLUDE ) +EndIf ( ) + +# Static +If ( LIBHELLOWORLD_INSTALL_STATIC ) + Install ( TARGETS libhelloworld-static + EXPORT libhelloworld + DESTINATION "${LIBHELLOWORLD_INSTALL_DIR_LIB}" ) +EndIf ( ) + +# Shared +If ( LIBHELLOWORLD_INSTALL_SHARED ) + Install ( TARGETS libhelloworld-shared + EXPORT libhelloworld + DESTINATION "${LIBHELLOWORLD_INSTALL_DIR_LIB}" ) +EndIf ( ) + +# Debug +If ( HAS_STRIP_SYMBOLS AND NOT LIBHELLOWORLD_NO_STRIP ) + Strip_Symbols ( libhelloworld-shared LIBHELLOWORLD_DBG_FILE ) + If ( LIBHELLOWORLD_INSTALL_DEBUG ) + Install ( FILES "${LIBHELLOWORLD_DBG_FILE}" + DESTINATION "${LIBHELLOWORLD_INSTALL_DIR_LIB}" ) + EndIf ( ) +EndIf ( ) + +# Package +Include ( CMakePackageConfigHelpers ) +Write_Basic_Package_Version_File ( + "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config-version.cmake" + VERSION "${LIBHELLOWORLD_VERSION}" + COMPATIBILITY AnyNewerVersion ) +Configure_File ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config.cmake" + @ONLY ) + +Set ( ConfigPackageLocation "${LIBHELLOWORLD_INSTALL_DIR_SHARE}/cmake" ) +Install ( EXPORT libhelloworld + NAMESPACE libhelloworld:: + DESTINATION ${ConfigPackageLocation} ) +Install ( FILES + "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config-version.cmake" + DESTINATION + ${ConfigPackageLocation} + COMPONENT + Devel ) diff --git a/projects/libhelloworld/cmake/libhelloworld-config.cmake b/projects/libhelloworld/cmake/libhelloworld-config.cmake index 9c99f92..81ce5fd 100644 --- a/projects/libhelloworld/cmake/libhelloworld-config.cmake +++ b/projects/libhelloworld/cmake/libhelloworld-config.cmake @@ -1,9 +1,10 @@ # libhelloworld-config.cmake - package configuration file -# Include ( CMakeFindDependencyMacro ) -# Find_Dependency ( ) +Message ( FATAL_ERROR "Please configure the dependencies!" ) +# Include ( CMakeFindDependencyMacro ) +# Find_Dependency ( ) -Include ( FindPackageHandleStandardArgs ) -Set ( ${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE} ) -Find_Package_Handle_Standard_Args ( libhelloworld CONFIG_MODE ) -Include ( "${CMAKE_CURRENT_LIST_DIR}/libhelloworld.cmake") +Include ( FindPackageHandleStandardArgs ) +Set ( ${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE} ) +Find_Package_Handle_Standard_Args ( libhelloworld CONFIG_MODE ) +Include ( "${CMAKE_CURRENT_LIST_DIR}/libhelloworld.cmake") diff --git a/projects/libhelloworld/cmake/libhelloworld-const.cmake b/projects/libhelloworld/cmake/libhelloworld-const.cmake index 5be3584..be84f79 100644 --- a/projects/libhelloworld/cmake/libhelloworld-const.cmake +++ b/projects/libhelloworld/cmake/libhelloworld-const.cmake @@ -1,28 +1,29 @@ # This file contains constant variables that are fixed to this project # Version -Set ( LIBHELLOWORLD_VERSION_MAJOR 1 ) -Set ( LIBHELLOWORLD_VERSION_MINOR 0 ) -Set ( LIBHELLOWORLD_VERSION_PATCH 0 ) -Set ( LIBHELLOWORLD_VERSION_BUILD 0 ) -Set ( LIBHELLOWORLD_VERSION_HASH "" ) -Set ( LIBHELLOWORLD_VERSION_BEHIND 0 ) -Set ( LIBHELLOWORLD_VERSION_DIRTY 0 ) +Set ( LIBHELLOWORLD_VERSION_MAJOR 1 ) +Set ( LIBHELLOWORLD_VERSION_MINOR 0 ) +Set ( LIBHELLOWORLD_VERSION_PATCH 0 ) +Set ( LIBHELLOWORLD_VERSION_BUILD 0 ) +Set ( LIBHELLOWORLD_VERSION_BEHIND 0 ) +Set ( LIBHELLOWORLD_VERSION_DIRTY 0 ) +Set ( LIBHELLOWORLD_VERSION_HASH "nogit" ) +Set ( LIBHELLOWORLD_VERSION_HASH_SHORT "nogit" ) # Names -Set ( LIBHELLOWORLD_PROJECT_NAME "libhelloworld" ) -Set ( LIBHELLOWORLD_PROJECT_DESCRIPTION "A simple hello world library" ) +Set ( LIBHELLOWORLD_PROJECT_NAME "libhelloworld" ) +Set ( LIBHELLOWORLD_PROJECT_DESCRIPTION "A simple hello world library" ) # Include generated variables for further usage -Include ( ${CMAKE_CURRENT_LIST_DIR}/libhelloworld-var.cmake ) +Include ( ${CMAKE_CURRENT_LIST_DIR}/libhelloworld-var.cmake ) # Install directories -Set ( LIBHELLOWORLD_INSTALL_DIR_INCLUDE "${CMAKE_INSTALL_INCLUDEDIR}/${LIBHELLOWORLD_NAME}" ) -Set ( LIBHELLOWORLD_INSTALL_DIR_LIB "${CMAKE_INSTALL_LIBDIR}" ) -Set ( LIBHELLOWORLD_INSTALL_DIR_SHARE "${CMAKE_INSTALL_DATAROOTDIR}/${LIBHELLOWORLD_NAME}" ) +Set ( LIBHELLOWORLD_INSTALL_DIR_LIB "${CMAKE_INSTALL_LIBDIR}" ) +Set ( LIBHELLOWORLD_INSTALL_DIR_SHARE "${CMAKE_INSTALL_DATAROOTDIR}/${LIBHELLOWORLD_NAME}" ) +Set ( LIBHELLOWORLD_INSTALL_DIR_INCLUDE "${CMAKE_INSTALL_INCLUDEDIR}/${LIBHELLOWORLD_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 20 ) +Set ( CMAKE_C_STANDARD_REQUIRED ON ) +Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) diff --git a/projects/libhelloworld/cmake/libhelloworld-options.cmake b/projects/libhelloworld/cmake/libhelloworld-options.cmake index 139859f..8ebca25 100644 --- a/projects/libhelloworld/cmake/libhelloworld-options.cmake +++ b/projects/libhelloworld/cmake/libhelloworld-options.cmake @@ -1,23 +1,26 @@ # This file contains options that can be passed to the cmake command -Option ( LIBHELLOWORLD_INSTALL_HEADER - "Install headers of libhelloworld." - ON ) -Option ( LIBHELLOWORLD_INSTALL_STATIC - "Install static library of libhelloworld." - ON ) -Option ( LIBHELLOWORLD_INSTALL_SHARED - "Install shared library of libhelloworld." - ON ) -Option ( LIBHELLOWORLD_INSTALL_DEBUG - "Install the stripped debug informations of libhelloworld." - OFF ) -Option ( LIBHELLOWORLD_INSTALL_PACKAGE - "Install the cmake package of libhelloworld." - ON ) -Option ( LIBHELLOWORLD_NO_STRIP - "Do not strip debug symbols from binary." - OFF ) -Option ( LIBHELLOWORLD_USE_GIT_VERSION - "Read the git tags to get the version of libhelloworld" - ON ) +Option ( LIBHELLOWORLD_INSTALL_HEADER + "Install headers of libhelloworld." + ON ) +Option ( LIBHELLOWORLD_INSTALL_STATIC + "Install static library of libhelloworld." + ON ) +Option ( LIBHELLOWORLD_INSTALL_SHARED + "Install shared library of libhelloworld." + ON ) +Option ( LIBHELLOWORLD_INSTALL_DEBUG + "Install the stripped debug informations of libhelloworld." + OFF ) +Option ( LIBHELLOWORLD_INSTALL_PACKAGE + "Install the cmake package of libhelloworld." + ON ) +Option ( LIBHELLOWORLD_NO_STRIP + "Do not strip debug symbols from binary." + OFF ) +Option ( LIBHELLOWORLD_USE_GIT_VERSION + "Read the git tags to get the version of libhelloworld" + ON ) +Option ( LIBHELLOWORLD_IGNORE_MODULES + "Use only config mode to find other packages" + OFF ) diff --git a/projects/libhelloworld/cmake/libhelloworld-var.cmake b/projects/libhelloworld/cmake/libhelloworld-var.cmake index 0f8a1c5..2dff0f7 100644 --- a/projects/libhelloworld/cmake/libhelloworld-var.cmake +++ b/projects/libhelloworld/cmake/libhelloworld-var.cmake @@ -1,32 +1,34 @@ # This file contains generated variables that are needed for the project # Git Version -If ( LIBHELLOWORLD_USE_GIT_VERSION ) - Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) - If ( HAS_GIT_HELPER ) - GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/.. - LIBHELLOWORLD_VERSION_MAJOR - LIBHELLOWORLD_VERSION_MINOR - LIBHELLOWORLD_VERSION_PATCH - LIBHELLOWORLD_VERSION_BUILD - LIBHELLOWORLD_VERSION_HASH - LIBHELLOWORLD_VERSION_BEHIND - LIBHELLOWORLD_VERSION_DIRTY ) - EndIf ( ) -EndIf ( ) +If ( LIBHELLOWORLD_USE_GIT_VERSION ) + Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) + If ( HAS_GIT_HELPER ) + GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/../../.. + LIBHELLOWORLD_VERSION_MAJOR + LIBHELLOWORLD_VERSION_MINOR + LIBHELLOWORLD_VERSION_PATCH + LIBHELLOWORLD_VERSION_BUILD + LIBHELLOWORLD_VERSION_HASH + LIBHELLOWORLD_VERSION_BEHIND + LIBHELLOWORLD_VERSION_DIRTY ) + EndIf ( ) +EndIf ( ) # Strings -Set ( LIBHELLOWORLD_VERSION_SHORT - "${LIBHELLOWORLD_VERSION_MAJOR}.${LIBHELLOWORLD_VERSION_MINOR}" ) -Set ( LIBHELLOWORLD_VERSION - "${LIBHELLOWORLD_VERSION_SHORT}.${LIBHELLOWORLD_VERSION_PATCH}.${LIBHELLOWORLD_VERSION_BUILD}" ) -Set ( LIBHELLOWORLD_VERSION_COMPLETE - "${LIBHELLOWORLD_VERSION}" ) -Set ( LIBHELLOWORLD_NAME - "${LIBHELLOWORLD_PROJECT_NAME}-${LIBHELLOWORLD_VERSION_SHORT}" ) -Set ( LIBHELLOWORLD_OUTPUTNAME - "${LIBHELLOWORLD_PROJECT_NAME}" ) -If ( LIBHELLOWORLD_VERSION_BEHIND ) - Set ( LIBHELLOWORLD_VERSION_COMPLETE - "${LIBHELLOWORLD_VERSION_COMPLETE}+${LIBHELLOWORLD_VERSION_BEHIND}" ) -EndIf ( ) +Set ( LIBHELLOWORLD_VERSION "${LIBHELLOWORLD_VERSION_SHORT}.${LIBHELLOWORLD_VERSION_PATCH}.${LIBHELLOWORLD_VERSION_BUILD}" ) +Set ( LIBHELLOWORLD_VERSION_SHORT "${LIBHELLOWORLD_VERSION_MAJOR}.${LIBHELLOWORLD_VERSION_MINOR}" ) +Set ( LIBHELLOWORLD_VERSION_COMPLETE "${LIBHELLOWORLD_VERSION}" ) +If ( LIBHELLOWORLD_VERSION_BEHIND ) + Set ( LIBHELLOWORLD_VERSION_COMPLETE "${LIBHELLOWORLD_VERSION_COMPLETE}+${LIBHELLOWORLD_VERSION_BEHIND}" ) +EndIf ( ) + +Set ( LIBHELLOWORLD_NAME "${LIBHELLOWORLD_PROJECT_NAME}-${LIBHELLOWORLD_VERSION_SHORT}" ) +Set ( LIBHELLOWORLD_OUTPUTNAME "${LIBHELLOWORLD_PROJECT_NAME}" ) + +String ( SUBSTRING "${LIBHELLOWORLD_VERSION_HASH}" 0 8 LIBHELLOWORLD_VERSION_HASH_SHORT ) + +# Extra +If ( LIBHELLOWORLD_IGNORE_MODULES ) + Set ( LIBHELLOWORLD_FIND_PACKAGE_EXTRA_ARGS "CONFIG" ) +EndIf ( ) diff --git a/projects/libhelloworld/src/CMakeLists.txt b/projects/libhelloworld/src/CMakeLists.txt deleted file mode 100644 index 78d6f46..0000000 --- a/projects/libhelloworld/src/CMakeLists.txt +++ /dev/null @@ -1,107 +0,0 @@ -# Initialize ###################################################################################### - -Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) -Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) -Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) - -Find_Package ( Sanitizers QUIET ) - -# Object Library ################################################################################## - -Set ( CMAKE_POSITION_INDEPENDENT_CODE ON ) -Set ( LIBHELLOWORLD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include ) -File ( GLOB_RECURSE LIBHELLOWORLD_HEADER_FILES ${LIBHELLOWORLD_INCLUDE_DIR}/*.h ) -File ( GLOB_RECURSE LIBHELLOWORLD_INLINE_FILES ${LIBHELLOWORLD_INCLUDE_DIR}/*.inl ) -File ( GLOB_RECURSE LIBHELLOWORLD_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) -Add_Library ( libhelloworld-objects - OBJECT - ${LIBHELLOWORLD_HEADER_FILES} - ${LIBHELLOWORLD_INLINE_FILES} - ${LIBHELLOWORLD_SOURCE_FILES} ) -Target_Include_Directories ( libhelloworld-objects - PUBLIC - $ - $ ) - -# Static Library ################################################################################## - -Add_Library ( libhelloworld-static STATIC $ ) -Set_Target_Properties ( libhelloworld-static - PROPERTIES - OUTPUT_NAME "${LIBHELLOWORLD_OUTPUTNAME}" - VERSION ${LIBHELLOWORLD_VERSION} ) -Target_Include_Directories ( libhelloworld-static - PUBLIC - $ - $ ) - -# Shared Library ################################################################################## - -Add_Library ( libhelloworld-shared SHARED $ ) -Set_Target_Properties ( libhelloworld-shared - PROPERTIES - OUTPUT_NAME "${LIBHELLOWORLD_OUTPUTNAME}" - VERSION ${LIBHELLOWORLD_VERSION} - SOVERSION ${LIBHELLOWORLD_VERSION_SHORT} ) -Target_Include_Directories ( libhelloworld-shared - PUBLIC - $ - $ ) - -# Optimization #################################################################################### - -# sanitizers -If ( Sanitizers_FOUND ) - Add_Sanitizers ( libhelloworld-objects ) -EndIf ( ) - -# pedantic -If ( HAS_PEDANTIC ) - Pedantic_Apply_Flags_Target ( libhelloworld-objects ALL ) - Pedantic_Apply_Flags_Target ( libhelloworld-static ALL ) - Pedantic_Apply_Flags_Target ( libhelloworld-shared ALL ) -EndIf ( ) - -# cotire -If ( HAS_COTIRE ) - Cotire ( libhelloworld-objects ) - Cotire ( libhelloworld-static ) - Cotire ( libhelloworld-shared ) -EndIf ( ) - -# Install ######################################################################################### - -Set ( LIBHELLOWORLD_HAS_EXPORT False PARENT_SCOPE ) - -# Header -If ( LIBHELLOWORLD_INSTALL_HEADER ) - Install ( FILES ${LIBHELLOWORLD_INCLUDE_DIR}/libhelloworld.h - DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_INCLUDE} ) - Install ( DIRECTORY ${LIBHELLOWORLD_INCLUDE_DIR}/libhelloworld - DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_INCLUDE} ) -EndIf ( ) - -# Static -If ( LIBHELLOWORLD_INSTALL_STATIC ) - Set ( LIBHELLOWORLD_HAS_EXPORT True PARENT_SCOPE ) - Install ( TARGETS libhelloworld-static - EXPORT libhelloworld - DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_LIB} ) -EndIf ( ) - -# Shared -If ( LIBHELLOWORLD_INSTALL_SHARED ) - Set ( LIBHELLOWORLD_HAS_EXPORT True PARENT_SCOPE ) - Install ( TARGETS libhelloworld-shared - EXPORT libhelloworld - DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_LIB} ) -EndIf ( ) - -# Debug -If ( HAS_STRIP_SYMBOLS AND NOT LIBHELLOWORLD_NO_STRIP ) - Strip_Symbols ( libhelloworld-shared LIBHELLOWORLD_DBG_FILE ) - If ( LIBHELLOWORLD_INSTALL_DEBUG ) - Install ( FILES ${LIBHELLOWORLD_DBG_FILE} - DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_LIB} ) - EndIf ( ) -EndIf ( ) diff --git a/projects/libhelloworld/include/libhelloworld.h b/projects/libhelloworld/src/libhelloworld.h similarity index 100% rename from projects/libhelloworld/include/libhelloworld.h rename to projects/libhelloworld/src/libhelloworld.h diff --git a/projects/libhelloworld/include/libhelloworld/dummy.h b/projects/libhelloworld/src/libhelloworld/dummy.h similarity index 100% rename from projects/libhelloworld/include/libhelloworld/dummy.h rename to projects/libhelloworld/src/libhelloworld/dummy.h diff --git a/projects/libhelloworld/test/libhelloworld/libhelloworld_tests.cpp b/projects/libhelloworld/src/libhelloworld/dummy.test.cpp similarity index 76% rename from projects/libhelloworld/test/libhelloworld/libhelloworld_tests.cpp rename to projects/libhelloworld/src/libhelloworld/dummy.test.cpp index 3ef2dfd..2e61380 100644 --- a/projects/libhelloworld/test/libhelloworld/libhelloworld_tests.cpp +++ b/projects/libhelloworld/src/libhelloworld/dummy.test.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/projects/libhelloworld/src/libhelloworld/dummy.test.h b/projects/libhelloworld/src/libhelloworld/dummy.test.h new file mode 100644 index 0000000..8ed389b --- /dev/null +++ b/projects/libhelloworld/src/libhelloworld/dummy.test.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/projects/libhelloworld/test/CMakeLists.txt b/projects/libhelloworld/test/CMakeLists.txt deleted file mode 100644 index 4410e9e..0000000 --- a/projects/libhelloworld/test/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -# Initialize ###################################################################################### - -Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) -Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) -Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) - -Find_Package ( Sanitizers QUIET ) - -# Test ############################################################################################ - -Find_Package ( GTest QUIET ) -If ( NOT "${GTest_FOUND}" ) - Return ( ) -EndIf ( ) - -File ( GLOB_RECURSE LIBHELLOWORLD_TEST_HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) -File ( GLOB_RECURSE LIBHELLOWORLD_TEST_INLINE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) -File ( GLOB_RECURSE LIBHELLOWORLD_TEST_SOURCE_FILES - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) - -ForEach ( FILE IN LISTS LIBHELLOWORLD_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 - ${LIBHELLOWORLD_TEST_HEADER_FILES} - ${LIBHELLOWORLD_TEST_INLINE_FILES} - ${FILE} ) - Target_Link_Libraries ( ${TEST_NAME} - PUBLIC - libhelloworld-objects - GTest::Main ) - - # Sanitizers - If ( Sanitizers_FOUND ) - Add_Sanitizers ( ${TEST_NAME} ) - EndIf ( ) - - # pedantic - If ( HAS_PEDANTIC ) - Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) - EndIf ( ) - - # test - If ( HAS_CMAKE_TESTS ) - Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} GROUP libhelloworld ) - Else ( ) - Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) - EndIf ( ) -EndForEach ( ) diff --git a/projects/libinterface/CMakeLists.txt b/projects/libinterface/CMakeLists.txt index c35ce7e..19e6490 100644 --- a/projects/libinterface/CMakeLists.txt +++ b/projects/libinterface/CMakeLists.txt @@ -1,63 +1,177 @@ # Initialize CMake ################################################################################ -CMake_Minimum_Required ( VERSION 3.12.0 FATAL_ERROR ) - -# Set CMAKE_BUILD_TYPE -If ( NOT CMAKE_BUILD_TYPE ) - Set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build!" FORCE ) -EndIf ( NOT CMAKE_BUILD_TYPE ) -Set_Property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel ) - -# Set CMAKE_MODULE_PATH -If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) - Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) -EndIf ( ) -If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) - Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) -EndIf ( ) +CMake_Minimum_Required ( VERSION 3.12.0 FATAL_ERROR ) + +# CMAKE_BUILD_TYPE +If ( NOT CMAKE_BUILD_TYPE ) + Set ( CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build!" FORCE ) +EndIf ( NOT CMAKE_BUILD_TYPE ) +Set_Property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel ) + +# CMAKE_MODULE_PATH +If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) + Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) +EndIf ( ) + +If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) + Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake" ) +EndIf ( ) # Project ######################################################################################### -Include ( GNUInstallDirs ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libinterface-options.cmake ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libinterface-const.cmake ) -Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libinterface-var.cmake ) -Project ( ${LIBINTERFACE_PROJECT_NAME} - DESCRIPTION "${LIBINTERFACE_PROJECT_DESCRIPTION}" - VERSION "${LIBINTERFACE_VERSION}" ) -Include ( CTest ) - -# Subdirectories -Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/src ) -Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/test ) - -# Install -If ( NOT LIBINTERFACE_HAS_EXPORT - OR NOT LIBINTERFACE_INSTALL_PACKAGE ) - Return ( ) -EndIf ( ) - -Include ( CMakePackageConfigHelpers ) -Write_Basic_Package_Version_File ( "${CMAKE_CURRENT_BINARY_DIR}/cmake/libinterface-config-version.cmake" - VERSION ${LIBINTERFACE_VERSION} - COMPATIBILITY AnyNewerVersion ) -Configure_File ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libinterface-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/cmake/libinterface-config.cmake" - @ONLY ) - -Set ( ConfigPackageLocation "${LIBINTERFACE_INSTALL_DIR_SHARE}/cmake" ) -Install ( EXPORT - libinterface - NAMESPACE - libinterface:: - DESTINATION - ${ConfigPackageLocation} ) -Install ( FILES - "${CMAKE_CURRENT_BINARY_DIR}/cmake/libinterface-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/cmake/libinterface-config-version.cmake" - DESTINATION - ${ConfigPackageLocation} - COMPONENT - Devel ) +Include ( GNUInstallDirs ) + +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libinterface-options.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libinterface-const.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libinterface-var.cmake ) + +Project ( ${LIBINTERFACE_PROJECT_NAME} + DESCRIPTION "${LIBINTERFACE_PROJECT_DESCRIPTION}" + VERSION "${LIBINTERFACE_VERSION}" ) + +Include ( CTest ) + +# Initialize ###################################################################################### + +Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) +Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) +Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) +Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) + +Find_Package ( GTest QUIET ) +Find_Package ( Sanitizers QUIET ) + +Message ( FATAL_ERROR "Please configure the dependencies of this project!" ) +# Find_Package ( libinterface REQUIRED ${LIBINTERFACE_FIND_PACKAGE_EXTRA_ARGS} ) + +# Object Library ################################################################################## + +Set ( CMAKE_POSITION_INDEPENDENT_CODE ON ) + +Set ( LIBINTERFACE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" ) +Set ( LIBINTERFACE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" ) + +File ( GLOB_RECURSE LIBINTERFACE_HEADER_FILES "${LIBINTERFACE_INCLUDE_DIR}/*.h" ) +File ( GLOB_RECURSE LIBINTERFACE_INLINE_FILES "${LIBINTERFACE_INCLUDE_DIR}/*.inl" ) + +File ( GLOB_RECURSE LIBINTERFACE_TEST_HEADER_FILES "${LIBINTERFACE_INCLUDE_DIR}/*.test.h" ) +File ( GLOB_RECURSE LIBINTERFACE_TEST_INLINE_FILES "${LIBINTERFACE_INCLUDE_DIR}/*.test.inl" ) +File ( GLOB_RECURSE LIBINTERFACE_TEST_SOURCE_FILES "${LIBINTERFACE_SOURCE_DIR}/*.test.cpp" ) + +ForEach ( TEST_FILE IN LISTS LIBINTERFACE_TEST_HEADER_FILES ) + List ( REMOVE_ITEM LIBINTERFACE_HEADER_FILES "${TEST_FILE}" ) +EndForEach ( ) + +ForEach ( TEST_FILE IN LISTS LIBINTERFACE_TEST_INLINE_FILES ) + List ( REMOVE_ITEM LIBINTERFACE_INLINE_FILES "${TEST_FILE}" ) +EndForEach ( ) + +Add_Library ( + libinterface + INTERFACE ) +Target_Include_Directories ( + libinterface + INTERFACE + $ + $ ) + +# Tests ########################################################################################### + +If ( GTest_FOUND ) + ForEach ( FILE IN LISTS LIBINTERFACE_TEST_SOURCE_FILES ) + + # Add Test + File ( RELATIVE_PATH RELFILE "${LIBINTERFACE_SOURCE_DIR}" "${FILE}" ) + Get_Filename_Component ( TEST_DIR "${RELFILE}" DIRECTORY ) + Get_Filename_Component ( TEST_NAME "${RELFILE}" NAME_WE ) + Set ( TEST_NAME "${TEST_DIR}/${TEST_NAME}" ) + String ( REPLACE ".test" "" TEST_NAME "${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 + ${HELLOWORLD_TEST_HEADER_FILES} + ${HELLOWORLD_TEST_INLINE_FILES} + ${FILE} ) + Target_Link_Libraries ( ${TEST_NAME} + PUBLIC + libinterface + GTest::Main ) + + # Sanitizers + If ( Sanitizers_FOUND ) + Add_Sanitizers ( ${TEST_NAME} ) + EndIf ( ) + + # pedantic + If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) + EndIf ( ) + + # test + If ( HAS_CMAKE_TESTS ) + Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} GROUP gedt ) + Else ( ) + Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + EndIf ( ) + EndForEach ( ) +EndIf ( ) + +# Optimization #################################################################################### + +# sanitizers +If ( Sanitizers_FOUND ) + Add_Sanitizers ( libinterface ) +EndIf ( ) + +# pedantic +If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( libinterface ALL VISIBILITY INTERFACE ) +EndIf ( ) + +# cotire +If ( HAS_COTIRE ) + Cotire ( libinterface ) +EndIf ( ) + +# Install ######################################################################################### + +# Header +If ( LIBINTERFACE_INSTALL_HEADER ) + Install ( DIRECTORY "${LIBINTERFACE_INCLUDE_DIR}/libinterface" + DESTINATION "${LIBINTERFACE_INSTALL_DIR_INCLUDE}" + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.inl" + PATTERN "*.test.h" EXCLUDE + PATTERN "*.test.inl" EXCLUDE ) + + Install( TARGETS libinterface + EXPORT libinterface + DESTINATION "${LIBINTERFACE_INSTALL_DIR_INCLUDE}" ) +EndIf ( ) + +# Package +Include ( CMakePackageConfigHelpers ) +Write_Basic_Package_Version_File ( + "${CMAKE_CURRENT_BINARY_DIR}/cmake/libinterface-config-version.cmake" + VERSION "${LIBINTERFACE_VERSION}" + COMPATIBILITY AnyNewerVersion ) +Configure_File ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libinterface-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/libinterface-config.cmake" + @ONLY ) + +Set ( ConfigPackageLocation "${LIBINTERFACE_INSTALL_DIR_SHARE}/cmake" ) +Install ( EXPORT libinterface + NAMESPACE libinterface:: + DESTINATION ${ConfigPackageLocation} ) +Install ( FILES + "${CMAKE_CURRENT_BINARY_DIR}/cmake/libinterface-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/libinterface-config-version.cmake" + DESTINATION + ${ConfigPackageLocation} + COMPONENT + Devel ) diff --git a/projects/libinterface/cmake/libinterface-config.cmake b/projects/libinterface/cmake/libinterface-config.cmake index ccab10b..cf858b9 100644 --- a/projects/libinterface/cmake/libinterface-config.cmake +++ b/projects/libinterface/cmake/libinterface-config.cmake @@ -1,9 +1,10 @@ # libinterface-config.cmake - package configuration file -# Include ( CMakeFindDependencyMacro ) -# Find_Dependency ( ) +Message ( FATAL_ERROR "Please configure the dependencies!" ) +# Include ( CMakeFindDependencyMacro ) +# Find_Dependency ( ) -Include ( FindPackageHandleStandardArgs ) -Set ( ${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE} ) -Find_Package_Handle_Standard_Args ( libinterface CONFIG_MODE ) -Include ( "${CMAKE_CURRENT_LIST_DIR}/libinterface.cmake") +Include ( FindPackageHandleStandardArgs ) +Set ( ${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE} ) +Find_Package_Handle_Standard_Args ( libinterface CONFIG_MODE ) +Include ( "${CMAKE_CURRENT_LIST_DIR}/libinterface.cmake") diff --git a/projects/libinterface/cmake/libinterface-const.cmake b/projects/libinterface/cmake/libinterface-const.cmake index 7902c00..c92b5a4 100644 --- a/projects/libinterface/cmake/libinterface-const.cmake +++ b/projects/libinterface/cmake/libinterface-const.cmake @@ -1,28 +1,29 @@ # This file contains constant variables that are fixed to this project # Version -Set ( LIBINTERFACE_VERSION_MAJOR 1 ) -Set ( LIBINTERFACE_VERSION_MINOR 0 ) -Set ( LIBINTERFACE_VERSION_PATCH 0 ) -Set ( LIBINTERFACE_VERSION_BUILD 0 ) -Set ( LIBINTERFACE_VERSION_HASH "" ) -Set ( LIBINTERFACE_VERSION_BEHIND 0 ) -Set ( LIBINTERFACE_VERSION_DIRTY 0 ) +Set ( LIBINTERFACE_VERSION_MAJOR 1 ) +Set ( LIBINTERFACE_VERSION_MINOR 0 ) +Set ( LIBINTERFACE_VERSION_PATCH 0 ) +Set ( LIBINTERFACE_VERSION_BUILD 0 ) +Set ( LIBINTERFACE_VERSION_BEHIND 0 ) +Set ( LIBINTERFACE_VERSION_DIRTY 0 ) +Set ( LIBINTERFACE_VERSION_HASH "nogit" ) +Set ( LIBINTERFACE_VERSION_HASH_SHORT "nogit" ) # Names -Set ( LIBINTERFACE_PROJECT_NAME "libinterface" ) -Set ( LIBINTERFACE_PROJECT_DESCRIPTION "A simple interface library" ) +Set ( LIBINTERFACE_PROJECT_NAME "libinterface" ) +Set ( LIBINTERFACE_PROJECT_DESCRIPTION "A simple interface library" ) # Include generated variables for further usage -Include ( ${CMAKE_CURRENT_LIST_DIR}/libinterface-var.cmake ) +Include ( ${CMAKE_CURRENT_LIST_DIR}/libinterface-var.cmake ) # Install directories -Set ( LIBINTERFACE_INSTALL_DIR_INCLUDE "${CMAKE_INSTALL_INCLUDEDIR}/${LIBINTERFACE_NAME}" ) -Set ( LIBINTERFACE_INSTALL_DIR_LIB "${CMAKE_INSTALL_LIBDIR}" ) -Set ( LIBINTERFACE_INSTALL_DIR_SHARE "${CMAKE_INSTALL_DATAROOTDIR}/${LIBINTERFACE_NAME}" ) +Set ( LIBINTERFACE_INSTALL_DIR_LIB "${CMAKE_INSTALL_LIBDIR}" ) +Set ( LIBINTERFACE_INSTALL_DIR_SHARE "${CMAKE_INSTALL_DATAROOTDIR}/${LIBINTERFACE_NAME}" ) +Set ( LIBINTERFACE_INSTALL_DIR_INCLUDE "${CMAKE_INSTALL_INCLUDEDIR}/${LIBINTERFACE_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 20 ) +Set ( CMAKE_C_STANDARD_REQUIRED ON ) +Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) diff --git a/projects/libinterface/cmake/libinterface-options.cmake b/projects/libinterface/cmake/libinterface-options.cmake index 9968362..5762736 100644 --- a/projects/libinterface/cmake/libinterface-options.cmake +++ b/projects/libinterface/cmake/libinterface-options.cmake @@ -1,11 +1,14 @@ # This file contains options that can be passed to the cmake command -Option ( LIBINTERFACE_INSTALL_HEADER - "Install headers of libinterface." - ON ) -Option ( LIBINTERFACE_INSTALL_PACKAGE - "Install the cmake package of libinterface." - ON ) -Option ( LIBINTERFACE_USE_GIT_VERSION - "Read the git tags to get the version of libinterface" - ON ) +Option ( LIBINTERFACE_INSTALL_HEADER + "Install headers of libinterface." + ON ) +Option ( LIBINTERFACE_INSTALL_PACKAGE + "Install the cmake package of libinterface." + ON ) +Option ( LIBINTERFACE_USE_GIT_VERSION + "Read the git tags to get the version of libinterface" + ON ) +Option ( LIBINTERFACE_IGNORE_MODULES + "Use only config mode to find other packages" + OFF ) diff --git a/projects/libinterface/cmake/libinterface-var.cmake b/projects/libinterface/cmake/libinterface-var.cmake index aaea5ac..3607f12 100644 --- a/projects/libinterface/cmake/libinterface-var.cmake +++ b/projects/libinterface/cmake/libinterface-var.cmake @@ -1,32 +1,34 @@ # This file contains generated variables that are needed for the project # Git Version -If ( LIBINTERFACE_USE_GIT_VERSION ) - Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) - If ( HAS_GIT_HELPER ) - GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/.. - LIBINTERFACE_VERSION_MAJOR - LIBINTERFACE_VERSION_MINOR - LIBINTERFACE_VERSION_PATCH - LIBINTERFACE_VERSION_BUILD - LIBINTERFACE_VERSION_HASH - LIBINTERFACE_VERSION_BEHIND - LIBINTERFACE_VERSION_DIRTY ) - EndIf ( ) -EndIf ( ) +If ( LIBINTERFACE_USE_GIT_VERSION ) + Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) + If ( HAS_GIT_HELPER ) + GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/../../.. + LIBINTERFACE_VERSION_MAJOR + LIBINTERFACE_VERSION_MINOR + LIBINTERFACE_VERSION_PATCH + LIBINTERFACE_VERSION_BUILD + LIBINTERFACE_VERSION_HASH + LIBINTERFACE_VERSION_BEHIND + LIBINTERFACE_VERSION_DIRTY ) + EndIf ( ) +EndIf ( ) # Strings -Set ( LIBINTERFACE_VERSION_SHORT - "${LIBINTERFACE_VERSION_MAJOR}.${LIBINTERFACE_VERSION_MINOR}" ) -Set ( LIBINTERFACE_VERSION - "${LIBINTERFACE_VERSION_SHORT}.${LIBINTERFACE_VERSION_PATCH}.${LIBINTERFACE_VERSION_BUILD}" ) -Set ( LIBINTERFACE_VERSION_COMPLETE - "${LIBINTERFACE_VERSION}" ) -Set ( LIBINTERFACE_NAME - "${LIBINTERFACE_PROJECT_NAME}-${LIBINTERFACE_VERSION_SHORT}" ) -Set ( LIBINTERFACE_OUTPUTNAME - "${LIBINTERFACE_PROJECT_NAME}" ) -If ( LIBINTERFACE_VERSION_BEHIND ) - Set ( LIBINTERFACE_VERSION_COMPLETE - "${LIBINTERFACE_VERSION_COMPLETE}+${LIBINTERFACE_VERSION_BEHIND}" ) -EndIf ( ) +Set ( LIBINTERFACE_VERSION "${LIBINTERFACE_VERSION_SHORT}.${LIBINTERFACE_VERSION_PATCH}.${LIBINTERFACE_VERSION_BUILD}" ) +Set ( LIBINTERFACE_VERSION_SHORT "${LIBINTERFACE_VERSION_MAJOR}.${LIBINTERFACE_VERSION_MINOR}" ) +Set ( LIBINTERFACE_VERSION_COMPLETE "${LIBINTERFACE_VERSION}" ) +If ( LIBINTERFACE_VERSION_BEHIND ) + Set ( LIBINTERFACE_VERSION_COMPLETE "${LIBINTERFACE_VERSION_COMPLETE}+${LIBINTERFACE_VERSION_BEHIND}" ) +EndIf ( ) + +Set ( LIBINTERFACE_NAME "${LIBINTERFACE_PROJECT_NAME}-${LIBINTERFACE_VERSION_SHORT}" ) +Set ( LIBINTERFACE_OUTPUTNAME "${LIBINTERFACE_PROJECT_NAME}" ) + +String ( SUBSTRING "${LIBINTERFACE_VERSION_HASH}" 0 8 LIBINTERFACE_VERSION_HASH_SHORT ) + +# Extra +If ( LIBINTERFACE_IGNORE_MODULES ) + Set ( LIBINTERFACE_FIND_PACKAGE_EXTRA_ARGS "CONFIG" ) +EndIf ( ) diff --git a/projects/libinterface/src/CMakeLists.txt b/projects/libinterface/src/CMakeLists.txt deleted file mode 100644 index b816a4f..0000000 --- a/projects/libinterface/src/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# Initialize ###################################################################################### - -Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) -Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) -Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) - -# Interface Library ############################################################################### - -Set ( LIBINTERFACE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include ) -Add_Library ( libinterface INTERFACE ) -Target_Include_Directories ( libinterface - INTERFACE - $ - $ ) - -# Install ######################################################################################### - -Set ( LIBINTERFACE_HAS_EXPORT False PARENT_SCOPE ) - -# Header -If ( LIBINTERFACE_INSTALL_HEADER ) - Set ( LIBINTERFACE_HAS_EXPORT True PARENT_SCOPE ) - Install ( FILES ${LIBINTERFACE_INCLUDE_DIR}/libinterface.h - DESTINATION ${LIBINTERFACE_INSTALL_DIR_INCLUDE} ) - Install ( DIRECTORY ${LIBINTERFACE_INCLUDE_DIR}/libinterface - DESTINATION ${LIBINTERFACE_INSTALL_DIR_INCLUDE} ) - Install ( TARGETS libinterface - EXPORT libinterface - DESTINATION ${LIBINTERFACE_INSTALL_DIR_INCLUDE} ) -EndIf ( ) diff --git a/projects/libinterface/include/libinterface.h b/projects/libinterface/src/libinterface.h similarity index 100% rename from projects/libinterface/include/libinterface.h rename to projects/libinterface/src/libinterface.h diff --git a/projects/libinterface/include/libinterface/dummy.h b/projects/libinterface/src/libinterface/dummy.h similarity index 100% rename from projects/libinterface/include/libinterface/dummy.h rename to projects/libinterface/src/libinterface/dummy.h diff --git a/projects/libinterface/include/libinterface/dummy.inl b/projects/libinterface/src/libinterface/dummy.inl similarity index 100% rename from projects/libinterface/include/libinterface/dummy.inl rename to projects/libinterface/src/libinterface/dummy.inl diff --git a/projects/libinterface/test/libinterface/libinterface_tests.cpp b/projects/libinterface/src/libinterface/dummy.test.cpp similarity index 77% rename from projects/libinterface/test/libinterface/libinterface_tests.cpp rename to projects/libinterface/src/libinterface/dummy.test.cpp index 6da310f..2507fb7 100644 --- a/projects/libinterface/test/libinterface/libinterface_tests.cpp +++ b/projects/libinterface/src/libinterface/dummy.test.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/projects/libinterface/src/libinterface/dummy.test.h b/projects/libinterface/src/libinterface/dummy.test.h new file mode 100644 index 0000000..8ed389b --- /dev/null +++ b/projects/libinterface/src/libinterface/dummy.test.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/projects/libinterface/test/CMakeLists.txt b/projects/libinterface/test/CMakeLists.txt deleted file mode 100644 index 8bf2a98..0000000 --- a/projects/libinterface/test/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -# Initialize ###################################################################################### - -Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) -Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) -Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) - -Find_Package ( Sanitizers QUIET ) - -# Test ############################################################################################ - -Find_Package ( GTest QUIET ) -If ( NOT "${GTest_FOUND}" ) - Return ( ) -EndIf ( ) - -File ( GLOB_RECURSE LIBINTERFACE_TEST_HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) -File ( GLOB_RECURSE LIBINTERFACE_TEST_INLINE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) -File ( GLOB_RECURSE LIBINTERFACE_TEST_SOURCE_FILES - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) - -ForEach ( FILE IN LISTS LIBINTERFACE_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 - ${LIBINTERFACE_TEST_HEADER_FILES} - ${LIBINTERFACE_TEST_INLINE_FILES} - ${FILE} ) - Target_Link_Libraries ( ${TEST_NAME} - PUBLIC - libinterface - GTest::Main ) - - # Sanitizers - If ( Sanitizers_FOUND ) - Add_Sanitizers ( ${TEST_NAME} ) - EndIf ( ) - - # pedantic - If ( HAS_PEDANTIC ) - Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) - EndIf ( ) - - # test - If ( HAS_CMAKE_TESTS ) - Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} GROUP libinterface ) - Else ( ) - Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) - EndIf ( ) -EndForEach ( ) diff --git a/tool b/tool index 615790f..6975ec4 100755 --- a/tool +++ b/tool @@ -4,7 +4,7 @@ ScriptFile=$(readlink -f "${BASH_SOURCE[0]}") ScriptDir=$(dirname "${ScriptFile}") IgnoreVsCodeSettings=1 -UseGit=1 +UseGit=0 Verbose=0 Update=0 CMakeModules="" @@ -40,24 +40,24 @@ function PrintHelp() Parameters: - -g|--group + -g|--group Create a new project group at the given directory. - -i|--interface + -i|--interface Create a new interface library project with the given name at the given directory. - -l|--library + -l|--library Create a new library project with the given name at the given directory. - -e|--executable + -e|--executable Create a new executable project with the given name at the given directory. -m|--modules -M|--force-modules Add the CMake Modules from the given remote repository as submodule of the new project. - -n|--nogit - Does not initialize a new git repository when creating a new project group. + --git + Initialize a new git repository when creating a new project or group. -u|--update Update an exsisting project. @@ -116,22 +116,20 @@ function CreateGroup() # Create git repository Log " Create git repository" - if [[ $UseGit -eq 1 ]]; then - git -C $dir init \ - || Panic "Git init failed!" + git -C $dir init \ + || Panic "Git init failed!" - # Add cmake modules - Log " Add git submodule for CMake modules" - if [[ -n "$CMakeModules" ]]; then - git -C $dir submodule add $CMakeModulesForced "$CMakeModules" "cmake/modules" \ - || Panic "Git submodule add failed!" + # Add cmake modules + Log " Add git submodule for CMake modules" + if [[ -n "$CMakeModules" ]]; then + git -C $dir submodule add $CMakeModulesForced "$CMakeModules" "cmake/modules" \ + || Panic "Git submodule add failed!" - git -C $dir/cmake/modules fetch --all \ - || Panic "Git submodule fetch failed!" + git -C $dir/cmake/modules fetch --all \ + || Panic "Git submodule fetch failed!" - git -C $dir/cmake/modules reset --hard origin/master \ - || Panic "Git submodule reset failed!" - fi + git -C $dir/cmake/modules reset --hard origin/master \ + || Panic "Git submodule reset failed!" fi # Copy files @@ -144,7 +142,7 @@ function CreateGroup() || [[ $file == $srcDir/.git/* ]] \ || [[ $file == $srcDir/.gitmodules ]] \ || [[ $file == $srcDir/projects/* ]] \ - || [[ $file == $srcDir/cmake/modules/* ]] + || [[ $file == $srcDir/cmake/* ]] then relFile=.${file/$srcDir/} Verbose " Ignore $relFile" @@ -156,13 +154,6 @@ function CreateGroup() relFile=.${file/$srcDir/} Verbose " Ignore $relFile" - # Ignore git files - elif [[ $UseGit -eq 0 ]] \ - && [[ $file == $srcDir/.git* ]] - then - relFile=.${file/$srcDir/} - Verbose " Ignore $relFile" - # Copy related files else Copy "$srcDir" "$dir" "${file/$srcDir/}" @@ -173,8 +164,9 @@ function CreateGroup() function CreateProject() { name="$1" - dir="$2" + groupdir="$2" src="$3" + dir="$groupdir/projects/$name" Log "\nCreate Project $1 in director $2" # Create directory @@ -214,6 +206,9 @@ function CreateProject() # Copy files Log " Copy files" + + Copy "$ScriptDir/cmake" "$groupdir/cmake" "/Find$src.cmake" "$src" "$name" + srcDir="$ScriptDir/projects/$src" for file in $(find $srcDir -type f); do @@ -323,8 +318,8 @@ while [ $# -gt 0 ]; do IgnoreVsCodeSettings=0 ;; - "-n" | "--nogit" ) - UseGit=0 + "--git" ) + UseGit=1 ;; "-v" | "--verbose" )