From 16cfcd91ce2021913c87fff12dbec6d773f57cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 22 Jun 2024 08:27:35 +0200 Subject: [PATCH] Improve mo2_configure_tests to make running tests easier. (#30) --- mo2_cpp.cmake | 17 ++++++++--------- mo2_targets.cmake | 3 ++- mo2_utils.cmake | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/mo2_cpp.cmake b/mo2_cpp.cmake index 2d7d3fc..25b8125 100644 --- a/mo2_cpp.cmake +++ b/mo2_cpp.cmake @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.21) if (POLICY CMP0144) cmake_policy(SET CMP0144 NEW) @@ -223,6 +223,7 @@ function(mo2_configure_tests TARGET) find_package(GTest REQUIRED) target_link_libraries(${TARGET} PRIVATE GTest::gtest GTest::gmock GTest::gtest_main) + mo2_add_dependencies(${TARGET} PRIVATE ${MO2_DEPENDS}) # gtest_discover_tests would be nice but it requires Qt DLL, uibase, etc., in the # path, etc., and is not working right now @@ -236,20 +237,18 @@ function(mo2_configure_tests TARGET) # ) # - set(extra_paths "${MO2_INSTALL_PATH}/bin/dlls") - foreach (DEPEND ${MO2_DEPENDS}) - target_link_libraries(${TARGET} PUBLIC ${DEPEND}) - string(APPEND extra_paths "\\;$") - endforeach() - gtest_add_tests(TARGET ${TARGET} TEST_LIST ${TARGET}_gtests) set(${TARGET}_gtests ${${TARGET}_gtests} PARENT_SCOPE) + mo2_deploy_qt_for_tests( + TARGET ${TARGET} + BINARIES "$,EXCLUDE,^.*[/\\]Qt[^/\\]*[.]dll>") + set_tests_properties(${${TARGET}_gtests} PROPERTIES - WORKING_DIRECTORY "${MO2_INSTALL_PATH}/bin" ENVIRONMENT_MODIFICATION - "PATH=path_list_prepend:${extra_paths}") + "PATH=path_list_prepend:$,\;>" + ) endfunction() #! mo2_configure_uibase : configure the uibase target for MO2 diff --git a/mo2_targets.cmake b/mo2_targets.cmake index b5fc26f..98cd001 100644 --- a/mo2_targets.cmake +++ b/mo2_targets.cmake @@ -92,7 +92,8 @@ function(mo2_find_uibase) add_library(mo2-uibase IMPORTED SHARED) set_target_properties(mo2-uibase PROPERTIES - IMPORTED_IMPLIB ${MO2_INSTALL_LIBS_PATH}/uibase.lib) + IMPORTED_IMPLIB ${MO2_INSTALL_LIBS_PATH}/uibase.lib + IMPORTED_LOCATION ${MO2_INSTALL_PATH}/bin/uibase.dll) mo2_add_dependencies(mo2-uibase INTERFACE Qt::Widgets Qt::Network Qt::QuickWidgets) target_include_directories(mo2-uibase diff --git a/mo2_utils.cmake b/mo2_utils.cmake index 5e295cf..afc6cb7 100644 --- a/mo2_utils.cmake +++ b/mo2_utils.cmake @@ -29,6 +29,15 @@ function(mo2_find_python_executable VARNAME) endif() endfunction() +#! mo2_find_windeployqt_executable : find the full path to the windeployqt executable +# +# \param:VARNAME name of the variable that will contain the path to Python +function(mo2_find_windeployqt_executable VARNAME) + # find_program() does not work for whatever reason, just going for the whole + # name + set(${VARNAME} ${QT_ROOT}/bin/windeployqt.exe PARENT_SCOPE) +endfunction() + #! mo2_set_project_to_run_from_install : set a target to run from a given executable # # this function is only meaningful for VS generator @@ -113,6 +122,34 @@ function(mo2_find_qt_version VAR) set(${VAR} ${${VAR}} CACHE STRING "Qt Version}") endfunction() +#! mo2_deploy_qt_for_tests : add comments to deploy Qt for tests +# +# unlike mo2_deploy_qt(), this function does not perform any cleaning +# +# \param:TARGET name of the target to deploy for +# \param:BINARIES names of the binaries to deploy from +# +function(mo2_deploy_qt_for_tests) + cmake_parse_arguments(DEPLOY "" "TARGET" "BINARIES" ${ARGN}) + + mo2_find_windeployqt_executable(windeployqt) + + add_custom_command(TARGET "${DEPLOY_TARGET}" + POST_BUILD + COMMAND ${windeployqt} + ARGS + --dir $ + --no-translations + --verbose 0 + --no-compiler-runtime + "$" + "${DEPLOY_BINARIES}" + VERBATIM + COMMAND_EXPAND_LISTS + WORKING_DIRECTORY $ + ) +endfunction() + #! mo2_deploy_qt : add commands to deploy Qt from the given binaries # # this function attach install() entries that deploy Qt for the given binaries @@ -123,9 +160,7 @@ endfunction() function(mo2_deploy_qt) cmake_parse_arguments(DEPLOY "NOPLUGINS" "" "BINARIES" ${ARGN}) - # find_program() does not work for whatever reason, just going for the whole - # name - set(windeployqt ${QT_ROOT}/bin/windeployqt.exe) + mo2_find_windeployqt_executable(windeployqt) set(args "--no-translations \