Skip to content

Commit 24fc376

Browse files
Qt6 support in CMake
1 parent 4d6a900 commit 24fc376

File tree

6 files changed

+64
-32
lines changed

6 files changed

+64
-32
lines changed

CMakeLists.txt

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ project(Natron
2828

2929
set(CMAKE_CXX_STANDARD 17)
3030

31+
include(GNUInstallDirs)
32+
33+
option(NATRON_QT6 "use Qt6" OFF)
3134
option(NATRON_SYSTEM_LIBS "use system versions of dependencies instead of bundled ones" OFF)
3235
option(NATRON_BUILD_TESTS "build the Natron test suite" ON)
3336

@@ -55,28 +58,53 @@ if(WIN32)
5558
set(Python3_FIND_REGISTRY NEVER)
5659
endif()
5760
find_package(Python3 COMPONENTS Interpreter Development)
58-
find_package(Qt5 5.15 CONFIG REQUIRED COMPONENTS Core Gui Network Widgets Concurrent)
5961

6062
if(IS_DEBUG_BUILD AND WIN32)
6163
# Explicitly setting SHIBOKEN_PYTHON_LIBRARIES variable to avoid PYTHON_DEBUG_LIBRARY-NOTFOUND
6264
# link errors on Windows debug builds.
6365
set(SHIBOKEN_PYTHON_LIBRARIES ${Python3_LIBRARIES})
6466
endif()
65-
find_package(Shiboken2 5.15 CONFIG REQUIRED COMPONENTS libshiboken2 shiboken2)
6667

67-
if(IS_DEBUG_BUILD AND WIN32)
68-
# Remove NDEBUG from Shiboken2 INTERFACE_COMPILE_DEFINITIONS so it is not inherited in debug builds.
69-
get_property(ShibokenInterfaceDefs TARGET Shiboken2::libshiboken PROPERTY INTERFACE_COMPILE_DEFINITIONS)
70-
list(REMOVE_ITEM ShibokenInterfaceDefs NDEBUG)
71-
set_property(TARGET Shiboken2::libshiboken PROPERTY INTERFACE_COMPILE_DEFINITIONS ShibokenInterfaceDefs)
68+
set(QT_COMPONENTS Core Gui Network Widgets Concurrent)
69+
if(NATRON_QT6)
70+
list(APPEND QT_COMPONENTS OpenGLWidgets)
71+
find_package(Qt6 6.3 CONFIG REQUIRED COMPONENTS ${QT_COMPONENTS})
72+
find_package(Shiboken6 6.3 CONFIG REQUIRED COMPONENTS libshiboken6)
73+
find_package(Shiboken6Tools 6.3 CONFIG REQUIRED COMPONENTS shiboken6)
74+
find_package(PySide6 6.3 CONFIG REQUIRED COMPONENTS pyside6)
75+
set(QT_VERSION_MAJOR 6)
76+
77+
get_target_property(PYSIDE_INCLUDE_DIRS PySide6::pyside6 INTERFACE_INCLUDE_DIRECTORIES)
78+
set(QTCORE_INCLUDE_DIRS ${Qt6Core_INCLUDE_DIRS})
79+
set(QTGUI_INCLUDE_DIRS ${Qt6Gui_INCLUDE_DIRS})
80+
set(QTWIDGETS_INCLUDE_DIRS ${Qt6Widgets_INCLUDE_DIRS})
81+
82+
set(SHIBOKEN_EXE Shiboken6::shiboken6)
83+
set(SHIBOKEN_LIB Shiboken6::libshiboken)
84+
set(PYSIDE_LIB PySide6::pyside6)
85+
else()
86+
find_package(Qt5 5.15 CONFIG REQUIRED COMPONENTS ${QT_COMPONENTS})
87+
find_package(Shiboken2 5.15 CONFIG REQUIRED COMPONENTS libshiboken2 shiboken2)
88+
89+
find_package(PySide2 5.15 CONFIG REQUIRED COMPONENTS pyside2)
90+
set(QT_VERSION_MAJOR 5)
91+
92+
get_target_property(PYSIDE_INCLUDE_DIRS PySide2::pyside2 INTERFACE_INCLUDE_DIRECTORIES)
93+
set(QTCORE_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS})
94+
set(QTGUI_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS})
95+
set(QTWIDGETS_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIRS})
96+
97+
set(SHIBOKEN_EXE Shiboken2::shiboken2)
98+
set(SHIBOKEN_LIB Shiboken2::libshiboken)
99+
set(PYSIDE_LIB PySide2::pyside2)
72100
endif()
73101

74-
find_package(PySide2 5.15 CONFIG REQUIRED COMPONENTS pyside2)
75-
set(QT_VERSION_MAJOR 5)
76-
get_target_property(PYSIDE_INCLUDE_DIRS PySide2::pyside2 INTERFACE_INCLUDE_DIRECTORIES)
77-
set(QTCORE_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS})
78-
set(QTGUI_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS})
79-
set(QTWIDGETS_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIRS})
102+
if(IS_DEBUG_BUILD AND WIN32)
103+
# Remove NDEBUG from Shiboken INTERFACE_COMPILE_DEFINITIONS so it is not inherited in debug builds.
104+
get_property(SHIBOKEN_DEFS TARGET ${SHIBOKEN_LIB} PROPERTY INTERFACE_COMPILE_DEFINITIONS)
105+
list(REMOVE_ITEM SHIBOKEN_DEFS NDEBUG)
106+
set_property(TARGET ${SHIBOKEN_LIB} PROPERTY INTERFACE_COMPILE_DEFINITIONS SHIBOKEN_DEFS)
107+
endif()
80108

81109
#Since in Natron and OpenFX all strings are supposed UTF-8 and that the constructor
82110
#for QString(const char*) assumes ASCII strings, we may run into troubles
@@ -119,8 +147,6 @@ elseif(WIN32)
119147
endif()
120148
endif()
121149

122-
include(GNUInstallDirs)
123-
124150
set(CMAKE_AUTOMOC ON)
125151
set(CMAKE_AUTORCC ON)
126152

Engine/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ target_link_libraries(NatronEngine
7575
Boost::serialization
7676
PkgConfig::Cairo
7777
PRIVATE
78-
Shiboken2::libshiboken
79-
PySide2::pyside2
80-
Qt5::Core
81-
Qt5::Concurrent
82-
Qt5::Network
78+
${SHIBOKEN_LIB}
79+
${PYSIDE_LIB}
80+
Qt::Core
81+
Qt::Concurrent
82+
Qt::Network
8383
Python3::Module
8484
${XDG_LIBS}
8585
ceres
@@ -109,5 +109,6 @@ target_compile_definitions(NatronEngine
109109
PRIVATE
110110
NATRON_CUSTOM_BUILD_USER_TOKEN="${BUILD_USER_NAME}"
111111
NATRON_BUILD_NUMBER=0
112+
QT_NO_KEYWORDS
112113
${XDG_DEFS}
113114
)

Gui/CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ list(TRANSFORM PYGUI_INCLUDE_DIRS PREPEND "-I" OUTPUT_VARIABLE PYGUI_INCS)
3131
set(PYGUI_HEADER PySide2_Gui_Python.h)
3232
set(POST_SHIBOKEN ../tools/utils/runPostShiboken2.sh)
3333

34+
if(NATRON_QT6)
35+
set(QT_OPENGLWIDGETS Qt::OpenGLWidgets)
36+
endif()
37+
3438
set(shiboken_args
3539
"-std=c++17" "--enable-parent-ctor-heuristic" "--use-isnull-as-nb_nonzero"
3640
"--avoid-protected-hack" "--enable-pyside-extensions"
@@ -60,13 +64,14 @@ list(APPEND NatronGui_SOURCES
6064
add_library(NatronGui STATIC ${NatronGui_HEADERS} ${NatronGui_SOURCES})
6165
target_link_libraries(NatronGui
6266
PUBLIC
63-
Shiboken2::libshiboken
64-
PySide2::pyside2
65-
Qt5::Core
66-
Qt5::Concurrent
67-
Qt5::Network
68-
Qt5::Gui
69-
Qt5::Widgets
67+
${SHIBOKEN_LIB}
68+
${PYSIDE_LIB}
69+
Qt::Core
70+
Qt::Concurrent
71+
Qt::Network
72+
Qt::Gui
73+
Qt::Widgets
74+
${QT_OPENGLWIDGETS}
7075
Python3::Module
7176
NatronEngine
7277
PRIVATE

Renderer/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ add_executable(NatronRenderer ${NatronRenderer_SOURCES})
2525
target_link_libraries(NatronRenderer
2626
PRIVATE
2727
NatronEngine
28-
Qt5::Core
29-
Qt5::Concurrent
30-
Qt5::Network
28+
Qt::Core
29+
Qt::Concurrent
30+
Qt::Network
3131
Python3::Python
3232
)
3333
target_include_directories(NatronRenderer

Tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ add_executable(Tests ${Tests_HEADERS} ${Tests_SOURCES})
3636
target_link_libraries(Tests
3737
PRIVATE
3838
NatronEngine
39-
Qt5::Core
39+
Qt::Core
4040
Python3::Python
4141
openMVG
4242
)

libs/qhttpserver/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ set(qhttpserver_HEADERS
2929
file(GLOB qhttpserver_SOURCES src/*.cpp)
3030
set(qhttpserver_SOURCES ${qhttpserver_SOURCES} http-parser/http_parser.c)
3131
add_library(qhttpserver STATIC ${qhttpserver_HEADERS} ${qhttpserver_SOURCES})
32-
target_link_libraries(qhttpserver PRIVATE Qt5::Core Qt5::Network)
32+
target_link_libraries(qhttpserver PRIVATE Qt::Core Qt::Network)
3333
target_include_directories(qhttpserver PRIVATE http-parser)
3434
set_target_properties(qhttpserver PROPERTIES POSITION_INDEPENDENT_CODE ON)

0 commit comments

Comments
 (0)