pro2cmake: Honor INSTALL_EXAMPLESDIR if defined

When building examples standalone, 'INSTALL_EXAMPLESDIR' may be
undefined.

The converted .pro files now check whether the variable is
set to prevent installation into unexpected locations.

Fixes: QTBUG-81797
Change-Id: I9f97568923c8103011a41d9af7cfe02dd1e40b56
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Christophe Giboudeaux 2020-02-06 11:32:48 +01:00
parent bf315c5526
commit 5dcaa11cc2

View File

@ -3287,8 +3287,8 @@ def write_example(
example_install_dir = scope.expandString("target.path")
if not example_install_dir:
example_install_dir = "examples"
example_install_dir = example_install_dir.replace("$$[QT_INSTALL_EXAMPLES]", "examples")
example_install_dir = "${INSTALL_EXAMPLESDIR}"
example_install_dir = example_install_dir.replace("$$[QT_INSTALL_EXAMPLES]", "${INSTALL_EXAMPLESDIR}")
cm_fh.write(
"cmake_minimum_required(VERSION 3.14)\n"
@ -3297,6 +3297,9 @@ def write_example(
"set(CMAKE_AUTOMOC ON)\n"
"set(CMAKE_AUTORCC ON)\n"
"set(CMAKE_AUTOUIC ON)\n\n"
"if(NOT DEFINED INSTALL_EXAMPLESDIR)\n"
" set(INSTALL_EXAMPLESDIR \"examples\")\n"
"endif()\n\n"
f'set(INSTALL_EXAMPLEDIR "{example_install_dir}")\n\n'
)