| @@ -0,0 +1 @@ | |||
| build/ | |||
| @@ -0,0 +1,3 @@ | |||
| [submodule "cmake/modules"] | |||
| path = cmake/modules | |||
| url = b3rgmann@git.bergmann89.de:cpp/CmakeModules.git | |||
| @@ -0,0 +1,27 @@ | |||
| # 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/" ) | |||
| Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ) | |||
| EndIf ( ) | |||
| # Projects ######################################################################################## | |||
| Message ( WARNING "Please configure the subprojects of this project group!" ) | |||
| Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/projects/libhelloworld ) | |||
| Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/projects/helloworld ) | |||
| @@ -0,0 +1 @@ | |||
| Subproject commit 1e74005bc2f91434fecb2e5f698c21b73f7e3a13 | |||
| @@ -0,0 +1,49 @@ | |||
| # 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/" ) | |||
| Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ) | |||
| EndIf ( ) | |||
| # 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_SHORT "${HELLOWORLD_VERSION_MAJOR}.${HELLOWORLD_VERSION_MINOR}" ) | |||
| Set ( HELLOWORLD_VERSION "${HELLOWORLD_VERSION_SHORT}.${HELLOWORLD_VERSION_PATCH}.${HELLOWORLD_VERSION_BUILD}" ) | |||
| Set ( HELLOWORLD_NAME "helloworld-${HELLOWORLD_VERSION_SHORT}" ) | |||
| # Install directories | |||
| Set ( HELLOWORLD_INSTALL_DIR_BIN "bin" ) | |||
| # Project | |||
| Project ( helloworld | |||
| DESCRIPTION "A simple library" | |||
| VERSION "${HELLOWORLD_VERSION}" ) | |||
| Include ( CTest ) | |||
| # C Standard | |||
| Set ( CMAKE_C_STANDARD 11 ) | |||
| Set ( CMAKE_CXX_STANDARD 17 ) | |||
| Set ( CMAKE_C_STANDARD_REQUIRED ON ) | |||
| Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) | |||
| # Subdirectories | |||
| Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/src ) | |||
| Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/test ) | |||
| @@ -0,0 +1,3 @@ | |||
| #pragma once | |||
| #include <helloworld/dummy.h> | |||
| @@ -0,0 +1,14 @@ | |||
| #pragma once | |||
| #include <libhelloworld.h> | |||
| namespace helloworld | |||
| { | |||
| struct DummyEx | |||
| : public libhelloworld::Dummy | |||
| { | |||
| static std::string getHelloWorldEx(); | |||
| }; | |||
| } | |||
| @@ -0,0 +1,69 @@ | |||
| # Initialize ###################################################################################### | |||
| Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) | |||
| Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) | |||
| Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) | |||
| If ( HAS_PEDANTIC ) | |||
| Pedantic_Apply_Flags ( ALL ) | |||
| EndIf ( ) | |||
| Option ( HELLOWORLD_INSTALL_DEBUG | |||
| "Install the stripped debug informations of helloworld." | |||
| OFF ) | |||
| Option ( HELLOWORLD_NO_STRIP | |||
| "Do not strip debug symbols from binary." | |||
| OFF ) | |||
| 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 | |||
| $<BUILD_INTERFACE:${HELLOWORLD_INCLUDE_DIR}> | |||
| $<INSTALL_INTERFACE:${HELLOWORLD_INSTALL_DIR_INCLUDE}> ) | |||
| 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 #################################################################################### | |||
| 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 ( ) | |||
| @@ -0,0 +1,8 @@ | |||
| #include <helloworld/dummy.h> | |||
| using namespace ::helloworld; | |||
| std::string DummyEx::getHelloWorldEx() | |||
| { | |||
| return Dummy::getHelloWorld() + "\nThis is a simple executable :)"; | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| #include <iostream> | |||
| #include <helloworld.h> | |||
| using namespace ::helloworld; | |||
| int main(int argc, const char * argv[]) | |||
| { | |||
| std::cout << DummyEx::getHelloWorldEx() << std::endl; | |||
| } | |||
| @@ -0,0 +1,42 @@ | |||
| # Initialize ###################################################################################### | |||
| Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) | |||
| Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) | |||
| Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) | |||
| If ( HAS_PEDANTIC ) | |||
| Pedantic_Apply_Flags ( ALL ) | |||
| EndIf ( ) | |||
| # Test ############################################################################################ | |||
| Find_Package ( GTest ) | |||
| 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 ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) | |||
| Add_Executable ( helloworld-test | |||
| EXCLUDE_FROM_ALL | |||
| ${HELLOWORLD_TEST_HEADER_FILES} | |||
| ${HELLOWORLD_TEST_INLINE_FILES} | |||
| ${HELLOWORLD_TEST_SOURCE_FILES} ) | |||
| Target_Link_Libraries ( helloworld-test | |||
| PUBLIC | |||
| helloworld-objects | |||
| GTest::Main ) | |||
| # optimization | |||
| If ( HAS_COTIRE ) | |||
| Cotire ( helloworld-test ) | |||
| EndIf ( ) | |||
| # test | |||
| If ( HAS_CMAKE_TESTS ) | |||
| Add_CMake_Test ( NAME helloworld TARGET helloworld-test ) | |||
| Else ( ) | |||
| Add_Test ( NAME helloworld COMMAND helloworld-test ) | |||
| EndIf ( ) | |||
| @@ -0,0 +1,11 @@ | |||
| #include <gtest/gtest.h> | |||
| #include <helloworld.h> | |||
| using namespace ::testing; | |||
| using namespace ::helloworld; | |||
| TEST(helloworld, getHelloWorldEx) | |||
| { | |||
| EXPECT_EQ(DummyEx::getHelloWorldEx(), "Hello World!\nThis is a simple executable :)"); | |||
| } | |||
| @@ -0,0 +1,71 @@ | |||
| # 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/" ) | |||
| Set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} | |||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ) | |||
| EndIf ( ) | |||
| # 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_SHORT "${LIBHELLOWORLD_VERSION_MAJOR}.${LIBHELLOWORLD_VERSION_MINOR}" ) | |||
| Set ( LIBHELLOWORLD_VERSION "${LIBHELLOWORLD_VERSION_SHORT}.${LIBHELLOWORLD_VERSION_PATCH}.${LIBHELLOWORLD_VERSION_BUILD}" ) | |||
| Set ( LIBHELLOWORLD_NAME "libhelloworld-${LIBHELLOWORLD_VERSION_SHORT}" ) | |||
| # Install directories | |||
| Set ( LIBHELLOWORLD_INSTALL_DIR_INCLUDE "include/${LIBHELLOWORLD_NAME}" ) | |||
| Set ( LIBHELLOWORLD_INSTALL_DIR_LIB "lib/${LIBHELLOWORLD_NAME}" ) | |||
| Set ( LIBHELLOWORLD_INSTALL_DIR_SHARE "share/${LIBHELLOWORLD_NAME}" ) | |||
| # Project | |||
| Project ( libhelloworld | |||
| DESCRIPTION "A simple library" | |||
| VERSION "${LIBHELLOWORLD_VERSION}" ) | |||
| Include ( CTest ) | |||
| # C Standard | |||
| Set ( CMAKE_C_STANDARD 11 ) | |||
| Set ( CMAKE_CXX_STANDARD 17 ) | |||
| Set ( CMAKE_C_STANDARD_REQUIRED ON ) | |||
| Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) | |||
| # Subdirectories | |||
| Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/src ) | |||
| Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/test ) | |||
| # Install | |||
| 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 | |||
| 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 ) | |||
| @@ -0,0 +1,4 @@ | |||
| # libhelloworld-config.cmake - package configuration file | |||
| Get_Filename_Component ( CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH ) | |||
| Include ( ${CURRENT_DIR}/libhelloworld.cmake ) | |||
| @@ -0,0 +1,3 @@ | |||
| #pragma once | |||
| #include <libhelloworld/dummy.h> | |||
| @@ -0,0 +1,13 @@ | |||
| #pragma once | |||
| #include <string> | |||
| namespace libhelloworld | |||
| { | |||
| struct Dummy | |||
| { | |||
| static std::string getHelloWorld(); | |||
| }; | |||
| } | |||
| @@ -0,0 +1,107 @@ | |||
| # Initialize ###################################################################################### | |||
| Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) | |||
| Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) | |||
| Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) | |||
| If ( HAS_PEDANTIC ) | |||
| Pedantic_Apply_Flags ( ALL ) | |||
| EndIf ( ) | |||
| 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_NO_STRIP | |||
| "Do not strip debug symbols from binary." | |||
| OFF ) | |||
| # 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 | |||
| $<BUILD_INTERFACE:${LIBHELLOWORLD_INCLUDE_DIR}> | |||
| $<INSTALL_INTERFACE:${LIBHELLOWORLD_INSTALL_DIR_INCLUDE}> ) | |||
| # Static Library ################################################################################## | |||
| Message ( WARNING "Please configure the output name of the static library target!" ) | |||
| Add_Library ( libhelloworld-static STATIC $<TARGET_OBJECTS:libhelloworld-objects> ) | |||
| Set_Target_Properties ( libhelloworld-static | |||
| PROPERTIES | |||
| OUTPUT_NAME "helloworld" ) | |||
| Target_Include_Directories ( libhelloworld-static | |||
| PUBLIC | |||
| $<BUILD_INTERFACE:${LIBHELLOWORLD_INCLUDE_DIR}> | |||
| $<INSTALL_INTERFACE:${LIBHELLOWORLD_INSTALL_DIR_INCLUDE}> ) | |||
| # Shared Library ################################################################################## | |||
| Message ( WARNING "Please configure the output name of the shared library target!" ) | |||
| Add_Library ( libhelloworld-shared SHARED $<TARGET_OBJECTS:libhelloworld-objects> ) | |||
| Set_Target_Properties ( libhelloworld-shared | |||
| PROPERTIES | |||
| OUTPUT_NAME "helloworld" ) | |||
| Target_Include_Directories ( libhelloworld-shared | |||
| PUBLIC | |||
| $<BUILD_INTERFACE:${LIBHELLOWORLD_INCLUDE_DIR}> | |||
| $<INSTALL_INTERFACE:${LIBHELLOWORLD_INSTALL_DIR_INCLUDE}> ) | |||
| # Optimization #################################################################################### | |||
| If ( HAS_COTIRE ) | |||
| Cotire ( libhelloworld-objects ) | |||
| Cotire ( libhelloworld-static ) | |||
| Cotire ( libhelloworld-shared ) | |||
| EndIf ( ) | |||
| # Install ######################################################################################### | |||
| # 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 ) | |||
| 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 ( ) | |||
| @@ -0,0 +1,8 @@ | |||
| #include <libhelloworld/dummy.h> | |||
| using namespace ::libhelloworld; | |||
| std::string Dummy::getHelloWorld() | |||
| { | |||
| return "Hello World!"; | |||
| } | |||
| @@ -0,0 +1,42 @@ | |||
| # Initialize ###################################################################################### | |||
| Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) | |||
| Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) | |||
| Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) | |||
| If ( HAS_PEDANTIC ) | |||
| Pedantic_Apply_Flags ( ALL ) | |||
| EndIf ( ) | |||
| # Test ############################################################################################ | |||
| Find_Package ( GTest ) | |||
| 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 ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) | |||
| Add_Executable ( libhelloworld-test | |||
| EXCLUDE_FROM_ALL | |||
| ${LIBHELLOWORLD_TEST_HEADER_FILES} | |||
| ${LIBHELLOWORLD_TEST_INLINE_FILES} | |||
| ${LIBHELLOWORLD_TEST_SOURCE_FILES} ) | |||
| Target_Link_Libraries ( libhelloworld-test | |||
| PUBLIC | |||
| libhelloworld-objects | |||
| GTest::Main ) | |||
| # optimization | |||
| If ( HAS_COTIRE ) | |||
| Cotire ( libhelloworld-test ) | |||
| EndIf ( ) | |||
| # test | |||
| If ( HAS_CMAKE_TESTS ) | |||
| Add_CMake_Test ( NAME libhelloworld TARGET libhelloworld-test ) | |||
| Else ( ) | |||
| Add_Test ( NAME libhelloworld COMMAND libhelloworld-test ) | |||
| EndIf ( ) | |||
| @@ -0,0 +1,11 @@ | |||
| #include <gtest/gtest.h> | |||
| #include <libhelloworld.h> | |||
| using namespace ::testing; | |||
| using namespace ::libhelloworld; | |||
| TEST(libhelloworld, getHelloWorld) | |||
| { | |||
| EXPECT_EQ(Dummy::getHelloWorld(), "Hello World!"); | |||
| } | |||
| @@ -0,0 +1,299 @@ | |||
| #!/bin/bash | |||
| ScriptFile=$(readlink -f "${BASH_SOURCE[0]}") | |||
| ScriptDir=$(dirname "${ScriptFile}") | |||
| UseGit=1 | |||
| Verbose=0 | |||
| CMakeModules="" | |||
| Operations=() | |||
| function Log() | |||
| { | |||
| printf "$@\n" | |||
| } | |||
| function Verbose() | |||
| { | |||
| if [[ $Verbose -eq 1 ]]; then | |||
| Log "$@" | |||
| fi | |||
| } | |||
| function Error() | |||
| { | |||
| >&2 printf "$@\n" | |||
| } | |||
| function Panic() | |||
| { | |||
| Error $@ | |||
| exit 1 | |||
| } | |||
| function PrintHelp() | |||
| { | |||
| printf "This is a tool to create a new project group or projects inside an exsisting group. | |||
| Parameters: | |||
| -g|--group <directory> | |||
| Create a new project group at the given directory. | |||
| -l|--library <name> <directory> | |||
| Create a new library project with the given name at the given directory. | |||
| -e|--executable <name ><directory> | |||
| Create a new executable project with the given name at the given directory. | |||
| -m|--modules <remote> | |||
| Add the CMake Modules fromthe given remote repository as submodule of the new project. | |||
| -n|--nogit | |||
| Does not initialize a new git repository when creating a new project group. | |||
| -v|--verbose | |||
| Print extra debug output. | |||
| -?|-h|--help | |||
| Print this help. | |||
| " | |||
| } | |||
| function Copy() | |||
| { | |||
| srcDir="$1" | |||
| dstDir="$2" | |||
| file="$3" | |||
| oldName="$4" | |||
| newName="$5" | |||
| tmpSrc="$srcDir$file" | |||
| tmpDst="$dstDir$file" | |||
| if [[ -n "$oldName$newName" ]]; then | |||
| tmpDst=${tmpDst//$oldName/$newName} | |||
| fi | |||
| tmpDir=$(dirname $tmpDst) | |||
| Verbose " Copy .$file to $tmpDst" | |||
| mkdir -p "$tmpDir" \ | |||
| || Panic "Unable to create directory: $tmpDir!" | |||
| cp "$tmpSrc" "$tmpDst" \ | |||
| || Panic "Unable to copy file: $tmpSrc > $tmpDst!" | |||
| if [[ -n "$oldName$newName" ]]; then | |||
| oldUpper=$(echo $oldName | awk -F: '{ print toupper($1) }') | |||
| newUpper=$(echo $newName | awk -F: '{ print toupper($1) }') | |||
| sed -i -e "s/$oldName/$newName/g" "$tmpDst" \ | |||
| || Panic "Unable to replace names!" | |||
| sed -i -e "s/$oldUpper/$newUpper/g" "$tmpDst" \ | |||
| || Panic "Unable to replace names!" | |||
| fi | |||
| } | |||
| function CreateGroup() | |||
| { | |||
| dir="$1" | |||
| Log "\nCreate Project Group: $dir" | |||
| # Create directory | |||
| Log " Create directory: $dir" | |||
| mkdir -p "$dir" \ | |||
| || Panic "Unable to create project group directory: $dir!" | |||
| # Create git repository | |||
| Log " Create git repository" | |||
| if [[ $UseGit -eq 1 ]]; then | |||
| 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 "$CMakeModules" "$dir/cmake/modules" \ | |||
| || Panic "Git submodule add failed!" | |||
| fi | |||
| fi | |||
| # Copy files | |||
| Log " Copy files" | |||
| srcDir="$ScriptDir" | |||
| for file in $(find $srcDir -type f); do | |||
| if [[ $file == $ScriptFile ]] \ | |||
| || [[ $file == $srcDir/build/* ]] \ | |||
| || [[ $file == $srcDir/.git/* ]] \ | |||
| || [[ $file == $srcDir/.gitmodules ]] \ | |||
| || [[ $file == $srcDir/.vscode/* ]] \ | |||
| || [[ $file == $srcDir/projects/* ]] \ | |||
| || [[ $file == $srcDir/cmake/modules/* ]] | |||
| then | |||
| relFile=.${file/$srcDir/} | |||
| Verbose " Ignore $relFile" | |||
| elif [[ $UseGit -eq 0 ]] \ | |||
| && [[ $file == $srcDir/.git* ]] | |||
| then | |||
| relFile=.${file/$srcDir/} | |||
| Verbose " Ignore $relFile" | |||
| else | |||
| Copy "$srcDir" "$dir" "${file/$srcDir/}" | |||
| fi | |||
| done | |||
| } | |||
| function CreateLibrary() | |||
| { | |||
| name="$1" | |||
| dir="$2" | |||
| Log "\nCreate Library: $1 $2" | |||
| # Create directory | |||
| Log " Create directory: $dir" | |||
| mkdir -p "$dir" \ | |||
| || Panic "Unable to create directory: $dir!" | |||
| # Add cmake modules | |||
| if [[ $UseGit -eq 1 ]] && [[ -n "$CMakeModules" ]]; then | |||
| git -C $dir submodule add "$CMakeModules" "$dir/cmake/modules" \ | |||
| || Panic "Git submodule add failed!" | |||
| fi | |||
| # Copy files | |||
| Log " Copy files" | |||
| srcDir="$ScriptDir/projects/libhelloworld" | |||
| for file in $(find $srcDir -type f); do | |||
| if [[ $file == $srcDir/build/* ]] \ | |||
| || [[ $file == $srcDir/cmake/modules/* ]] | |||
| then | |||
| relFile=.${file/$srcDir/} | |||
| Verbose " Ignore $relFile" | |||
| elif [[ $UseGit -eq 0 ]] \ | |||
| && [[ $file == $srcDir/.git* ]] | |||
| then | |||
| relFile=.${file/$srcDir/} | |||
| Verbose " Ignore $relFile" | |||
| else | |||
| Copy "$srcDir" "$dir" "${file/$srcDir/}" "libhelloworld" "$name" | |||
| fi | |||
| done | |||
| } | |||
| function CreateExecutable() | |||
| { | |||
| name="$1" | |||
| dir="$2" | |||
| Log "\nCreate Executable: $1 $2" | |||
| # Create directory | |||
| Log " Create directory: $dir" | |||
| mkdir -p "$dir" \ | |||
| || Panic "Unable to create directory: $dir!" | |||
| # Add cmake modules | |||
| if [[ $UseGit -eq 1 ]] && [[ -n "$CMakeModules" ]]; then | |||
| git -C $dir submodule add "$CMakeModules" "$dir/cmake/modules" \ | |||
| || Panic "Git submodule add failed!" | |||
| fi | |||
| # Copy files | |||
| Log " Copy files" | |||
| srcDir="$ScriptDir/projects/helloworld" | |||
| for file in $(find $srcDir -type f); do | |||
| if [[ $file == $srcDir/build/* ]] \ | |||
| || [[ $file == $srcDir/cmake/modules/* ]] | |||
| then | |||
| relFile=.${file/$srcDir/} | |||
| Verbose " Ignore $relFile" | |||
| elif [[ $UseGit -eq 0 ]] \ | |||
| && [[ $file == $srcDir/.git* ]] | |||
| then | |||
| relFile=.${file/$srcDir/} | |||
| Verbose " Ignore $relFile" | |||
| else | |||
| Copy "$srcDir" "$dir" "${file/$srcDir/}" "helloworld" "$name" | |||
| fi | |||
| done | |||
| } | |||
| # Parse arguments | |||
| while [ $# -gt 0 ]; do | |||
| case $1 in | |||
| "-g" | "--group" ) | |||
| if [ $# -lt 2 ]; then | |||
| Panic "Parameter $1 expects exactly one parameter!" | |||
| fi | |||
| Operations+=("grp:$2") | |||
| shift | |||
| ;; | |||
| "-l" | "--library" ) | |||
| if [ $# -lt 3 ]; then | |||
| Panic "Parameter $1 expects exactly two parameter!" | |||
| fi | |||
| Operations+=("lib:$2:$3") | |||
| shift | |||
| shift | |||
| ;; | |||
| "-e" | "--executable" ) | |||
| if [ $# -lt 3 ]; then | |||
| Panic "Parameter $1 expects exactly two parameter!" | |||
| fi | |||
| Operations+=("exe:$2:$3") | |||
| shift | |||
| shift | |||
| ;; | |||
| "-m" | "--modules" ) | |||
| if [ $# -lt 2 ]; then | |||
| Panic "Parameter $1 expects exactly one parameter!" | |||
| fi | |||
| CMakeModules="$2" | |||
| shift | |||
| ;; | |||
| "-n" | "--nogit" ) | |||
| UseGit=0 | |||
| ;; | |||
| "-v" | "--verbose" ) | |||
| Verbose=1 | |||
| ;; | |||
| "-h" | "-?" | "--help" ) | |||
| PrintHelp | |||
| exit 0 | |||
| ;; | |||
| * ) | |||
| Panic "Invalid or unknown parameter: $1" | |||
| ;; | |||
| esac | |||
| shift | |||
| done | |||
| # Execute operations | |||
| for data in "${Operations[@]}"; do | |||
| op=$(echo $data | awk -F: '{ print $1 }') | |||
| case $op in | |||
| grp) | |||
| dir=$(echo $data | awk -F: '{ print $2 }') | |||
| CreateGroup "$dir" | |||
| ;; | |||
| lib) | |||
| name=$(echo $data | awk -F: '{ print $2 }') | |||
| dir=$(echo $data | awk -F: '{ print $3 }') | |||
| CreateLibrary "$name" "$dir" | |||
| ;; | |||
| exe) | |||
| name=$(echo $data | awk -F: '{ print $2 }') | |||
| dir=$(echo $data | awk -F: '{ print $3 }') | |||
| CreateExecutable "$name" "$dir" | |||
| ;; | |||
| *) | |||
| Panic "Invalid or unknown operation: $op" | |||
| ;; | |||
| esac | |||
| done | |||