From 4b2790aa6d61790c291d4744d77732db7cccc752 Mon Sep 17 00:00:00 2001
From: Mikhail Svetkin <mikhail.svetkin@gmail.com>
Date: Thu, 9 Apr 2020 11:18:07 +0200
Subject: [PATCH] Add cmake support for Qt6/dev branch
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Change-Id: Icca0edab01d6028d786b76f99fba388565bd6e76
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
---
 CMakeLists.txt                                | 15 ++++++
 examples/CMakeLists.txt                       |  7 +++
 examples/httpserver/CMakeLists.txt            |  3 ++
 examples/httpserver/simple/CMakeLists.txt     | 40 ++++++++++++++
 src/CMakeLists.txt                            |  6 +++
 src/httpserver/CMakeLists.txt                 | 54 +++++++++++++++++++
 src/sslserver/CMakeLists.txt                  | 16 ++++++
 tests/CMakeLists.txt                          |  7 +++
 tests/auto/CMakeLists.txt                     |  7 +++
 tests/auto/qabstracthttpserver/CMakeLists.txt | 12 +++++
 .../qabstracthttpserver.pro                   |  2 -
 .../tst_qabstracthttpserver.cpp               |  6 +--
 tests/auto/qhttpserver/CMakeLists.txt         | 17 ++++++
 .../auto/qhttpserverresponder/CMakeLists.txt  | 17 ++++++
 .../{ => data}/index.html                     |  0
 .../qhttpserverresponder.pro                  |  2 +-
 .../tst_qhttpserverresponder.cpp              |  4 +-
 tests/auto/qhttpserverresponse/CMakeLists.txt | 17 ++++++
 tests/auto/qhttpserverrouter/CMakeLists.txt   | 12 +++++
 19 files changed, 236 insertions(+), 8 deletions(-)
 create mode 100644 CMakeLists.txt
 create mode 100644 examples/CMakeLists.txt
 create mode 100644 examples/httpserver/CMakeLists.txt
 create mode 100644 examples/httpserver/simple/CMakeLists.txt
 create mode 100644 src/CMakeLists.txt
 create mode 100644 src/httpserver/CMakeLists.txt
 create mode 100644 src/sslserver/CMakeLists.txt
 create mode 100644 tests/CMakeLists.txt
 create mode 100644 tests/auto/CMakeLists.txt
 create mode 100644 tests/auto/qabstracthttpserver/CMakeLists.txt
 create mode 100644 tests/auto/qhttpserver/CMakeLists.txt
 create mode 100644 tests/auto/qhttpserverresponder/CMakeLists.txt
 rename tests/auto/qhttpserverresponder/{ => data}/index.html (100%)
 create mode 100644 tests/auto/qhttpserverresponse/CMakeLists.txt
 create mode 100644 tests/auto/qhttpserverrouter/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..e6e9931
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,15 @@
+# Generated from qthttpserver.pro.
+
+cmake_minimum_required(VERSION 3.15.0)
+
+project(QtHttpServer
+    VERSION 6.0.0
+    DESCRIPTION "Qt HTTP Server"
+    HOMEPAGE_URL "https://qt.io/"
+    LANGUAGES CXX C
+)
+
+find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core Network)
+find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Concurrent)
+
+qt_build_repo()
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..247cb4e
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,7 @@
+# Generated from examples.pro.
+
+qt_examples_build_begin()
+
+add_subdirectory(httpserver)
+
+qt_examples_build_end()
diff --git a/examples/httpserver/CMakeLists.txt b/examples/httpserver/CMakeLists.txt
new file mode 100644
index 0000000..693183c
--- /dev/null
+++ b/examples/httpserver/CMakeLists.txt
@@ -0,0 +1,3 @@
+# Generated from httpserver.pro.
+
+add_subdirectory(simple)
diff --git a/examples/httpserver/simple/CMakeLists.txt b/examples/httpserver/simple/CMakeLists.txt
new file mode 100644
index 0000000..07d21a7
--- /dev/null
+++ b/examples/httpserver/simple/CMakeLists.txt
@@ -0,0 +1,40 @@
+# Generated from simple.pro.
+
+cmake_minimum_required(VERSION 3.14)
+project(simple LANGUAGES CXX)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+set(CMAKE_AUTOUIC ON)
+
+set(INSTALL_EXAMPLEDIR "examples/httpserver/simple")
+
+find_package(Qt6 COMPONENTS HttpServer)
+
+add_executable(simple
+    main.cpp
+)
+target_link_libraries(simple PUBLIC
+    Qt::HttpServer
+)
+
+
+# Resources:
+set(assets_resource_files
+    "assets/qt-logo.png"
+)
+
+qt6_add_resources(simple "assets"
+    PREFIX
+        "/"
+    FILES
+        ${assets_resource_files}
+)
+
+install(TARGETS simple
+    RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+    BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+    LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..588815f
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,6 @@
+# Generated from src.pro.
+
+if(QT_FEATURE_ssl)
+    add_subdirectory(sslserver)
+endif()
+add_subdirectory(httpserver)
diff --git a/src/httpserver/CMakeLists.txt b/src/httpserver/CMakeLists.txt
new file mode 100644
index 0000000..b3586eb
--- /dev/null
+++ b/src/httpserver/CMakeLists.txt
@@ -0,0 +1,54 @@
+# Generated from httpserver.pro.
+
+#####################################################################
+## HttpServer Module:
+#####################################################################
+
+qt_add_module(HttpServer
+    SOURCES
+        ../3rdparty/http-parser/http_parser.c ../3rdparty/http-parser/http_parser.h
+        qabstracthttpserver.cpp qabstracthttpserver.h qabstracthttpserver_p.h
+        qhttpserver.cpp qhttpserver.h qhttpserver_p.h
+        qhttpserverliterals.cpp qhttpserverliterals_p.h
+        qhttpserverrequest.cpp qhttpserverrequest.h qhttpserverrequest_p.h
+        qhttpserverresponder.cpp qhttpserverresponder.h qhttpserverresponder_p.h
+        qhttpserverresponse.cpp qhttpserverresponse.h qhttpserverresponse_p.h
+        qhttpserverrouter.cpp qhttpserverrouter.h qhttpserverrouter_p.h
+        qhttpserverrouterrule.cpp qhttpserverrouterrule.h qhttpserverrouterrule_p.h
+        qhttpserverrouterviewtraits.h
+        qthttpserverglobal.h
+    INCLUDE_DIRECTORIES
+        .
+        ../3rdparty/http-parser
+    LIBRARIES
+        Qt::CorePrivate
+    PUBLIC_LIBRARIES
+        Qt::Core
+        Qt::Network
+    PRIVATE_MODULE_INTERFACE
+        Qt::CorePrivate
+)
+
+## Scopes:
+#####################################################################
+
+qt_extend_target(HttpServer CONDITION TARGET Qt::WebSockets
+    LIBRARIES
+        Qt::WebSocketsPrivate
+    PUBLIC_LIBRARIES
+        Qt::WebSockets
+    PRIVATE_MODULE_INTERFACE
+        Qt::WebSocketsPrivate
+)
+
+qt_extend_target(HttpServer CONDITION QT_FEATURE_ssl
+    PUBLIC_LIBRARIES
+        Qt::SslServer
+)
+
+qt_extend_target(HttpServer CONDITION TARGET Qt::Concurrent
+    SOURCES
+        qhttpserverfutureresponse.cpp qhttpserverfutureresponse.h
+    PUBLIC_LIBRARIES
+        Qt::Concurrent
+)
diff --git a/src/sslserver/CMakeLists.txt b/src/sslserver/CMakeLists.txt
new file mode 100644
index 0000000..580d824
--- /dev/null
+++ b/src/sslserver/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Generated from sslserver.pro.
+
+#####################################################################
+## SslServer Module:
+#####################################################################
+
+qt_add_module(SslServer
+    SOURCES
+        qsslserver.cpp qsslserver.h qsslserver_p.h
+        qtsslserverglobal.h
+    INCLUDE_DIRECTORIES
+        .
+    PUBLIC_LIBRARIES
+        Qt::Core
+        Qt::Network
+)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..2214137
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,7 @@
+# Generated from tests.pro.
+
+if(QT_BUILD_STANDALONE_TESTS)
+    # Add qt_find_package calls for extra dependencies that need to be found when building
+    # the standalone tests here.
+endif()
+qt_build_tests()
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt
new file mode 100644
index 0000000..a7e0cb5
--- /dev/null
+++ b/tests/auto/CMakeLists.txt
@@ -0,0 +1,7 @@
+# Generated from auto.pro.
+
+add_subdirectory(qabstracthttpserver)
+add_subdirectory(qhttpserver)
+add_subdirectory(qhttpserverresponder)
+add_subdirectory(qhttpserverrouter)
+add_subdirectory(qhttpserverresponse)
diff --git a/tests/auto/qabstracthttpserver/CMakeLists.txt b/tests/auto/qabstracthttpserver/CMakeLists.txt
new file mode 100644
index 0000000..f7de801
--- /dev/null
+++ b/tests/auto/qabstracthttpserver/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Generated from qabstracthttpserver.pro.
+
+#####################################################################
+## tst_qabstracthttpserver Test:
+#####################################################################
+
+qt_add_test(tst_qabstracthttpserver
+    SOURCES
+        tst_qabstracthttpserver.cpp
+    PUBLIC_LIBRARIES
+        Qt::HttpServer
+)
diff --git a/tests/auto/qabstracthttpserver/qabstracthttpserver.pro b/tests/auto/qabstracthttpserver/qabstracthttpserver.pro
index ae089bf..ca20055 100644
--- a/tests/auto/qabstracthttpserver/qabstracthttpserver.pro
+++ b/tests/auto/qabstracthttpserver/qabstracthttpserver.pro
@@ -3,5 +3,3 @@ TARGET = tst_qabstracthttpserver
 SOURCES  += tst_qabstracthttpserver.cpp
 
 QT = httpserver testlib
-
-qtHaveModule(websockets): QT += websockets
diff --git a/tests/auto/qabstracthttpserver/tst_qabstracthttpserver.cpp b/tests/auto/qabstracthttpserver/tst_qabstracthttpserver.cpp
index d8dc0ef..48c637c 100644
--- a/tests/auto/qabstracthttpserver/tst_qabstracthttpserver.cpp
+++ b/tests/auto/qabstracthttpserver/tst_qabstracthttpserver.cpp
@@ -30,7 +30,7 @@
 #include <QtHttpServer/qabstracthttpserver.h>
 
 #if defined(QT_WEBSOCKETS_LIB)
-#include <QtWebSockets/qwebsocket.h>
+#  include <QtWebSockets/qwebsocket.h>
 #endif
 
 #include <QtTest/qsignalspy.h>
@@ -45,8 +45,8 @@
 #include <QtHttpServer/qhttpserverrequest.h>
 
 #if defined(Q_OS_UNIX)
-#   include <signal.h>
-#   include <unistd.h>
+#  include <signal.h>
+#  include <unistd.h>
 #endif
 
 QT_BEGIN_NAMESPACE
diff --git a/tests/auto/qhttpserver/CMakeLists.txt b/tests/auto/qhttpserver/CMakeLists.txt
new file mode 100644
index 0000000..806494e
--- /dev/null
+++ b/tests/auto/qhttpserver/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Generated from qhttpserver.pro.
+
+#####################################################################
+## tst_qhttpserver Test:
+#####################################################################
+
+# Collect test data
+list(APPEND test_data "data/")
+
+qt_add_test(tst_qhttpserver
+    SOURCES
+        tst_qhttpserver.cpp
+    PUBLIC_LIBRARIES
+        Qt::HttpServer
+        Qt::HttpServerPrivate
+    TESTDATA ${test_data}
+)
diff --git a/tests/auto/qhttpserverresponder/CMakeLists.txt b/tests/auto/qhttpserverresponder/CMakeLists.txt
new file mode 100644
index 0000000..51a2a33
--- /dev/null
+++ b/tests/auto/qhttpserverresponder/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Generated from qhttpserverresponder.pro.
+
+#####################################################################
+## tst_qhttpserverresponder Test:
+#####################################################################
+
+# Collect test data
+list(APPEND test_data "data/")
+
+qt_add_test(tst_qhttpserverresponder
+    SOURCES
+        tst_qhttpserverresponder.cpp
+    PUBLIC_LIBRARIES
+        Qt::HttpServer
+        Qt::HttpServerPrivate
+    TESTDATA ${test_data}
+)
diff --git a/tests/auto/qhttpserverresponder/index.html b/tests/auto/qhttpserverresponder/data/index.html
similarity index 100%
rename from tests/auto/qhttpserverresponder/index.html
rename to tests/auto/qhttpserverresponder/data/index.html
diff --git a/tests/auto/qhttpserverresponder/qhttpserverresponder.pro b/tests/auto/qhttpserverresponder/qhttpserverresponder.pro
index e3031db..c170060 100644
--- a/tests/auto/qhttpserverresponder/qhttpserverresponder.pro
+++ b/tests/auto/qhttpserverresponder/qhttpserverresponder.pro
@@ -4,4 +4,4 @@ SOURCES  += tst_qhttpserverresponder.cpp
 
 QT = httpserver httpserver-private testlib
 
-TESTDATA += *.html
+TESTDATA += data/
diff --git a/tests/auto/qhttpserverresponder/tst_qhttpserverresponder.cpp b/tests/auto/qhttpserverresponder/tst_qhttpserverresponder.cpp
index b6dd81f..20b9480 100644
--- a/tests/auto/qhttpserverresponder/tst_qhttpserverresponder.cpp
+++ b/tests/auto/qhttpserverresponder/tst_qhttpserverresponder.cpp
@@ -189,7 +189,7 @@ void tst_QHttpServerResponder::writeFile_data()
     QTest::addColumn<QString>("data");
 
     QTest::addRow("index.html")
-        << qobject_cast<QIODevice *>(new QFile(QFINDTESTDATA("index.html"), this))
+        << qobject_cast<QIODevice *>(new QFile(QFINDTESTDATA("data/index.html"), this))
         << 200
         << "text/html"
         << "<html></html>";
@@ -231,7 +231,7 @@ void tst_QHttpServerResponder::writeFile()
 
 void tst_QHttpServerResponder::writeFileExtraHeader()
 {
-    auto file = new QFile(QFINDTESTDATA("index.html"), this);
+    auto file = new QFile(QFINDTESTDATA("data/index.html"), this);
     QSignalSpy spyDestroyIoDevice(file, &QObject::destroyed);
 
     HttpServer server([=](QHttpServerResponder responder) {
diff --git a/tests/auto/qhttpserverresponse/CMakeLists.txt b/tests/auto/qhttpserverresponse/CMakeLists.txt
new file mode 100644
index 0000000..7ab6d6c
--- /dev/null
+++ b/tests/auto/qhttpserverresponse/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Generated from qhttpserverresponse.pro.
+
+#####################################################################
+## tst_qhttpserverresponse Test:
+#####################################################################
+
+# Collect test data
+list(APPEND test_data "data/")
+
+qt_add_test(tst_qhttpserverresponse
+    SOURCES
+        tst_qhttpserverresponse.cpp
+    PUBLIC_LIBRARIES
+        Qt::HttpServer
+        Qt::HttpServerPrivate
+    TESTDATA ${test_data}
+)
diff --git a/tests/auto/qhttpserverrouter/CMakeLists.txt b/tests/auto/qhttpserverrouter/CMakeLists.txt
new file mode 100644
index 0000000..27901fc
--- /dev/null
+++ b/tests/auto/qhttpserverrouter/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Generated from qhttpserverrouter.pro.
+
+#####################################################################
+## tst_qhttpserverrouter Test:
+#####################################################################
+
+qt_add_test(tst_qhttpserverrouter
+    SOURCES
+        tst_qhttpserverrouter.cpp
+    PUBLIC_LIBRARIES
+        Qt::HttpServer
+)