diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e30e3e9f6000debe2983cb90146313f96377f2d1..c72871e7c4f1fbf24ddb95764ddb2116d563afa5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,7 +31,6 @@ variables: ci_local_packages: "yes" ci_parallel: "2" ci_sudo: "yes" - ci_distro: "debian" ci_suite: "bullseye" ### # IMPORTANT @@ -156,8 +155,6 @@ debian buster autotools: .suse-build: extends: .unix-host-build image: "opensuse/leap:15" - variables: - ci_distro: "opensuse" opensuse cmake: extends: .suse-build diff --git a/CMakeLists.txt b/CMakeLists.txt index 99f102c53d848d3d8c7d0191d2757f0c25978a2c..cff890a9287188364bfa98b83b5d9887f72787f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ if(CMAKE_MAJOR_VERSION GREATER 2) endif() option(DBUS_BUILD_TESTS "enable unit test code" ON) +option(ENABLE_CLIENT_PACKAGE_TEST "enable test for building a client package" OFF) # detect version include(MacrosAutotools) @@ -735,7 +736,8 @@ message(" install libexecdir: ${CMAKE_INSTALL_FULL_LIBEXECDIR} " message(" install bindir: ${CMAKE_INSTALL_FULL_BINDIR} ") message(" install sysconfdir: ${CMAKE_INSTALL_FULL_SYSCONFDIR} ") message(" install datadir: ${CMAKE_INSTALL_FULL_DATADIR} ") -message(" source code location: ${CMAKE_SOURCE_DIR} ") +message(" source code location: ${DBUS_SOURCE_DIR} ") +message(" host prefix: ${DBUS_TARGET_PREFIX} ") message(" build dir: ${CMAKE_BINARY_DIR} ") message(" c compiler: ${C_COMPILER} ") message(" cflags: ${CMAKE_C_FLAGS} ") diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 45136cc33bbc1dc43260765354a1f09d89bfdbd8..61ef14951484981451d33ea6f3689672cf7a3fe6 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -213,5 +213,12 @@ elseif(SIZEOF_SHORT EQUAL 2) set(DBUS_INT16_TYPE "short") endif() +# detect target prefix +get_filename_component(COMPILER_BASE_NAME ${CMAKE_C_COMPILER} NAME_WE) +if(COMPILER_BASE_NAME MATCHES ".*-.*-.*-.*") + string(REGEX REPLACE "^([0-9a-z_]+)-([0-9a-z]+)-([0-9a-z]+)-([-0-9a-z]+)$" "\\1-\\2-\\3" DBUS_TARGET_PREFIX ${COMPILER_BASE_NAME}) + string(REGEX REPLACE "^([0-9a-z_]+)-([0-9a-z]+)-([0-9a-z]+)-([-0-9a-z]+)$" "\\1" DBUS_TARGET_ARCH ${COMPILER_BASE_NAME}) +endif() + find_program(DOXYGEN doxygen) find_program(XMLTO xmlto) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4689c78b53be32b3509f76afeed2021252cbfe9a..e9554e5e5337f42b36928e4de6c79f18b7b13ed9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,6 +13,74 @@ add_library(dbus-testutils STATIC ) target_link_libraries(dbus-testutils ${DBUS_INTERNAL_LIBRARIES}) +# +# cmake install test +# +set(TEMP_INSTALL_DIR ${CMAKE_BINARY_DIR}/tmp) + +set(ENABLE_CLIENT_PACKAGE_TEST 1) + +if(CMAKE_CROSSCOMPILING) + if(NOT DBUS_TARGET_SYSROOT) + execute_process( + COMMAND ${CMAKE_C_COMPILER} --print-sysroot + OUTPUT_VARIABLE DBUS_TARGET_SYSROOT + ERROR_VARIABLE ERROR + RESULT_VARIABLE RESULT + ) + if(RESULT) + set(ENABLE_CLIENT_PACKAGE_TEST 0) + message(WARNING "disabled client package build, because sysroot could not be fetched from compiler - error is ${ERROR_VARIABLE}") + endif() + string(REPLACE "\n" "/${DBUS_TARGET_PREFIX}" DBUS_TARGET_SYSROOT "${DBUS_TARGET_SYSROOT}") + endif() +endif() + +if(ENABLE_CLIENT_PACKAGE_TEST) + # clean local install directories used by client build/install test + add_test( + NAME test-install-local-clean + COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEMP_INSTALL_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + + # install dbus in local directoy for client build/install test + add_test( + NAME test-install-local + COMMAND ${CMAKE_MAKE_PROGRAM} install DESTDIR=${TEMP_INSTALL_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + + # build/install a client package using dbus cmake package support from this build + add_test( + NAME test-install-build-client-package + COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test + ${CMAKE_CURRENT_SOURCE_DIR}/client-package + ${CMAKE_CURRENT_BINARY_DIR}/client-package + --build-config "${CMAKE_BUILD_TYPE}" + --build-generator ${CMAKE_GENERATOR} + --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-target install + --build-options + #--trace-expand + -DDBus1_DIR=${TEMP_INSTALL_DIR}${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR} + -DCHECK_VERSION=${DBUS_VERSION_STRING} + -DCMAKE_CROSSCOMPILING=${CMAKE_CROSSCOMPILING} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_INSTALL_PREFIX:PATH=${TEMP_INSTALL_DIR}${CMAKE_INSTALL_PREFIX} + -DCMAKE_FIND_ROOT_PATH="${TEMP_INSTALL_DIR}${CMAKE_INSTALL_PREFIX};${DBUS_TARGET_SYSROOT}" + -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER + -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY + -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY + -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} + -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR} + ) + + set_property(TEST test-install-build-client-package APPEND PROPERTY DEPENDS test-install-local-clean test-install-local) +endif() + if(DBUS_ENABLE_EMBEDDED_TESTS) add_subdirectory( name-test ) endif() diff --git a/test/Makefile.am b/test/Makefile.am index b539524ce23ba608de871c41c07c522acaa2df16..4996e506bfcd68f5f9e1bdd6f35f34b75c1048b1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -717,6 +717,10 @@ static_data = \ EXTRA_DIST += $(static_data) +# for testing cmake find_package support +EXTRA_DIST += client-package/CMakeLists.txt +EXTRA_DIST += client-package/test.c + ## copy tests to builddir so that generated tests and static tests ## are all in one place. ## Note that we can't create the XDG_RUNTIME_DIR with permissions 0700 diff --git a/test/client-package/CMakeLists.txt b/test/client-package/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..733157c063d816123e1c1850805d47d72653c73a --- /dev/null +++ b/test/client-package/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.0) + +if(COMMAND cmake_policy) + cmake_policy(SET CMP0074 NEW) +endif() + +project(DBus1test) +find_package(DBus1 CONFIG) + +if(NOT DBus1_VERSION OR NOT CHECK_VERSION OR NOT DBus1_VERSION VERSION_EQUAL CHECK_VERSION) + message(FATAL_ERROR "version mismatch actual '${DBus1_VERSION}' expected '${CHECK_VERSION}'") +endif() + +add_executable(mytest test.c) +target_link_libraries(mytest dbus-1) +install(TARGETS mytest DESTINATION bin) diff --git a/test/client-package/test.c b/test/client-package/test.c new file mode 100644 index 0000000000000000000000000000000000000000..29cc109b4e633203b73ad40941f17195ec596fbd --- /dev/null +++ b/test/client-package/test.c @@ -0,0 +1,9 @@ + +#include + +int main() +{ + DBusError error; + dbus_error_init(&error); + return 0; +} diff --git a/tools/ci-build.sh b/tools/ci-build.sh index d6951cb8131474a6dc846b8e86a6aaa7d8f4df7c..8231c0e7698e1ec08e6ee1be52214957a5d4abdd 100755 --- a/tools/ci-build.sh +++ b/tools/ci-build.sh @@ -79,8 +79,8 @@ init_wine() { # ci_distro: # OS distribution in which we are testing -# Typical values: ubuntu, debian; maybe fedora in future -: "${ci_distro:=ubuntu}" +# Typical values: ubuntu, debian, auto for auto detection; maybe fedora in future +: "${ci_distro:=auto}" # ci_docker: # If non-empty, this is the name of a Docker image. ci-install.sh will @@ -132,6 +132,11 @@ init_wine() { echo "ci_buildsys=$ci_buildsys ci_distro=$ci_distro ci_docker=$ci_docker ci_host=$ci_host ci_local_packages=$ci_local_packages ci_parallel=$ci_parallel ci_suite=$ci_suite ci_test=$ci_test ci_test_fatal=$ci_test_fatal ci_variant=$ci_variant ci_runtime=$ci_runtime $0" +# choose distribution +if [ "$ci_distro" = "auto" ]; then + ci_distro=$(. /etc/os-release; echo ${ID} | sed 's, ,_,g') +fi + if [ -n "$ci_docker" ]; then exec docker run \ --env=ci_buildsys="${ci_buildsys}" \ @@ -401,7 +406,7 @@ case "$ci_buildsys" in ;; esac - $cmake "$@" -DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_WERROR=ON .. + $cmake "$@" -DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_WERROR=ON -DENABLE_CLIENT_PACKAGE_TEST=ON .. ${make} # The test coverage for OOM-safety is too verbose to be useful on diff --git a/tools/ci-install.sh b/tools/ci-install.sh index a331f931dbfa1a20f283c785043fc840bc622348..60d4c814cd7c2b0182d24011375c687fa9b5c882 100755 --- a/tools/ci-install.sh +++ b/tools/ci-install.sh @@ -29,8 +29,8 @@ NULL= # ci_distro: # OS distribution in which we are testing -# Typical values: ubuntu, debian; maybe fedora in future -: "${ci_distro:=ubuntu}" +# Typical values: ubuntu, debian, auto for auto detection; maybe fedora in future +: "${ci_distro:=auto}" # ci_docker: # If non-empty, this is the name of a Docker image. ci-install.sh will @@ -70,6 +70,12 @@ else sudo=sudo fi + +# choose distribution +if [ "$ci_distro" = "auto" ]; then + ci_distro=$(. /etc/os-release; echo ${ID} | sed 's, ,_,g') +fi + if [ -n "$ci_docker" ]; then sed \ -e "s/@ci_distro@/${ci_distro}/" \ @@ -80,7 +86,7 @@ if [ -n "$ci_docker" ]; then fi case "$ci_distro" in - (debian|ubuntu) + (debian*|ubuntu*) # Don't ask questions, just do it sudo="$sudo env DEBIAN_FRONTEND=noninteractive" @@ -178,7 +184,7 @@ case "$ci_distro" in fi ;; - (opensuse) + (opensuse-*) zypper="/usr/bin/zypper --non-interactive" # system packages=(