From e85c4a65a4c523a472e710dba2433a65044654ad Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 20 Dec 2019 10:19:54 +1100 Subject: [PATCH 1/2] cmake: convert_to_cmake: Fix possible whitespace issues As reported on forum: https://esp32.com/viewtopic.php?f=2&t=13565&p=53476#p53453 split() with no arg will match any whitespace sequence not just a single space, so takes care of case where two spaces are inserted in the variable value. --- tools/cmake/convert_to_cmake.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/cmake/convert_to_cmake.py b/tools/cmake/convert_to_cmake.py index 0ba7fa62f..2ac147006 100755 --- a/tools/cmake/convert_to_cmake.py +++ b/tools/cmake/convert_to_cmake.py @@ -78,14 +78,14 @@ def get_component_variables(project_path, component_path): return None srcs = [] - for obj in make_vars["COMPONENT_OBJS"].split(" "): + for obj in make_vars["COMPONENT_OBJS"].split(): src = find_src(obj) if src is not None: srcs.append(src) make_vars["COMPONENT_SRCS"] = " ".join(srcs) else: component_srcs = list() - for component_srcdir in make_vars.get("COMPONENT_SRCDIRS", ".").split(" "): + for component_srcdir in make_vars.get("COMPONENT_SRCDIRS", ".").split(): component_srcdir_path = os.path.abspath(os.path.join(component_path, component_srcdir)) srcs = list() @@ -114,7 +114,7 @@ def convert_project(project_path): if "PROJECT_NAME" not in project_vars: raise RuntimeError("PROJECT_NAME does not appear to be defined in IDF project Makefile at %s" % project_path) - component_paths = project_vars["COMPONENT_PATHS"].split(" ") + component_paths = project_vars["COMPONENT_PATHS"].split() # Convert components as needed for p in component_paths: From 3d0ecfdc70abb2c02edc0e1f8814245494db5c9f Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 20 Dec 2019 10:28:41 +1100 Subject: [PATCH 2/2] cmake: Add warnings that convert_to_cmake.py doesn't calculate component requirements Any component which requires another component will need this manually added to its CMakeLists.txt file. --- docs/en/api-guides/build-system.rst | 2 ++ tools/cmake/convert_to_cmake.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index a0cb96d39..f409c0219 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -1422,6 +1422,8 @@ The tool will convert the project Makefile and any component ``component.mk`` fi It does so by running ``make`` to expand the ESP-IDF build system variables which are set by the build, and then producing equivalent CMakelists files to set the same variables. +.. important:: When the conversion tool converts a ``component.mk`` file, it doesn't determine what other components that component depends on. This information needs to be added manually by editing the new component ``CMakeLists.txt`` file and adding ``REQUIRES`` and/or ``PRIV_REQUIRES`` clauses. Otherwise, source files in the component will fail to compile as headers from other components are not found. See :ref:`component requirements`. + The conversion tool is not capable of dealing with complex Makefile logic or unusual targets. These will need to be converted by hand. No Longer Available in CMake diff --git a/tools/cmake/convert_to_cmake.py b/tools/cmake/convert_to_cmake.py index 2ac147006..588b9bdd5 100755 --- a/tools/cmake/convert_to_cmake.py +++ b/tools/cmake/convert_to_cmake.py @@ -116,13 +116,15 @@ def convert_project(project_path): component_paths = project_vars["COMPONENT_PATHS"].split() + converted_components = 0 + # Convert components as needed for p in component_paths: if "MSYSTEM" in os.environ: cmd = ["cygpath", "-w", p] p = subprocess.check_output(cmd).strip() - convert_component(project_path, p) + converted_components += convert_component(project_path, p) project_name = project_vars["PROJECT_NAME"] @@ -143,6 +145,13 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) print("Converted project %s" % project_cmakelists) + if converted_components > 0: + print("Note: Newly created component CMakeLists.txt do not have any REQUIRES or PRIV_REQUIRES " + "lists to declare their component requirements. Builds may fail to include other " + "components' header files. If so requirements need to be added to the components' " + "CMakeLists.txt files. See the 'Component Requirements' section of the " + "Build System docs for more details.") + def convert_component(project_path, component_path): if debug: @@ -150,7 +159,7 @@ def convert_component(project_path, component_path): cmakelists_path = os.path.join(component_path, "CMakeLists.txt") if os.path.exists(cmakelists_path): print("Skipping already-converted component %s..." % cmakelists_path) - return + return 0 v = get_component_variables(project_path, component_path) # Look up all the variables before we start writing the file, so it's not @@ -173,6 +182,7 @@ def convert_component(project_path, component_path): f.write("target_compile_options(${COMPONENT_LIB} PRIVATE %s)\n" % cflags) print("Converted %s" % cmakelists_path) + return 1 def main():