From daf6b057f62429a594e98a030ae1b83aa6c24257 Mon Sep 17 00:00:00 2001 From: Kemal Bidzhiev Date: Fri, 7 Aug 2026 11:31:39 +0200 Subject: [PATCH 1/4] gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b72747e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +#CMAKE +build + From b0eda432188c6195bd1b59ca96da42fd22774167 Mon Sep 17 00:00:00 2001 From: Kemal Bidzhiev Date: Fri, 7 Aug 2026 12:30:05 +0200 Subject: [PATCH 2/4] preliminary cmake --- CMakeLists.txt | 69 ++++++++++++++++++++++++++++ hello_world/CMakeLists.txt | 14 ++++++ hello_world/examples/CMakeLists.txt | 9 ++++ hello_world/examples/basic_usage.cpp | 0 hello_world/include/hw.hpp | 7 +++ hello_world/src/hw.cpp | 6 +++ hello_world/tests/CMakeLists.txt | 13 ++++++ hello_world/tests/hw_tests.cpp | 9 ++++ 8 files changed, 127 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 hello_world/CMakeLists.txt create mode 100644 hello_world/examples/CMakeLists.txt create mode 100644 hello_world/examples/basic_usage.cpp create mode 100644 hello_world/include/hw.hpp create mode 100644 hello_world/src/hw.cpp create mode 100644 hello_world/tests/CMakeLists.txt create mode 100644 hello_world/tests/hw_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7bf1bd3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.23) + +project( + DataStructures + #DESCRITPRION "C++ Data Stuctures" + LANGUAGES CXX +) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + + +# include(CTest) +# add_subdirectory(tests) + +# ------------------------------------------------------------------------------ +# Options +# ------------------------------------------------------------------------------ + +option(DSA_BUILD_TESTS "Build unit tests" ON) +option(DSA_BUILD_EXAMPLES "Build examples" ON) + +# ------------------------------------------------------------------------------ +# Dependencies +# ------------------------------------------------------------------------------ + +if (DSA_BUILD_TESTS) + include(FetchContent) + + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip + ) + + FetchContent_MakeAvailable(googletest) + + enable_testing() +endif() + +# ------------------------------------------------------------------------------ +# Compiler warnings +# ------------------------------------------------------------------------------ + +add_library(project_warnings INTERFACE) + +if (MSVC) + target_compile_options(project_warnings INTERFACE + /W4 + /permissive- + ) +else() + target_compile_options(project_warnings INTERFACE + -Wall + -Wextra + -Wpedantic + -Wconversion + -Wsign-conversion + ) +endif() + +# ------------------------------------------------------------------------------ +# Modules +# ------------------------------------------------------------------------------ + +add_subdirectory(hello_world) +# add_subdirectory(linked_list) diff --git a/hello_world/CMakeLists.txt b/hello_world/CMakeLists.txt new file mode 100644 index 0000000..1ace617 --- /dev/null +++ b/hello_world/CMakeLists.txt @@ -0,0 +1,14 @@ +add_library(HelloWorld) + +target_sources(HelloWorld + PRIVATE + src/hw.cpp +) + +target_include_directories(HelloWorld + PUBLIC + include +) + +#add_subdirectory(tests) +#add_subdirectory(examples) diff --git a/hello_world/examples/CMakeLists.txt b/hello_world/examples/CMakeLists.txt new file mode 100644 index 0000000..868ba3e --- /dev/null +++ b/hello_world/examples/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(basic_usage + basic_usage.cpp +) + +target_link_libraries(hello_world # hpp name + PRIVATE + hello_world # include foldername +) + diff --git a/hello_world/examples/basic_usage.cpp b/hello_world/examples/basic_usage.cpp new file mode 100644 index 0000000..e69de29 diff --git a/hello_world/include/hw.hpp b/hello_world/include/hw.hpp new file mode 100644 index 0000000..4862e64 --- /dev/null +++ b/hello_world/include/hw.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace HW { + std::string hello(); +} diff --git a/hello_world/src/hw.cpp b/hello_world/src/hw.cpp new file mode 100644 index 0000000..05768c6 --- /dev/null +++ b/hello_world/src/hw.cpp @@ -0,0 +1,6 @@ +#include +#include + +namespace HW{ +std::string hello() { return "Hello, world"; } +} // namespace diff --git a/hello_world/tests/CMakeLists.txt b/hello_world/tests/CMakeLists.txt new file mode 100644 index 0000000..f7850e3 --- /dev/null +++ b/hello_world/tests/CMakeLists.txt @@ -0,0 +1,13 @@ +add_executable(hello_world_tests + hw_tests.cpp +) + +target_link_libraries(hello_world_tests + PRIVATE + hello_world + #project_warnings + GTest::gtest_main +) + +include(GoogleTest) +gtest_discover_tests(hello_world_tests) diff --git a/hello_world/tests/hw_tests.cpp b/hello_world/tests/hw_tests.cpp new file mode 100644 index 0000000..d91633c --- /dev/null +++ b/hello_world/tests/hw_tests.cpp @@ -0,0 +1,9 @@ +#include "hello_world.hpp" +#include + + +TEST(Hello_world, returns) { + auto hw = hello_world_namespace::hello(); + EXPECT_EQ(hw, "Hello, World"); +} + From 6c10bb0682313ee67aacd052ba95922f6edbfcc1 Mon Sep 17 00:00:00 2001 From: Kemal Bidzhiev Date: Fri, 7 Aug 2026 12:49:19 +0200 Subject: [PATCH 3/4] Hello world --- .gitignore | 2 +- README.md | 7 +++++++ hello_world/CMakeLists.txt | 4 ++-- hello_world/examples/CMakeLists.txt | 4 ++-- hello_world/examples/basic_usage.cpp | 4 ++++ hello_world/tests/CMakeLists.txt | 2 +- hello_world/tests/hw_tests.cpp | 6 +++--- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index b72747e..ed4300b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ #CMAKE build - +Testing diff --git a/README.md b/README.md index d6d2350..5a18b83 100644 --- a/README.md +++ b/README.md @@ -1 +1,8 @@ Data structures and algorithms in C++ + + + +## How to build and run tests +cmake -S . -B build +cmake --build build +ctest --test-dir build --output-on-failure diff --git a/hello_world/CMakeLists.txt b/hello_world/CMakeLists.txt index 1ace617..6952f35 100644 --- a/hello_world/CMakeLists.txt +++ b/hello_world/CMakeLists.txt @@ -10,5 +10,5 @@ target_include_directories(HelloWorld include ) -#add_subdirectory(tests) -#add_subdirectory(examples) +add_subdirectory(tests) +add_subdirectory(examples) diff --git a/hello_world/examples/CMakeLists.txt b/hello_world/examples/CMakeLists.txt index 868ba3e..ce981cb 100644 --- a/hello_world/examples/CMakeLists.txt +++ b/hello_world/examples/CMakeLists.txt @@ -2,8 +2,8 @@ add_executable(basic_usage basic_usage.cpp ) -target_link_libraries(hello_world # hpp name +target_link_libraries(basic_usage PRIVATE - hello_world # include foldername + HelloWorld ) diff --git a/hello_world/examples/basic_usage.cpp b/hello_world/examples/basic_usage.cpp index e69de29..0039608 100644 --- a/hello_world/examples/basic_usage.cpp +++ b/hello_world/examples/basic_usage.cpp @@ -0,0 +1,4 @@ +#include "hw.hpp" +#include + +int main() { std::cout << HW::hello() << std::endl; } diff --git a/hello_world/tests/CMakeLists.txt b/hello_world/tests/CMakeLists.txt index f7850e3..c96dd71 100644 --- a/hello_world/tests/CMakeLists.txt +++ b/hello_world/tests/CMakeLists.txt @@ -4,7 +4,7 @@ add_executable(hello_world_tests target_link_libraries(hello_world_tests PRIVATE - hello_world + HelloWorld #project_warnings GTest::gtest_main ) diff --git a/hello_world/tests/hw_tests.cpp b/hello_world/tests/hw_tests.cpp index d91633c..9778f89 100644 --- a/hello_world/tests/hw_tests.cpp +++ b/hello_world/tests/hw_tests.cpp @@ -1,9 +1,9 @@ -#include "hello_world.hpp" +#include "hw.hpp" #include TEST(Hello_world, returns) { - auto hw = hello_world_namespace::hello(); - EXPECT_EQ(hw, "Hello, World"); + auto hw = HW::hello(); + EXPECT_EQ(hw, "Hello, world"); } From 9fcd1fa9aa84c8d07b4cd6cb8ed9782f8ebc2834 Mon Sep 17 00:00:00 2001 From: Kemal Bidzhiev Date: Fri, 7 Aug 2026 15:40:54 +0200 Subject: [PATCH 4/4] CI yml file --- .github/workflows/cmake-multi-platform.yml | 75 ++++++++++++++++++++++ CMakeLists.txt | 4 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cmake-multi-platform.yml diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml new file mode 100644 index 0000000..d2840a2 --- /dev/null +++ b/.github/workflows/cmake-multi-platform.yml @@ -0,0 +1,75 @@ +# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml +name: CMake on multiple platforms + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: true + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release] + c_compiler: [gcc, clang, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compilel: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v4 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bf1bd3..f486d95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,8 +33,10 @@ if (DSA_BUILD_TESTS) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip + DOWNLOAD_EXTRACT_TIMESTAMP TRUE # updates file stamps on extraction ) - + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) enable_testing()