summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/test_interface/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/cmake/test_interface/CMakeLists.txt')
-rw-r--r--tests/auto/cmake/test_interface/CMakeLists.txt25
1 files changed, 10 insertions, 15 deletions
diff --git a/tests/auto/cmake/test_interface/CMakeLists.txt b/tests/auto/cmake/test_interface/CMakeLists.txt
index 0cae16668e..7028b41f7b 100644
--- a/tests/auto/cmake/test_interface/CMakeLists.txt
+++ b/tests/auto/cmake/test_interface/CMakeLists.txt
@@ -1,5 +1,8 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-cmake_minimum_required(VERSION 3.14)
+
+cmake_minimum_required(VERSION 3.16)
project(test_interface)
@@ -14,23 +17,15 @@ add_executable(test_interface_exe WIN32 main.cpp mainwindow.cpp)
# link explicitly to Qt::WinMain.
target_link_libraries(test_interface_exe Qt::Widgets)
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/try_compile-test.cpp"
- "
-#include <QString>
-#include <QWidget>
-
-int main(int,char**) { QWidget w; w.show(); return 0; }
-"
-)
-
# Fix try_compile to inherit the parent configuration.
set(CMAKE_TRY_COMPILE_CONFIGURATION "${CMAKE_BUILD_TYPE}")
-# The try_compile works because Qt::Widgets is listed in the LINK_LIBRARIES,
-# which causes the includes, defines and appropriate PIC flag to be used.
-try_compile(_TRY_COMPILE_RES "${CMAKE_CURRENT_BINARY_DIR}/try_compile-test"
- "${CMAKE_CURRENT_BINARY_DIR}/try_compile-test.cpp"
- LINK_LIBRARIES Qt::Widgets
+# Can't use source file based try_compile, because it doesn't handle object libraries
+# referenced in generator expressions properly.
+try_compile(_TRY_COMPILE_RES
+ "${CMAKE_CURRENT_BINARY_DIR}/widget_test"
+ "${CMAKE_CURRENT_SOURCE_DIR}/widget_test"
+ widget_test
OUTPUT_VARIABLE TC_OV
)