From 50df475fdd4674b3af37f7d1d745e4e9aa4ddae7 Mon Sep 17 00:00:00 2001 From: bergmann Date: Tue, 11 Jun 2019 16:15:49 +0200 Subject: [PATCH] * Initial commit --- .gitignore | 1 + .gitmodules | 3 + CMakeLists.txt | 27 ++ cmake/modules | 1 + projects/helloworld/CMakeLists.txt | 49 +++ projects/helloworld/include/helloworld.h | 3 + .../helloworld/include/helloworld/dummy.h | 14 + projects/helloworld/src/CMakeLists.txt | 69 ++++ projects/helloworld/src/helloworld/dummy.cpp | 8 + projects/helloworld/src/main.cpp | 9 + projects/helloworld/test/CMakeLists.txt | 42 +++ .../test/helloworld/helloworld-tests.cpp | 11 + projects/libhelloworld/CMakeLists.txt | 71 +++++ .../cmake/libhelloworld-config.cmake | 4 + .../libhelloworld/include/libhelloworld.h | 3 + .../include/libhelloworld/dummy.h | 13 + projects/libhelloworld/src/CMakeLists.txt | 107 +++++++ .../libhelloworld/src/libhelloworld/dummy.cpp | 8 + projects/libhelloworld/test/CMakeLists.txt | 42 +++ .../libhelloworld/libhelloworld-tests.cpp | 11 + tool | 299 ++++++++++++++++++ 21 files changed, 795 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 160000 cmake/modules create mode 100644 projects/helloworld/CMakeLists.txt create mode 100644 projects/helloworld/include/helloworld.h create mode 100644 projects/helloworld/include/helloworld/dummy.h create mode 100644 projects/helloworld/src/CMakeLists.txt create mode 100644 projects/helloworld/src/helloworld/dummy.cpp create mode 100644 projects/helloworld/src/main.cpp create mode 100644 projects/helloworld/test/CMakeLists.txt create mode 100644 projects/helloworld/test/helloworld/helloworld-tests.cpp create mode 100644 projects/libhelloworld/CMakeLists.txt create mode 100644 projects/libhelloworld/cmake/libhelloworld-config.cmake create mode 100644 projects/libhelloworld/include/libhelloworld.h create mode 100644 projects/libhelloworld/include/libhelloworld/dummy.h create mode 100644 projects/libhelloworld/src/CMakeLists.txt create mode 100644 projects/libhelloworld/src/libhelloworld/dummy.cpp create mode 100644 projects/libhelloworld/test/CMakeLists.txt create mode 100644 projects/libhelloworld/test/libhelloworld/libhelloworld-tests.cpp create mode 100755 tool diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a89889c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmake/modules"] + path = cmake/modules + url = b3rgmann@git.bergmann89.de:cpp/CmakeModules.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f2525cb --- /dev/null +++ b/CMakeLists.txt @@ -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 ) diff --git a/cmake/modules b/cmake/modules new file mode 160000 index 0000000..1e74005 --- /dev/null +++ b/cmake/modules @@ -0,0 +1 @@ +Subproject commit 1e74005bc2f91434fecb2e5f698c21b73f7e3a13 diff --git a/projects/helloworld/CMakeLists.txt b/projects/helloworld/CMakeLists.txt new file mode 100644 index 0000000..2e50fb6 --- /dev/null +++ b/projects/helloworld/CMakeLists.txt @@ -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 ) diff --git a/projects/helloworld/include/helloworld.h b/projects/helloworld/include/helloworld.h new file mode 100644 index 0000000..28807e7 --- /dev/null +++ b/projects/helloworld/include/helloworld.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/projects/helloworld/include/helloworld/dummy.h b/projects/helloworld/include/helloworld/dummy.h new file mode 100644 index 0000000..eb58654 --- /dev/null +++ b/projects/helloworld/include/helloworld/dummy.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace helloworld +{ + + struct DummyEx + : public libhelloworld::Dummy + { + static std::string getHelloWorldEx(); + }; + +} diff --git a/projects/helloworld/src/CMakeLists.txt b/projects/helloworld/src/CMakeLists.txt new file mode 100644 index 0000000..8937f33 --- /dev/null +++ b/projects/helloworld/src/CMakeLists.txt @@ -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 + $ + $ ) +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 ( ) diff --git a/projects/helloworld/src/helloworld/dummy.cpp b/projects/helloworld/src/helloworld/dummy.cpp new file mode 100644 index 0000000..f9c88da --- /dev/null +++ b/projects/helloworld/src/helloworld/dummy.cpp @@ -0,0 +1,8 @@ +#include + +using namespace ::helloworld; + +std::string DummyEx::getHelloWorldEx() +{ + return Dummy::getHelloWorld() + "\nThis is a simple executable :)"; +} diff --git a/projects/helloworld/src/main.cpp b/projects/helloworld/src/main.cpp new file mode 100644 index 0000000..ce628bb --- /dev/null +++ b/projects/helloworld/src/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +using namespace ::helloworld; + +int main(int argc, const char * argv[]) +{ + std::cout << DummyEx::getHelloWorldEx() << std::endl; +} diff --git a/projects/helloworld/test/CMakeLists.txt b/projects/helloworld/test/CMakeLists.txt new file mode 100644 index 0000000..e0383eb --- /dev/null +++ b/projects/helloworld/test/CMakeLists.txt @@ -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 ( ) diff --git a/projects/helloworld/test/helloworld/helloworld-tests.cpp b/projects/helloworld/test/helloworld/helloworld-tests.cpp new file mode 100644 index 0000000..0877beb --- /dev/null +++ b/projects/helloworld/test/helloworld/helloworld-tests.cpp @@ -0,0 +1,11 @@ +#include + +#include + +using namespace ::testing; +using namespace ::helloworld; + +TEST(helloworld, getHelloWorldEx) +{ + EXPECT_EQ(DummyEx::getHelloWorldEx(), "Hello World!\nThis is a simple executable :)"); +} diff --git a/projects/libhelloworld/CMakeLists.txt b/projects/libhelloworld/CMakeLists.txt new file mode 100644 index 0000000..cb00eca --- /dev/null +++ b/projects/libhelloworld/CMakeLists.txt @@ -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 ) diff --git a/projects/libhelloworld/cmake/libhelloworld-config.cmake b/projects/libhelloworld/cmake/libhelloworld-config.cmake new file mode 100644 index 0000000..b19b8da --- /dev/null +++ b/projects/libhelloworld/cmake/libhelloworld-config.cmake @@ -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 ) diff --git a/projects/libhelloworld/include/libhelloworld.h b/projects/libhelloworld/include/libhelloworld.h new file mode 100644 index 0000000..5cbdae3 --- /dev/null +++ b/projects/libhelloworld/include/libhelloworld.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/projects/libhelloworld/include/libhelloworld/dummy.h b/projects/libhelloworld/include/libhelloworld/dummy.h new file mode 100644 index 0000000..afc52a3 --- /dev/null +++ b/projects/libhelloworld/include/libhelloworld/dummy.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace libhelloworld +{ + + struct Dummy + { + static std::string getHelloWorld(); + }; + +} diff --git a/projects/libhelloworld/src/CMakeLists.txt b/projects/libhelloworld/src/CMakeLists.txt new file mode 100644 index 0000000..6fdf16b --- /dev/null +++ b/projects/libhelloworld/src/CMakeLists.txt @@ -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 + $ + $ ) + +# Static Library ################################################################################## + +Message ( WARNING "Please configure the output name of the static library target!" ) +Add_Library ( libhelloworld-static STATIC $ ) +Set_Target_Properties ( libhelloworld-static + PROPERTIES + OUTPUT_NAME "helloworld" ) +Target_Include_Directories ( libhelloworld-static + PUBLIC + $ + $ ) + +# Shared Library ################################################################################## + +Message ( WARNING "Please configure the output name of the shared library target!" ) +Add_Library ( libhelloworld-shared SHARED $ ) +Set_Target_Properties ( libhelloworld-shared + PROPERTIES + OUTPUT_NAME "helloworld" ) +Target_Include_Directories ( libhelloworld-shared + PUBLIC + $ + $ ) + +# 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 ( ) diff --git a/projects/libhelloworld/src/libhelloworld/dummy.cpp b/projects/libhelloworld/src/libhelloworld/dummy.cpp new file mode 100644 index 0000000..1632dcc --- /dev/null +++ b/projects/libhelloworld/src/libhelloworld/dummy.cpp @@ -0,0 +1,8 @@ +#include + +using namespace ::libhelloworld; + +std::string Dummy::getHelloWorld() +{ + return "Hello World!"; +} diff --git a/projects/libhelloworld/test/CMakeLists.txt b/projects/libhelloworld/test/CMakeLists.txt new file mode 100644 index 0000000..b4f8c38 --- /dev/null +++ b/projects/libhelloworld/test/CMakeLists.txt @@ -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 ( ) diff --git a/projects/libhelloworld/test/libhelloworld/libhelloworld-tests.cpp b/projects/libhelloworld/test/libhelloworld/libhelloworld-tests.cpp new file mode 100644 index 0000000..7542845 --- /dev/null +++ b/projects/libhelloworld/test/libhelloworld/libhelloworld-tests.cpp @@ -0,0 +1,11 @@ +#include + +#include + +using namespace ::testing; +using namespace ::libhelloworld; + +TEST(libhelloworld, getHelloWorld) +{ + EXPECT_EQ(Dummy::getHelloWorld(), "Hello World!"); +} diff --git a/tool b/tool new file mode 100755 index 0000000..891bb87 --- /dev/null +++ b/tool @@ -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 + Create a new project group at the given directory. + + -l|--library + Create a new library project with the given name at the given directory. + + -e|--executable + Create a new executable project with the given name at the given directory. + + -m|--modules + 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