commit 7e51d1fbf26ea500aebb31958d3e49846882bdb0 Author: bergmann Date: Fri Jun 28 21:30:13 2019 +0200 * Initial commit 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..ae530fe --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,56 @@ +# 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 ######################################################################################### + +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppmp-var.cmake ) +Project ( cppmp + DESCRIPTION "A simple library" + VERSION "${CPPMP_VERSION}" ) +Include ( CTest ) +Include ( GNUInstallDirs ) + +# 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/cppmp-config-version.cmake" + VERSION ${CPPMP_VERSION} + COMPATIBILITY AnyNewerVersion ) +Configure_File ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppmp-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/cppmp-config.cmake" + @ONLY ) + +Set ( ConfigPackageLocation "${CPPMP_INSTALL_DIR_SHARE}/cmake" ) +Install ( EXPORT + cppmp + NAMESPACE + cppmp:: + DESTINATION + ${ConfigPackageLocation} ) +Install ( FILES + "${CMAKE_CURRENT_BINARY_DIR}/cmake/cppmp-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/cppmp-config-version.cmake" + DESTINATION + ${ConfigPackageLocation} + COMPONENT + Devel ) diff --git a/cmake/cppmp-config.cmake b/cmake/cppmp-config.cmake new file mode 100644 index 0000000..3eb9de0 --- /dev/null +++ b/cmake/cppmp-config.cmake @@ -0,0 +1,10 @@ +# cppmp-config.cmake - package configuration file + +Message ( WARNING "Please configure the dependencies of this package!" ) +# Include ( CMakeFindDependencyMacro ) +# Find_Dependency ( ) + +Include ( FindPackageHandleStandardArgs ) +Set ( ${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE} ) +Find_Package_Handle_Standard_Args ( cppmp CONFIG_MODE ) +Include ( "${CMAKE_CURRENT_LIST_DIR}/cppmp.cmake") diff --git a/cmake/cppmp-var.cmake b/cmake/cppmp-var.cmake new file mode 100644 index 0000000..d81be74 --- /dev/null +++ b/cmake/cppmp-var.cmake @@ -0,0 +1,31 @@ +# Version +Set ( CPPMP_VERSION_MAJOR 1 ) +Set ( CPPMP_VERSION_MINOR 0 ) +Set ( CPPMP_VERSION_PATCH 0 ) +Set ( CPPMP_VERSION_BUILD 0 ) +Set ( CPPMP_VERSION_SHORT "${CPPMP_VERSION_MAJOR}.${CPPMP_VERSION_MINOR}" ) +Set ( CPPMP_VERSION "${CPPMP_VERSION_SHORT}.${CPPMP_VERSION_PATCH}.${CPPMP_VERSION_BUILD}" ) +Set ( CPPMP_NAME "cppmp-${CPPMP_VERSION_SHORT}" ) +Set ( CPPMP_OUTPUTNAME "cppmp" ) + +# Install directories +Set ( CPPMP_INSTALL_DIR_INCLUDE "include/${CPPMP_NAME}" ) +Set ( CPPMP_INSTALL_DIR_LIB "lib" ) +Set ( CPPMP_INSTALL_DIR_SHARE "share/${CPPMP_NAME}" ) + +# C Standard +Set ( CMAKE_C_STANDARD 11 ) +Set ( CMAKE_CXX_STANDARD 17 ) +Set ( CMAKE_C_STANDARD_REQUIRED ON ) +Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) + +# Git Version +Include ( git_helper OPTIONAL RESULT_VARIABLE HAS_GIT_HELPER ) +If ( HAS_GIT_HELPER ) + GitGetVersion ( ${CMAKE_CURRENT_LIST_DIR}/.. + CPPMP_VERSION_MAJOR + CPPMP_VERSION_MINOR + CPPMP_VERSION_PATCH + CPPMP_VERSION_BUILD + CPPMP_VERSION_HASH ) +EndIf ( ) diff --git a/cmake/modules b/cmake/modules new file mode 160000 index 0000000..1a32531 --- /dev/null +++ b/cmake/modules @@ -0,0 +1 @@ +Subproject commit 1a32531aef2deeebd5637b1873bc4e976628801c diff --git a/include/cppmp.h b/include/cppmp.h new file mode 100644 index 0000000..4f08f26 --- /dev/null +++ b/include/cppmp.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/include/cppmp/dummy.h b/include/cppmp/dummy.h new file mode 100644 index 0000000..5120598 --- /dev/null +++ b/include/cppmp/dummy.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace cppmp +{ + + struct Dummy + { + static std::string getHelloWorld(); + }; + +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..673ec5a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,25 @@ +# 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 ( CPPMP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include ) +Add_Library ( cppmp INTERFACE ) +Target_Include_Directories ( cppmp + INTERFACE + $ + $ ) + +# Install ######################################################################################### + +# Header +Install ( FILES ${CPPMP_INCLUDE_DIR}/cppmp.h + DESTINATION ${CPPMP_INSTALL_DIR_INCLUDE} ) +Install ( DIRECTORY ${CPPMP_INCLUDE_DIR}/cppmp + DESTINATION ${CPPMP_INSTALL_DIR_INCLUDE} ) +Install ( TARGETS cppmp + EXPORT cppmp + DESTINATION ${CPPMP_INSTALL_DIR_INCLUDE} ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..391ba82 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,43 @@ +# Initialize ###################################################################################### + +Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE ) +Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) +Include ( cmake_tests OPTIONAL RESULT_VARIABLE HAS_CMAKE_TESTS ) + +# Test ############################################################################################ + +Find_Package ( GTest ) +If ( NOT "${GTest_FOUND}" ) + Return ( ) +EndIf ( ) + +File ( GLOB_RECURSE CPPMP_TEST_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h ) +File ( GLOB_RECURSE CPPMP_TEST_INLINE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.inl ) +File ( GLOB_RECURSE CPPMP_TEST_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ) + +Add_Executable ( cppmp-test + EXCLUDE_FROM_ALL + ${CPPMP_TEST_HEADER_FILES} + ${CPPMP_TEST_INLINE_FILES} + ${CPPMP_TEST_SOURCE_FILES} ) +Target_Link_Libraries ( cppmp-test + PUBLIC + cppmp-objects + GTest::Main ) + +# pedantic +If ( HAS_PEDANTIC ) + Pedantic_Apply_Flags_Target ( cppmp-test ALL ) +EndIf ( ) + +# optimization +If ( HAS_COTIRE ) + Cotire ( cppmp-test ) +EndIf ( ) + +# test +If ( HAS_CMAKE_TESTS ) + Add_CMake_Test ( NAME cppmp TARGET cppmp-test ) +Else ( ) + Add_Test ( NAME cppmp COMMAND cppmp-test ) +EndIf ( ) diff --git a/test/cppmp/cppmp-tests.cpp b/test/cppmp/cppmp-tests.cpp new file mode 100644 index 0000000..a8b556a --- /dev/null +++ b/test/cppmp/cppmp-tests.cpp @@ -0,0 +1,11 @@ +#include + +#include + +using namespace ::testing; +using namespace ::cppmp; + +TEST(cppmp, getHelloWorld) +{ + EXPECT_EQ(Dummy::getHelloWorld(), "Hello World!"); +}