From 0ceed231b488192a643ef32d8414a516ee80583d Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Fri, 2 Aug 2019 14:14:16 +0200 Subject: [PATCH] Add __default_public_args to add_qt_test and add_qt_executable Due to the missing argument processing on PUBLIC arguments we could run into situations where the defines for an executable (mostly tests) would be incorrectly processed. If one were to pass a define into a test that also specifies public libraries, the defines passed in by test would fall under the PUBLIC_LIBRARIES argument in add_qt_executable. For instance, in a test with DEFINES Foo PUBLIC_LIBRARIES Core would cause arg_DEFINES to be "Foo=BAR;PUBLIC_LIBRARIES;Core". This combined with the defines specified by add_qt_test would result in the following string "Foo=BAR;PUBLIC_LIBRARIES;Core;TEST_DIR=..." and would cause TEST_DIR to be treated as a public library in add add_qt_executable. For some reason I can't figure out, these two defines end up in the linker flag section of certain test programs. There is nothing wrong with the rest of the propagation chain into add_qt_executable. My best guess is that it has something to do with the generators. In any case add an explicit -D fixes the issue. Change-Id: I340790c1c2426fa76785d1bd1b3332a904323d56 Reviewed-by: Alexandru Croitor --- cmake/QtBuild.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index f0a8c348756..3e2d406d9b1 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -2159,7 +2159,7 @@ endfunction() # Please consider to use a more specific version target like the one created # by add_qt_test or add_qt_tool below. function(add_qt_executable name) - qt_parse_all_arguments(arg "add_qt_executable" "GUI;BOOTSTRAP;NO_QT;NO_INSTALL;EXCEPTIONS" "OUTPUT_DIRECTORY;INSTALL_DIRECTORY" "EXE_FLAGS;${__default_private_args}" ${ARGN}) + qt_parse_all_arguments(arg "add_qt_executable" "GUI;BOOTSTRAP;NO_QT;NO_INSTALL;EXCEPTIONS" "OUTPUT_DIRECTORY;INSTALL_DIRECTORY" "EXE_FLAGS;${__default_private_args};${__default_public_args}" ${ARGN}) if ("x${arg_OUTPUT_DIRECTORY}" STREQUAL "x") set(arg_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${INSTALL_BINDIR}") @@ -2189,7 +2189,7 @@ function(add_qt_executable name) ${arg_INCLUDE_DIRECTORIES} DEFINES ${arg_DEFINES} LIBRARIES ${arg_LIBRARIES} - PUBLIC_LIBRARIES ${extra_libraries} + PUBLIC_LIBRARIES ${extra_libraries} ${arg_PUBLIC_LIBRARIES} DBUS_ADAPTOR_SOURCES "${arg_DBUS_ADAPTOR_SOURCES}" DBUS_ADAPTOR_FLAGS "${arg_DBUS_ADAPTOR_FLAGS}" DBUS_INTERFACE_SOURCES "${arg_DBUS_INTERFACE_SOURCES}" @@ -2222,7 +2222,7 @@ endfunction() function(add_qt_test name) qt_parse_all_arguments(arg "add_qt_test" "RUN_SERIAL;EXCEPTIONS;GUI;QMLTEST" - "QML_IMPORTPATH" "TESTDATA;${__default_private_args}" ${ARGN}) + "QML_IMPORTPATH" "TESTDATA;${__default_private_args};${__default_public_args}" ${ARGN}) set(path "${CMAKE_CURRENT_BINARY_DIR}") if (${arg_EXCEPTIONS}) @@ -2243,12 +2243,12 @@ function(add_qt_test name) "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" $ - "${arg_INCLUDE_DIRECTORIES}" + ${arg_INCLUDE_DIRECTORIES} DEFINES - "${arg_DEFINES}" QT_TESTCASE_BUILDDIR="${CMAKE_CURRENT_BINARY_DIR}" QT_TESTCASE_SOURCEDIR="${CMAKE_CURRENT_SOURCE_DIR}" - PUBLIC_LIBRARIES ${QT_CMAKE_EXPORT_NAMESPACE}::Core ${QT_CMAKE_EXPORT_NAMESPACE}::Test + ${arg_DEFINES} + PUBLIC_LIBRARIES ${QT_CMAKE_EXPORT_NAMESPACE}::Core ${QT_CMAKE_EXPORT_NAMESPACE}::Test ${arg_PUBLIC_LIBRARIES} LIBRARIES ${arg_LIBRARIES} COMPILE_OPTIONS ${arg_COMPILE_OPTIONS} LINK_OPTIONS ${arg_LINK_OPTIONS}