Added first compiling version
This commit is contained in:
parent
26d8821665
commit
5453f173ca
11 changed files with 370 additions and 0 deletions
80
CMakeLists.txt
Normal file
80
CMakeLists.txt
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
# SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.14...3.22)
|
||||||
|
|
||||||
|
include(cmake/version-from-git.cmake)
|
||||||
|
|
||||||
|
# ---- Project ----
|
||||||
|
|
||||||
|
project(
|
||||||
|
Glimpses
|
||||||
|
VERSION ${VERSION_STRING}
|
||||||
|
LANGUAGES CXX
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Include guards ----
|
||||||
|
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||||
|
message(
|
||||||
|
FATAL_ERROR
|
||||||
|
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---- Add dependencies via CPM ----
|
||||||
|
# see https://github.com/TheLartians/CPM.cmake for more info
|
||||||
|
|
||||||
|
include(cmake/CPM.cmake)
|
||||||
|
|
||||||
|
# PackageProject.cmake will be used to make our target installable
|
||||||
|
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.8.0")
|
||||||
|
|
||||||
|
# CPMAddPackage( NAME fmt GIT_TAG 9.1.0 GITHUB_REPOSITORY fmtlib/fmt OPTIONS "FMT_INSTALL YES" # create an installable
|
||||||
|
# target )
|
||||||
|
|
||||||
|
# ---- Add source files ----
|
||||||
|
file(
|
||||||
|
GLOB_RECURSE
|
||||||
|
headers
|
||||||
|
CONFIGURE_DEPENDS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h"
|
||||||
|
)
|
||||||
|
file(
|
||||||
|
GLOB_RECURSE
|
||||||
|
sources
|
||||||
|
CONFIGURE_DEPENDS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Create library ----
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} ${headers} ${sources})
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
|
||||||
|
|
||||||
|
# being a cross-platform target, we enforce standards conformance on MSVC
|
||||||
|
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")
|
||||||
|
|
||||||
|
# Link dependencies
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE # fmt::fmt
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
|
||||||
|
)
|
||||||
|
|
||||||
|
# the location where the project's version header will be placed should match the project's regular header paths
|
||||||
|
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)
|
||||||
|
|
||||||
|
packageProject(
|
||||||
|
NAME ${PROJECT_NAME}
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
NAMESPACE ${PROJECT_NAME}
|
||||||
|
BINARY_DIR ${PROJECT_BINARY_DIR}
|
||||||
|
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
|
||||||
|
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||||
|
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
|
||||||
|
COMPATIBILITY SameMajorVersion
|
||||||
|
DEPENDENCIES ""
|
||||||
|
)
|
35
cmake/version-from-git.cmake
Normal file
35
cmake/version-from-git.cmake
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
# ---- retrieve version information from git ----
|
||||||
|
set(GIT_DEFAULT_VERSION "0.0.0")
|
||||||
|
execute_process(
|
||||||
|
COMMAND git describe --tags --dirty --always
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION_STRING
|
||||||
|
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
if(GIT_DESCRIBE_ERROR_CODE EQUAL 0)
|
||||||
|
string(
|
||||||
|
REGEX MATCH
|
||||||
|
"^v?([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?(\\.([0-9]+))?.*$"
|
||||||
|
_
|
||||||
|
"${GIT_DESCRIBE_VERSION_STRING}"
|
||||||
|
)
|
||||||
|
if(DEFINED CMAKE_MATCH_1)
|
||||||
|
set(VERSION_STRING "${CMAKE_MATCH_1}")
|
||||||
|
if(DEFINED CMAKE_MATCH_3)
|
||||||
|
string(APPEND VERSION_STRING ".${CMAKE_MATCH_3}")
|
||||||
|
if(DEFINED CMAKE_MATCH_5)
|
||||||
|
string(APPEND VERSION_STRING ".${CMAKE_MATCH_5}")
|
||||||
|
if(DEFINED CMAKE_MATCH_7)
|
||||||
|
string(APPEND VERSION_STRING ".${CMAKE_MATCH_7}")
|
||||||
|
endif(DEFINED CMAKE_MATCH_7)
|
||||||
|
endif(DEFINED CMAKE_MATCH_5)
|
||||||
|
endif(DEFINED CMAKE_MATCH_3)
|
||||||
|
else(DEFINED CMAKE_MATCH_1)
|
||||||
|
set(VERSION_STRING "${GIT_DEFAULT_VERSION}")
|
||||||
|
endif(DEFINED CMAKE_MATCH_1)
|
||||||
|
endif()
|
38
documentation/CMakeLists.txt
Normal file
38
documentation/CMakeLists.txt
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# SPDX-FileCopyrightText: 2023 github.com/TheLartians
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.14...3.22)
|
||||||
|
|
||||||
|
project(GlimpsesDocs)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(../cmake/CPM.cmake)
|
||||||
|
|
||||||
|
CPMAddPackage("gh:mosra/m.css#a0d292ec311b97fefd21e93cdefb60f88d19ede6")
|
||||||
|
CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
|
||||||
|
|
||||||
|
# ---- Doxygen variables ----
|
||||||
|
|
||||||
|
# set Doxyfile variables
|
||||||
|
set(DOXYGEN_PROJECT_NAME Glimpses)
|
||||||
|
set(DOXYGEN_PROJECT_VERSION ${Glimpses_VERSION})
|
||||||
|
set(DOXYGEN_PROJECT_ROOT "${CMAKE_CURRENT_LIST_DIR}/..")
|
||||||
|
set(DOXYGEN_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen")
|
||||||
|
|
||||||
|
configure_file(${CMAKE_CURRENT_LIST_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||||
|
|
||||||
|
configure_file(${CMAKE_CURRENT_LIST_DIR}/conf.py ${CMAKE_CURRENT_BINARY_DIR}/conf.py)
|
||||||
|
|
||||||
|
# cmake-lint: disable=C0113
|
||||||
|
add_custom_target(
|
||||||
|
GenerateDocs
|
||||||
|
${CMAKE_COMMAND}
|
||||||
|
-E
|
||||||
|
make_directory
|
||||||
|
"${DOXYGEN_OUTPUT_DIRECTORY}"
|
||||||
|
COMMAND "${m.css_SOURCE_DIR}/documentation/doxygen.py" "${CMAKE_CURRENT_BINARY_DIR}/conf.py"
|
||||||
|
COMMAND echo "Docs written to: ${DOXYGEN_OUTPUT_DIRECTORY}"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
)
|
8
documentation/pages/about.dox
Normal file
8
documentation/pages/about.dox
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
/** @page about About
|
||||||
|
@section doc Glimpses Documentation
|
||||||
|
This is the auto-generated documentation for the Glimpses project.
|
||||||
|
*/
|
25
include/glimpses/glimpses.hpp
Normal file
25
include/glimpses/glimpses.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace glimpses {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A class for saying hello in multiple languages
|
||||||
|
*/
|
||||||
|
class Glimpses
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Creates a new glimpses
|
||||||
|
* @param name the name to greet
|
||||||
|
*/
|
||||||
|
Glimpses();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace glimpses
|
9
source/glimpses.cpp
Normal file
9
source/glimpses.cpp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
#include <glimpses/glimpses.hpp>
|
||||||
|
|
||||||
|
using namespace glimpses;
|
||||||
|
|
||||||
|
Glimpses::Glimpses() {}
|
33
standalone/CMakeLists.txt
Normal file
33
standalone/CMakeLists.txt
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.14...3.22)
|
||||||
|
|
||||||
|
project(GlimpsesStandalone LANGUAGES CXX)
|
||||||
|
|
||||||
|
# --- Import tools ----
|
||||||
|
|
||||||
|
include(../cmake/tools.cmake)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(../cmake/CPM.cmake)
|
||||||
|
|
||||||
|
CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
|
||||||
|
|
||||||
|
# ---- Create standalone executable ----
|
||||||
|
|
||||||
|
file(
|
||||||
|
GLOB
|
||||||
|
sources
|
||||||
|
CONFIGURE_DEPENDS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} ${sources})
|
||||||
|
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 OUTPUT_NAME "Glimpses")
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} Glimpses::Glimpses # Boost::System
|
||||||
|
)
|
16
standalone/source/main.cpp
Normal file
16
standalone/source/main.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
#include <glimpses/glimpses.hpp>
|
||||||
|
#include <glimpses/version.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int, char**)
|
||||||
|
{
|
||||||
|
glimpses::Glimpses glimpses;
|
||||||
|
std::cout << "Hello, World." << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
87
test/CMakeLists.txt
Normal file
87
test/CMakeLists.txt
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
# SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.14...3.22)
|
||||||
|
|
||||||
|
project(GlimpsesTests LANGUAGES CXX)
|
||||||
|
|
||||||
|
# ---- Options ----
|
||||||
|
|
||||||
|
option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF)
|
||||||
|
|
||||||
|
# --- Import tools ----
|
||||||
|
|
||||||
|
include(../cmake/tools.cmake)
|
||||||
|
|
||||||
|
# ---- Dependencies ----
|
||||||
|
|
||||||
|
include(../cmake/CPM.cmake)
|
||||||
|
|
||||||
|
# CPMAddPackage("gh:doctest/doctest@2.4.9")
|
||||||
|
CPMAddPackage("gh:TheLartians/Format.cmake@1.7.3")
|
||||||
|
|
||||||
|
if(TEST_INSTALLED_VERSION)
|
||||||
|
find_package(Glimpses REQUIRED)
|
||||||
|
else()
|
||||||
|
CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---- Create binary ----
|
||||||
|
|
||||||
|
file(
|
||||||
|
GLOB
|
||||||
|
sources
|
||||||
|
CONFIGURE_DEPENDS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
|
||||||
|
)
|
||||||
|
add_executable(${PROJECT_NAME} ${sources})
|
||||||
|
target_link_libraries(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
# doctest::doctest
|
||||||
|
Glimpses::Glimpses
|
||||||
|
)
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
|
||||||
|
|
||||||
|
# enable compiler warnings
|
||||||
|
if(NOT TEST_INSTALLED_VERSION)
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||||
|
target_compile_options(
|
||||||
|
Glimpses
|
||||||
|
PUBLIC -Wall
|
||||||
|
-Wpedantic
|
||||||
|
-Wextra
|
||||||
|
-Werror
|
||||||
|
)
|
||||||
|
elseif(MSVC)
|
||||||
|
target_compile_options(Glimpses PUBLIC /W4 /WX)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---- Add GlimpsesTests ----
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
# Note: doctest and similar testing frameworks can automatically configure CMake tests. For other testing frameworks add
|
||||||
|
# the tests target instead: add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
|
||||||
|
|
||||||
|
# include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake) doctest_discover_tests(${PROJECT_NAME})
|
||||||
|
|
||||||
|
# ---- code coverage ----
|
||||||
|
|
||||||
|
if(ENABLE_TEST_COVERAGE)
|
||||||
|
target_compile_options(
|
||||||
|
Glimpses
|
||||||
|
PUBLIC -O0
|
||||||
|
-g
|
||||||
|
-fprofile-arcs
|
||||||
|
-ftest-coverage
|
||||||
|
)
|
||||||
|
target_link_options(
|
||||||
|
Glimpses
|
||||||
|
PUBLIC
|
||||||
|
-fprofile-arcs
|
||||||
|
-ftest-coverage
|
||||||
|
)
|
||||||
|
endif()
|
25
test/source/glimpses.cpp
Normal file
25
test/source/glimpses.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
#include <glimpses/glimpses.hpp>
|
||||||
|
#include <glimpses/version.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
/*
|
||||||
|
TEST_CASE("Glimpses") {
|
||||||
|
using namespace greeter;
|
||||||
|
|
||||||
|
Glimpses greeter("Tests");
|
||||||
|
|
||||||
|
CHECK(greeter.greet(LanguageCode::EN) == "Hello, Tests!");
|
||||||
|
CHECK(greeter.greet(LanguageCode::DE) == "Hallo Tests!");
|
||||||
|
CHECK(greeter.greet(LanguageCode::ES) == "¡Hola Tests!");
|
||||||
|
CHECK(greeter.greet(LanguageCode::FR) == "Bonjour Tests!");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Glimpses version") {
|
||||||
|
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0"));
|
||||||
|
CHECK(std::string(GREETER_VERSION) == std::string("1.0"));
|
||||||
|
}
|
||||||
|
*/
|
14
test/source/main.cpp
Normal file
14
test/source/main.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
#if 0
|
||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
|
||||||
|
#include <doctest/doctest.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue