From 748b56159f9432bdcc825b0ee033f4e5d1b2bac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Urs=20F=C3=A4ssler?= Date: Mon, 1 Jan 2024 22:09:31 +0100 Subject: [PATCH 1/2] let cmake fail when dependency for requested option is not available --- CMakeLists.txt | 29 +++++++++++++++-------------- tests/CMakeLists.txt | 2 ++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c3b44fe..4e99f5b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,7 +111,7 @@ set(Boost_USE_STATIC_RUNTIME OFF) if(CUKE_ENABLE_BOOST_TEST) # "An external test runner utility is required to link with dynamic library" (Boost User's Guide) set(CMAKE_CXX_FLAGS "-DBOOST_TEST_DYN_LINK ${CMAKE_CXX_FLAGS}") - find_package(Boost 1.70 COMPONENTS unit_test_framework) + find_package(Boost 1.70 COMPONENTS unit_test_framework REQUIRED) endif() # @@ -119,7 +119,7 @@ endif() # if(CUKE_ENABLE_GTEST) - find_package(GTest 1.11.0) + find_package(GTest 1.11.0 REQUIRED) endif() # @@ -131,6 +131,7 @@ if(CUKE_ENABLE_QT) 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}") @@ -144,19 +145,19 @@ if(CUKE_ENABLE_QT) 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") + 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() - find_package(Qt4 COMPONENTS QtCore QtGui QtTest) - if(QT4_FOUND) - 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}) - endif() + message(FATAL_ERROR "Qt not found") endif() endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7ec0e91f..8a66c56b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(GTest REQUIRED) + add_library(utils INTERFACE utils/HookRegistrationFixture.hpp utils/ContextManagerTestDouble.hpp From fb759c8b8b8a420197d089301b20318ee921251b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Urs=20F=C3=A4ssler?= Date: Wed, 3 Jan 2024 17:01:59 +0100 Subject: [PATCH 2/2] only enable minimal set of options by default This is to reduce error output since cmake fails when an option is enabled but a dependency for it not installed. Test frameworks are off by default because every one has an external dependency. A warning is shown when no test framework is selected as one is needed for cucumber-cpp to be usable. --- CMakeLists.txt | 32 +++++++++++++++++++++++++++----- README.md | 16 +++++++++++----- run-all.sh | 17 +++++++++++------ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e99f5b1..6f2b7e7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,14 @@ endif() project(Cucumber-Cpp) -option(BUILD_SHARED_LIBS "Generate shared libraries" OFF) -option(CUKE_ENABLE_BOOST_TEST "Enable Boost.Test framework" ON) +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_EXAMPLES "Build examples" OFF) -option(CUKE_ENABLE_GTEST "Enable Google Test framework" ON) -option(CUKE_ENABLE_QT "Enable Qt framework" ON) -option(CUKE_TESTS_UNIT "Enable unit tests" ON) +option(CUKE_TESTS_UNIT "Enable unit tests" OFF) + +option(BUILD_SHARED_LIBS "Generate shared libraries" OFF) option(CUKE_CODE_COVERAGE "Enable instrumentation for code coverage" OFF) set(CUKE_ENABLE_SANITIZER "OFF" CACHE STRING "Sanitizer to use for checking") set_property(CACHE CUKE_ENABLE_SANITIZER PROPERTY STRINGS OFF "address" "thread" "undefined") @@ -68,6 +70,26 @@ option_depr_invert (CUKE_DISABLE_QT CUKE_ENABLE_QT) option_depr_invert (CUKE_DISABLE_UNIT_TESTS CUKE_TESTS_UNIT) option_depr (VALGRIND_TESTS CUKE_TESTS_VALGRIND) +# +# Check that at least one test framework is enabled +# + +set(CUKE_TEST_FRAMEWORKS + CUKE_ENABLE_BOOST_TEST + CUKE_ENABLE_GTEST + CUKE_ENABLE_QT +) + +set(TEST_FRAMEWORK_FOUND FALSE) +foreach(test_framework ${CUKE_TEST_FRAMEWORKS}) + if(${test_framework}) + set(TEST_FRAMEWORK_FOUND TRUE) + endif() +endforeach() + +if(NOT TEST_FRAMEWORK_FOUND) + message(WARNING "No test framework enabled. At least one should be enabled. Options are: ${CUKE_TEST_FRAMEWORKS}.") +endif() # # Generic Compiler Flags diff --git a/README.md b/README.md index 456764b4..e7fd4c52 100644 --- a/README.md +++ b/README.md @@ -55,23 +55,29 @@ Building Cucumber-Cpp with tests and samples: cmake -E make_directory build # Generate Makefiles -cmake -E chdir build cmake -DCUKE_ENABLE_EXAMPLES=on -DCMAKE_INSTALL_PREFIX=${prefix} .. - -# Build cucumber-cpp and tests +cmake -E chdir build cmake \ + -DCUKE_ENABLE_BOOST_TEST=on \ + -DCUKE_ENABLE_GTEST=on \ + -DCUKE_ENABLE_QT=on \ + -DCUKE_TESTS_UNIT=on \ + -DCUKE_ENABLE_EXAMPLES=on \ + .. + +# Build cucumber-cpp cmake --build build # Run unit tests cmake --build build --target test # Run install -cmake --build build --target install +cmake --install build ``` Running the Calc example on Unix: ``` build/examples/Calc/BoostCalculatorSteps >/dev/null & -cucumber examples/Calc +(cd examples/Calc; cucumber) ``` Running the Calc example on Windows (NMake): diff --git a/run-all.sh b/run-all.sh index 3c25416c..cd0f580d 100755 --- a/run-all.sh +++ b/run-all.sh @@ -21,15 +21,20 @@ export CTEST_OUTPUT_ON_FAILURE cmake -E make_directory build cmake -E chdir build cmake \ -G Ninja \ + -DCUKE_ENABLE_BOOST_TEST=on \ + -DCUKE_ENABLE_GTEST=on \ + -DCUKE_ENABLE_QT=on \ -DCUKE_ENABLE_EXAMPLES=on \ + -DCUKE_TESTS_UNIT=on \ -DCUKE_CODE_COVERAGE=on \ - -DBUILD_SHARED_LIBS="${BUILD_SHARED_LIBS:-OFF}" \ - -DCMAKE_INSTALL_PREFIX=${HOME}/.local \ - ${CMAKE_PREFIX_PATH:+"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"} \ - ${VALGRIND_TESTS:+"-DVALGRIND_TESTS=${VALGRIND_TESTS}"} \ .. cmake --build build --parallel -cmake --build build --parallel --target test + +# +# Run tests +# + +cmake --build build --target test # # Execute Calc examples @@ -80,4 +85,4 @@ wait % mkdir -p coverage gcovr build/ --html-details --output coverage/index.html --xml coverage/cobertura.xml -cmake --build build --target install +sudo cmake --install build