From 2a1da4b261eeb4c2389cf6c01cdf7d325819bad2 Mon Sep 17 00:00:00 2001 From: Mikhail Svetkin Date: Wed, 16 Mar 2022 10:21:32 +0100 Subject: [PATCH 1/4] cmake: Split QtWebApp/CMakeLists into lib cmake and project cmake files That will allow to use QtWebApp as subdirectory with provided Qt version --- .github/workflows/build.yml | 4 +--- CMakeLists.txt | 6 ++++++ QtWebApp/CMakeLists.txt | 4 ---- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 CMakeLists.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 936b6ae..b62b91c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,14 +39,12 @@ jobs: - name: Build QtWebApp run: | if [ "${{ matrix.os }}" == "ubuntu-latest" ] && [ "$CC" == "clang" ]; then export LDFLAGS=-fuse-ld=lld; fi - pushd QtWebApp mkdir build pushd build cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release .. make sudo make install popd # build - popd # QtWebApp env: CC: ${{ matrix.compiler.cc }} CXX: ${{ matrix.compiler.cxx }} @@ -109,7 +107,7 @@ jobs: if: matrix.arch == 'win32_mingw81' run: echo "$env:IQTA_TOOLS/mingw810_32/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - run: cmake -S QtWebApp -B build-qtwebapp ${{ matrix.generator }} -DCMAKE_BUILD_TYPE=Release + - run: cmake -B build-qtwebapp ${{ matrix.generator }} -DCMAKE_BUILD_TYPE=Release - run: cmake --build build-qtwebapp - run: cmake --build build-qtwebapp --target install diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d07f3dd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.1) +project(QtWebApp CXX) + +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED HINTS $ENV{Qt6_DIR} $ENV{Qt5_DIR}) + +add_subdirectory(QtWebApp) diff --git a/QtWebApp/CMakeLists.txt b/QtWebApp/CMakeLists.txt index b682903..5eddd31 100644 --- a/QtWebApp/CMakeLists.txt +++ b/QtWebApp/CMakeLists.txt @@ -1,12 +1,8 @@ -cmake_minimum_required(VERSION 3.1) -project(QtWebApp CXX) - set(qtwebapp_MAJOR 1) set(qtwebapp_MINOR 8) set(qtwebapp_PATCH 3) set(qtwebapp_VERSION ${qtwebapp_MAJOR}.${qtwebapp_MINOR}.${qtwebapp_PATCH}) -find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED HINTS $ENV{Qt6_DIR} $ENV{Qt5_DIR}) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network REQUIRED) if (Qt6_FOUND) From c4c736ba4ba54ab3399d8a1572700e3a74e6082d Mon Sep 17 00:00:00 2001 From: Mikhail Svetkin Date: Wed, 16 Mar 2022 13:58:47 +0100 Subject: [PATCH 2/4] qt6: Fix build with QT_USE_QSTRINGBUILDER MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit httprequest.cpp:374:44: error: no matching function for call to ‘QByteArray::startsWith(QStringBuilder)’ 374 | if (line.startsWith("--" + boundary)) { httprequest.cpp:406:50: error: no matching function for call to ‘QByteArray::contains(QStringBuilder)’ 406 | if (line.contains(boundary + "--")) { Also we don't change the boundary during the loop so we don't need to create helper strings every iteration. --- QtWebApp/httpserver/httprequest.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/QtWebApp/httpserver/httprequest.cpp b/QtWebApp/httpserver/httprequest.cpp index 59b5122..a9dc037 100644 --- a/QtWebApp/httpserver/httprequest.cpp +++ b/QtWebApp/httpserver/httprequest.cpp @@ -369,9 +369,11 @@ void HttpRequest::parseMultiPartFile() { #endif QTemporaryFile *uploadedFile = nullptr; QByteArray fieldValue; + QByteArray boundaryStart = "--" + boundary; + QByteArray boundaryEnd = boundary + "--"; while (!tempFile->atEnd() && !finished && !tempFile->error()) { QByteArray line = tempFile->readLine(65536); - if (line.startsWith("--" + boundary)) { + if (line.startsWith(boundaryStart)) { // Boundary found. Until now we have collected 2 bytes too much, // so remove them from the last result if (fileName.isEmpty() && !fieldName.isEmpty()) { @@ -403,7 +405,7 @@ void HttpRequest::parseMultiPartFile() { qWarning("HttpRequest: format error, unexpected end of file data"); } } - if (line.contains(boundary + "--")) { + if (line.contains(boundaryEnd)) { finished = true; } break; From ffc328700f8b9ee991892f2b7e211a509c47112f Mon Sep 17 00:00:00 2001 From: Mikhail Svetkin Date: Mon, 21 Mar 2022 12:36:28 +0100 Subject: [PATCH 3/4] cmake: Move confs flags from QtWebApp/CMakeLists to top CMakeLists.txt This flags effects entire project and they should not effect whoever uses this project as subdirectory. --- CMakeLists.txt | 23 +++++++++++++++++++++++ QtWebApp/CMakeLists.txt | 22 ---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d07f3dd..e4ab64e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,27 @@ project(QtWebApp CXX) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED HINTS $ENV{Qt6_DIR} $ENV{Qt5_DIR}) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(NOT MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format -Werror=return-type") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format -Werror=return-type") +endif() + +if(CMAKE_BUILD_TYPE MATCHES Debug) + if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fsanitize=undefined") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") + endif() + add_definitions("-D_GLIBCXX_DEBUG") + add_definitions("-DQT_SHAREDPOINTER_TRACK_POINTERS") + add_definitions("-DCMAKE_DEBUG") + add_definitions("-DSUPERVERBOSE") +endif() + +set(CMAKE_AUTOMOC ON) + add_subdirectory(QtWebApp) diff --git a/QtWebApp/CMakeLists.txt b/QtWebApp/CMakeLists.txt index 5eddd31..5f00e19 100644 --- a/QtWebApp/CMakeLists.txt +++ b/QtWebApp/CMakeLists.txt @@ -9,30 +9,8 @@ if (Qt6_FOUND) find_package(Qt6 COMPONENTS Core5Compat REQUIRED) endif() -set(CMAKE_AUTOMOC ON) - add_definitions(-DQTWEBAPPLIB_EXPORT) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -if(NOT MSVC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format -Werror=return-type") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format -Werror=return-type") -endif() - -if(CMAKE_BUILD_TYPE MATCHES Debug) - if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fsanitize=undefined") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") - endif() - add_definitions("-D_GLIBCXX_DEBUG") - add_definitions("-DQT_SHAREDPOINTER_TRACK_POINTERS") - add_definitions("-DCMAKE_DEBUG") - add_definitions("-DSUPERVERBOSE") -endif() add_definitions("-DCMAKE_QTWEBAPP_SO") configure_file(qtwebappglobal.h.in qtwebappglobal.h @ONLY) From 7a3b7f31867a70d4ad17a350eb0f5d8edf6c7db8 Mon Sep 17 00:00:00 2001 From: Kristian Date: Mon, 8 May 2023 23:03:22 +0200 Subject: [PATCH 4/4] Update requirements CMakeLists --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4ab64e..4151e30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.22) project(QtWebApp CXX) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED HINTS $ENV{Qt6_DIR} $ENV{Qt5_DIR}) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT MSVC)