summaryrefslogtreecommitdiffstats
path: root/util/cmake/pro2cmake.py
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-09-22 18:45:14 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-09-27 21:36:36 +0200
commit96659297064ad0eb15f173a4452d349e8d43e2c5 (patch)
tree16dec2adee2a813ea6d17fc610a39a8061771026 /util/cmake/pro2cmake.py
parent124f7c681fd74f01aaa60dc31c26e51c52f2b1e9 (diff)
pro2cmake: Generate public CMake API code for projects by default
Previously pro2cmake assumed that all .pro were internal Qt projects like qtbase/src/corelib.pro and generated private api calls like qt_internal_add_module(). Public CMake API calls (like qt_add_executable) were only generated if an --is-example command line flag was passed to the script or if the .pro file was located under the examples subfolder of a qt repo source directory (indicated by the presence of a .qmake.conf file). Change the logic to always generate public CMake API code by default, unless a .cmake.conf/.qmake.conf file is encountered with a valid repo module version inside, in which case apply the old heuristic of checking for the ./examples subfolder. The intention is to have a sensible default so that Qt users can use the script to more easily migrate their qmake projects without having to explicitly specify the --is-example flag. Pick-to: 6.2 Task-number: QTBUG-96799 Change-Id: I38f4f1b349a5b9688cf7bc5914d4fde72e660a98 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'util/cmake/pro2cmake.py')
-rwxr-xr-xutil/cmake/pro2cmake.py47
1 files changed, 43 insertions, 4 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index 2e9295c883..e3e46df549 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -241,15 +241,40 @@ def is_top_level_repo_examples_project(project_file_path: str = "") -> bool:
def is_example_project(project_file_path: str = "") -> bool:
- qmake_or_cmake_conf_path = find_qmake_or_cmake_conf(project_file_path)
- qmake_or_cmake_conf_dir_path = os.path.dirname(qmake_or_cmake_conf_path)
+ # If there's a .qmake.conf or .cmake.conf file in the parent
+ # directories of the given project path, it is likely that the
+ # project is an internal Qt project that uses private Qt CMake
+ # API.
+ found_qt_repo_version = False
+ qmake_conf = find_qmake_conf(project_file_path)
+ if qmake_conf:
+ repo_version = parse_qt_repo_module_version_from_qmake_conf(qmake_conf)
+ if repo_version:
+ found_qt_repo_version = True
+
+ cmake_conf = find_cmake_conf(project_file_path)
+ if cmake_conf:
+ repo_version = parse_qt_repo_module_version_from_cmake_conf(cmake_conf)
+ if repo_version:
+ found_qt_repo_version = True
+
+ # If we haven't found a conf file, we assume this is an example
+ # project and not a project under a qt source repository.
+ if not found_qt_repo_version:
+ return True
- project_relative_path = os.path.relpath(project_file_path, qmake_or_cmake_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, but
# some examples contain 3rdparty libraries that do not need to be
# built as examples.
- return project_relative_path.startswith("examples") and "3rdparty" not in project_relative_path
+ qmake_or_cmake_conf_path = find_qmake_or_cmake_conf(project_file_path)
+ qmake_or_cmake_conf_dir_path = os.path.dirname(qmake_or_cmake_conf_path)
+ project_relative_path = os.path.relpath(project_file_path, qmake_or_cmake_conf_dir_path)
+
+ is_example_under_repo_sources = (
+ project_relative_path.startswith("examples") and "3rdparty" not in project_relative_path
+ )
+ return is_example_under_repo_sources
def is_config_test_project(project_file_path: str = "") -> bool:
@@ -330,6 +355,20 @@ def find_qmake_or_cmake_conf(project_file_path: str = "") -> str:
return cmake_conf
+def parse_qt_repo_module_version_from_qmake_conf(qmake_conf_path: str = "") -> str:
+ with open(qmake_conf_path) as f:
+ file_contents = f.read()
+ m = re.search(fr"MODULE_VERSION\s*=\s*([0-9.]+)", file_contents)
+ return m.group(1) if m else ""
+
+
+def parse_qt_repo_module_version_from_cmake_conf(cmake_conf_path: str = "") -> str:
+ with open(cmake_conf_path) as f:
+ file_contents = f.read()
+ m = re.search(fr'set\(QT_REPO_MODULE_VERSION\s*"([0-9.]+)"\)', file_contents)
+ return m.group(1) if m else ""
+
+
def set_up_cmake_api_calls():
def nested_dict():
return defaultdict(nested_dict)