Skip to content

Commit

Permalink
Determine whether to load the frameless library based on the QT version
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Nov 2, 2023
1 parent 9ffc03f commit 7327d66
Show file tree
Hide file tree
Showing 30 changed files with 9,655 additions and 9,344 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-win-qt5.15.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake-Windows-Qt5.15
name: CMake-Windows-Qt5.15LTS

on: [pull_request,push]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake-win-qt6.2.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake-Windows-Qt6.2
name: CMake-Windows-Qt6.2LTS

on: [pull_request,push]

Expand Down
59 changes: 46 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,60 @@ cmake_minimum_required(VERSION 3.5)

set(SARIBBON_VERSION_MAJOR 1)
set(SARIBBON_VERSION_MINOR 0)
set(SARIBBON_VERSION_PATCH 3)
set(SARIBBON_VERSION_PATCH 4)
set(SARIBBON_VERSION "${SARIBBON_VERSION_MAJOR}.${SARIBBON_VERSION_MINOR}.${SARIBBON_VERSION_PATCH}")
project(SARibbon VERSION ${SARIBBON_VERSION} LANGUAGES CXX)

# option(BUILD_SHARED_LIBS "build the SARibbonBar in shared lib mode" ON)
option(BUILD_EXAMPLES "build the examples" ON)

# load Qt library, minimum version required is 5.8
# cn:Qt库加载,最低版本要求为5.8

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC)
# CMAKE_CXX_STANDARD对有些版本的msvc无效
set(CMAKE_CXX_FLAGS"${CMAKE_CXX_FLAGS} /std:c++17")
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} 5.8 COMPONENTS Core Gui Widgets REQUIRED)
message(STATUS "current Qt version is Qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")


# 根据qt版本选择是否使用frameless库,目前frameless库支持qt5.14,qt5.15,qt6.4+,除了上诉版本,都使用不了
if(${QT_VERSION_MAJOR} EQUAL 5)
# qt版本为5,判断是否小版本大于14
if(${QT_VERSION_MINOR} GREATER_EQUAL 14)
#5.14和5.15可以使用frameless
set(SARIBBON_USE_FRAMELESS_LIB ON)
else()
set(SARIBBON_USE_FRAMELESS_LIB OFF)
endif()
elseif(${QT_VERSION_MAJOR} EQUAL 6)
# qt版本为6,判断是否小版本大于4
if(${QT_VERSION_MINOR} GREATER_EQUAL 4)
#6.4及以上可以使用frameless
set(SARIBBON_USE_FRAMELESS_LIB ON)
else()
set(SARIBBON_USE_FRAMELESS_LIB OFF)
endif()
endif()


# 如果是使用frameless库,需要c++17,否则c++11足以
if(SARIBBON_USE_FRAMELESS_LIB)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC)
# CMAKE_CXX_STANDARD对有些版本的msvc无效
set(CMAKE_CXX_FLAGS"${CMAKE_CXX_FLAGS} /std:c++17")
endif()
message(STATUS "The current QT version can use the frameless library and enable C++17")
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC)
# CMAKE_CXX_STANDARD对有些版本的msvc无效
set(CMAKE_CXX_FLAGS"${CMAKE_CXX_FLAGS} /std:c++11")
endif()
message(STATUS "The current qt version cannot use the frameless library, enable C++11")
endif()

set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows")
set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
set(CMAKE_RELWITHDEBINFO_POSTFIX "rd" CACHE STRING "add a postfix, usually empty on windows")
Expand Down Expand Up @@ -58,13 +98,6 @@ else()
set(SARIBBON_PLATFORM "64")
endif()

# load Qt library, minimum version required is 5.8
# cn:Qt库加载,最低版本要求为5.8

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} 5.8 COMPONENTS Core Gui Widgets REQUIRED)
message(STATUS "current Qt version is Qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")



include(cmake/WinResource.cmake)
Expand Down
39 changes: 32 additions & 7 deletions SARibbonBar.pri
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
include($$PWD/common.pri)
INCLUDEPATH += $$PWD/src/SARibbonBar
DEPENDPATH += $$PWD/src/SARibbonBar
# framelessHelper的引用路径
INCLUDEPATH += $$PWD/src/SARibbonBar/3rdparty/framelesshelper/include
DEPENDPATH += $$PWD/src/SARibbonBar/3rdparty/framelesshelper/include
INCLUDEPATH += $$PWD/src/SARibbonBar/3rdparty/framelesshelper/qmake/inc/core
DEPENDPATH += $$PWD/src/SARibbonBar/3rdparty/framelesshelper/qmake/inc/core
# 定义FRAMELESSHELPER_FEATURE_static_build为-1让frameless也作为库的一部分
DEFINES += FRAMELESSHELPER_FEATURE_static_build=-1


greaterThan(QT_MAJOR_VERSION, 4){
# 目前 frameless支持qt5.14,qt5.15,qt6.4+,除了上诉版本,都使用不了
greaterThan(QT_MINOR_VERSION, 13){
SA_RIBBON_CONFIG += use_frameless
}
}else{
# Qt6,qt6.4+可使用frameless
greaterThan(QT_MAJOR_VERSION, 5){
greaterThan(QT_MINOR_VERSION, 3){
SA_RIBBON_CONFIG += use_frameless
}
}
}

contains( SA_RIBBON_CONFIG, use_frameless ) {
!contains(CONFIG,C++17){
CONFIG += c++17
}
# framelessHelper的引用路径
INCLUDEPATH += $$PWD/src/SARibbonBar/3rdparty/framelesshelper/include
DEPENDPATH += $$PWD/src/SARibbonBar/3rdparty/framelesshelper/include
INCLUDEPATH += $$PWD/src/SARibbonBar/3rdparty/framelesshelper/qmake/inc/core
DEPENDPATH += $$PWD/src/SARibbonBar/3rdparty/framelesshelper/qmake/inc/core
# 定义FRAMELESSHELPER_FEATURE_static_build为-1让frameless也作为库的一部分
DEFINES += FRAMELESSHELPER_FEATURE_static_build=-1
# 定义SARIBBON_USE_3RDPARTY_FRAMELESSHELPER为1
DEFINES += SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=1
}else{
DEFINES += SARIBBON_USE_3RDPARTY_FRAMELESSHELPER=0
}
LIBS += -L$${SARIBBON_BIN_DIR} -l$${SARIBBON_LIB_NAME}

6 changes: 4 additions & 2 deletions readme-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ SARibbon提供了几种布局方式,以及可以通过qss自由定义主题

# 构建

> 注意:要求c++17标准支持(由于使用了frameless库,此库最低要求c++17),Qt版本至少在Qt5.14及以上,否则无法编译frameless库,推荐使用Qt5.14以上版本,因为Qt5.14完善了高分辨率的支持
> qmake和cmake会根据qt版本选择是否加载frameless库,会根据不同的qt版本选择使用c++11还是C++17
> 注意:如果使用frameless库,要求c++17标准支持(由于使用了frameless库,此库最低要求c++17),Qt版本至少在Qt5.14及以上,否则无法编译frameless库,推荐使用Qt5.14以上版本,因为Qt5.14完善了高分辨率的支持
由于最低C++版本为17,因此,在你的qmake文件中,需要添加:

Expand All @@ -61,7 +63,7 @@ CONFIG += c++17

## 直接引入工程(静态)

SARibbon提供了合并好的`SARibbon.h`文件和`SARibbon.cpp`文件,只需要在工程引入这两个文件,同时把资源文件和第三方库文件引入就可以使用,无需编译为动态库,可以参考SimpleExample的例子(位于`src/example/SimpleExample`),静态引入使用到`SARibbon.h``SARibbon.cpp``SARibbon.pri``SARibbonBar/resource.qrc`4个文件以及`SARibbonBar/3rdparty`,`SARibbonBar/resource`这两个文件夹:
SARibbon提供了合并好的`SARibbon.h`文件和`SARibbon.cpp`文件,只需要在工程引入这两个文件,同时把资源文件和第三方库文件引入就可以使用,无需编译为动态库,可以参考StaticExample的例子(位于`src/example/StaticExample`),静态引入使用到`SARibbon.h``SARibbon.cpp``SARibbon.pri``SARibbonBar/resource.qrc`4个文件以及`SARibbonBar/3rdparty`,`SARibbonBar/resource`这两个文件夹:

你的工程目录将如下所示:

Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ Several layout methods are provided, and themes can be freely defined through QS

# Build

Note: Requires C++17 standard support (due to the use of the frameless library, this library requires C++17 as a minimum), Qt version is at least above Qt5.14, otherwise it unable to compile frameless library. Recommend using Qt5.14 or above, as Qt5.14 improves support for high resolutions.
> Qmake and cmake will choose whether to load the frameless library based on the qt version, and will choose whether to use C++11 or C++17 based on different qt versions
> Note: Requires C++17 standard support (due to the use of the frameless library, this library requires C++17 as a minimum), Qt version is at least above Qt5.14, otherwise it unable to compile frameless library. Recommend using Qt5.14 or above, as Qt5.14 improves support for high resolutions.
Since the minimum C++ version is 17, you need to add the following in your qmake file:

Expand Down Expand Up @@ -82,6 +84,8 @@ Use qmake to compile, by following these steps:
- 4.Copy the `resource` folder and `3rdparty` folder under the source code `src/SARibbonBar` to the `SARibbonBar` folder under your project directory
- 5.Import the `SARibbon.pri` file in the pro file of your own project, such as: `include($$PWD/SARibbon.pri)`

Static use of SARibbon can refer to the example of StaticExample (located in `src/example/StaticExample`)

## Compile as Library (Dynamic)

Open `SARibbon.pro` directly using Qt Creator, and compile it. The SARibbonBar library and an example (there is only one example at present) will be compiled. The directories of lib and examples are located in `bin_Qt{Qt version}_{debug/release}_{32/64}` under directory.
Expand Down
Loading

0 comments on commit 7327d66

Please sign in to comment.