diff options
author | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2019-10-04 17:02:53 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2019-10-07 08:58:37 +0000 |
commit | ed35e1ac845cfa1e4f3e46983f0d4c39d9ea0a4f (patch) | |
tree | 393ed84e88cf7c589b4053cff78d5b761f21a7ae /util/cmake | |
parent | 123ef6c391209b84a245abb536117b1f6a04a860 (diff) |
CMake: clean up target.path and DESTDIR replacements
Change-Id: I0891008cff939aa98b39a28a23710add0781901e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'util/cmake')
-rwxr-xr-x | util/cmake/pro2cmake.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index d32014a8c5..91b60f710d 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -1592,6 +1592,24 @@ def map_condition(condition: str) -> str: return cmake_condition.strip() +_path_replacements = { + "$$[QT_INSTALL_PREFIX]": "${INSTALL_DIRECTORY}", + "$$[QT_INSTALL_EXAMPLES]": "${INSTALL_EXAMPLESDIR}", + "$$[QT_INSTALL_TESTS]": "${INSTALL_TESTSDIR}", + } + +def replace_path_constants(path: str, scope: Scope) -> str: + """ Clean up DESTDIR and target.path """ + if path.startswith("./"): + path = f"${{CMAKE_CURRENT_BINARY_DIR}}/{path[2:]}" + elif path.startswith("../"): + path = f"${{CMAKE_CURRENT_BINARY_DIR}}/{path}" + for original, replacement in _path_replacements: + path = path.replace(original, replacement) + path = path.replace("$$TARGET", scope.TARGET) + return path + + def handle_subdir( scope: Scope, cm_fh: IO[str], *, indent: int = 0, is_example: bool = False ) -> None: @@ -2625,9 +2643,7 @@ def write_main_part( # Check for DESTDIR override destdir = scope.get_string("DESTDIR") if destdir: - if destdir.startswith("./") or destdir.startswith("../"): - destdir = f"${{CMAKE_CURRENT_BINARY_DIR}}/{destdir}" - destdir = destdir.replace("$$[QT_INSTALL_PREFIX]", "${INSTALL_DIRECTORY}") + destdir = replace_path_constants(destdir, scope) extra_lines.append(f'OUTPUT_DIRECTORY "{destdir}"') cm_fh.write(f"{spaces(indent)}{cmake_function}({name}\n") @@ -2796,10 +2812,7 @@ def write_binary(cm_fh: IO[str], scope: Scope, gui: bool = False, *, indent: int target_path = scope.get_string("target.path") if target_path: - target_path = target_path.replace("$$[QT_INSTALL_PREFIX]", "${INSTALL_DIRECTORY}") - target_path = target_path.replace("$$[QT_INSTALL_EXAMPLES]", "${INSTALL_EXAMPLESDIR}") - target_path = target_path.replace("$$[QT_INSTALL_TESTS]", "${INSTALL_TESTSDIR}") - target_path = target_path.replace("$$TARGET", scope.TARGET) + target_path = replace_path_constants(target_path, scope) if not scope.get("DESTDIR"): extra.append(f'OUTPUT_DIRECTORY "{target_path}"') if "target" in scope.get("INSTALLS"): |