2018-09-26 09:28:10 +02:00
#-------------------------------
# DOWNLOAD AND BUILD OF GOOGLETEST
#-------------------------------
2020-11-16 17:05:36 +01:00
set ( GOOGLETEST_VERSION 1.10.0 CACHE STRING "Version of gmock to use" )
set ( GOOGLETEST_GIT_REPO "https://github.com/google/googletest.git" CACHE STRING "A git repo to clone and build googletest from if gmock is not found in the system" )
2018-09-26 09:28:10 +02:00
2020-11-16 17:05:36 +01:00
find_package ( GTest ${ GOOGLETEST_VERSION } CONFIG )
if ( NOT TARGET GTest::gmock )
# Try pkg-config if GTest was not found through CMake config
find_package ( PkgConfig )
if ( PkgConfig_FOUND )
pkg_check_modules ( GMock IMPORTED_TARGET GLOBAL gmock>= ${ GOOGLETEST_VERSION } )
if ( TARGET PkgConfig::GMock )
add_library ( GTest::gmock ALIAS PkgConfig::GMock )
endif ()
endif ()
# GTest was not found in the system, build it on our own
if ( NOT TARGET GTest::gmock )
include ( FetchContent )
2018-09-26 09:28:10 +02:00
2023-05-17 19:45:38 +02:00
if ( GOOGLETEST_VERSION VERSION_GREATER_EQUAL 1.13.0 )
set ( GOOGLETEST_TAG "v${GOOGLETEST_VERSION}" )
else ()
set ( GOOGLETEST_TAG "release-${GOOGLETEST_VERSION}" )
endif ()
message ( "Manually fetching & building googletest v${GOOGLETEST_VERSION}..." )
2020-11-16 17:05:36 +01:00
FetchContent_Declare ( googletest
GIT_REPOSITORY ${ GOOGLETEST_GIT_REPO }
2023-05-17 19:45:38 +02:00
GIT_TAG ${ GOOGLETEST_TAG }
2020-11-16 17:05:36 +01:00
GIT_SHALLOW 1
UPDATE_COMMAND "" )
2023-05-17 20:00:35 +02:00
set ( gtest_force_shared_crt ON CACHE INTERNAL "" FORCE )
set ( INSTALL_GTEST OFF CACHE INTERNAL "" FORCE )
set ( BUILD_SHARED_LIBS_BAK ${ BUILD_SHARED_LIBS } )
set ( BUILD_SHARED_LIBS OFF )
FetchContent_MakeAvailable ( googletest )
set ( BUILD_SHARED_LIBS ${ BUILD_SHARED_LIBS_BAK } )
add_library ( GTest::gmock ALIAS gmock )
2020-11-16 17:05:36 +01:00
endif ()
2018-09-26 09:28:10 +02:00
endif ()
#-------------------------------
# SOURCE FILES CONFIGURATION
#-------------------------------
set ( UNITTESTS_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } /unittests )
set ( UNITTESTS_SRCS
2019-03-28 18:25:31 +01:00
${ UNITTESTS_SOURCE_DIR } /sdbus-c++-unit-tests.cpp
2018-09-26 09:28:10 +02:00
${ UNITTESTS_SOURCE_DIR } /Message_test.cpp
2023-01-21 01:47:24 +01:00
${ UNITTESTS_SOURCE_DIR } /PollData_test.cpp
2018-09-26 09:28:10 +02:00
${ UNITTESTS_SOURCE_DIR } /Types_test.cpp
2019-03-17 18:02:47 +03:00
${ UNITTESTS_SOURCE_DIR } /TypeTraits_test.cpp
2019-03-20 18:52:05 +01:00
${ UNITTESTS_SOURCE_DIR } /Connection_test.cpp
${ UNITTESTS_SOURCE_DIR } /mocks/SdBusMock.h )
2018-09-26 09:28:10 +02:00
set ( INTEGRATIONTESTS_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } /integrationtests )
set ( INTEGRATIONTESTS_SRCS
2020-07-18 20:16:57 +02:00
${ INTEGRATIONTESTS_SOURCE_DIR } /DBusConnectionTests.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /DBusGeneralTests.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /DBusMethodsTests.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /DBusAsyncMethodsTests.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /DBusSignalsTests.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /DBusPropertiesTests.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /DBusStandardInterfacesTests.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /Defs.h
${ INTEGRATIONTESTS_SOURCE_DIR } /integrationtests-adaptor.h
${ INTEGRATIONTESTS_SOURCE_DIR } /integrationtests-proxy.h
${ INTEGRATIONTESTS_SOURCE_DIR } /TestFixture.h
${ INTEGRATIONTESTS_SOURCE_DIR } /TestFixture.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /TestAdaptor.h
${ INTEGRATIONTESTS_SOURCE_DIR } /TestAdaptor.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /TestProxy.h
${ INTEGRATIONTESTS_SOURCE_DIR } /TestProxy.cpp
${ INTEGRATIONTESTS_SOURCE_DIR } /sdbus-c++-integration-tests.cpp )
2018-09-26 09:28:10 +02:00
2019-03-26 08:59:50 +01:00
set ( PERFTESTS_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } /perftests )
set ( STRESSTESTS_CLIENT_SRCS
${ PERFTESTS_SOURCE_DIR } /client.cpp
2019-04-09 21:28:07 +02:00
${ PERFTESTS_SOURCE_DIR } /perftests-proxy.h )
2019-03-26 08:59:50 +01:00
set ( STRESSTESTS_SERVER_SRCS
${ PERFTESTS_SOURCE_DIR } /server.cpp
2019-04-09 21:28:07 +02:00
${ PERFTESTS_SOURCE_DIR } /perftests-adaptor.h )
2019-03-26 08:59:50 +01:00
set ( STRESSTESTS_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } /stresstests )
set ( STRESSTESTS_SRCS
2019-03-28 18:25:31 +01:00
${ STRESSTESTS_SOURCE_DIR } /sdbus-c++-stress-tests.cpp
2019-03-26 08:59:50 +01:00
${ STRESSTESTS_SOURCE_DIR } /fahrenheit-thermometer-adaptor.h
${ STRESSTESTS_SOURCE_DIR } /fahrenheit-thermometer-proxy.h
2019-04-07 21:16:47 +02:00
${ STRESSTESTS_SOURCE_DIR } /celsius-thermometer-adaptor.h
${ STRESSTESTS_SOURCE_DIR } /celsius-thermometer-proxy.h
2019-03-26 08:59:50 +01:00
${ STRESSTESTS_SOURCE_DIR } /concatenator-adaptor.h
${ STRESSTESTS_SOURCE_DIR } /concatenator-proxy.h )
2018-09-26 09:28:10 +02:00
#-------------------------------
# GENERAL COMPILER CONFIGURATION
#-------------------------------
include_directories ( ${ CMAKE_CURRENT_SOURCE_DIR } )
#----------------------------------
# BUILD INFORMATION
#----------------------------------
2020-02-01 23:45:28 +01:00
add_executable ( sdbus-c++-unit-tests ${ UNITTESTS_SRCS } )
2023-09-16 14:28:58 +00:00
target_compile_definitions ( sdbus-c++-unit-tests PRIVATE
LIBSYSTEMD_VERSION= ${ LIBSYSTEMD_VERSION }
2023-01-25 00:02:51 +01:00
SDBUS_ ${ LIBSYSTEMD_IMPL }
2023-11-20 14:41:59 +01:00
SDBUS_HEADER=< ${ LIBSYSTEMD_IMPL } /sd-bus.h> )
2020-11-16 17:05:36 +01:00
target_link_libraries ( sdbus-c++-unit-tests sdbus-c++-objlib GTest::gmock )
2018-09-26 09:28:10 +02:00
2019-03-28 18:25:31 +01:00
add_executable ( sdbus-c++-integration-tests ${ INTEGRATIONTESTS_SRCS } )
2023-01-25 00:02:51 +01:00
target_compile_definitions ( sdbus-c++-integration-tests PRIVATE
LIBSYSTEMD_VERSION= ${ LIBSYSTEMD_VERSION }
SDBUS_ ${ LIBSYSTEMD } )
if ( NOT LIBSYSTEMD STREQUAL "basu" )
# Systemd::Libsystemd is included because integration tests use sd-event. Otherwise sdbus-c++ encapsulates and hides libsystemd.
target_link_libraries ( sdbus-c++-integration-tests sdbus-c++ Systemd::Libsystemd GTest::gmock )
else ()
# sd-event implementation is not part of basu, so its integration tests will be skipped
target_link_libraries ( sdbus-c++-integration-tests sdbus-c++ GTest::gmock )
endif ()
2018-09-26 09:28:10 +02:00
2019-03-28 18:47:49 +01:00
# Manual performance and stress tests
2019-03-28 18:25:31 +01:00
option ( ENABLE_PERF_TESTS "Build and install manual performance tests (default OFF)" OFF )
option ( ENABLE_STRESS_TESTS "Build and install manual stress tests (default OFF)" OFF )
2019-03-28 18:47:49 +01:00
if ( ENABLE_PERF_TESTS OR ENABLE_STRESS_TESTS )
2019-03-26 08:59:50 +01:00
set ( THREADS_PREFER_PTHREAD_FLAG ON )
find_package ( Threads REQUIRED )
2019-03-28 18:47:49 +01:00
if ( ENABLE_PERF_TESTS )
2020-07-21 12:12:14 +02:00
message ( STATUS "Building with performance tests" )
2019-03-28 18:47:49 +01:00
add_executable ( sdbus-c++-perf-tests-client ${ STRESSTESTS_CLIENT_SRCS } )
target_link_libraries ( sdbus-c++-perf-tests-client sdbus-c++ Threads::Threads )
add_executable ( sdbus-c++-perf-tests-server ${ STRESSTESTS_SERVER_SRCS } )
target_link_libraries ( sdbus-c++-perf-tests-server sdbus-c++ Threads::Threads )
endif ()
if ( ENABLE_STRESS_TESTS )
2020-07-21 12:12:14 +02:00
message ( STATUS "Building with stress tests" )
2019-03-28 18:47:49 +01:00
add_executable ( sdbus-c++-stress-tests ${ STRESSTESTS_SRCS } )
target_link_libraries ( sdbus-c++-stress-tests sdbus-c++ Threads::Threads )
endif ()
2019-03-26 08:59:50 +01:00
endif ()
2018-09-26 09:28:10 +02:00
#----------------------------------
# INSTALLATION
#----------------------------------
2023-11-23 21:05:44 +01:00
option ( INSTALL_TESTS "Install tests (default OFF)" OFF )
2019-03-28 18:47:49 +01:00
2023-11-23 21:05:44 +01:00
if ( INSTALL_TESTS )
include ( GNUInstallDirs )
set ( TESTS_INSTALL_PATH "tests/${PROJECT_NAME}" CACHE STRING "Specifies where the test binaries will be installed" )
2018-09-26 09:28:10 +02:00
2023-11-23 21:05:44 +01:00
install ( TARGETS sdbus-c++-unit-tests DESTINATION ${ TESTS_INSTALL_PATH } COMPONENT test )
install ( TARGETS sdbus-c++-integration-tests DESTINATION ${ TESTS_INSTALL_PATH } COMPONENT test )
install ( FILES ${ INTEGRATIONTESTS_SOURCE_DIR } /files/org.sdbuscpp.integrationtests.conf DESTINATION ${ CMAKE_INSTALL_FULL_SYSCONFDIR } /dbus-1/system.d COMPONENT test )
2019-03-26 08:59:50 +01:00
2023-11-23 21:05:44 +01:00
if ( ENABLE_PERF_TESTS )
install ( TARGETS sdbus-c++-perf-tests-client DESTINATION ${ TESTS_INSTALL_PATH } COMPONENT test )
install ( TARGETS sdbus-c++-perf-tests-server DESTINATION ${ TESTS_INSTALL_PATH } COMPONENT test )
install ( FILES ${ PERFTESTS_SOURCE_DIR } /files/org.sdbuscpp.perftests.conf DESTINATION ${ CMAKE_INSTALL_FULL_SYSCONFDIR } /dbus-1/system.d COMPONENT test )
endif ()
if ( ENABLE_STRESS_TESTS )
install ( TARGETS sdbus-c++-stress-tests DESTINATION ${ TESTS_INSTALL_PATH } COMPONENT test )
install ( FILES ${ STRESSTESTS_SOURCE_DIR } /files/org.sdbuscpp.stresstests.conf DESTINATION ${ CMAKE_INSTALL_FULL_SYSCONFDIR } /dbus-1/system.d COMPONENT test )
endif ()
2019-03-15 11:34:25 +01:00
endif ()
2018-09-26 09:28:10 +02:00
#----------------------------------
# RUNNING THE TESTS UPON BUILD
#----------------------------------
2019-03-28 18:47:49 +01:00
if ( NOT CMAKE_CROSSCOMPILING )
add_test ( NAME sdbus-c++-unit-tests COMMAND sdbus-c++-unit-tests )
add_test ( NAME sdbus-c++-integration-tests COMMAND sdbus-c++-integration-tests )
2023-08-04 13:26:45 +02:00
endif ()