From db25a067b0e1b5905e9cd3316df45f2be1b44594 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 17 May 2021 14:09:37 +0200 Subject: [PATCH] Fix build of standalone painting examples Since commit f5c69a51956 the examples/widgets/painting examples could not be built standalone anymore. Move the find_package calls out of the examples/widgets/painting/shared subdirectory and add a .cmake file that can be included to use the library conveniently. Change-Id: I35cb5bd8419a67c782d109104c4a88d64477a8be Reviewed-by: Alexandru Croitor --- examples/widgets/painting/affine/CMakeLists.txt | 2 +- .../widgets/painting/composition/CMakeLists.txt | 2 +- examples/widgets/painting/deform/CMakeLists.txt | 2 +- examples/widgets/painting/gradients/CMakeLists.txt | 2 +- examples/widgets/painting/pathstroke/CMakeLists.txt | 2 +- examples/widgets/painting/shared/CMakeLists.txt | 8 -------- examples/widgets/painting/shared/use_lib.cmake | 13 +++++++++++++ 7 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 examples/widgets/painting/shared/use_lib.cmake diff --git a/examples/widgets/painting/affine/CMakeLists.txt b/examples/widgets/painting/affine/CMakeLists.txt index c3323693b8f..cd264e6be4e 100644 --- a/examples/widgets/painting/affine/CMakeLists.txt +++ b/examples/widgets/painting/affine/CMakeLists.txt @@ -39,7 +39,7 @@ target_include_directories(affine PUBLIC # special case begin if(NOT TARGET painting_shared::painting_shared) - add_subdirectory(../shared painting_shared) + include(../shared/use_lib.cmake) endif() # special case end diff --git a/examples/widgets/painting/composition/CMakeLists.txt b/examples/widgets/painting/composition/CMakeLists.txt index 81924397374..f693d48569d 100644 --- a/examples/widgets/painting/composition/CMakeLists.txt +++ b/examples/widgets/painting/composition/CMakeLists.txt @@ -39,7 +39,7 @@ target_include_directories(composition PUBLIC # special case begin if(NOT TARGET painting_shared::painting_shared) - add_subdirectory(../shared painting_shared) + include(../shared/use_lib.cmake) endif() # special case end diff --git a/examples/widgets/painting/deform/CMakeLists.txt b/examples/widgets/painting/deform/CMakeLists.txt index c2517ac66f3..6b8a66d9a2f 100644 --- a/examples/widgets/painting/deform/CMakeLists.txt +++ b/examples/widgets/painting/deform/CMakeLists.txt @@ -39,7 +39,7 @@ target_include_directories(deform PUBLIC # special case begin if(NOT TARGET painting_shared::painting_shared) - add_subdirectory(../shared painting_shared) + include(../shared/use_lib.cmake) endif() # special case end diff --git a/examples/widgets/painting/gradients/CMakeLists.txt b/examples/widgets/painting/gradients/CMakeLists.txt index 6ad4dfa771d..78d659ee847 100644 --- a/examples/widgets/painting/gradients/CMakeLists.txt +++ b/examples/widgets/painting/gradients/CMakeLists.txt @@ -39,7 +39,7 @@ target_include_directories(gradients PUBLIC # special case begin if(NOT TARGET painting_shared::painting_shared) - add_subdirectory(../shared painting_shared) + include(../shared/use_lib.cmake) endif() # special case end diff --git a/examples/widgets/painting/pathstroke/CMakeLists.txt b/examples/widgets/painting/pathstroke/CMakeLists.txt index 17de61fedeb..feb33328973 100644 --- a/examples/widgets/painting/pathstroke/CMakeLists.txt +++ b/examples/widgets/painting/pathstroke/CMakeLists.txt @@ -39,7 +39,7 @@ target_include_directories(pathstroke PUBLIC # special case begin if(NOT TARGET painting_shared::painting_shared) - add_subdirectory(../shared painting_shared) + include(../shared/use_lib.cmake) endif() # special case end diff --git a/examples/widgets/painting/shared/CMakeLists.txt b/examples/widgets/painting/shared/CMakeLists.txt index 9d43e4a980d..0fc65d3d99c 100644 --- a/examples/widgets/painting/shared/CMakeLists.txt +++ b/examples/widgets/painting/shared/CMakeLists.txt @@ -1,14 +1,6 @@ # 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() - 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:-/ diff --git a/examples/widgets/painting/shared/use_lib.cmake b/examples/widgets/painting/shared/use_lib.cmake new file mode 100644 index 00000000000..11e9c2cf710 --- /dev/null +++ b/examples/widgets/painting/shared/use_lib.cmake @@ -0,0 +1,13 @@ +# Include this file in your example project to use the library defined in this directory. +# This avoids find_package calls in a directory scope different from the directory scope of the +# consuming target. + +if(NOT TARGET Qt::Widgets) + find_package(Qt6 REQUIRED COMPONENTS Widgets) +endif() + +if(NOT TARGET Qt::OpenGL) + find_package(Qt6 OPTIONAL_COMPONENTS OpenGL) +endif() + +add_subdirectory("${CMAKE_CURRENT_LIST_DIR}" painting_shared)