From f16a77d78342acba9df2195dd20c9e2ce06a61ff Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 15 May 2012 14:35:42 +0200 Subject: [PATCH] Use IF(NOT TARGET ...) before creating imported targets. Initially we didn't do this because someone could accidentally create another target of a conflicting name, and used a variable to store whether we have created the target already or not. That wasn't adequeate to deal with finding the package in a scope like a function, so we used a directory property. However, the directory property is not valid in the same scopes as the defined target. For example, finding a Qt module in both a directory and a subdirectory causes a conflict. As it is already unlikely that a target would be accidentally created with a name like Qt5::Core, we should simply use the IF(TARGET) form. Change-Id: If64f25d45f51edcd1edb0d4bfb5ed3bb2479bd27 Reviewed-by: David Faure --- mkspecs/cmake/Qt5BasicConfig.cmake.in | 4 +--- tests/auto/cmake/CMakeLists.txt | 1 + tests/auto/cmake/pass10/CMakeLists.txt | 9 +++++++++ tests/auto/cmake/pass10/subdir1/CMakeLists.txt | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 tests/auto/cmake/pass10/CMakeLists.txt create mode 100644 tests/auto/cmake/pass10/subdir1/CMakeLists.txt diff --git a/mkspecs/cmake/Qt5BasicConfig.cmake.in b/mkspecs/cmake/Qt5BasicConfig.cmake.in index a6e39b6e99..fa8a371bb9 100644 --- a/mkspecs/cmake/Qt5BasicConfig.cmake.in +++ b/mkspecs/cmake/Qt5BasicConfig.cmake.in @@ -109,9 +109,7 @@ list(APPEND _Qt5Gui_LIB_DEPENDENCIES ${JPEG_LIBRARIES}) !!ENDIF # Static -get_property(_qt5$${CMAKE_MODULE_NAME}TargetExists DIRECTORY PROPERTY _Qt5$${CMAKE_MODULE_NAME}_target) -if (NOT _qt5$${CMAKE_MODULE_NAME}TargetExists) - set_property(DIRECTORY PROPERTY _Qt5$${CMAKE_MODULE_NAME}_target TRUE) +if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME}) !!IF !isEmpty(CMAKE_STATIC_TYPE) add_library(Qt5::$${CMAKE_MODULE_NAME} STATIC IMPORTED) !!ELSE diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 64b2b8acec..40ceea1fc0 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -97,3 +97,4 @@ find_package(Qt5DBus QUIET) if (Qt5DBus_FOUND AND NOT APPLE) expect_pass(pass9) endif() +expect_pass(pass10) diff --git a/tests/auto/cmake/pass10/CMakeLists.txt b/tests/auto/cmake/pass10/CMakeLists.txt new file mode 100644 index 0000000000..bd7051a768 --- /dev/null +++ b/tests/auto/cmake/pass10/CMakeLists.txt @@ -0,0 +1,9 @@ + +cmake_minimum_required(VERSION 2.8) + +project(pass10) + +find_package(Qt5Core REQUIRED) + +add_subdirectory(subdir1) + diff --git a/tests/auto/cmake/pass10/subdir1/CMakeLists.txt b/tests/auto/cmake/pass10/subdir1/CMakeLists.txt new file mode 100644 index 0000000000..86c05f5de5 --- /dev/null +++ b/tests/auto/cmake/pass10/subdir1/CMakeLists.txt @@ -0,0 +1,2 @@ + +find_package(Qt5Core REQUIRED)