From a6bb8c070ea2406c4c7bbc60893d0c909228401a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanislav=20Angelovi=C4=8D?= Date: Wed, 26 Sep 2018 09:28:10 +0200 Subject: [PATCH] Switch from autotools to CMake build system (#23) * Switch from autotools to CMake * CMake: require at least cmake 3.8 * cmake: updates for tests --- CMakeLists.txt | 145 +++++++++++++++++++++ ChangeLog | 3 + INSTALL | 4 +- Makefile.am | 22 ---- README.md | 14 +- autogen.sh | 10 -- configure.ac | 62 --------- include/Makefile.am | 24 ---- sdbus-c++-config-version.cmake.in | 11 ++ sdbus-c++-config.cmake.in | 14 ++ sdbus-c++.pc.in | 16 +-- src/Makefile.am | 27 ---- stub-generator/BaseGenerator.cpp | 2 +- stub-generator/CMakeLists.txt | 40 +++++- stub-generator/xml.cpp | 14 +- test/CMakeLists.txt | 100 ++++++++++++++ test/Makefile.am | 67 ---------- test/googletest-download/CMakeLists.txt.in | 17 +++ 18 files changed, 353 insertions(+), 239 deletions(-) create mode 100755 CMakeLists.txt delete mode 100644 Makefile.am delete mode 100755 autogen.sh delete mode 100644 configure.ac delete mode 100644 include/Makefile.am create mode 100755 sdbus-c++-config-version.cmake.in create mode 100755 sdbus-c++-config.cmake.in mode change 100644 => 100755 sdbus-c++.pc.in delete mode 100644 src/Makefile.am create mode 100755 test/CMakeLists.txt delete mode 100644 test/Makefile.am create mode 100755 test/googletest-download/CMakeLists.txt.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 00000000..8f45305d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,145 @@ +#------------------------------- +# PROJECT INFORMATION +#------------------------------- + +cmake_minimum_required(VERSION 3.8) + +project(sdbus-c++ VERSION 0.3.2 LANGUAGES C CXX) + +include(GNUInstallDirs) # Installation directories for `install` command and pkgconfig file + +#------------------------------- +# PERFORMING CHECKS +#------------------------------- + +find_package(PkgConfig REQUIRED) +pkg_check_modules(SYSTEMD REQUIRED libsystemd>=236) + +#------------------------------- +# SOURCE FILES CONFIGURATION +#------------------------------- + +set(SDBUSCPP_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src) +set(SDBUSCPP_INCLUDE_SUBDIR sdbus-c++) +set(SDBUSCPP_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include/${SDBUSCPP_INCLUDE_SUBDIR}) + +set(SDBUSCPP_CPP_SRCS + ${SDBUSCPP_SOURCE_DIR}/Connection.cpp + ${SDBUSCPP_SOURCE_DIR}/ConvenienceClasses.cpp + ${SDBUSCPP_SOURCE_DIR}/Error.cpp + ${SDBUSCPP_SOURCE_DIR}/Message.cpp + ${SDBUSCPP_SOURCE_DIR}/MethodResult.cpp + ${SDBUSCPP_SOURCE_DIR}/Object.cpp + ${SDBUSCPP_SOURCE_DIR}/ObjectProxy.cpp + ${SDBUSCPP_SOURCE_DIR}/Types.cpp + ${SDBUSCPP_SOURCE_DIR}/VTableUtils.c) + +set(SDBUSCPP_HDR_SRCS + ${SDBUSCPP_SOURCE_DIR}/Connection.h + ${SDBUSCPP_SOURCE_DIR}/IConnection.h + ${SDBUSCPP_SOURCE_DIR}/MessageUtils.h + ${SDBUSCPP_SOURCE_DIR}/Object.h + ${SDBUSCPP_SOURCE_DIR}/ObjectProxy.h + ${SDBUSCPP_SOURCE_DIR}/ScopeGuard.h + ${SDBUSCPP_SOURCE_DIR}/VTableUtils.h) + +set(SDBUSCPP_PUBLIC_HDRS + ${SDBUSCPP_INCLUDE_DIR}/ConvenienceClasses.h + ${SDBUSCPP_INCLUDE_DIR}/ConvenienceClasses.inl + ${SDBUSCPP_INCLUDE_DIR}/Error.h + ${SDBUSCPP_INCLUDE_DIR}/IConnection.h + ${SDBUSCPP_INCLUDE_DIR}/Interfaces.h + ${SDBUSCPP_INCLUDE_DIR}/Introspection.h + ${SDBUSCPP_INCLUDE_DIR}/IObject.h + ${SDBUSCPP_INCLUDE_DIR}/IObjectProxy.h + ${SDBUSCPP_INCLUDE_DIR}/Message.h + ${SDBUSCPP_INCLUDE_DIR}/MethodResult.h + ${SDBUSCPP_INCLUDE_DIR}/sdbus-c++.h + ${SDBUSCPP_INCLUDE_DIR}/Types.h + ${SDBUSCPP_INCLUDE_DIR}/TypeTraits.h) + +set(SDBUSCPP_SRCS ${SDBUSCPP_CPP_SRCS} ${SDBUSCPP_HDR_SRCS} ${SDBUSCPP_PUBLIC_HDRS}) + +#------------------------------- +# GENERAL COMPILER CONFIGURATION +#------------------------------- + +set(CMAKE_CXX_STANDARD 17) +add_compile_options(-W -Wextra -Wall -Werror -pedantic) +include_directories("${CMAKE_SOURCE_DIR}/include") +include_directories("${CMAKE_SOURCE_DIR}/src") + +#---------------------------------- +# LIBRARY BUILD INFORMATION +#---------------------------------- + +set(SDBUSCPP_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +set(SDBUSCPP_VERSION "${PROJECT_VERSION}") + +# We are building in two steps: first objects, then link them into a library, +# and that's because we need object files since unit tests link against them. +add_library(sdbuscppobjects OBJECT ${SDBUSCPP_SRCS}) +target_include_directories(sdbuscppobjects PUBLIC ${SYSTEMD_INCLUDE_DIRS}) +target_compile_definitions(sdbuscppobjects PRIVATE BUILDLIB=1) +set_target_properties(sdbuscppobjects PROPERTIES POSITION_INDEPENDENT_CODE ON) + +add_library(sdbus-c++ SHARED $) +set_target_properties(sdbus-c++ + PROPERTIES + PUBLIC_HEADER "${SDBUSCPP_PUBLIC_HDRS}" + VERSION "${SDBUSCPP_VERSION}" + SOVERSION "${SDBUSCPP_VERSION_MAJOR}" + OUTPUT_NAME "sdbus-c++") +target_link_libraries(sdbus-c++ ${SYSTEMD_LIBRARIES}) + +#---------------------------------- +# INSTALLATION +#---------------------------------- + +install(TARGETS sdbus-c++ + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT static_libraries + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${SDBUSCPP_INCLUDE_SUBDIR} COMPONENT dev) + +#---------------------------------- +# TESTS +#---------------------------------- + +option(ENABLE_TESTS "Build and install tests (default ON)" ON) + +if(ENABLE_TESTS) + enable_testing() + add_subdirectory("${CMAKE_SOURCE_DIR}/test") +endif() + +#---------------------------------- +# UTILS +#---------------------------------- + +option(BUILD_CODE_GEN "Build and install interface stub code generator (default OFF)" OFF) + +if(BUILD_CODE_GEN) + add_subdirectory("${CMAKE_SOURCE_DIR}/stub-generator") +endif() + +#---------------------------------- +# DOCUMENTATION +#---------------------------------- + +# TODO Build doxygen + +#---------------------------------- +# CMAKE CONFIG & PACKAGE CONFIG +#---------------------------------- + +set(SDBUSCPP_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/sdbus-c++) + +configure_file(sdbus-c++-config.cmake.in sdbus-c++-config.cmake @ONLY) +install(FILES ${CMAKE_BINARY_DIR}/sdbus-c++-config.cmake DESTINATION ${SDBUSCPP_CONFIG_INSTALL_DIR} COMPONENT dev) + +configure_file(sdbus-c++-config-version.cmake.in sdbus-c++-config-version.cmake @ONLY) +install(FILES ${CMAKE_BINARY_DIR}/sdbus-c++-config-version.cmake DESTINATION ${SDBUSCPP_CONFIG_INSTALL_DIR} COMPONENT dev) + +configure_file(sdbus-c++.pc.in sdbus-c++.pc @ONLY) +install(FILES ${CMAKE_BINARY_DIR}/sdbus-c++.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT dev) diff --git a/ChangeLog b/ChangeLog index 32bfefff..d05fb1db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,3 +26,6 @@ v0.3.0 v0.3.1 - Fixed hogging the CPU by server with async methods (issue #15) + +v0.3.2 +- Switched from autotools to CMake build system diff --git a/INSTALL b/INSTALL index 5635a776..ae9f9663 100644 --- a/INSTALL +++ b/INSTALL @@ -1,5 +1,7 @@ Building: - $ ./autogen.sh ${CONFIGURE_FLAGS} + $ mkdir build + $ cd build + $ cmake .. ${CONFIGURE_FLAGS_IF_NECESSARY} $ make Installing: diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 6b7e4c3f..00000000 --- a/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -EXTRA_DIST = autogen.sh -SUBDIRS = include src test - -DISTCHECK_CONFIGURE_FLAGS= - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = sdbus-c++.pc - -CLEANFILES = *~ *.lo *.la - -MOSTLYCLEANFILES = *.o - -DISTCLEANFILES = \ - *libtool* \ - aclocal.m4 \ - compile config.* configure \ - depcomp install-sh \ - ltmain.sh \ - Makefile Makefile.in \ - missing \ - stamp-h1 \ - sdbus-c++.pc diff --git a/README.md b/README.md index daaec206..582a0360 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,26 @@ sdbus-c++ is a C++ API library for D-Bus IPC, based on sd-bus implementation. Building and installing the library ----------------------------------- +The library is built using CMake: + ```bash -$ ./autogen.sh ${CONFIGURE_FLAGS} +$ mkdir build +$ cd build +$ cmake .. ${CONFIGURE_FLAGS_IF_NECESSARY} $ make $ sudo make install ``` -Use `--disable-tests` flag when configuring to disable building unit and integration tests for the library. +By default, the library builds its unit and integration tests. That incorporates downloading and building static libraries of Google Test. Use `-DENABLE_TESTS=OFF` configure flag if you want to disable building the tests. + +By default, the library doesn't build the code generator for adaptor and proxy interfaces. Use `-DBUILD_CODE_GEN=ON` flag to also build the code generator. Dependencies ------------ * `C++17` - the library uses C++17 `std::uncaught_exceptions()` feature. When building sdbus-c++ manually, make sure you use a compiler that supports that feature. * `libsystemd` - systemd library containing sd-bus implementation. Systemd v236 at least is needed for sdbus-c++ to compile. -* `googletest` - google unit testing framework, only necessary when building tests +* `googletest` - google unit testing framework, only necessary when building tests, will be downloaded and built automatically Licensing --------- @@ -41,4 +47,4 @@ Contributions that increase the library quality, functionality, or fix issues ar Contact ------- -stanislav.angelovic[at]kistler.com +https://github.com/Kistler-Group/sdbus-cpp diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 7fd81e28..00000000 --- a/autogen.sh +++ /dev/null @@ -1,10 +0,0 @@ -#! /bin/sh -[ -e config.cache ] && rm -f config.cache - -libtoolize --automake -aclocal ${OECORE_ACLOCAL_OPTS} -autoconf -autoheader -automake -a -./configure $@ -exit diff --git a/configure.ac b/configure.ac deleted file mode 100644 index ee4c01a0..00000000 --- a/configure.ac +++ /dev/null @@ -1,62 +0,0 @@ -AC_PREREQ(2.61) - -# package version number (not shared library version) -# odd micro numbers indicate in-progress development -# even micro numbers indicate released versions -m4_define(sdbus_cpp_version_major, 0) -m4_define(sdbus_cpp_version_minor, 3) -m4_define(sdbus_cpp_version_micro, 1) - -m4_define([sdbus_cpp_version], - [sdbus_cpp_version_major.sdbus_cpp_version_minor.sdbus_cpp_version_micro]) -m4_define([sdbus_cpp_api_version], - [sdbus_cpp_version_major.sdbus_cpp_version_minor]) - -AC_INIT(libsdbus-c++, sdbus_cpp_version) -AM_INIT_AUTOMAKE -AC_CONFIG_HEADERS(config.h) - -# Checks for programs. -AC_PROG_LIBTOOL -AC_PROG_CXX -AC_PROG_CC -AC_PROG_INSTALL - -# enable pkg-config -PKG_PROG_PKG_CONFIG - -PKG_CHECK_MODULES(SYSTEMD, [libsystemd >= 236],, - AC_MSG_ERROR([You need the libsystemd library (version 236 or newer)] - [https://www.freedesktop.org/wiki/Software/systemd/]) -) - -# Checks for library functions. -#AC_CHECK_FUNCS([memset]) - -AC_SUBST(libsdbus_cpp_CFLAGS) -AC_SUBST(libsdbus_cpp_LIBS) - -AC_ARG_ENABLE([tests], - [AS_HELP_STRING([--enable-tests], - [build and install tests @<:@default=yes@:>@])], - [], - [enable_tests=yes]) -AM_CONDITIONAL([ENABLE_TESTS], [test x$enable_tests = xyes]) - -#icondir=${datadir}/icons/hicolor/32x32/apps -#AC_SUBST(icondir) - -AC_OUTPUT([ -Makefile -include/Makefile -src/Makefile -test/Makefile -sdbus-c++.pc -]) - -echo "" -echo " sdbus-cpp $VERSION" -echo " =====================" -echo "" -echo " To build the project, run \"make\"" -echo "" diff --git a/include/Makefile.am b/include/Makefile.am deleted file mode 100644 index b4f4236e..00000000 --- a/include/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ - -# Distribution -# Headers will be installed to $(includedir)/sdbus-c++ directory - -HEADER_DIR = sdbus-c++ -libsdbuscppdir = $(includedir)/$(HEADER_DIR) -libsdbuscpp_HEADERS = \ - $(HEADER_DIR)/ConvenienceClasses.h \ - $(HEADER_DIR)/ConvenienceClasses.inl \ - $(HEADER_DIR)/Error.h \ - $(HEADER_DIR)/IConnection.h \ - $(HEADER_DIR)/Interfaces.h \ - $(HEADER_DIR)/Introspection.h \ - $(HEADER_DIR)/IObject.h \ - $(HEADER_DIR)/IObjectProxy.h \ - $(HEADER_DIR)/Message.h \ - $(HEADER_DIR)/MethodResult.h \ - $(HEADER_DIR)/Types.h \ - $(HEADER_DIR)/TypeTraits.h \ - $(HEADER_DIR)/sdbus-c++.h - -EXTRA_DIST = ($libsdbuscpp_HEADERS) - -DISTCLEANFILES = Makefile Makefile.in diff --git a/sdbus-c++-config-version.cmake.in b/sdbus-c++-config-version.cmake.in new file mode 100755 index 00000000..a5c6ad6c --- /dev/null +++ b/sdbus-c++-config-version.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@SDBUSCPP_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/sdbus-c++-config.cmake.in b/sdbus-c++-config.cmake.in new file mode 100755 index 00000000..e6af7a7c --- /dev/null +++ b/sdbus-c++-config.cmake.in @@ -0,0 +1,14 @@ +# Config file for the sdbus-c++ package. +# +# It defines the following variables: +# SDBUSCPP_VERSION - version of sdbus-c++ +# SDBUSCPP_FOUND - set to true +# SDBUSCPP_INCLUDE_DIRS - include directories for sdbus-c++ +# SDBUSCPP_LIBRARY_DIR - library directories for sdbus-c++ +# SDBUSCPP_LIBRARIES - libraries to link against + +set(SDBUSCPP_VERSION "@SDBUSCPP_VERSION@") +set(SDBUSCPP_FOUND "TRUE") +set(SDBUSCPP_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@") +set(SDBUSCPP_LIBRARY_DIR "@CMAKE_INSTALL_FULL_LIBDIR@") +set(SDBUSCPP_LIBRARIES sdbus-c++) diff --git a/sdbus-c++.pc.in b/sdbus-c++.pc.in old mode 100644 new mode 100755 index 4e99276b..21e0f0b1 --- a/sdbus-c++.pc.in +++ b/sdbus-c++.pc.in @@ -1,11 +1,11 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ -Name: @PACKAGE@ -Description: C++ bindings library for sd-bus +Name: @PROJECT_NAME@ +Description: C++ library on top of sd-bus, a systemd D-Bus library Requires: libsystemd -Version: @VERSION@ -Libs: -L${libdir} -lsdbus-c++ +Version: @SDBUSCPP_VERSION@ +Libs: -L${libdir} -l@PROJECT_NAME@ Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index e8d45255..00000000 --- a/src/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ - -lib_LTLIBRARIES = libsdbus-c++.la - -libsdbus_c___la_SOURCES = \ - Connection.cpp \ - ConvenienceClasses.cpp \ - Message.cpp \ - MethodResult.cpp \ - Object.cpp \ - ObjectProxy.cpp \ - Types.cpp \ - Error.cpp \ - VTableUtils.c - -libsdbus_c___la_LIBADD = @SYSTEMD_LIBS@ - -# Setting per-file flags -AM_CPPFLAGS = -I$(top_srcdir)/include -AM_CXXFLAGS = @libsdbus_cpp_CFLAGS@ @SYSTEMD_CFLAGS@ -std=c++17 -pipe -pedantic -W -Wall -AM_LDFLAGS = @libsdbus_cpp_LIBS@ @SYSTEMD_LIBS@ - -libsdbus_c___la_LDFLAGS = -version-info 0:0:0 - -# Cleaning -CLEANFILES = *~ *.lo *.la -MOSTLYCLEANFILES = *.o -DISTCLEANFILES = Makefile Makefile.in diff --git a/stub-generator/BaseGenerator.cpp b/stub-generator/BaseGenerator.cpp index 812d2359..619ef017 100644 --- a/stub-generator/BaseGenerator.cpp +++ b/stub-generator/BaseGenerator.cpp @@ -108,7 +108,7 @@ std::tuple BaseGenerator::argsToNamesAndT { std::ostringstream argSS, argTypeSS, typeSS; - for (auto i = 0; i < args.size(); ++i) + for (size_t i = 0; i < args.size(); ++i) { auto arg = args.at(i); if (i > 0) diff --git a/stub-generator/CMakeLists.txt b/stub-generator/CMakeLists.txt index 5dfab3c1..e0e5b888 100644 --- a/stub-generator/CMakeLists.txt +++ b/stub-generator/CMakeLists.txt @@ -1,13 +1,41 @@ -cmake_minimum_required (VERSION 3.4) +#------------------------------- +# PROJECT INFORMATION +#------------------------------- -add_definitions(-std=c++14) +cmake_minimum_required(VERSION 3.5) -project (sdbuscpp-xml2cpp) +project(sdbuscpp-xml2cpp) -add_executable(${PROJECT_NAME} xml2cpp.cpp xml.cpp generator_utils.cpp BaseGenerator.cpp AdaptorGenerator.cpp ProxyGenerator.cpp) +include(GNUInstallDirs) -find_package (EXPAT REQUIRED) +#------------------------------- +# PERFORMING CHECKS +#------------------------------- + +find_package(EXPAT REQUIRED) + +#------------------------------- +# SOURCE FILES CONFIGURATION +#------------------------------- + +set(SDBUSCPP_XML2CPP_SRCS xml2cpp.cpp xml.cpp generator_utils.cpp BaseGenerator.cpp AdaptorGenerator.cpp ProxyGenerator.cpp) + +#------------------------------- +# GENERAL COMPILER CONFIGURATION +#------------------------------- + +set(CMAKE_CXX_STANDARD 17) + +#---------------------------------- +# EXECUTABLE BUILD INFORMATION +#---------------------------------- + +add_executable(${PROJECT_NAME} ${SDBUSCPP_XML2CPP_SRCS}) target_link_libraries (${PROJECT_NAME} ${EXPAT_LIBRARIES}) -install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} DESTINATION bin) +#---------------------------------- +# INSTALLATION +#---------------------------------- + +install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/stub-generator/xml.cpp b/stub-generator/xml.cpp index 3b1977c3..17ec36ef 100644 --- a/stub-generator/xml.cpp +++ b/stub-generator/xml.cpp @@ -247,15 +247,15 @@ std::string Document::to_xml() const } void Document::Expat::start_doctype_decl_handler( - void* data, - const XML_Char* name, - const XML_Char* sysid, - const XML_Char *pubid, - int has_internal_subset) + void* /*data*/, + const XML_Char* /*name*/, + const XML_Char* /*sysid*/, + const XML_Char */*pubid*/, + int /*has_internal_subset*/) { } -void Document::Expat::end_doctype_decl_handler(void* data) +void Document::Expat::end_doctype_decl_handler(void* /*data*/) { } @@ -300,7 +300,7 @@ void Document::Expat::character_data_handler(void* data, const XML_Char* chars, nod->cdata = std::string(chars, x, y + 1); } -void Document::Expat::end_element_handler(void* data, const XML_Char* name) +void Document::Expat::end_element_handler(void* data, const XML_Char* /*name*/) { Document* doc = static_cast(data); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100755 index 00000000..1905f2dd --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,100 @@ +#------------------------------- +# DOWNLOAD AND BUILD OF GOOGLETEST +# https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project +#------------------------------- + +configure_file(googletest-download/CMakeLists.txt.in googletest-download/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download) + +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() + +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download) + +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +#------------------------------- +# SOURCE FILES CONFIGURATION +#------------------------------- + +set(UNITTESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/unittests) +set(UNITTESTS_SRCS + ${UNITTESTS_SOURCE_DIR}/libsdbus-c++_unittests.cpp + ${UNITTESTS_SOURCE_DIR}/Message_test.cpp + ${UNITTESTS_SOURCE_DIR}/Types_test.cpp + ${UNITTESTS_SOURCE_DIR}/TypeTraits_test.cpp) + +set(INTEGRATIONTESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/integrationtests) +set(INTEGRATIONTESTS_SRCS + ${INTEGRATIONTESTS_SOURCE_DIR}/AdaptorAndProxy_test.cpp + ${INTEGRATIONTESTS_SOURCE_DIR}/Connection_test.cpp + ${INTEGRATIONTESTS_SOURCE_DIR}/libsdbus-c++_integrationtests.cpp + ${INTEGRATIONTESTS_SOURCE_DIR}/adaptor-glue.h + ${INTEGRATIONTESTS_SOURCE_DIR}/defs.h + ${INTEGRATIONTESTS_SOURCE_DIR}/proxy-glue.h + ${INTEGRATIONTESTS_SOURCE_DIR}/TestingAdaptor.h + ${INTEGRATIONTESTS_SOURCE_DIR}/TestingProxy.h) + +#------------------------------- +# GENERAL COMPILER CONFIGURATION +#------------------------------- + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +#---------------------------------- +# BUILD INFORMATION +#---------------------------------- + +# Turn off -isystem gcc option that CMake uses for imported +# targets even when INTERFACE_INCLUDE_DIRECTORIES is used. +set(CMAKE_NO_SYSTEM_FROM_IMPORTED "1") + +add_executable(libsdbus-c++_unittests ${UNITTESTS_SRCS} $) +target_link_libraries(libsdbus-c++_unittests ${SYSTEMD_LIBRARIES} gmock gmock_main) + +add_executable(libsdbus-c++_integrationtests ${INTEGRATIONTESTS_SRCS}) +target_link_libraries(libsdbus-c++_integrationtests sdbus-c++ gmock gmock_main) + +#---------------------------------- +# INSTALLATION +#---------------------------------- + +install(TARGETS libsdbus-c++_unittests DESTINATION /opt/test/bin) +install(TARGETS libsdbus-c++_integrationtests DESTINATION /opt/test/bin) +install(FILES ${INTEGRATIONTESTS_SOURCE_DIR}/files/libsdbus-cpp-test.conf DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/dbus-1/system.d) + +#---------------------------------- +# RUNNING THE TESTS UPON BUILD +#---------------------------------- + +if(CMAKE_CROSSCOMPILING) + if(NOT DEFINED UNIT_TESTS_RUNNER) + set(UNIT_TESTS_RUNNER $ENV{UNIT_TESTS_RUNNER}) + endif() + if(NOT DEFINED TEST_DEVICE_IP) + set(TEST_DEVICE_IP $ENV{TEST_DEVICE_IP}) + endif() + + if(NOT (UNIT_TESTS_RUNNER AND TEST_DEVICE_IP)) + message(WARNING "UNIT_TESTS_RUNNER and TEST_DEVICE_IP variables must be defined to run tests remotely") + endif() + add_test(NAME libsdbus-c++_unittests COMMAND ${UNIT_TESTS_RUNNER} --deviceip=${TEST_DEVICE_IP} --testbin=libsdbus-c++_unittests) + add_test(NAME libsdbus-c++_integrationtests COMMAND ${UNIT_TESTS_RUNNER} --deviceip=${TEST_DEVICE_IP} --testbin=libsdbus-c++_integrationtests) +else() + add_test(NAME libsdbus-c++_unittests COMMAND libsdbus-c++_unittests) + add_test(NAME libsdbus-c++_integrationtests COMMAND libsdbus-c++_integrationtests) +endif() diff --git a/test/Makefile.am b/test/Makefile.am deleted file mode 100644 index 455dfe5e..00000000 --- a/test/Makefile.am +++ /dev/null @@ -1,67 +0,0 @@ -# Defines how to build and install libsdbus-c++ tests - -AUTOMAKE_OPTIONS = subdir-objects - -# Target dirs for test binaries, scripts and files -testbindir = /opt/test/bin -dbusconfdir = $(sysconfdir)/dbus-1/system.d - -# ENABLE_TESTS is defined by configure when user enables tests during configuration -if ENABLE_TESTS -testbin_PROGRAMS = libsdbus-c++_unittests libsdbus-c++_integrationtests -dbusconf_DATA = integrationtests/files/libsdbus-cpp-test.conf -endif - -# Setting per-file flags -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -AM_CXXFLAGS = @libsdbus_cpp_CFLAGS@ @SYSTEMD_CFLAGS@ -W -Wall -Werror -pedantic -pipe -std=c++17 -AM_LDFLAGS = @libsdbus_cpp_LIBS@ @SYSTEMD_LIBS@ - -CLEANFILES = *~ *.lo *.la -MOSTLYCLEANFILES = *.o - -TESTS = - -# Configuration for libsdbus-c++_unittests -libsdbus_c___unittests_SOURCES = \ -unittests/libsdbus-c++_unittests.cpp \ -unittests/TypeTraits_test.cpp \ -unittests/Types_test.cpp \ -unittests/Message_test.cpp - -libsdbus_c___unittests_LDFLAGS = -L$(top_builddir)/src -pthread - -libsdbus_c___unittests_LDADD = \ - -lsdbus-c++ \ - @libsdbus_cpp_LIBS@ \ - @SYSTEMD_LIBS@ \ - -lgmock - -TESTS += libsdbus-c++_unittests - -# Configuration for libsdbus-c++_integrationtests -libsdbus_c___integrationtests_SOURCES = \ -integrationtests/libsdbus-c++_integrationtests.cpp \ -integrationtests/Connection_test.cpp \ -integrationtests/AdaptorAndProxy_test.cpp - -libsdbus_c___integrationtests_LDFLAGS = -L$(top_builddir)/src -pthread - -libsdbus_c___integrationtests_LDADD = \ - -lsdbus-c++ \ - @libsdbus_cpp_LIBS@ \ - @SYSTEMD_LIBS@ \ - -lgmock - -TESTS += libsdbus-c++_integrationtests - -check_PROGRAMS = libsdbus-c++_unittests libsdbus-c++_integrationtests - -DISTCLEANFILES = Makefile Makefile.in - -# Post-build action: executing tests from the IDE -if ENABLE_TESTS -all-local: libsdbus-c++_unittests libsdbus-c++_integrationtests - if [ "${UNIT_TESTS_RUNNER}" ]; then "${UNIT_TESTS_RUNNER}" --deviceip="${TEST_DEVICE_IP}" --testbin=.libs/libsdbus-c++_unittests; fi; exit 0 - if [ "${UNIT_TESTS_RUNNER}" ]; then "${UNIT_TESTS_RUNNER}" --deviceip="${TEST_DEVICE_IP}" --testbin=.libs/libsdbus-c++_integrationtests; fi; exit 0 -endif diff --git a/test/googletest-download/CMakeLists.txt.in b/test/googletest-download/CMakeLists.txt.in new file mode 100755 index 00000000..aff4f6fb --- /dev/null +++ b/test/googletest-download/CMakeLists.txt.in @@ -0,0 +1,17 @@ +# Taken from https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project + +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) + +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "")