summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2019-08-08 09:52:36 +0200
committerLeander Beernaert <leander.beernaert@qt.io>2019-08-08 08:07:11 +0000
commit6396840182dd80518493c66fe025a4f032954dbd (patch)
tree79da1e2ec98be0cb341b606de98102f0b91ad88f
parentd8a7c0f40fff382fb4dbe6088b6f86ca4f4d03f5 (diff)
Fix conversion of SUBDIR pro files not in current directory
This patch fixes the processing of pro files that do not reside in the current directory. Before this patch statements such as SUBDIRS += Foo/Bar/z.pro would cause z.pro to be parsed in the current CMakeLists.txt. What we want instead is a call to add_subdirectory(Foo/Bar). Failing to do so leads to issues with relative paths specified in z.pro being invalid. Change-Id: I7bfa7837d54877e5340081d1c9aebe855cf6796d Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rwxr-xr-xutil/cmake/pro2cmake.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index c9fd604b2e..3ebb6c7e1c 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -1091,14 +1091,22 @@ def handle_subdir(scope: Scope,
collect_subdir_info(sd, current_conditions=current_conditions)
# For the file case, directly write into the file handle.
elif os.path.isfile(sd):
- subdir_result = parseProFile(sd, debug=False)
- subdir_scope \
- = Scope.FromDict(scope, sd,
- subdir_result.asDict().get('statements'),
- '', scope.basedir)
-
- do_include(subdir_scope)
- cmakeify_scope(subdir_scope, cm_fh, indent=indent, is_example=is_example)
+ # Handle cases with SUBDIRS += Foo/bar/z.pro. We want to be able
+ # to generate add_subdirectory(Foo/bar) instead of parsing the full
+ # .pro file in the current CMakeLists.txt. This causes issues
+ # with relative paths in certain projects otherwise.
+ dirname = os.path.dirname(sd)
+ if dirname:
+ collect_subdir_info(dirname, current_conditions=current_conditions)
+ else:
+ subdir_result = parseProFile(sd, debug=False)
+ subdir_scope \
+ = Scope.FromDict(scope, sd,
+ subdir_result.asDict().get('statements'),
+ '', scope.basedir)
+
+ do_include(subdir_scope)
+ cmakeify_scope(subdir_scope, cm_fh, indent=indent, is_example=is_example)
else:
print(' XXXX: SUBDIR {} in {}: Not found.'.format(sd, scope))