[cpp] Fix root project build and dependencies.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
################################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ##
|
||||
## About: Example of making widget plugins for Qt Designer ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
@@ -14,6 +14,9 @@ project(
|
||||
DESCRIPTION "Example of a widget plugin for Qt Designer"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
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)
|
||||
|
||||
include(GenerateExportHeader)
|
||||
|
||||
@@ -42,35 +45,44 @@ endif()
|
||||
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}")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS UiPlugin Core Gui Widgets)
|
||||
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()
|
||||
|
||||
# Creating the plugin
|
||||
|
||||
qt_add_library(widget-plugin)
|
||||
target_sources(widget-plugin PRIVATE
|
||||
set(WIDGET_PLUGIN widget-plugin_${PROJECT_NAME_LOWER})
|
||||
qt_add_library(${WIDGET_PLUGIN})
|
||||
target_sources(${WIDGET_PLUGIN} PRIVATE
|
||||
text-view.cpp text-view.h
|
||||
widget-plugin.cpp widget-plugin.h
|
||||
)
|
||||
set_target_properties(widget-plugin PROPERTIES
|
||||
set_target_properties(${WIDGET_PLUGIN} PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
target_link_libraries(widget-plugin PUBLIC
|
||||
target_link_libraries(${WIDGET_PLUGIN} PUBLIC
|
||||
Qt::UiPlugin Qt::Core Qt::Gui Qt::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS widget-plugin
|
||||
install(TARGETS ${WIDGET_PLUGIN}
|
||||
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
|
||||
|
||||
qt_add_executable(widget-app
|
||||
set(WIDGET_APP widget-app_${PROJECT_NAME_LOWER})
|
||||
qt_add_executable(${WIDGET_APP}
|
||||
widget-app.cpp widget-app.h widget-app.ui
|
||||
main.cpp
|
||||
)
|
||||
target_link_libraries(widget-app PRIVATE
|
||||
Qt::Widgets widget-plugin
|
||||
target_link_libraries(${WIDGET_APP} PRIVATE
|
||||
Qt::Widgets ${WIDGET_PLUGIN}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user