Warning, /pim/akonadi/KPimAkonadiMacros.cmake is written in an unsupported language. File is not indexed.
0001 # 0002 # Convenience macros to add akonadi testrunner unit-tests 0003 # 0004 # Set AKONADI_RUN_ISOLATED_TESTS to false to prevent any isolated Akonadi tests from being run 0005 # Set AKONADI_RUN_MYSQL_ISOLATED_TESTS to false to prevent run the tests against MySQL 0006 # Set AKONADI_RUN_PGSQL_ISOLATED_TESTS to false to prevent run the tests against PostgreSQL 0007 # Set AKONADI_RUN_SQLITE_ISOLATED_TESTS to false to prevent run the tests against SQLite 0008 # Set AKONADI_TESTS_XML to true if you want qtestlib to generate (per backend) XML files with the test results 0009 # 0010 # You still need to provide the test environment, see akonadi/autotests/libs/unittestenv 0011 # copy the unittestenv directory to your unit test directory and update the files 0012 # as necessary 0013 0014 function(add_akonadi_isolated_test) 0015 0016 function(add_akonadi_isolated_test_impl) 0017 set(options) 0018 set(oneValueArgs SOURCE) 0019 set(multiValueArgs BACKENDS ADDITIONAL_SOURCES LINK_LIBRARIES) 0020 cmake_parse_arguments(CONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 0021 set(_test ${CONFIG_SOURCE}) 0022 get_filename_component(_name ${CONFIG_SOURCE} NAME_WE) 0023 add_executable(${_name} ${_test} ${CONFIG_ADDITIONAL_SOURCES}) 0024 ecm_mark_as_test(${_name}) 0025 target_link_libraries(${_name} 0026 Qt::Test Qt::Gui Qt::Widgets Qt::Network KF6::KIOCore 0027 KPim6::AkonadiCore KPim6::AkonadiPrivate Qt::DBus 0028 ${CONFIG_LINK_LIBRARIES} 0029 ) 0030 0031 if (NOT DEFINED _testrunner) 0032 if (${PROJECT_NAME} STREQUAL Akonadi AND TARGET akonaditest) 0033 # If this macro is used in Akonadi itself, just use the target name; 0034 # CMake will replace it with the path to the executable in the build 0035 # directory. This will ensure it works even on a clean build, 0036 # where the executable doesn't exist yet at cmake time. 0037 set(_testrunner akonaditest) 0038 else() 0039 find_program(_testrunner NAMES akonaditest akonaditest.exe) 0040 if (NOT _testrunner) 0041 message(WARNING "Could not locate akonaditest executable, isolated Akonadi tests will fail!") 0042 endif() 0043 endif() 0044 endif() 0045 0046 # based on kde4_add_unit_test 0047 set(_executable $<TARGET_FILE:${_name}>) 0048 if (APPLE) 0049 set(_executable ${_executable}.app/Contents/MacOS/${_name}) 0050 endif() 0051 0052 function(_defineTest name backend) 0053 set(backends ${ARGN}) 0054 if ((NOT DEFINED AKONADI_RUN_${backend}_ISOLATED_TESTS OR AKONADI_RUN_${backend}_ISOLATED_TESTS) AND 0055 (NOT DEFINED AKONADI_RUN_ISOLATED_TESTS OR AKONADI_RUN_ISOLATED_TESTS)) 0056 LIST(LENGTH "${backends}" backendsLen) 0057 string(TOLOWER ${backend} lcbackend) 0058 LIST(FIND "${backends}" ${lcbackend} enableBackend) 0059 if (${backendsLen} EQUAL 0 OR ${enableBackend} GREATER -1) 0060 set(configFile ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config.xml) 0061 if (AKONADI_TESTS_XML) 0062 set(extraOptions -xml -o "${TEST_RESULT_OUTPUT_PATH}/${lcbackend}-${name}.xml") 0063 endif() 0064 set(_test_name akonadi-${lcbackend}-${name}) 0065 add_test(NAME ${_test_name} 0066 COMMAND ${_testrunner} -c "${configFile}" -b ${lcbackend} 0067 ${_executable} ${extraOptions} 0068 ) 0069 # Taken from ECMAddTests.cmake 0070 if (CMAKE_LIBRARY_OUTPUT_DIRECTORY) 0071 if(CMAKE_HOST_SYSTEM MATCHES "Windows") 0072 set(PATHSEP ";") 0073 else() # e.g. Linux 0074 set(PATHSEP ":") 0075 endif() 0076 set(_plugin_path $ENV{QT_PLUGIN_PATH}) 0077 set(_test_env 0078 QT_PLUGIN_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}${PATHSEP}$ENV{QT_PLUGIN_PATH} 0079 LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}${PATHSEP}$ENV{LD_LIBRARY_PATH} 0080 ) 0081 set_tests_properties(${_test_name} PROPERTIES ENVIRONMENT "${_test_env}") 0082 endif() 0083 endif() 0084 endif() 0085 endfunction() 0086 0087 # MySQL/PostgreSQL are unable to run in the containers used for the FreeBSD CI 0088 find_program(MYSQLD_EXECUTABLE mysqld /usr/sbin /usr/local/sbin /usr/libexec /usr/local/libexec /opt/mysql/libexec /usr/mysql/bin) 0089 if (MYSQLD_EXECUTABLE AND NOT WIN32 AND NOT (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" AND DEFINED ENV{KDECI_BUILD})) 0090 _defineTest(${_name} "MYSQL" ${CONFIG_BACKENDS}) 0091 endif() 0092 0093 find_program(POSTGRES_EXECUTABLE postgres) 0094 if (POSTGRES_EXECUTABLE AND NOT WIN32 AND NOT (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" AND DEFINED ENV{KDECI_BUILD})) 0095 _defineTest(${_name} "PGSQL" ${CONFIG_BACKENDS}) 0096 endif() 0097 0098 _defineTest(${_name} "SQLITE" ${CONFIG_BACKENDS}) 0099 endfunction() 0100 0101 LIST(LENGTH "${ARGN}" argc) 0102 if (${argc} EQUAL 0) 0103 add_akonadi_isolated_test_impl(SOURCE ${ARGN}) 0104 else() 0105 add_akonadi_isolated_test_impl(${ARGN}) 0106 endif() 0107 endfunction() 0108 0109 function(add_akonadi_isolated_test_advanced source additional_sources link_libraries) 0110 add_akonadi_isolated_test(SOURCE ${source} 0111 ADDITIONAL_SOURCES "${additional_sources}" 0112 LINK_LIBRARIES "${link_libraries}" 0113 ) 0114 endfunction() 0115 0116 function(kcfg_generate_dbus_interface _kcfg _name) 0117 find_program(XSLTPROC_EXECUTABLE xsltproc) 0118 if (NOT XSLTPROC_EXECUTABLE) 0119 message(FATAL_ERROR "xsltproc executable not found but needed by KCFG_GENERATE_DBUS_INTERFACE()") 0120 endif() 0121 0122 # When using this macro inside Akonadi, we need to refer to the file in the 0123 # repo 0124 if (Akonadi_SOURCE_DIR) 0125 set(xsl_path ${Akonadi_SOURCE_DIR}/src/core/kcfg2dbus.xsl) 0126 else() 0127 set(xsl_path ${KF5Akonadi_DATA_DIR}/kcfg2dbus.xsl) 0128 endif() 0129 file(RELATIVE_PATH xsl_relpath ${CMAKE_CURRENT_BINARY_DIR} ${xsl_path}) 0130 if (IS_ABSOLUTE ${_kcfg}) 0131 file(RELATIVE_PATH kcfg_relpath ${CMAKE_CURRENT_BINARY_DIR} ${_kcfg}) 0132 else() 0133 file(RELATIVE_PATH kcfg_relpath ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfg}) 0134 endif() 0135 add_custom_command( 0136 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}.xml 0137 COMMAND ${XSLTPROC_EXECUTABLE} 0138 --output ${_name}.xml 0139 --stringparam interfaceName ${_name} 0140 ${xsl_relpath} 0141 ${kcfg_relpath} 0142 DEPENDS 0143 ${xsl_path} 0144 ${_kcfg} 0145 ) 0146 endfunction()