From f956c1c0023f4f46b59aa0af865afe066ff831d8 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Mon, 5 Dec 2022 17:12:17 +0800 Subject: [PATCH] cmake: minor tweaks Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/dialog/CMakeLists.txt | 4 ---- examples/mainwindow/CMakeLists.txt | 4 ---- examples/openglwidget/CMakeLists.txt | 4 ---- examples/quick/CMakeLists.txt | 1 - examples/widget/CMakeLists.txt | 4 ---- src/core/CMakeLists.txt | 1 - src/core/cmakehelper.cmake | 35 ++++++++++++++++++---------- src/quick/CMakeLists.txt | 2 ++ src/widgets/CMakeLists.txt | 1 - 9 files changed, 25 insertions(+), 31 deletions(-) diff --git a/examples/dialog/CMakeLists.txt b/examples/dialog/CMakeLists.txt index cd62aee..922d741 100644 --- a/examples/dialog/CMakeLists.txt +++ b/examples/dialog/CMakeLists.txt @@ -47,10 +47,6 @@ target_link_libraries(Dialog PRIVATE FramelessHelper::Widgets ) -target_compile_definitions(Dialog PRIVATE - QT_NO_KEYWORDS -) - include(../../src/core/cmakehelper.cmake) setup_gui_app(Dialog) setup_compile_params(Dialog) diff --git a/examples/mainwindow/CMakeLists.txt b/examples/mainwindow/CMakeLists.txt index fb1212b..2165dc1 100644 --- a/examples/mainwindow/CMakeLists.txt +++ b/examples/mainwindow/CMakeLists.txt @@ -48,10 +48,6 @@ target_link_libraries(MainWindow PRIVATE FramelessHelper::Widgets ) -target_compile_definitions(MainWindow PRIVATE - QT_NO_KEYWORDS -) - include(../../src/core/cmakehelper.cmake) setup_gui_app(MainWindow) setup_compile_params(MainWindow) diff --git a/examples/openglwidget/CMakeLists.txt b/examples/openglwidget/CMakeLists.txt index ff3dedc..a7311dc 100644 --- a/examples/openglwidget/CMakeLists.txt +++ b/examples/openglwidget/CMakeLists.txt @@ -67,10 +67,6 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) ) endif() -target_compile_definitions(OpenGLWidget PRIVATE - QT_NO_KEYWORDS -) - include(../../src/core/cmakehelper.cmake) setup_gui_app(OpenGLWidget) setup_compile_params(OpenGLWidget) diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt index 846f3cb..0e40de5 100644 --- a/examples/quick/CMakeLists.txt +++ b/examples/quick/CMakeLists.txt @@ -82,7 +82,6 @@ target_link_libraries(Quick PRIVATE ) target_compile_definitions(Quick PRIVATE - QT_NO_KEYWORDS $<$,$>:QT_QML_DEBUG> ) diff --git a/examples/widget/CMakeLists.txt b/examples/widget/CMakeLists.txt index 66e2e07..06376ad 100644 --- a/examples/widget/CMakeLists.txt +++ b/examples/widget/CMakeLists.txt @@ -47,10 +47,6 @@ target_link_libraries(Widget PRIVATE FramelessHelper::Widgets ) -target_compile_definitions(Widget PRIVATE - QT_NO_KEYWORDS -) - include(../../src/core/cmakehelper.cmake) setup_gui_app(Widget) setup_compile_params(Widget) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 8f44265..7a93f0f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -165,7 +165,6 @@ if(FRAMELESSHELPER_NO_PRIVATE) endif() target_compile_definitions(${SUB_PROJ_NAME} PRIVATE - QT_NO_KEYWORDS FRAMELESSHELPER_CORE_LIBRARY ) diff --git a/src/core/cmakehelper.cmake b/src/core/cmakehelper.cmake index 2e2ea79..0a8df4e 100644 --- a/src/core/cmakehelper.cmake +++ b/src/core/cmakehelper.cmake @@ -28,26 +28,33 @@ function(setup_compile_params arg_target) QT_NO_CAST_FROM_ASCII QT_NO_CAST_FROM_BYTEARRAY QT_NO_URL_CAST_FROM_STRING - #QT_NO_KEYWORDS # Some QtQuick private headers still use the traditional Qt keywords. Fixed by me since 6.4. QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_FOREACH #QT_TYPESAFE_FLAGS # QtQuick private headers prevent us from enabling this flag. QT_USE_QSTRINGBUILDER QT_USE_FAST_OPERATOR_PLUS - #QT_STRICT_ITERATORS # Need Qt itself also compile with this flag enabled. QT_DEPRECATED_WARNINGS # Have no effect since 6.0 QT_DEPRECATED_WARNINGS_SINCE=0x070000 QT_WARN_DEPRECATED_UP_TO=0x070000 # Since 6.5 QT_DISABLE_DEPRECATED_BEFORE=0x070000 QT_DISABLE_DEPRECATED_UP_TO=0x070000 # Since 6.5 ) - if(WIN32) # Needed by both MSVC and MinGW + if(NOT DEFINED __DONT_DISABLE_QT_KEYWORDS OR NOT __DONT_DISABLE_QT_KEYWORDS) + target_compile_definitions(${arg_target} PRIVATE + QT_NO_KEYWORDS # Some QtQuick private headers still use the traditional Qt keywords. + ) + endif() + if(WIN32) # Needed by both MSVC and MinGW, otherwise some APIs we need will be invisible. set(_WIN32_WINNT_WIN10 0x0A00) set(NTDDI_WIN10_NI 0x0A00000C) target_compile_definitions(${arg_target} PRIVATE WINVER=${_WIN32_WINNT_WIN10} _WIN32_WINNT=${_WIN32_WINNT_WIN10} _WIN32_IE=${_WIN32_WINNT_WIN10} NTDDI_VERSION=${NTDDI_WIN10_NI} ) + else() + target_compile_definitions(${arg_target} PRIVATE + QT_STRICT_ITERATORS # On Windows we need to re-compile Qt with this flag enabled, so only enable it on non-Windows platforms. + ) endif() if(MSVC) target_compile_definitions(${arg_target} PRIVATE @@ -182,9 +189,9 @@ function(setup_package_export arg_target arg_path arg_public arg_alias arg_priva endif() install(TARGETS ${__targets} EXPORT ${arg_target}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${arg_path}" ) export(EXPORT ${arg_target}Targets @@ -197,18 +204,20 @@ function(setup_package_export arg_target arg_path arg_public arg_alias arg_priva install(EXPORT ${arg_target}Targets FILE ${arg_target}Targets.cmake NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) endfunction() function(deploy_qt_runtime arg_target) - find_package(QT NAMES Qt6 Qt5 QUIET COMPONENTS Core) + if(NOT (DEFINED Qt5_FOUND OR DEFINED Qt6_FOUND)) + find_package(QT NAMES Qt6 Qt5 QUIET COMPONENTS Core) + endif() if(NOT (Qt5_FOUND OR Qt6_FOUND)) message("You need to install the QtCore module first to be able to deploy the Qt libraries.") return() endif() find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) - if(NOT DEFINED QT_QMAKE_EXECUTABLE) + if(NOT DEFINED QT_QMAKE_EXECUTABLE) # QT_QMAKE_EXECUTABLE is usually defined by QtCreator. get_target_property(QT_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION) endif() if(NOT EXISTS "${QT_QMAKE_EXECUTABLE}") @@ -286,9 +295,9 @@ function(deploy_qt_runtime arg_target) include(GNUInstallDirs) install(TARGETS ${arg_target} BUNDLE DESTINATION . - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ) - if(${QT_VERSION} VERSION_GREATER_EQUAL "6.3") + if(QT_VERSION VERSION_GREATER_EQUAL "6.3") set(__deploy_script) if(${__is_quick_app}) qt_generate_deploy_qml_app_script( @@ -316,7 +325,9 @@ function(setup_translations arg_target) # really can't use them until Qt6 (the functions have been completely # re-written in Qt6 and according to my experiments they work reliably # now finally). - find_package(Qt6 QUIET COMPONENTS LinguistTools) + if(NOT DEFINED Qt6LinguistTools_FOUND) + find_package(Qt6 QUIET COMPONENTS LinguistTools) + endif() if(NOT Qt6LinguistTools_FOUND) message("You need to install the Qt Linguist Tools first to be able to create translations.") return() diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index 9199bd9..1f26df5 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -201,6 +201,8 @@ target_include_directories(${SUB_PROJ_NAME} PUBLIC "$" ) +set(__DONT_DISABLE_QT_KEYWORDS ON) + include(../core/cmakehelper.cmake) setup_compile_params(${SUB_PROJ_NAME}) setup_package_export(${SUB_PROJ_NAME} ${SUB_PROJ_PATH} "${PUBLIC_HEADERS}" "${PUBLIC_HEADERS_ALIAS}" "${PRIVATE_HEADERS}") diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 83b2b4e..405979f 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -114,7 +114,6 @@ if(FRAMELESSHELPER_NO_PRIVATE) endif() target_compile_definitions(${SUB_PROJ_NAME} PRIVATE - QT_NO_KEYWORDS FRAMELESSHELPER_WIDGETS_LIBRARY )