summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2017-12-08 16:09:30 (GMT)
committerSebastian Holtermann <sebholt@xwmw.org>2017-12-13 12:48:27 (GMT)
commit227a7974f426e0966d1736c66dd606b068985d1b (patch)
tree1b0048d6c54e4c0d88c1313bc6bc30c3f0c18610
parentbd10c3cf82f6e9d58b121498eaa2b9d8cc19dd2f (diff)
downloadCMake-227a7974f426e0966d1736c66dd606b068985d1b.zip
CMake-227a7974f426e0966d1736c66dd606b068985d1b.tar.gz
CMake-227a7974f426e0966d1736c66dd606b068985d1b.tar.bz2
Autogen: Tests: Add basic scripts for separate tests
-rw-r--r--Tests/CMakeLists.txt4
-rw-r--r--Tests/Qt4Autogen/CMakeLists.txt9
-rw-r--r--Tests/Qt5Autogen/CMakeLists.txt6
-rw-r--r--Tests/QtAutogen/AutogenTest.cmake53
-rw-r--r--Tests/QtAutogen/CommonTests.cmake1
-rw-r--r--Tests/QtAutogen/DefinesTest/CMakeLists.txt13
-rw-r--r--Tests/QtAutogen/DefinesTest/defines_test.cpp38
-rw-r--r--Tests/QtAutogen/TestMacros.cmake61
8 files changed, 185 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 1d13f1c..5608933 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1263,6 +1263,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
find_package(Qt5Widgets QUIET NO_MODULE)
endif()
if(CMake_TEST_Qt5 AND Qt5Widgets_FOUND)
+ add_subdirectory(Qt5Autogen)
+
add_test(NAME Qt5Autogen COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/QtAutogen"
@@ -1309,6 +1311,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt5AutoUicInterface")
endif()
if(QT4_WORKS AND QT_QTGUI_FOUND)
+ add_subdirectory(Qt4Autogen)
+
add_test(NAME Qt4Autogen COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/QtAutogen"
diff --git a/Tests/Qt4Autogen/CMakeLists.txt b/Tests/Qt4Autogen/CMakeLists.txt
new file mode 100644
index 0000000..818e888
--- /dev/null
+++ b/Tests/Qt4Autogen/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Set Qt test version and include the Autogen test macros
+set(QT_TEST_VERSION 4)
+include("../QtAutogen/TestMacros.cmake")
+
+# Qt4 only tests
+ADD_AUTOGEN_TEST(DefinesTest)
+
+# Common tests
+include("../QtAutogen/CommonTests.cmake")
diff --git a/Tests/Qt5Autogen/CMakeLists.txt b/Tests/Qt5Autogen/CMakeLists.txt
new file mode 100644
index 0000000..527e5ff
--- /dev/null
+++ b/Tests/Qt5Autogen/CMakeLists.txt
@@ -0,0 +1,6 @@
+# Set Qt test version and include the Autogen test macros
+set(QT_TEST_VERSION 5)
+include("../QtAutogen/TestMacros.cmake")
+
+# Common tests
+include("../QtAutogen/CommonTests.cmake")
diff --git a/Tests/QtAutogen/AutogenTest.cmake b/Tests/QtAutogen/AutogenTest.cmake
new file mode 100644
index 0000000..8c0a14f
--- /dev/null
+++ b/Tests/QtAutogen/AutogenTest.cmake
@@ -0,0 +1,53 @@
+
+# Tell find_package(Qt5) where to find Qt.
+if(QT_QMAKE_EXECUTABLE)
+ get_filename_component(Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH)
+ get_filename_component(Qt_PREFIX_DIR "${Qt_BIN_DIR}" PATH)
+ list(APPEND CMAKE_PREFIX_PATH ${Qt_PREFIX_DIR})
+endif()
+
+if (QT_TEST_VERSION STREQUAL 4)
+ find_package(Qt4 REQUIRED)
+ include(UseQt4)
+
+ set(QT_QTCORE_TARGET Qt4::QtCore)
+ set(QT_QTGUI_TARGET Qt4::QtGui)
+
+ # Qt macros
+ macro(qtx_wrap_cpp)
+ qt4_wrap_cpp(${ARGN})
+ endmacro()
+ macro(qtx_generate_moc)
+ qt4_generate_moc(${ARGN})
+ endmacro()
+
+elseif(QT_TEST_VERSION STREQUAL 5)
+ find_package(Qt5Widgets REQUIRED)
+
+ set(QT_QTCORE_TARGET Qt5::Core)
+ set(QT_QTGUI_TARGET Qt5::Widgets)
+
+ include_directories(${Qt5Widgets_INCLUDE_DIRS})
+ set(QT_LIBRARIES Qt5::Widgets)
+
+ if(Qt5_POSITION_INDEPENDENT_CODE AND CMAKE_CXX_COMPILE_OPTIONS_PIC)
+ add_definitions(${CMAKE_CXX_COMPILE_OPTIONS_PIC})
+ endif()
+
+ # Qt macros
+ macro(qtx_wrap_cpp)
+ qt5_wrap_cpp(${ARGN})
+ endmacro()
+ macro(qtx_generate_moc)
+ qt5_generate_moc(${ARGN})
+ endmacro()
+
+else()
+ message(SEND_ERROR "Invalid Qt version specified: ${QT_TEST_VERSION}")
+endif()
+
+# Get Qt compile features
+get_property(QT_COMPILE_FEATURES
+ TARGET ${QT_QTCORE_TARGET}
+ PROPERTY INTERFACE_COMPILE_FEATURES
+)
diff --git a/Tests/QtAutogen/CommonTests.cmake b/Tests/QtAutogen/CommonTests.cmake
new file mode 100644
index 0000000..0eaf831
--- /dev/null
+++ b/Tests/QtAutogen/CommonTests.cmake
@@ -0,0 +1 @@
+# Autogen tests common for Qt4 and Qt5
diff --git a/Tests/QtAutogen/DefinesTest/CMakeLists.txt b/Tests/QtAutogen/DefinesTest/CMakeLists.txt
new file mode 100644
index 0000000..de22845
--- /dev/null
+++ b/Tests/QtAutogen/DefinesTest/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 3.10)
+project(DefinesTest)
+
+# Qt4 only definitions test
+if(NOT QT_TEST_VERSION STREQUAL 4)
+ message(ERROR "Invalid Qt test version. This test is for Qt4 only.")
+endif()
+
+find_package(Qt4 REQUIRED)
+
+add_executable(DefinesTest defines_test.cpp)
+set_target_properties(DefinesTest PROPERTIES AUTOMOC TRUE)
+target_link_libraries(DefinesTest Qt4::QtGui)
diff --git a/Tests/QtAutogen/DefinesTest/defines_test.cpp b/Tests/QtAutogen/DefinesTest/defines_test.cpp
new file mode 100644
index 0000000..cf4e9cb
--- /dev/null
+++ b/Tests/QtAutogen/DefinesTest/defines_test.cpp
@@ -0,0 +1,38 @@
+
+#include <QObject>
+
+#ifdef QT_GUI_LIB
+#include <QTextDocument>
+
+class SomeDocument : public QTextDocument
+{
+ Q_OBJECT
+
+Q_SIGNALS:
+ void someSig();
+};
+#endif
+
+#ifdef QT_CORE_LIB
+class SomeObject : public QObject
+{
+ Q_OBJECT
+
+Q_SIGNALS:
+ void someSig();
+};
+#endif
+
+int main(int argc, char** argv)
+{
+#ifdef QT_CORE_LIB
+ QMetaObject sosmo = SomeObject::staticMetaObject;
+#endif
+#ifdef QT_GUI_LIB
+ QMetaObject sdsmo = SomeDocument::staticMetaObject;
+#endif
+
+ return 0;
+}
+
+#include "defines_test.moc"
diff --git a/Tests/QtAutogen/TestMacros.cmake b/Tests/QtAutogen/TestMacros.cmake
new file mode 100644
index 0000000..849a733
--- /dev/null
+++ b/Tests/QtAutogen/TestMacros.cmake
@@ -0,0 +1,61 @@
+# Autogen build options
+set(Autogen_BUILD_OPTIONS "-DQT_TEST_VERSION=${QT_TEST_VERSION}")
+if(NOT CMAKE_CONFIGURATION_TYPES)
+ list(APPEND Autogen_BUILD_OPTIONS "-DCMAKE_BUILD_TYPE=$<CONFIGURATION>")
+endif()
+list(APPEND Autogen_BUILD_OPTIONS
+ "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
+)
+
+# A macro to add a QtAutogen test
+macro(ADD_AUTOGEN_TEST NAME)
+ if(${ARGC} GREATER 1)
+ # On Windows there is no RPATH, so while Qt might be available for building,
+ # the required dlls may not be in the PATH, so we can't run the executables
+ # on that platform.
+ if(WIN32)
+ set(_TestCommand --test-command ${CMAKE_CTEST_COMMAND} -V)
+ else()
+ set(_TestCommand --test-command ${ARGN})
+ endif()
+ endif()
+
+ set(_QtXAutogen "Qt${QT_TEST_VERSION}Autogen")
+ set(_SourceDir "${CMake_SOURCE_DIR}/Tests/QtAutogen/${NAME}")
+ set(_BuildDir "${CMake_BINARY_DIR}/Tests/${_QtXAutogen}/${NAME}")
+ add_test(NAME "${_QtXAutogen}.${NAME}" COMMAND "${CMAKE_CTEST_COMMAND}"
+ --build-and-test
+ "${_SourceDir}"
+ "${_BuildDir}"
+ ${build_generator_args}
+ --build-project ${NAME}
+ --build-exe-dir "${_BuildDir}"
+ --force-new-ctest-process
+ --build-options ${build_options} ${Autogen_BUILD_OPTIONS}
+ ${_TestCommand}
+ )
+ list(APPEND TEST_BUILD_DIRS "${_BuildDir}")
+ unset(_TestCommand)
+ unset(_QtXAutogen)
+ unset(_SourceDir)
+ unset(_BuildDir)
+endmacro()
+
+
+# Allow using qtx_wrap_cpp and qtx_generate_moc or not
+set(ALLOW_WRAP_CPP TRUE)
+# Do a simple check if there is are non ASCII character in the build path
+string(REGEX MATCH "[^ -~]+" NON_ASCII_BDIR ${CMAKE_CURRENT_BINARY_DIR})
+if(NON_ASCII_BDIR)
+ # Qt4 moc does not support utf8 paths in _parameter files generated by
+ # qtx_wrap_cpp
+ # https://bugreports.qt.io/browse/QTBUG-35480
+ if(QT_TEST_VERSION STREQUAL 4)
+ set(ALLOW_WRAP_CPP FALSE)
+ endif()
+ # On windows qtx_wrap_cpp also fails in Qt5 when used on a path that
+ # contains non ASCII characters
+ if(WIN32)
+ set(ALLOW_WRAP_CPP FALSE)
+ endif()
+endif()