mirror of
https://github.com/ModOrganizer2/cmake_common.git
synced 2026-07-27 14:06:46 -07:00
Improve mo2_configure_tests to make running tests easier. (#30)
This commit is contained in:
+8
-9
@@ -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 "\\;$<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
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
+38
-3
@@ -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 $<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
|
||||
@@ -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 \
|
||||
|
||||
Reference in New Issue
Block a user