Skip to content

Commit 3a0280e

Browse files
committed
Simplify find_package function calls for Qt5 and Qt6
1 parent e3ef06d commit 3a0280e

File tree

4 files changed

+32
-40
lines changed

4 files changed

+32
-40
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*.pyc
22
CMakeLists.txt.user
33

4-
build/
4+
build*/
55
.vscode/
66

77
tags

CMakeLists.txt

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
cmake_minimum_required(VERSION 3.8)
22

3-
cmake_policy(SET CMP0072 NEW)
4-
cmake_policy(SET CMP0068 NEW)
3+
cmake_policy(SET CMP0072 NEW) # new in 3.11. The NEW behavior for this policy is to set OpenGL_GL_PREFERENCE to GLVND.
4+
cmake_policy(SET CMP0068 NEW) # new in 3.9. The NEW behavior of this policy is to ignore the RPATH settings for install_name on macOS.
5+
56

67
project(QtNodesLibrary CXX)
78

@@ -37,41 +38,26 @@ if(QT_NODES_DEVELOPER_DEFAULTS)
3738
endif()
3839

3940
if(BUILD_DEBUG_POSTFIX_D)
40-
set(CMAKE_DEBUG_POSTFIX d)
41+
set(CMAKE_DEBUG_POSTFIX "d")
42+
set(CMAKE_RELEASE_POSTFIX "")
43+
set(CMAKE_RELWITHDEBINFO_POSTFIX "rd")
44+
set(CMAKE_MINSIZEREL_POSTFIX "s")
4145
endif()
4246

4347
add_subdirectory(external)
4448

49+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
50+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Gui OpenGL)
51+
message(STATUS "QT_VERSION: ${QT_VERSION}, QT_DIR: ${QT_DIR}")
4552

46-
# Find the QtWidgets library
47-
find_package(Qt6 QUIET
48-
COMPONENTS
49-
Core
50-
Widgets
51-
Gui
52-
OpenGL
53-
)
54-
55-
if (NOT Qt6_FOUND)
56-
find_package(Qt5 QUIET
57-
COMPONENTS
58-
Core
59-
Widgets
60-
Gui
61-
OpenGL
62-
)
53+
if (${QT_VERSION} VERSION_LESS 5.11.0)
54+
message(FATAL_ERROR "Requires qt version >= 5.11.0, Your current version is ${QT_VERSION}")
6355
endif()
6456

65-
if (NOT (Qt6_FOUND OR Qt5_FOUND))
66-
message(FATAL_ERRROR "Qt libraries were not found.")
67-
endif()
68-
69-
if (Qt6_FOUND)
57+
if (${QT_VERSION_MAJOR} EQUAL 6)
7058
qt_add_resources(RESOURCES ./resources/resources.qrc)
71-
set(Qt Qt)
7259
else()
7360
qt5_add_resources(RESOURCES ./resources/resources.qrc)
74-
set(Qt Qt5)
7561
endif()
7662

7763
# Unfortunately, as we have a split include/src, AUTOMOC doesn't work.
@@ -165,10 +151,10 @@ target_include_directories(QtNodes
165151

166152
target_link_libraries(QtNodes
167153
PUBLIC
168-
${Qt}::Core
169-
${Qt}::Widgets
170-
${Qt}::Gui
171-
${Qt}::OpenGL
154+
Qt${QT_VERSION_MAJOR}::Core
155+
Qt${QT_VERSION_MAJOR}::Widgets
156+
Qt${QT_VERSION_MAJOR}::Gui
157+
Qt${QT_VERSION_MAJOR}::OpenGL
172158
)
173159

174160
target_compile_definitions(QtNodes
@@ -180,9 +166,10 @@ target_compile_definitions(QtNodes
180166
QT_NO_KEYWORDS
181167
)
182168

169+
183170
target_compile_options(QtNodes
184171
PRIVATE
185-
$<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4127 /EHsc>
172+
$<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4127 /EHsc /utf-8>
186173
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra>
187174
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Wextra -Werror>
188175
)
@@ -213,7 +200,7 @@ set_target_properties(QtNodes
213200

214201
file(GLOB_RECURSE HEADERS_TO_MOC include/QtNodes/internal/*.hpp)
215202

216-
if (Qt6_FOUND)
203+
if (${QT_VERSION_MAJOR} EQUAL 6)
217204
qt_wrap_cpp(nodes_moc
218205
${HEADERS_TO_MOC}
219206
TARGET QtNodes

cmake/QtNodesConfig.cmake.in

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ include(CMakeFindDependencyMacro)
44

55
# NOTE Had to use find_package because find_dependency does not support COMPONENTS or MODULE until 3.8.0
66

7-
find_package(Qt6 REQUIRED COMPONENTS
8-
Core
9-
Widgets
10-
Gui
11-
OpenGL)
7+
find_dependency(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
8+
find_dependency(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS
9+
Core
10+
Widgets
11+
Gui
12+
OpenGL)
1213

1314
if(NOT TARGET QtNodes::QtNodes)
1415
include("${QtNodes_CMAKE_DIR}/QtNodesTargets.cmake")

include/QtNodes/internal/Definitions.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include "Export.hpp"
44

@@ -13,7 +13,11 @@
1313

1414
namespace QtNodes
1515
{
16+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
17+
NODE_EDITOR_PUBLIC Q_NAMESPACE
18+
#else
1619
Q_NAMESPACE_EXPORT(NODE_EDITOR_PUBLIC)
20+
#endif
1721

1822
/**
1923
* Constants used for fetching QVariant data from GraphModel.

0 commit comments

Comments
 (0)