Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Qt6, keep Qt5, remove Qt4 #283

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ jobs:
git \
libasio-dev \
libboost-test-dev \
libgl1-mesa-dev \
libtclap-dev \
ninja-build \
nlohmann-json3-dev \
qtbase5-dev
qt6-base-dev

- name: install gtest
run: |
Expand All @@ -58,7 +59,7 @@ jobs:
-G Ninja \
-DCUKE_ENABLE_BOOST_TEST=on \
-DCUKE_ENABLE_GTEST=on \
-DCUKE_ENABLE_QT=on \
-DCUKE_ENABLE_QT_6=on \
-DCUKE_ENABLE_EXAMPLES=on \
-DCUKE_TESTS_UNIT=on \
..
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/qt5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: build and test with Qt5

on:
pull_request:
branches: [ main ]
workflow_dispatch:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2

- name: setup environment
run: |
sudo apt-get install --no-install-recommends \
cmake \
g++ \
git \
libasio-dev \
libboost-test-dev \
libtclap-dev \
ninja-build \
nlohmann-json3-dev \
qtbase5-dev \
ruby \
ruby-dev

- name: install ruby tools
run: |
sudo gem install bundler
sudo bundle install

- name: install gtest
run: |
git clone https://github.com/google/googletest.git
cd googletest
mkdir build
cd build
cmake ../
cmake --build . --parallel
sudo cmake --install .

- name: build
run: |
cmake -E make_directory build
cmake -E chdir build cmake \
-G Ninja \
-DCUKE_ENABLE_BOOST_TEST=on \
-DCUKE_ENABLE_GTEST=on \
-DCUKE_ENABLE_QT_5=on \
-DCUKE_ENABLE_EXAMPLES=on \
-DCUKE_TESTS_UNIT=on \
..
cmake --build build --parallel

- name: unit tests
run: |
cmake --build build --target test

- name: QtCalc examples
run: |
for TEST in \
build/examples/CalcQt/GTestCalculatorQtSteps \
build/examples/CalcQt/QtTestCalculatorQtSteps \
build/examples/CalcQt/BoostCalculatorQtSteps \
; do
"${TEST}" 2> /dev/null &
sleep 1
(cd examples/CalcQt; cucumber)
wait %
done

28 changes: 13 additions & 15 deletions .github/workflows/run-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ jobs:
- name: setup environment
run: |
sudo apt-get install --no-install-recommends \
cmake \
g++ \
gcovr \
git \
libasio-dev \
libboost-test-dev \
libtclap-dev \
make \
ninja-build \
nlohmann-json3-dev \
qtbase5-dev \
ruby \
ruby-dev \
xvfb
cmake \
g++ \
gcovr \
git \
libasio-dev \
libboost-test-dev \
libgl1-mesa-dev \
libtclap-dev \
ninja-build \
nlohmann-json3-dev \
qt6-base-dev \
ruby \
ruby-dev

- name: install ruby tools
run: |
Expand All @@ -50,7 +49,6 @@ jobs:

- name: build and run
run: |
export DISPLAY=:99
./run-all.sh

- name: code coverage summary report
Expand Down
69 changes: 37 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.16)

if(NOT CMAKE_VERSION VERSION_LESS "3.3")
# Don't ignore visibility related properties for non-SHARED targets
Expand All @@ -15,7 +15,8 @@ project(Cucumber-Cpp)

option(CUKE_ENABLE_BOOST_TEST "Enable Boost.Test framework" OFF)
option(CUKE_ENABLE_GTEST "Enable Google Test framework" OFF)
option(CUKE_ENABLE_QT "Enable Qt framework" OFF)
option(CUKE_ENABLE_QT_5 "Enable Qt5 framework" OFF)
option(CUKE_ENABLE_QT_6 "Enable Qt6 framework" OFF)

option(CUKE_ENABLE_EXAMPLES "Build examples" OFF)
option(CUKE_TESTS_UNIT "Enable unit tests" OFF)
Expand Down Expand Up @@ -66,7 +67,8 @@ endfunction()

option_depr_invert (CUKE_DISABLE_BOOST_TEST CUKE_ENABLE_BOOST_TEST)
option_depr_invert (CUKE_DISABLE_GTEST CUKE_ENABLE_GTEST)
option_depr_invert (CUKE_DISABLE_QT CUKE_ENABLE_QT)
option_depr_invert (CUKE_DISABLE_QT_5 CUKE_ENABLE_QT_5)
option_depr_invert (CUKE_DISABLE_QT_6 CUKE_ENABLE_QT_6)
option_depr_invert (CUKE_DISABLE_UNIT_TESTS CUKE_TESTS_UNIT)
option_depr (VALGRIND_TESTS CUKE_TESTS_VALGRIND)

Expand All @@ -77,7 +79,8 @@ option_depr (VALGRIND_TESTS CUKE_TESTS_VALGRIND)
set(CUKE_TEST_FRAMEWORKS
CUKE_ENABLE_BOOST_TEST
CUKE_ENABLE_GTEST
CUKE_ENABLE_QT
CUKE_ENABLE_QT_5
CUKE_ENABLE_QT_6
)

set(TEST_FRAMEWORK_FOUND FALSE)
Expand Down Expand Up @@ -148,41 +151,43 @@ endif()
# Qt
#

if(CUKE_ENABLE_QT)
find_package(Qt5Core)
find_package(Qt5Gui)
find_package(Qt5Widgets)
find_package(Qt5Test)
find_package(Qt4 COMPONENTS QtCore QtGui QtTest)

if(Qt5Core_FOUND AND Qt5Gui_FOUND AND Qt5Widgets_FOUND AND Qt5Test_FOUND)
message(STATUS "Found Qt version: ${Qt5Core_VERSION_STRING}")
if(Qt5Core_VERSION_STRING VERSION_LESS 5.15.0)
add_library(Qt::Core INTERFACE IMPORTED)
add_library(Qt::Gui INTERFACE IMPORTED)
add_library(Qt::Widgets INTERFACE IMPORTED)
add_library(Qt::Test INTERFACE IMPORTED)
set_target_properties(Qt::Core PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Core )
set_target_properties(Qt::Gui PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Gui )
set_target_properties(Qt::Widgets PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Widgets)
set_target_properties(Qt::Test PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Test )
endif()
elseif(QT4_FOUND)
message(STATUS "Found Qt4")
if(CUKE_ENABLE_QT_5 AND CUKE_ENABLE_QT_6)
message(FATAL_ERROR "Qt version 5 and 6 enabled, please select at most one")
endif()


if(CUKE_ENABLE_QT_5)
find_package(Qt5 REQUIRED COMPONENTS
Core
Gui
Widgets
Test
)

message(STATUS "Found Qt version: ${Qt5Core_VERSION_STRING}")
if(Qt5Core_VERSION_STRING VERSION_LESS 5.15.0)
add_library(Qt::Core INTERFACE IMPORTED)
add_library(Qt::Gui INTERFACE IMPORTED)
add_library(Qt::Widgets INTERFACE IMPORTED)
add_library(Qt::Test INTERFACE IMPORTED)
set_target_properties(Qt::Core PROPERTIES INTERFACE_LINK_LIBRARIES Qt4::QtCore)
set_target_properties(Qt::Gui PROPERTIES INTERFACE_LINK_LIBRARIES Qt4::QtGui )
set_target_properties(Qt::Widgets PROPERTIES INTERFACE_LINK_LIBRARIES Qt4::QtGui )
set_target_properties(Qt::Test PROPERTIES INTERFACE_LINK_LIBRARIES Qt4::QtTest)
include(${QT_USE_FILE})
else()
message(FATAL_ERROR "Qt not found")
set_target_properties(Qt::Core PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Core )
set_target_properties(Qt::Gui PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Gui )
set_target_properties(Qt::Widgets PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Widgets)
set_target_properties(Qt::Test PROPERTIES INTERFACE_LINK_LIBRARIES Qt5::Test )
endif()
endif()

if(CUKE_ENABLE_QT_6)
find_package(Qt6 REQUIRED COMPONENTS
Core
Gui
Widgets
Test
)

message(STATUS "Found Qt version: ${Qt6Core_VERSION}")
endif()


#
# Sanitizers
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If you want to contribute code to the project, guidelines are in [CONTRIBUTING.m

It relies on a few executables:

* [cmake](https://cmake.org/download/) 3.9 or later.
* [cmake](https://cmake.org/download/) 3.16 or later.
Required to setup environment and build software

It relies on a few libraries:
Expand All @@ -27,7 +27,7 @@ It relies on a few libraries:
* [GTest](https://github.com/google/googletest) 1.11.0 or later. Optional for the GTest driver.
* [GMock](https://github.com/google/googletest) 1.11.0 or later. Optional for the internal test suite.
* [nlohmann-json](https://github.com/nlohmann/json) 3.10.5 or later.
* [Qt 4 or 5](http://qt-project.org/). Optional for the CalcQt example and QtTest driver (only Qt 5).
* [Qt6 or Qt5](http://qt-project.org/). Optional for the CalcQt example and QtTest driver.
* [TCLAP](https://tclap.sourceforge.net/) 1.2.5 or later.

It might work with earlier versions of the libraries, but it was not tested with them.
Expand Down Expand Up @@ -58,7 +58,7 @@ cmake -E make_directory build
cmake -E chdir build cmake \
-DCUKE_ENABLE_BOOST_TEST=on \
-DCUKE_ENABLE_GTEST=on \
-DCUKE_ENABLE_QT=on \
-DCUKE_ENABLE_QT_6=on \
-DCUKE_TESTS_UNIT=on \
-DCUKE_ENABLE_EXAMPLES=on \
..
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <cucumber-cpp/autodetect.hpp>

#include <Calculator.h>
#include <Calculator.hpp>

using cucumber::ScenarioScope;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <cucumber-cpp/autodetect.hpp>

#include <Calculator.h>
#include <Calculator.hpp>

using cucumber::ScenarioScope;

Expand Down
2 changes: 1 addition & 1 deletion examples/Calc/src/Calculator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <limits>
#include "Calculator.h"
#include "Calculator.hpp"

void Calculator::push(double n) {
values.push_back(n);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once

#include <list>

class Calculator {
private:
std::list<double> values;

public:
void push(double);
double add();
double divide();
};

25 changes: 16 additions & 9 deletions examples/CalcQt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
project(CalcQt)

if(TARGET Qt::Core AND TARGET Qt::Gui AND TARGET Qt::Widgets AND TARGET Qt::Test)
add_library(libcalcqt STATIC src/CalculatorWidget.cpp src/CalculatorWidget.h)
target_compile_options(libcalcqt PRIVATE "-Wno-deprecated-declarations")
set_target_properties(libcalcqt PROPERTIES AUTOMOC ON)
set(CMAKE_AUTOMOC ON)

add_library(libcalcqt STATIC src/Calculator.cpp src/Calculator.hpp)
target_include_directories(libcalcqt INTERFACE src)
target_link_libraries(libcalcqt
PUBLIC
Qt::Core
Qt::Widgets
)

add_executable(calcqt
src/CalcQt.cpp
src/CalculatorWidget.cpp
src/CalculatorWidget.hpp
)
target_link_libraries(calcqt
PRIVATE
libcalcqt
Qt::Core
Qt::Gui
Qt::Widgets
)

add_executable(calcqt src/CalcQt.cpp)
target_link_libraries(calcqt PRIVATE libcalcqt Qt::Widgets)

add_executable(QtTestCalculatorQtSteps features/step_definitions/QtTestCalculatorQtSteps.cpp)
target_link_libraries(QtTestCalculatorQtSteps PRIVATE libcalcqt Qt::Test cucumber-cpp)

if(TARGET Boost::unit_test_framework)
add_executable(BoostCalculatorQtSteps features/step_definitions/BoostCalculatorQtSteps.cpp)
target_link_libraries(BoostCalculatorQtSteps PRIVATE libcalcqt Boost::unit_test_framework cucumber-cpp Qt::Test)
target_link_libraries(BoostCalculatorQtSteps PRIVATE libcalcqt Boost::unit_test_framework cucumber-cpp)
endif()

if(TARGET GTest::gtest)
add_executable(GTestCalculatorQtSteps features/step_definitions/GTestCalculatorQtSteps.cpp)
target_link_libraries(GTestCalculatorQtSteps PRIVATE libcalcqt cucumber-cpp GTest::gtest Qt::Test)
target_link_libraries(GTestCalculatorQtSteps PRIVATE libcalcqt GTest::gtest cucumber-cpp)
endif()

endif()
Loading
Loading