cmake: make main a component again

This commit is contained in:
Renz Christian Bagaporo
2018-09-11 09:44:12 +08:00
committed by Angus Gratton
parent f9bed53ea2
commit d9939cedd9
282 changed files with 1740 additions and 673 deletions

View File

@@ -82,10 +82,20 @@ def get_component_variables(project_path, component_path):
if src is not None:
srcs.append(src)
make_vars["COMPONENT_SRCS"] = " ".join(srcs)
else: # Use COMPONENT_SRCDIRS
make_vars["COMPONENT_SRCDIRS"] = make_vars.get("COMPONENT_SRCDIRS", ".")
else:
component_srcs = list()
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()
srcs += glob.glob(os.path.join(component_srcdir_path, "*.[cS]"))
srcs += glob.glob(os.path.join(component_srcdir_path, "*.cpp"))
srcs = [('"%s"' % str(os.path.relpath(s, component_path))) for s in srcs]
make_vars["COMPONENT_ADD_INCLUDEDIRS"] = make_vars.get("COMPONENT_ADD_INCLUDEDIRS", "include")
component_srcs += srcs
make_vars["COMPONENT_SRCS"] = " ".join(component_srcs)
return make_vars
@@ -106,32 +116,10 @@ def convert_project(project_path):
component_paths = project_vars["COMPONENT_PATHS"].split(" ")
# "main" component is made special in cmake, so extract it from the component_paths list
try:
main_component_path = [ p for p in component_paths if os.path.basename(p) == "main" ][0]
if debug:
print("Found main component %s" % main_component_path)
main_vars = get_component_variables(project_path, main_component_path)
except IndexError:
print("WARNING: Project has no 'main' component, but CMake-based system requires at least one file in MAIN_SRCS...")
main_vars = { "COMPONENT_SRCS" : ""} # dummy for MAIN_SRCS
# Remove main component from list of components we're converting to cmake
component_paths = [ p for p in component_paths if os.path.basename(p) != "main" ]
# Convert components as needed
for p in component_paths:
convert_component(project_path, p)
# Look up project variables before we start writing the file, so nothing
# is created if there is an error
main_srcs = main_vars["COMPONENT_SRCS"].split(" ")
# convert from component-relative to absolute paths
main_srcs = [ os.path.normpath(os.path.join(main_component_path, m)) for m in main_srcs ]
# convert to make relative to the project directory
main_srcs = [ os.path.relpath(m, project_path) for m in main_srcs ]
project_name = project_vars["PROJECT_NAME"]
# Generate the project CMakeLists.txt file
@@ -139,12 +127,11 @@ def convert_project(project_path):
f.write("""
# (Automatically converted from project Makefile by convert_to_cmake.py.)
# The following four lines of boilerplate have to be in your project's CMakeLists
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
""")
f.write("set(MAIN_SRCS %s)\n" % " ".join(main_srcs))
f.write("""
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
""")
@@ -164,16 +151,6 @@ def convert_component(project_path, component_path):
# Look up all the variables before we start writing the file, so it's not
# created if there's an erro
component_srcs = v.get("COMPONENT_SRCS", None)
component_srcdirs = None
if component_srcs is not None:
# see if we should be using COMPONENT_SRCS or COMPONENT_SRCDIRS, if COMPONENT_SRCS is everything in SRCDIRS
component_allsrcs = []
for d in v.get("COMPONENT_SRCDIRS", "").split(" "):
component_allsrcs += glob.glob(os.path.normpath(os.path.join(component_path, d, "*.[cS]")))
component_allsrcs += glob.glob(os.path.normpath(os.path.join(component_path, d, "*.cpp")))
abs_component_srcs = [os.path.normpath(os.path.join(component_path, p)) for p in component_srcs.split(" ")]
if set(component_allsrcs) == set(abs_component_srcs):
component_srcdirs = v.get("COMPONENT_SRCDIRS")
component_add_includedirs = v["COMPONENT_ADD_INCLUDEDIRS"]
cflags = v.get("CFLAGS", None)
@@ -185,10 +162,7 @@ def convert_component(project_path, component_path):
f.write("set(COMPONENT_REQUIRES "")\n")
f.write("set(COMPONENT_PRIV_REQUIRES "")\n\n")
if component_srcdirs is not None:
f.write("set(COMPONENT_SRCDIRS %s)\n\n" % component_srcdirs)
f.write("register_component()\n")
elif component_srcs is not None:
if component_srcs is not None:
f.write("set(COMPONENT_SRCS %s)\n\n" % component_srcs)
f.write("register_component()\n")
else: