CMake: Fix metatype file generation not to happen in the source dir

When building qtdeclarative in a non-prefix configuration,
metatypes.json files were created in the source dir. This happened
because the default arg_INSTALL_DIR value is relative in
qt6_generate_meta_types_json_file, and thus a file(TOUCH) with a
relative path creats it in the source dir.

The fix is to check if it's relative during a non-prefix build,
and make it absolute (relative to the install prefix, which is the
qtbase build dir).

Change-Id: Ie9abbd5d93a64e79184d77655d8d8399e894fde5
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Alexandru Croitor 2020-03-20 10:03:59 +01:00
parent 1f442c684f
commit 16df037f9d

View File

@ -768,6 +768,13 @@ function(qt6_generate_meta_types_json_file target)
file(MAKE_DIRECTORY "${target_binary_dir}/meta_types")
file(TOUCH ${metatypes_file})
endif()
# Need to make the path absolute during a Qt non-prefix build, otherwise files are written
# to the source dir because the paths are relative to the source dir when using file(TOUCH).
if(arg_COPY_OVER_INSTALL AND NOT IS_ABSOLUTE "${arg_INSTALL_DIR}/${metatypes_file_name}")
set(arg_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${arg_INSTALL_DIR}")
endif()
if (arg_COPY_OVER_INSTALL AND NOT EXISTS ${arg_INSTALL_DIR}/${metatypes_file_name})
file(MAKE_DIRECTORY "${arg_INSTALL_DIR}")
file(TOUCH "${arg_INSTALL_DIR}/${metatypes_file_name}")