From 2f3a28e89c147ea648911e82e84bbdb9e4bb9f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerard=20Gasc=C3=B3n?= Date: Sun, 8 Jun 2025 00:21:41 +0200 Subject: [PATCH] init --- .gitignore | 93 +++++++++++++++++++++++++++++++++++++++++++++ .gitmodules | 3 ++ CMakeLists.txt | 8 ++++ README.md | 14 +++++++ src/CMakeLists.txt | 3 ++ src/library.cpp | 5 +++ src/library.h | 6 +++ test/CMakeLists.txt | 7 ++++ test/Catch2 | 1 + test/test.cpp | 10 +++++ 10 files changed, 150 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 src/CMakeLists.txt create mode 100644 src/library.cpp create mode 100644 src/library.h create mode 100644 test/CMakeLists.txt create mode 160000 test/Catch2 create mode 100644 test/test.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd1538a --- /dev/null +++ b/.gitignore @@ -0,0 +1,93 @@ +### CMake template +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps +CMakeUserPresets.json +### CLion template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +.idea \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..310fe8f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test/Catch2"] + path = test/Catch2 + url = https://github.com/catchorg/Catch2.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3fc4f69 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.31) + +project(MyProject) + +set(CMAKE_CXX_STANDARD 20) + +add_subdirectory(src) +add_subdirectory(test) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..526d64f --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# C++ Template with tests + +A CMake template with C++20 and Catch2 + +--- + +## Setup + +Under [test/Catch2](test/Catch2) run the following commands: + +```shell +$ cmake -B build -S . -DBUILD_TESTING=OFF +$ sudo cmake --build build/ --target install +``` diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..f61b0af --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(src STATIC library.cpp) + +target_include_directories(src PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/library.cpp b/src/library.cpp new file mode 100644 index 0000000..a244504 --- /dev/null +++ b/src/library.cpp @@ -0,0 +1,5 @@ +#include "library.h" + +int hello() { + return 0; +} \ No newline at end of file diff --git a/src/library.h b/src/library.h new file mode 100644 index 0000000..52da59e --- /dev/null +++ b/src/library.h @@ -0,0 +1,6 @@ +#ifndef CPP_TEMPLATE_LIBRARY_H +#define CPP_TEMPLATE_LIBRARY_H + +int hello(); + +#endif //CPP_TEMPLATE_LIBRARY_H \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..baa7912 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,7 @@ +find_package(Catch2 3 REQUIRED) + +add_executable(test test.cpp) + +target_link_libraries(test PRIVATE Catch2::Catch2WithMain) + +target_link_libraries(test PRIVATE src) diff --git a/test/Catch2 b/test/Catch2 new file mode 160000 index 0000000..3013cb8 --- /dev/null +++ b/test/Catch2 @@ -0,0 +1 @@ +Subproject commit 3013cb897b5706e8532507cb2b6ac33e1fc35d93 diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..a0b519d --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,10 @@ +#include +#include "library.h" + +TEST_CASE("This test should pass") { + REQUIRE(hello() == 0); +} + +TEST_CASE("This test should fail") { + REQUIRE(hello() == 1); +}