CMake: Shorten ExternalProject example project paths

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 <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2021-12-14 15:53:15 +01:00
parent 209438c16a
commit 1a103beff6

View File

@ -863,9 +863,18 @@ function(qt_internal_add_example_external_project subdir)
cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${singleOpts}" "${multiOpts}") 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) if(NOT arg_NAME)
file(RELATIVE_PATH rel_path ${QT_EXAMPLE_BASE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}) set(arg_NAME "${subdir}")
string(REPLACE "/" "_" arg_NAME "${rel_path}") 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() endif()
if(QtBase_BINARY_DIR) if(QtBase_BINARY_DIR)
@ -975,7 +984,10 @@ function(qt_internal_add_example_external_project subdir)
ExternalProject_Add(${arg_NAME} ExternalProject_Add(${arg_NAME}
EXCLUDE_FROM_ALL TRUE 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 "" INSTALL_COMMAND ""
TEST_COMMAND "" TEST_COMMAND ""
DEPENDS ${deps} DEPENDS ${deps}