Skip to content

Commit

Permalink
Improve mo2_configure_tests to make running tests easier. (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 authored Jun 22, 2024
1 parent 7deea3d commit 16cfcd9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
17 changes: 8 additions & 9 deletions mo2_cpp.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.21)

if (POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
Expand Down Expand Up @@ -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
Expand All @@ -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 "\\;$<TARGET_FILE_DIR:${DEPEND}>")
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 "$<FILTER:$<TARGET_RUNTIME_DLLS:${TARGET}>,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:$<JOIN:$<TARGET_RUNTIME_DLL_DIRS:${TARGET}>,\;>"
)
endfunction()

#! mo2_configure_uibase : configure the uibase target for MO2
Expand Down
3 changes: 2 additions & 1 deletion mo2_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 38 additions & 3 deletions mo2_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $<TARGET_FILE_DIR:${DEPLOY_TARGET}>
--no-translations
--verbose 0
--no-compiler-runtime
"$<TARGET_FILE:${DEPLOY_TARGET}>"
"${DEPLOY_BINARIES}"
VERBATIM
COMMAND_EXPAND_LISTS
WORKING_DIRECTORY $<TARGET_FILE_DIR:${DEPLOY_TARGET}>
)
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
Expand All @@ -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 \
Expand Down

0 comments on commit 16cfcd9

Please sign in to comment.