Skip to content

Commit

Permalink
Qt6 support in CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
YakoYakoYokuYoku committed Dec 19, 2024
1 parent c3df901 commit 1b035ab
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 32 deletions.
56 changes: 41 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ project(Natron

set(CMAKE_CXX_STANDARD 17)

include(GNUInstallDirs)

option(NATRON_QT6 "use Qt6" OFF)
option(NATRON_SYSTEM_LIBS "use system versions of dependencies instead of bundled ones" OFF)
option(NATRON_BUILD_TESTS "build the Natron test suite" ON)

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

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

if(IS_DEBUG_BUILD AND WIN32)
# Remove NDEBUG from Shiboken2 INTERFACE_COMPILE_DEFINITIONS so it is not inherited in debug builds.
get_property(ShibokenInterfaceDefs TARGET Shiboken2::libshiboken PROPERTY INTERFACE_COMPILE_DEFINITIONS)
list(REMOVE_ITEM ShibokenInterfaceDefs NDEBUG)
set_property(TARGET Shiboken2::libshiboken PROPERTY INTERFACE_COMPILE_DEFINITIONS ShibokenInterfaceDefs)
set(QT_COMPONENTS Core Gui Network Widgets Concurrent)
if(NATRON_QT6)
list(APPEND QT_COMPONENTS OpenGLWidgets)
find_package(Qt6 6.3 CONFIG REQUIRED COMPONENTS ${QT_COMPONENTS})
find_package(Shiboken6 6.3 CONFIG REQUIRED COMPONENTS libshiboken6)
find_package(Shiboken6Tools 6.3 CONFIG REQUIRED COMPONENTS shiboken6)
find_package(PySide6 6.3 CONFIG REQUIRED COMPONENTS pyside6)
set(QT_VERSION_MAJOR 6)

get_target_property(PYSIDE_INCLUDE_DIRS PySide6::pyside6 INTERFACE_INCLUDE_DIRECTORIES)
set(QTCORE_INCLUDE_DIRS ${Qt6Core_INCLUDE_DIRS})
set(QTGUI_INCLUDE_DIRS ${Qt6Gui_INCLUDE_DIRS})
set(QTWIDGETS_INCLUDE_DIRS ${Qt6Widgets_INCLUDE_DIRS})

set(SHIBOKEN_EXE Shiboken6::shiboken6)
set(SHIBOKEN_LIB Shiboken6::libshiboken)
set(PYSIDE_LIB PySide6::pyside6)
else()
find_package(Qt5 5.15 CONFIG REQUIRED COMPONENTS ${QT_COMPONENTS})
find_package(Shiboken2 5.15 CONFIG REQUIRED COMPONENTS libshiboken2 shiboken2)

find_package(PySide2 5.15 CONFIG REQUIRED COMPONENTS pyside2)
set(QT_VERSION_MAJOR 5)

get_target_property(PYSIDE_INCLUDE_DIRS PySide2::pyside2 INTERFACE_INCLUDE_DIRECTORIES)
set(QTCORE_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS})
set(QTGUI_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS})
set(QTWIDGETS_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIRS})

set(SHIBOKEN_EXE Shiboken2::shiboken2)
set(SHIBOKEN_LIB Shiboken2::libshiboken)
set(PYSIDE_LIB PySide2::pyside2)
endif()

find_package(PySide2 5.15 CONFIG REQUIRED COMPONENTS pyside2)
set(QT_VERSION_MAJOR 5)
get_target_property(PYSIDE_INCLUDE_DIRS PySide2::pyside2 INTERFACE_INCLUDE_DIRECTORIES)
set(QTCORE_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS})
set(QTGUI_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS})
set(QTWIDGETS_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIRS})
if(IS_DEBUG_BUILD AND WIN32)
# Remove NDEBUG from Shiboken INTERFACE_COMPILE_DEFINITIONS so it is not inherited in debug builds.
get_property(SHIBOKEN_DEFS TARGET ${SHIBOKEN_LIB} PROPERTY INTERFACE_COMPILE_DEFINITIONS)
list(REMOVE_ITEM SHIBOKEN_DEFS NDEBUG)
set_property(TARGET ${SHIBOKEN_LIB} PROPERTY INTERFACE_COMPILE_DEFINITIONS SHIBOKEN_DEFS)
endif()

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

include(GNUInstallDirs)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

Expand Down
11 changes: 6 additions & 5 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ target_link_libraries(NatronEngine
Boost::serialization
PkgConfig::Cairo
PRIVATE
Shiboken2::libshiboken
PySide2::pyside2
Qt5::Core
Qt5::Concurrent
Qt5::Network
${SHIBOKEN_LIB}
${PYSIDE_LIB}
Qt::Core
Qt::Concurrent
Qt::Network
Python3::Module
${XDG_LIBS}
ceres
Expand Down Expand Up @@ -109,5 +109,6 @@ target_compile_definitions(NatronEngine
PRIVATE
NATRON_CUSTOM_BUILD_USER_TOKEN="${BUILD_USER_NAME}"
NATRON_BUILD_NUMBER=0
QT_NO_KEYWORDS
${XDG_DEFS}
)
19 changes: 12 additions & 7 deletions Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ list(TRANSFORM PYGUI_INCLUDE_DIRS PREPEND "-I" OUTPUT_VARIABLE PYGUI_INCS)
set(PYGUI_HEADER PySide2_Gui_Python.h)
set(POST_SHIBOKEN ../tools/utils/runPostShiboken2.sh)

if(NATRON_QT6)
set(QT_OPENGLWIDGETS Qt::OpenGLWidgets)
endif()

set(shiboken_args
"-std=c++17" "--enable-parent-ctor-heuristic" "--use-isnull-as-nb_nonzero"
"--avoid-protected-hack" "--enable-pyside-extensions"
Expand Down Expand Up @@ -60,13 +64,14 @@ list(APPEND NatronGui_SOURCES
add_library(NatronGui STATIC ${NatronGui_HEADERS} ${NatronGui_SOURCES})
target_link_libraries(NatronGui
PUBLIC
Shiboken2::libshiboken
PySide2::pyside2
Qt5::Core
Qt5::Concurrent
Qt5::Network
Qt5::Gui
Qt5::Widgets
${SHIBOKEN_LIB}
${PYSIDE_LIB}
Qt::Core
Qt::Concurrent
Qt::Network
Qt::Gui
Qt::Widgets
${QT_OPENGLWIDGETS}
Python3::Module
NatronEngine
PRIVATE
Expand Down
6 changes: 3 additions & 3 deletions Renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ add_executable(NatronRenderer ${NatronRenderer_SOURCES})
target_link_libraries(NatronRenderer
PRIVATE
NatronEngine
Qt5::Core
Qt5::Concurrent
Qt5::Network
Qt::Core
Qt::Concurrent
Qt::Network
Python3::Python
)
target_include_directories(NatronRenderer
Expand Down
2 changes: 1 addition & 1 deletion Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ add_executable(Tests ${Tests_HEADERS} ${Tests_SOURCES})
target_link_libraries(Tests
PRIVATE
NatronEngine
Qt5::Core
Qt::Core
Python3::Python
openMVG
)
Expand Down
2 changes: 1 addition & 1 deletion libs/qhttpserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ set(qhttpserver_HEADERS
file(GLOB qhttpserver_SOURCES src/*.cpp)
set(qhttpserver_SOURCES ${qhttpserver_SOURCES} http-parser/http_parser.c)
add_library(qhttpserver STATIC ${qhttpserver_HEADERS} ${qhttpserver_SOURCES})
target_link_libraries(qhttpserver PRIVATE Qt5::Core Qt5::Network)
target_link_libraries(qhttpserver PRIVATE Qt::Core Qt::Network)
target_include_directories(qhttpserver PRIVATE http-parser)
set_target_properties(qhttpserver PROPERTIES POSITION_INDEPENDENT_CODE ON)

0 comments on commit 1b035ab

Please sign in to comment.