summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/test_interface/CMakeLists.txt
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-11-05 15:18:14 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-27 14:54:49 +0100
commitec37cdbc8016042afcd3a77cebe4b3e6b8238092 (patch)
treeac04e54f3bf7199b36c9123a0de2993489e1cba6 /tests/auto/cmake/test_interface/CMakeLists.txt
parent70115a81075da9f50849b50dc37a333a18498c2d (diff)
Populate includes, defines and pic flags in target interfaces.
Used by features in CMake 2.8.11. This matches the features in FindQt4 in that version of CMake, namely that the IMPORTED targets contain the appropriate INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_COMPILE_DEFINITIONS and that the qtmain.lib static library is automatically linked to on Windows by executables. Additionally, the INTERFACE_POSITION_INDEPENDENT_CODE property is set appropriately if Qt requires users to use position independent code. Change-Id: Ide341f43fcaf7d722a7bdf1a12b1071c7e548ccc Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/cmake/test_interface/CMakeLists.txt')
-rw-r--r--tests/auto/cmake/test_interface/CMakeLists.txt36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/cmake/test_interface/CMakeLists.txt b/tests/auto/cmake/test_interface/CMakeLists.txt
new file mode 100644
index 0000000000..a8af92da63
--- /dev/null
+++ b/tests/auto/cmake/test_interface/CMakeLists.txt
@@ -0,0 +1,36 @@
+
+cmake_minimum_required(VERSION 2.8.11)
+
+project(test_interface)
+
+find_package(Qt5Widgets)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_executable(test_interface_exe WIN32 main.cpp mainwindow.cpp)
+
+# No need to specify include directories, compile definitions, the PIC flag, or to
+# link explicitly to Qt5::WinMain.
+target_link_libraries(test_interface_exe Qt5::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; }
+"
+)
+
+# The try_compile works because Qt5::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 Qt5::Widgets
+ OUTPUT_VARIABLE TC_OV
+)
+
+if (NOT _TRY_COMPILE_RES)
+ message(SEND_ERROR "The use of try_compile with Qt5::Widgets failed. The output was :\n${TC_OV}")
+endif()