2022-12-24 10:11:33 -05:00
|
|
|
################################################################################
|
|
|
|
## Author: Shaun Reed ##
|
2025-07-05 13:38:47 -04:00
|
|
|
## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ##
|
2022-12-24 10:11:33 -05:00
|
|
|
## About: Example of making widget plugins for Qt Designer ##
|
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
|
|
|
|
project(
|
|
|
|
#[[NAME]] DesignerPlugin
|
|
|
|
VERSION 1.0
|
|
|
|
DESCRIPTION "Example of a widget plugin for Qt Designer"
|
|
|
|
LANGUAGES CXX
|
|
|
|
)
|
2025-07-05 13:38:47 -04:00
|
|
|
message(STATUS "[Klips] Configuring example: ${PROJECT_NAME}")
|
|
|
|
# Lowercase string to use as a slug for executable names for identification.
|
|
|
|
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
|
2022-12-24 10:11:33 -05:00
|
|
|
|
|
|
|
include(GenerateExportHeader)
|
|
|
|
|
|
|
|
add_compile_options(-Wall)
|
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
|
|
set(CMAKE_AUTORCC ON)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
set(CMAKE_SHARED_MODULE_PREFIX "")
|
|
|
|
|
|
|
|
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/" CACHE PATH "Path to Qt6")
|
|
|
|
# Qt Designer will look in different locations if WIN / Unix.
|
|
|
|
if (WIN32)
|
|
|
|
set(QT_PLUGIN_INSTALL_DIR
|
|
|
|
"${QT_DIR}/Tools/QtCreator/bin/plugins/designer"
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
set(QT_PLUGIN_INSTALL_DIR
|
|
|
|
"${QT_DIR}/Tools/QtCreator/lib/Qt/plugins/designer"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
# This should be set to your Qt6 installation directory.
|
|
|
|
set(QT_INSTALL_DIR "${QT_DIR}/6.3.1/gcc_64/" CACHE PATH "Path to Qt6 install")
|
|
|
|
list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}")
|
|
|
|
|
2025-07-05 13:38:47 -04:00
|
|
|
find_package(Qt6 COMPONENTS UiPlugin Core Gui Widgets)
|
|
|
|
if (NOT Qt6_FOUND)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"[Klips] Error: CMake was unable to find Qt6 libraries.\n"
|
|
|
|
"The example will not be built until the build is configured with these packages installed.\n"
|
|
|
|
"On Ubuntu 24.04 Qt6 can be installed using apt:\n"
|
|
|
|
" sudo apt-get install qt6-base-dev qt6-tools-dev\n"
|
|
|
|
)
|
|
|
|
endif()
|
2022-12-24 10:11:33 -05:00
|
|
|
|
|
|
|
# Creating the plugin
|
2025-07-05 13:38:47 -04:00
|
|
|
set(WIDGET_PLUGIN widget-plugin_${PROJECT_NAME_LOWER})
|
|
|
|
qt_add_library(${WIDGET_PLUGIN})
|
|
|
|
target_sources(${WIDGET_PLUGIN} PRIVATE
|
2022-12-24 10:11:33 -05:00
|
|
|
text-view.cpp text-view.h
|
|
|
|
widget-plugin.cpp widget-plugin.h
|
|
|
|
)
|
2025-07-05 13:38:47 -04:00
|
|
|
set_target_properties(${WIDGET_PLUGIN} PROPERTIES
|
2022-12-24 10:11:33 -05:00
|
|
|
WIN32_EXECUTABLE TRUE
|
|
|
|
MACOSX_BUNDLE TRUE
|
|
|
|
)
|
2025-07-05 13:38:47 -04:00
|
|
|
target_link_libraries(${WIDGET_PLUGIN} PUBLIC
|
2022-12-24 10:11:33 -05:00
|
|
|
Qt::UiPlugin Qt::Core Qt::Gui Qt::Widgets
|
|
|
|
)
|
|
|
|
|
2025-07-05 13:38:47 -04:00
|
|
|
install(TARGETS ${WIDGET_PLUGIN}
|
2022-12-24 10:11:33 -05:00
|
|
|
RUNTIME DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
|
|
|
|
BUNDLE DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
|
|
|
|
LIBRARY DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Application that will use the widget plugin
|
2025-07-05 13:38:47 -04:00
|
|
|
set(WIDGET_APP widget-app_${PROJECT_NAME_LOWER})
|
|
|
|
qt_add_executable(${WIDGET_APP}
|
2022-12-24 10:11:33 -05:00
|
|
|
widget-app.cpp widget-app.h widget-app.ui
|
|
|
|
main.cpp
|
|
|
|
)
|
2025-07-05 13:38:47 -04:00
|
|
|
target_link_libraries(${WIDGET_APP} PRIVATE
|
|
|
|
Qt::Widgets ${WIDGET_PLUGIN}
|
2022-12-24 10:11:33 -05:00
|
|
|
)
|