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

Strict cmake options #281

Merged
merged 2 commits into from
Jan 4, 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
61 changes: 42 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -111,15 +133,15 @@ 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()

#
# GTest
#

if(CUKE_ENABLE_GTEST)
find_package(GTest 1.11.0)
find_package(GTest 1.11.0 REQUIRED)
endif()

#
Expand All @@ -131,6 +153,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}")
Expand All @@ -144,19 +167,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()

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 11 additions & 6 deletions run-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
find_package(GTest REQUIRED)

add_library(utils INTERFACE
utils/HookRegistrationFixture.hpp
utils/ContextManagerTestDouble.hpp
Expand Down
Loading