summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-10-27 12:07:51 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-10-27 19:26:45 +0100
commit638ac41293da9c6ae5e4ccb9baa7819c772ba9dd (patch)
tree0d0aa42f2fbbacc42b874d460c0e9a796a93c271 /examples
parentf65abc63441bf821c4e4619b842c74b6d5074cbd (diff)
CMake: Fix painting examples to build as standalone projects
The examples use an intermediate object library to avoid duplicate file compilation. The examples worked when built as part of Qt because the shared directory was always added, and Qt::OpenGL is available implicitly. Change each project to add_subdirectory(../shared) if the object library is not available, thus making the examples build as standalone projects. Call find_package inside the shared project, to ensure the Qt packages are found. Create an alias called 'painting_shared::painting_shared' and link against that to ensure that any failure is caught at configure time rather than build time. Adapt the pathstroke example to use the object library. Comment out the code for the OpenGL scopes, because it's handled by the object library. Make sure the OpenGL dependency is public. Make sure to run moc and compile the OpenGL specific files as well. Task-number: QTBUG-87444 Change-Id: Ib0ecb68948581c5267ca04f19d8043fa44ff3d54 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/widgets/painting/affine/CMakeLists.txt27
-rw-r--r--examples/widgets/painting/composition/CMakeLists.txt27
-rw-r--r--examples/widgets/painting/deform/CMakeLists.txt27
-rw-r--r--examples/widgets/painting/gradients/CMakeLists.txt27
-rw-r--r--examples/widgets/painting/pathstroke/.prev_CMakeLists.txt222
-rw-r--r--examples/widgets/painting/pathstroke/CMakeLists.txt35
-rw-r--r--examples/widgets/painting/shared/CMakeLists.txt18
7 files changed, 332 insertions, 51 deletions
diff --git a/examples/widgets/painting/affine/CMakeLists.txt b/examples/widgets/painting/affine/CMakeLists.txt
index c1ee72d15b..c3323693b8 100644
--- a/examples/widgets/painting/affine/CMakeLists.txt
+++ b/examples/widgets/painting/affine/CMakeLists.txt
@@ -37,11 +37,17 @@ target_include_directories(affine PUBLIC
../shared
)
+# special case begin
+if(NOT TARGET painting_shared::painting_shared)
+ add_subdirectory(../shared painting_shared)
+endif()
+# special case end
+
target_link_libraries(affine PUBLIC
Qt::Core
Qt::Gui
Qt::Widgets
- painting_shared # special case
+ painting_shared::painting_shared # special case
)
@@ -210,15 +216,18 @@ qt6_add_resources(affine "affine"
${affine_resource_files}
)
-if(QT_FEATURE_opengl)
- target_sources(affine PUBLIC
- ../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
- )
+# special case begin
+# remove files from ../shared
+#if(QT_FEATURE_opengl)
+ #target_sources(affine PUBLIC
+ #../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
+ #)
- target_link_libraries(affine PUBLIC
- Qt::OpenGL
- )
-endif()
+ #target_link_libraries(affine PUBLIC
+ #Qt::OpenGL
+ #)
+#endif()
+# special case end
install(TARGETS affine
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/widgets/painting/composition/CMakeLists.txt b/examples/widgets/painting/composition/CMakeLists.txt
index 6d12f8a899..8192439737 100644
--- a/examples/widgets/painting/composition/CMakeLists.txt
+++ b/examples/widgets/painting/composition/CMakeLists.txt
@@ -37,11 +37,17 @@ target_include_directories(composition PUBLIC
../shared
)
+# special case begin
+if(NOT TARGET painting_shared::painting_shared)
+ add_subdirectory(../shared painting_shared)
+endif()
+# special case end
+
target_link_libraries(composition PUBLIC
Qt::Core
Qt::Gui
Qt::Widgets
- painting_shared # special case
+ painting_shared::painting_shared # special case
)
@@ -211,15 +217,18 @@ qt6_add_resources(composition "composition"
${composition_resource_files}
)
-if(QT_FEATURE_opengl)
- target_sources(composition PUBLIC
- ../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
- )
+# special case begin
+# remove files from ../shared
+#if(QT_FEATURE_opengl)
+ #target_sources(affine PUBLIC
+ #../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
+ #)
- target_link_libraries(composition PUBLIC
- Qt::OpenGL
- )
-endif()
+ #target_link_libraries(affine PUBLIC
+ #Qt::OpenGL
+ #)
+#endif()
+# special case end
install(TARGETS composition
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/widgets/painting/deform/CMakeLists.txt b/examples/widgets/painting/deform/CMakeLists.txt
index 61b28f1b3a..c2517ac66f 100644
--- a/examples/widgets/painting/deform/CMakeLists.txt
+++ b/examples/widgets/painting/deform/CMakeLists.txt
@@ -37,11 +37,17 @@ target_include_directories(deform PUBLIC
../shared
)
+# special case begin
+if(NOT TARGET painting_shared::painting_shared)
+ add_subdirectory(../shared painting_shared)
+endif()
+# special case end
+
target_link_libraries(deform PUBLIC
Qt::Core
Qt::Gui
Qt::Widgets
- painting_shared # special case
+ painting_shared::painting_shared # special case
)
@@ -209,15 +215,18 @@ qt6_add_resources(deform "deform"
${deform_resource_files}
)
-if(QT_FEATURE_opengl)
- target_sources(deform PUBLIC
- ../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
- )
+# special case begin
+# remove files from ../shared
+#if(QT_FEATURE_opengl)
+ #target_sources(affine PUBLIC
+ #../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
+ #)
- target_link_libraries(deform PUBLIC
- Qt::OpenGL
- )
-endif()
+ #target_link_libraries(affine PUBLIC
+ #Qt::OpenGL
+ #)
+#endif()
+# special case end
install(TARGETS deform
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/widgets/painting/gradients/CMakeLists.txt b/examples/widgets/painting/gradients/CMakeLists.txt
index 0570ccfa37..6ad4dfa771 100644
--- a/examples/widgets/painting/gradients/CMakeLists.txt
+++ b/examples/widgets/painting/gradients/CMakeLists.txt
@@ -37,11 +37,17 @@ target_include_directories(gradients PUBLIC
../shared
)
+# special case begin
+if(NOT TARGET painting_shared::painting_shared)
+ add_subdirectory(../shared painting_shared)
+endif()
+# special case end
+
target_link_libraries(gradients PUBLIC
Qt::Core
Qt::Gui
Qt::Widgets
- painting_shared # special case
+ painting_shared::painting_shared # special case
)
@@ -209,15 +215,18 @@ qt6_add_resources(gradients "gradients"
${gradients_resource_files}
)
-if(QT_FEATURE_opengl)
- target_sources(gradients PUBLIC
- ../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
- )
+# special case begin
+# remove files from ../shared
+#if(QT_FEATURE_opengl)
+ #target_sources(affine PUBLIC
+ #../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
+ #)
- target_link_libraries(gradients PUBLIC
- Qt::OpenGL
- )
-endif()
+ #target_link_libraries(affine PUBLIC
+ #Qt::OpenGL
+ #)
+#endif()
+# special case end
install(TARGETS gradients
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/widgets/painting/pathstroke/.prev_CMakeLists.txt b/examples/widgets/painting/pathstroke/.prev_CMakeLists.txt
new file mode 100644
index 0000000000..22a6635164
--- /dev/null
+++ b/examples/widgets/painting/pathstroke/.prev_CMakeLists.txt
@@ -0,0 +1,222 @@
+# Generated from pathstroke.pro.
+
+cmake_minimum_required(VERSION 3.14)
+project(pathstroke LANGUAGES CXX)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+set(CMAKE_AUTOUIC ON)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/pathstroke")
+
+find_package(Qt6 COMPONENTS Core)
+find_package(Qt6 COMPONENTS Gui)
+find_package(Qt6 COMPONENTS Widgets)
+
+qt_add_executable(pathstroke
+ ../shared/arthurstyle.cpp ../shared/arthurstyle.h
+ ../shared/arthurwidgets.cpp ../shared/arthurwidgets.h
+ ../shared/hoverpoints.cpp ../shared/hoverpoints.h
+ main.cpp
+ pathstroke.cpp pathstroke.h
+)
+set_target_properties(pathstroke PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+target_include_directories(pathstroke PUBLIC
+ ../shared
+)
+
+target_link_libraries(pathstroke PUBLIC
+ Qt::Core
+ Qt::Gui
+ Qt::Widgets
+)
+
+
+# Resources:
+set_source_files_properties("../shared/images/button_normal_cap_left.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/button_normal_cap_left.png"
+)
+set_source_files_properties("../shared/images/button_normal_cap_right.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/button_normal_cap_right.png"
+)
+set_source_files_properties("../shared/images/button_normal_stretch.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/button_normal_stretch.png"
+)
+set_source_files_properties("../shared/images/button_pressed_cap_left.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/button_pressed_cap_left.png"
+)
+set_source_files_properties("../shared/images/button_pressed_cap_right.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/button_pressed_cap_right.png"
+)
+set_source_files_properties("../shared/images/button_pressed_stretch.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/button_pressed_stretch.png"
+)
+set_source_files_properties("../shared/images/frame_bottom.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/frame_bottom.png"
+)
+set_source_files_properties("../shared/images/frame_bottomleft.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/frame_bottomleft.png"
+)
+set_source_files_properties("../shared/images/frame_bottomright.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/frame_bottomright.png"
+)
+set_source_files_properties("../shared/images/frame_left.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/frame_left.png"
+)
+set_source_files_properties("../shared/images/frame_right.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/frame_right.png"
+)
+set_source_files_properties("../shared/images/frame_top.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/frame_top.png"
+)
+set_source_files_properties("../shared/images/frame_topleft.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/frame_topleft.png"
+)
+set_source_files_properties("../shared/images/frame_topright.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/frame_topright.png"
+)
+set_source_files_properties("../shared/images/groupframe_bottom_left.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/groupframe_bottom_left.png"
+)
+set_source_files_properties("../shared/images/groupframe_bottom_right.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/groupframe_bottom_right.png"
+)
+set_source_files_properties("../shared/images/groupframe_bottom_stretch.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/groupframe_bottom_stretch.png"
+)
+set_source_files_properties("../shared/images/groupframe_left_stretch.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/groupframe_left_stretch.png"
+)
+set_source_files_properties("../shared/images/groupframe_right_stretch.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/groupframe_right_stretch.png"
+)
+set_source_files_properties("../shared/images/groupframe_top_stretch.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/groupframe_top_stretch.png"
+)
+set_source_files_properties("../shared/images/groupframe_topleft.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/groupframe_topleft.png"
+)
+set_source_files_properties("../shared/images/groupframe_topright.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/groupframe_topright.png"
+)
+set_source_files_properties("../shared/images/line_dash_dot.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/line_dash_dot.png"
+)
+set_source_files_properties("../shared/images/line_dash_dot_dot.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/line_dash_dot_dot.png"
+)
+set_source_files_properties("../shared/images/line_dashed.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/line_dashed.png"
+)
+set_source_files_properties("../shared/images/line_dotted.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/line_dotted.png"
+)
+set_source_files_properties("../shared/images/line_solid.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/line_solid.png"
+)
+set_source_files_properties("../shared/images/radiobutton-on.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/radiobutton-on.png"
+)
+set_source_files_properties("../shared/images/radiobutton_off.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/radiobutton_off.png"
+)
+set_source_files_properties("../shared/images/radiobutton_on.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/radiobutton_on.png"
+)
+set_source_files_properties("../shared/images/slider_bar.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/slider_bar.png"
+)
+set_source_files_properties("../shared/images/slider_thumb_on.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/slider_thumb_on.png"
+)
+set_source_files_properties("../shared/images/title_cap_left.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/title_cap_left.png"
+)
+set_source_files_properties("../shared/images/title_cap_right.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/title_cap_right.png"
+)
+set_source_files_properties("../shared/images/title_stretch.png"
+ PROPERTIES QT_RESOURCE_ALIAS "images/title_stretch.png"
+)
+set(shared_resource_files
+ "images/button_normal_cap_left.png"
+ "images/button_normal_cap_right.png"
+ "images/button_normal_stretch.png"
+ "images/button_pressed_cap_left.png"
+ "images/button_pressed_cap_right.png"
+ "images/button_pressed_stretch.png"
+ "images/frame_bottom.png"
+ "images/frame_bottomleft.png"
+ "images/frame_bottomright.png"
+ "images/frame_left.png"
+ "images/frame_right.png"
+ "images/frame_top.png"
+ "images/frame_topleft.png"
+ "images/frame_topright.png"
+ "images/groupframe_bottom_left.png"
+ "images/groupframe_bottom_right.png"
+ "images/groupframe_bottom_stretch.png"
+ "images/groupframe_left_stretch.png"
+ "images/groupframe_right_stretch.png"
+ "images/groupframe_top_stretch.png"
+ "images/groupframe_topleft.png"
+ "images/groupframe_topright.png"
+ "images/line_dash_dot.png"
+ "images/line_dash_dot_dot.png"
+ "images/line_dashed.png"
+ "images/line_dotted.png"
+ "images/line_solid.png"
+ "images/radiobutton-on.png"
+ "images/radiobutton_off.png"
+ "images/radiobutton_on.png"
+ "images/slider_bar.png"
+ "images/slider_thumb_on.png"
+ "images/title_cap_left.png"
+ "images/title_cap_right.png"
+ "images/title_stretch.png"
+)
+
+qt6_add_resources(pathstroke "shared"
+ PREFIX
+ "/res"
+ BASE
+ "../shared"
+ FILES
+ ${shared_resource_files}
+)
+set(pathstroke_resource_files
+ "pathstroke.cpp"
+ "pathstroke.html"
+)
+
+qt6_add_resources(pathstroke "pathstroke"
+ PREFIX
+ "/res/pathstroke"
+ FILES
+ ${pathstroke_resource_files}
+)
+
+if(QT_FEATURE_opengl)
+ target_sources(pathstroke PUBLIC
+ ../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
+ )
+
+ target_link_libraries(pathstroke PUBLIC
+ Qt::OpenGL
+ )
+endif()
+
+install(TARGETS pathstroke
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/examples/widgets/painting/pathstroke/CMakeLists.txt b/examples/widgets/painting/pathstroke/CMakeLists.txt
index 22a6635164..17de61fede 100644
--- a/examples/widgets/painting/pathstroke/CMakeLists.txt
+++ b/examples/widgets/painting/pathstroke/CMakeLists.txt
@@ -20,9 +20,12 @@ find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Widgets)
qt_add_executable(pathstroke
- ../shared/arthurstyle.cpp ../shared/arthurstyle.h
- ../shared/arthurwidgets.cpp ../shared/arthurwidgets.h
- ../shared/hoverpoints.cpp ../shared/hoverpoints.h
+ # special case begin
+ # remove files from ../shared
+ #../shared/arthurstyle.cpp ../shared/arthurstyle.h
+ #../shared/arthurwidgets.cpp ../shared/arthurwidgets.h
+ #../shared/hoverpoints.cpp ../shared/hoverpoints.h
+ # special case end
main.cpp
pathstroke.cpp pathstroke.h
)
@@ -34,10 +37,17 @@ target_include_directories(pathstroke PUBLIC
../shared
)
+# special case begin
+if(NOT TARGET painting_shared::painting_shared)
+ add_subdirectory(../shared painting_shared)
+endif()
+# special case end
+
target_link_libraries(pathstroke PUBLIC
Qt::Core
Qt::Gui
Qt::Widgets
+ painting_shared::painting_shared # special case
)
@@ -205,15 +215,18 @@ qt6_add_resources(pathstroke "pathstroke"
${pathstroke_resource_files}
)
-if(QT_FEATURE_opengl)
- target_sources(pathstroke PUBLIC
- ../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
- )
+# special case begin
+# remove files from ../shared
+#if(QT_FEATURE_opengl)
+ #target_sources(affine PUBLIC
+ #../shared/fbopaintdevice.cpp ../shared/fbopaintdevice.h
+ #)
- target_link_libraries(pathstroke PUBLIC
- Qt::OpenGL
- )
-endif()
+ #target_link_libraries(affine PUBLIC
+ #Qt::OpenGL
+ #)
+#endif()
+# special case end
install(TARGETS pathstroke
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/widgets/painting/shared/CMakeLists.txt b/examples/widgets/painting/shared/CMakeLists.txt
index 4c7049e01d..9d43e4a980 100644
--- a/examples/widgets/painting/shared/CMakeLists.txt
+++ b/examples/widgets/painting/shared/CMakeLists.txt
@@ -1,7 +1,16 @@
-# special case: Entire file!
+# special case skip regeneration
+# Port of shared.pri to be included by painting examples
+
+if(NOT TARGET Qt::Widgets)
+ find_package(Qt6 REQUIRED COMPONENTS Widgets)
+endif()
+
+if(NOT TARGET Qt::OpenGL)
+ find_package(Qt6 OPTIONAL_COMPONENTS OpenGL)
+endif()
-# special case:
add_library(painting_shared OBJECT)
+add_library(painting_shared::painting_shared ALIAS painting_shared)
qt6_wrap_cpp(moc_files arthurwidgets.h hoverpoints.h) # no automoc for OBJECT libs:-/
target_sources(painting_shared PRIVATE
arthurstyle.cpp arthurstyle.h
@@ -17,8 +26,9 @@ target_include_directories(painting_shared PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
if (TARGET Qt::OpenGL OR QT_FEATURE_opengles2)
target_compile_definitions(painting_shared PRIVATE QT_OPENGL_SUPPORT)
- target_link_libraries(painting_shared PRIVATE
+ target_link_libraries(painting_shared PUBLIC
Qt::OpenGL
- Qt::Widgets
)
+ qt6_wrap_cpp(moc_files_gl fbopaintdevice.h) # no automoc for OBJECT libs
+ target_sources(painting_shared PRIVATE fbopaintdevice.cpp fbopaintdevice.h ${moc_files_gl})
endif()