CMake: pro2cmake: Handle $$PWD in included .pri files correct-ish

Previously the $$PWD was evaluated within the including .pro file,
which generated incorrect relative paths to source files.

Now we use a horrible hack to evaluate keys ending with SOURCES
and HEADERS. If such is a case, use a map_file transformer which
will use the included scope, thus creating correct relative paths.

Fixes projects in qtdeclarative like src/qmltypregistrar and qmllint.

Checked that it doesn't break projects in qtdeclarative and qtbase.

Change-Id: I21f1e4c638c2cf8d0f67e94e1a583ebc54c175a2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Alexandru Croitor 2020-04-08 18:34:00 +02:00
parent 0651a4c274
commit 0a13c3a3f0

View File

@ -1285,7 +1285,18 @@ class Scope(object):
else:
return [f"${{CMAKE_CURRENT_BINARY_DIR}}/{relative_path}"]
return self._evalOps(key, None, [], inherit=inherit)
# Horrible hack. If we're returning the values for some key
# that looks like source or header files, make sure to use a
# map_files transformer, so that $$PWD values are evaluated
# in the transformer scope, otherwise relative paths will be
# broken.
# Looking at you qmltyperegistrar.pro.
eval_ops_transformer = None
if key.endswith("SOURCES") or key.endswith("HEADERS"):
def file_transformer(scope, files):
return scope._map_files(files)
eval_ops_transformer = file_transformer
return self._evalOps(key, eval_ops_transformer, [], inherit=inherit)
def get_string(self, key: str, default: str = "", inherit: bool = False) -> str:
v = self.get(key, inherit=inherit)