summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-09-09 14:16:26 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-09-09 19:20:49 +0000
commite87677ad4f2dec8c6e5991de1180016ddc937342 (patch)
tree1663d7acf10d5478203f5536db1f1c3336a9f993 /util
parent3215f5457a202a252be49a4ef41db501d7609cce (diff)
Try to detect if project given to pro2cmake is an example
If the project path starts with "examples/" relative to the repo source directory (which is decided by location of .qmake.conf), consider the given project file to be an example. This makes the usage of run_pro2cmake.py easier, specifically by being able to point it to a repo source directory, and getting most project conversions correctly. Change-Id: I93de98f8fc97af509c1f96cdebad3681190a53d1 Reviewed-by: Qt CMake Build Bot Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-xutil/cmake/pro2cmake.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index dbf58dc558..91e7f5f5f4 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -133,6 +133,18 @@ def is_top_level_repo_examples_project(project_file_path: str = '') -> bool:
return False
+def is_example_project(project_file_path: str = '') -> bool:
+ qmake_conf_path = find_qmake_conf(project_file_path)
+ qmake_conf_dir_path = os.path.dirname(qmake_conf_path)
+
+ project_relative_path = os.path.relpath(project_file_path, qmake_conf_dir_path)
+ # If the project file is found in a subdir called 'examples'
+ # relative to the repo source dir, then it must be an example.
+ if project_relative_path.startswith('examples'):
+ return True
+ return False
+
+
def find_qmake_conf(project_file_path: str = '') -> typing.Optional[str]:
if not os.path.isabs(project_file_path):
print('Warning: could not find .qmake.conf file, given path is not an absolute path: {}'
@@ -2437,7 +2449,10 @@ def generate_new_cmakelists(scope: Scope, *, is_example: bool=False) -> None:
assert scope.file
cm_fh.write('# Generated from {}.\n\n'
.format(os.path.basename(scope.file)))
- cmakeify_scope(scope, cm_fh, is_example=is_example)
+
+ is_example_heuristic = is_example_project(scope.file_absolute_path)
+ final_is_example_decision = is_example or is_example_heuristic
+ cmakeify_scope(scope, cm_fh, is_example=final_is_example_decision)
def do_include(scope: Scope, *, debug: bool = False) -> None: