From 6dd47f5de52172c62feb6dabed51e1837c896278 Mon Sep 17 00:00:00 2001 From: Petra Baranski Date: Sun, 23 Jul 2023 05:36:57 +0200 Subject: [PATCH 1/3] build: move gtest into cmake and up cmake min version cmake minimum required version is now 3.25. Instead of loading gtest via git submodule, it is now loaded in the cmake files. gtest version upped to v1.13.0. --- .gitmodules | 3 --- CHANGELOG.md | 2 ++ CMakeLists.txt | 4 +--- libs/CMakeLists.txt | 17 +++++++---------- libs/gtest | 1 - 5 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 .gitmodules delete mode 160000 libs/gtest diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index a692fc2..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "libs/gtest"] - path = libs/gtest - url = https://github.com/google/googletest.git diff --git a/CHANGELOG.md b/CHANGELOG.md index 0acd92d..72633bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ maddy uses [semver versioning](https://semver.org/). * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added Changelog * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added contribution guideline +* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) updated cmake minimum required version to 3.25 +* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) gtest is now loaded via cmake and not a git submodule any longer - updated gtest version to 1.13.0 * ? ## version 1.1.2 2020-10-04 diff --git a/CMakeLists.txt b/CMakeLists.txt index ec6649f..526e905 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # This project is licensed under the MIT license. For more information see the # LICENSE file. -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.25) project(maddy) @@ -54,8 +54,6 @@ endif() # ------------------------------------------------------------------------------ -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/gtest/googlemock) add_subdirectory(libs) # ------------------------------------------------------------------------------ diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index ec8335f..6391206 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,14 +1,11 @@ # This project is licensed under the MIT license. For more information see the # LICENSE file. -cmake_minimum_required(VERSION 2.8) +include(FetchContent) -set(LIBS_INCLUDE_DIRS -# -- googletest / -mock -------------------------------------------------------- - ${CMAKE_CURRENT_SOURCE_DIR}/gtest/googletest/include - ${CMAKE_CURRENT_SOURCE_DIR}/gtest/googlemock/include -# ------------------------------------------------------------------------------ -PARENT_SCOPE) - -set(LIBS_SRC_FILES -PARENT_SCOPE) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG b796f7d44681514f58a683a3a71ff17c94edb0c1 # v1.13.0 +) +FetchContent_MakeAvailable(googletest) diff --git a/libs/gtest b/libs/gtest deleted file mode 160000 index 703bd9c..0000000 --- a/libs/gtest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e From 87ec259c28d6dadf0ede7ba6e1702c9270823615 Mon Sep 17 00:00:00 2001 From: Petra Baranski Date: Sun, 23 Jul 2023 06:04:29 +0200 Subject: [PATCH 2/3] build: add option for running tests cmake configuration for running tests is now in the tests folder. Add option in main cmake file that has to be set to ON and only build the tests in that case. Update appveyor and travis ci configurations accordingly. --- .travis.yml | 2 +- CHANGELOG.md | 1 + CMakeLists.txt | 29 +++++++++++------------------ README.md | 5 ++--- appveyor.yml | 2 +- libs/CMakeLists.txt | 11 ----------- tests/CMakeLists.txt | 28 ++++++++++++++++++++++++++++ 7 files changed, 44 insertions(+), 34 deletions(-) delete mode 100644 libs/CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index 4daaa67..424c24c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,6 @@ before_install: script: - mkdir tmp - cd tmp - - cmake .. + - cmake -DMADDY_ENABLED_TESTS=ON .. - make -j4 - ../build/MaddyTests diff --git a/CHANGELOG.md b/CHANGELOG.md index 72633bb..e08fd7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ maddy uses [semver versioning](https://semver.org/). * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added contribution guideline * ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) updated cmake minimum required version to 3.25 * ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) gtest is now loaded via cmake and not a git submodule any longer - updated gtest version to 1.13.0 +* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) tests are only run if the cmake option `MADDY_ENABLED_TESTS` is on, moved test cmake code to the `tests` subfolder * ? ## version 1.1.2 2020-10-04 diff --git a/CMakeLists.txt b/CMakeLists.txt index 526e905..a19207d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,6 @@ cmake_minimum_required(VERSION 3.25) project(maddy) -enable_testing() - # ------------------------------------------------------------------------------ set(MADDY_CPP_VERSION 14) @@ -20,8 +18,15 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) # ------------------------------------------------------------------------------ +option(MADDY_ENABLED_TESTS "enable building tests" OFF) + +if(${MADDY_ENABLED_TESTS}) + enable_testing() +endif() + +# ------------------------------------------------------------------------------ + set(MADDY_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) -file(GLOB_RECURSE MADDY_TESTS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/maddy/*.cpp) # ------------------------------------------------------------------------------ @@ -54,10 +59,6 @@ endif() # ------------------------------------------------------------------------------ -add_subdirectory(libs) - -# ------------------------------------------------------------------------------ - add_library(maddy INTERFACE) target_include_directories(maddy INTERFACE ${MADDY_INCLUDE_DIR} @@ -65,14 +66,6 @@ target_include_directories(maddy INTERFACE # ------------------------------------------------------------------------------ -add_executable( - MaddyTests - ${MADDY_TESTS_FILES} - ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp -) -target_include_directories(MaddyTests PUBLIC - ${LIBS_INCLUDE_DIRS} - ${CMAKE_CURRENT_SOURCE_DIR}/tests -) -target_link_libraries(MaddyTests maddy gmock_main) -add_test(MaddyTests ${CMAKE_CURRENT_SOURCE_DIR}/build/MaddyTests) +if(${MADDY_ENABLED_TESTS}) + add_subdirectory(tests) +endif() diff --git a/README.md b/README.md index e5d457f..8c2c65b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ It is tested to work on: * Linux (gcc) * OSX (clang) -* Windows (Visual Studio 2017) +* Windows (Visual Studio 2017, mingw) ## Dependencies @@ -63,10 +63,9 @@ Open your preferred terminal and type: ```shell git clone https://github.com/progsource/maddy.git cd maddy -git submodule update --init --recursive mkdir tmp cd tmp -cmake .. +cmake -DMADDY_ENABLED_TESTS=ON .. make make test # or run the executable in ../build/MaddyTests ``` diff --git a/appveyor.yml b/appveyor.yml index e8842c3..847894d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,7 @@ install: before_build: - cmd: mkdir tmp - cmd: cd tmp - - cmd: cmake -G "Visual Studio 15 Win64" .. + - cmd: cmake -G "Visual Studio 15 Win64" -DMADDY_ENABLED_TESTS=ON .. build: project: $(APPVEYOR_BUILD_FOLDER)\tmp\$(APPVEYOR_PROJECT_NAME).sln diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt deleted file mode 100644 index 6391206..0000000 --- a/libs/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -# This project is licensed under the MIT license. For more information see the -# LICENSE file. - -include(FetchContent) - -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG b796f7d44681514f58a683a3a71ff17c94edb0c1 # v1.13.0 -) -FetchContent_MakeAvailable(googletest) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..0252b57 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,28 @@ +# This project is licensed under the MIT license. For more information see the +# LICENSE file. + +include(FetchContent) + +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG b796f7d44681514f58a683a3a71ff17c94edb0c1 # v1.13.0 +) +FetchContent_MakeAvailable(googletest) + +# ------------------------------------------------------------------------------ + +file(GLOB_RECURSE MADDY_TESTS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/maddy/*.cpp) + +# ------------------------------------------------------------------------------ + +add_executable( + MaddyTests + ${MADDY_TESTS_FILES} + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp +) +target_include_directories(MaddyTests PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) +target_link_libraries(MaddyTests maddy gmock_main) +add_test(MaddyTests MaddyTests) From 823645995e5c9841783853f8e93c311b1559c8f6 Mon Sep 17 00:00:00 2001 From: Petra Baranski Date: Sun, 23 Jul 2023 06:18:49 +0200 Subject: [PATCH 3/3] ci: use github workflow instead of travis and appveyor --- .github/workflows/run-tests.yml | 61 +++++++++++++++++++++++++++++++++ .travis.yml | 32 ----------------- CHANGELOG.md | 4 ++- CMakeLists.txt | 11 ++---- README.md | 4 +-- appveyor.yml | 15 -------- 6 files changed, 69 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/run-tests.yml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..43d827d --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,61 @@ +name: run-tests +run-name: test ${{ github.ref }} +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + test-on-ubuntu: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version + ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version + - name: build + run: | + mkdir tmp + cd tmp + cmake -DMADDY_BUILD_WITH_TESTS=ON .. + make -j4 + - name: run tests + run: | + ./build/MaddyTests + test-on-windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version + ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version + - name: build + run: | + mkdir tmp + cd tmp + cmake -G "Visual Studio 17 2022" -A x64 -DMADDY_BUILD_WITH_TESTS=ON .. + cmake --build . --config Debug + - name: run tests + run: | + ./build/Debug/MaddyTests.exe + test-on-osx: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version + ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version + - name: build + run: | + mkdir tmp + cd tmp + cmake -DMADDY_BUILD_WITH_TESTS=ON .. + make -j4 + - name: run tests + run: | + ./build/MaddyTests diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 424c24c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -sudo: false -language: cpp -matrix: - include: - - os: linux - dist: xenial - sudo: require - addons: - apt: - sources: - - sourceline: 'ppa:ubuntu-toolchain-r/test' - packages: - - g++-7 - env: - - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" - - - os: osx - osx_image: xcode10 - compiler: clang - env: - - MATRIX_EVAL="CC=clang && CXX=clang++" - -before_install: - # This is necessary to solve https://github.com/travis-ci/travis-ci/issues/9649 - - eval "${MATRIX_EVAL}" - -script: - - mkdir tmp - - cd tmp - - cmake -DMADDY_ENABLED_TESTS=ON .. - - make -j4 - - ../build/MaddyTests diff --git a/CHANGELOG.md b/CHANGELOG.md index e08fd7c..a8e6ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,9 @@ maddy uses [semver versioning](https://semver.org/). * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added contribution guideline * ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) updated cmake minimum required version to 3.25 * ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) gtest is now loaded via cmake and not a git submodule any longer - updated gtest version to 1.13.0 -* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) tests are only run if the cmake option `MADDY_ENABLED_TESTS` is on, moved test cmake code to the `tests` subfolder +* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) tests are only run if the cmake option `MADDY_BUILD_WITH_TESTS` is on, moved test cmake code to the `tests` subfolder +* ![**REMOVED**](https://img.shields.io/badge/-REMOVED-%23900) travis CI and appveyor +* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) GitHub workflow * ? ## version 1.1.2 2020-10-04 diff --git a/CMakeLists.txt b/CMakeLists.txt index a19207d..af99f39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,9 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) # ------------------------------------------------------------------------------ -option(MADDY_ENABLED_TESTS "enable building tests" OFF) +option(MADDY_BUILD_WITH_TESTS "enable building tests" OFF) -if(${MADDY_ENABLED_TESTS}) +if(${MADDY_BUILD_WITH_TESTS}) enable_testing() endif() @@ -35,11 +35,6 @@ if (UNIX) CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++${MADDY_CPP_VERSION} -Wall -Wpedantic -Wextra -Wno-ignored-qualifiers -fno-rtti -fno-exceptions -fsanitize=address -fno-omit-frame-pointer" ) -else() - set( - CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -std=c++${MADDY_CPP_VERSION}" - ) endif() # ------------------------------------------------------------------------------ @@ -66,6 +61,6 @@ target_include_directories(maddy INTERFACE # ------------------------------------------------------------------------------ -if(${MADDY_ENABLED_TESTS}) +if(${MADDY_BUILD_WITH_TESTS}) add_subdirectory(tests) endif() diff --git a/README.md b/README.md index 8c2c65b..83f9b6d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ It is tested to work on: * Linux (gcc) * OSX (clang) -* Windows (Visual Studio 2017, mingw) +* Windows (Visual Studio 17 2022, mingw) ## Dependencies @@ -65,7 +65,7 @@ git clone https://github.com/progsource/maddy.git cd maddy mkdir tmp cd tmp -cmake -DMADDY_ENABLED_TESTS=ON .. +cmake -DMADDY_BUILD_WITH_TESTS=ON .. make make test # or run the executable in ../build/MaddyTests ``` diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 847894d..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,15 +0,0 @@ -image: Visual Studio 2017 - -install: - - cmd: git submodule update --init --recursive - -before_build: - - cmd: mkdir tmp - - cmd: cd tmp - - cmd: cmake -G "Visual Studio 15 Win64" -DMADDY_ENABLED_TESTS=ON .. - -build: - project: $(APPVEYOR_BUILD_FOLDER)\tmp\$(APPVEYOR_PROJECT_NAME).sln - -test_script: - - cmd: ctest -VV -C "Debug"