From 1a103beff61542c5149c3876a7bb0885ec989c0a Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 14 Dec 2021 15:53:15 +0100 Subject: [PATCH] CMake: Shorten ExternalProject example project paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of nesting the external project build dir under the current binary dir, place the EP build dir where it would usually be when we use add_subdirectory. Shorten the name of the external project to just ${subdir} instead of using the relative current binary dir path. Place the EP prefix and stamp dirs under a new ${subdir}-ep folder next to the example build dir. Overall this places example executables where you'd usually expect them to be, as well as shortens a bunch of build paths to circumvent path limit issues when building on Windows. Pick-to: 6.2 6.3 Fixes: QTBUG-94608 Task-number: QTBUG-96232 Change-Id: Ifb921c5a6397385e8a914111bf56ee59cda003fd Reviewed-by: Jörg Bornemann Reviewed-by: Alexey Edelev --- .../QtBuildInternalsConfig.cmake | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index 08302572b17..fe6c0c7f7ba 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -863,9 +863,18 @@ function(qt_internal_add_example_external_project subdir) cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${singleOpts}" "${multiOpts}") + file(RELATIVE_PATH example_rel_path + "${QT_EXAMPLE_BASE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${subdir}") + if(NOT arg_NAME) - file(RELATIVE_PATH rel_path ${QT_EXAMPLE_BASE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}) - string(REPLACE "/" "_" arg_NAME "${rel_path}") + set(arg_NAME "${subdir}") + endif() + + # Likely a clash with an example subdir ExternalProject custom target of the same name. + if(TARGET "${arg_NAME}") + string(SHA1 rel_path_hash "${example_rel_path}") + string(SUBSTRING "${rel_path_hash}" 0 4 short_hash) + set(arg_NAME "${arg_NAME}-${short_hash}") endif() if(QtBase_BINARY_DIR) @@ -975,7 +984,10 @@ function(qt_internal_add_example_external_project subdir) ExternalProject_Add(${arg_NAME} EXCLUDE_FROM_ALL TRUE - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${subdir} + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${subdir}" + PREFIX "${CMAKE_CURRENT_BINARY_DIR}/${subdir}-ep" + STAMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/${subdir}-ep/stamp" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${subdir}" INSTALL_COMMAND "" TEST_COMMAND "" DEPENDS ${deps}