Ignores empty directories and creates root CMakeLists library
This commit is contained in:
@@ -25,7 +25,7 @@ HEADER_EXTS = [
|
|||||||
CMAKE_EXCLUDE_SOURCES = [
|
CMAKE_EXCLUDE_SOURCES = [
|
||||||
"*_template.c"
|
"*_template.c"
|
||||||
]
|
]
|
||||||
CMAKE_TARGET = "" # Set from argv
|
CMAKE_TARGET = "" # Set from config
|
||||||
ASSUME_YES = False
|
ASSUME_YES = False
|
||||||
|
|
||||||
|
|
||||||
@@ -80,15 +80,35 @@ def recurse_cmakelists(path: Path):
|
|||||||
lines.append(")")
|
lines.append(")")
|
||||||
lines += ["add_subdirectory(%s)"%(directory.name) for directory in dirs]
|
lines += ["add_subdirectory(%s)"%(directory.name) for directory in dirs]
|
||||||
|
|
||||||
# Write CMakeLists
|
# Write CMakeLists if not empty
|
||||||
lists_path = path / "CMakeLists.txt"
|
if len(lines) != 0:
|
||||||
with open(lists_path, "w") as of:
|
lists_path = path / "CMakeLists.txt"
|
||||||
of.write("\n".join(lines)+"\n")
|
with open(lists_path, "w") as of:
|
||||||
|
of.write("\n".join(lines)+"\n")
|
||||||
|
|
||||||
# Recurse
|
# Recurse
|
||||||
for directory in dirs:
|
for directory in dirs:
|
||||||
recurse_cmakelists(directory)
|
recurse_cmakelists(directory)
|
||||||
|
|
||||||
|
def root_cmakelists(path: Path):
|
||||||
|
lines: list[str] = []
|
||||||
|
lists_path = path / "CMakeLists.txt"
|
||||||
|
|
||||||
|
# Define custom libraries
|
||||||
|
lines.append("add_library(%s STATIC)"%(CMAKE_TARGET))
|
||||||
|
lines.append("target_compile_definitions(%s PRIVATE ${COMPILER_DEFINES})"%(CMAKE_TARGET))
|
||||||
|
lines.append("target_compile_options(${EXECUTABLE} PRIVATE \"-Os -ffunction-sections -fdata-sections -g -lto\")")
|
||||||
|
lines.append("target_link_options(${EXECUTABLE} PRIVATE \"-T ${LINKER_SCRIPT} --specs=nano.specs -Wl,--gc-sections\")")
|
||||||
|
|
||||||
|
# Read previously generated contents
|
||||||
|
with open(lists_path, "r") as _if:
|
||||||
|
lines = _if.readlines()
|
||||||
|
|
||||||
|
# Save final result
|
||||||
|
with open(lists_path, "w") as of:
|
||||||
|
of.write("\n".join(lines)+"\n")
|
||||||
|
pass
|
||||||
|
|
||||||
def load_config(path: Path):
|
def load_config(path: Path):
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return
|
return
|
||||||
@@ -162,6 +182,7 @@ def main2(ns: Namespace):
|
|||||||
|
|
||||||
mx_cleanup(ns.path)
|
mx_cleanup(ns.path)
|
||||||
recurse_cmakelists(ns.path)
|
recurse_cmakelists(ns.path)
|
||||||
|
root_cmakelists(ns.path)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = ArgumentParser(prog="MX Convert")
|
parser = ArgumentParser(prog="MX Convert")
|
||||||
@@ -169,7 +190,7 @@ def main():
|
|||||||
parser.add_argument("-d", "--discard", action="append", help="Add a file to the discard list (delete if found).")
|
parser.add_argument("-d", "--discard", action="append", help="Add a file to the discard list (delete if found).")
|
||||||
parser.add_argument("-H", "--header", action="append", help="Add a pattern to the headers list, single wildcards allowed. Includes *.h by default.")
|
parser.add_argument("-H", "--header", action="append", help="Add a pattern to the headers list, single wildcards allowed. Includes *.h by default.")
|
||||||
parser.add_argument("-s", "--source", action="append", help="Add a pattern to the sources list, single wildcards allowed. Includes *.c and *.s by default.")
|
parser.add_argument("-s", "--source", action="append", help="Add a pattern to the sources list, single wildcards allowed. Includes *.c and *.s by default.")
|
||||||
parser.add_argument("-t", "--target", action="store", default="${EXECUTABLE}", help="The CMake target to generate references to. Defaults to '${EXECUTABLE}'.")
|
parser.add_argument("-t", "--target", action="store", default="cubemx", help="The CMake target to generate references to. Defaults to 'cubemx'.")
|
||||||
parser.add_argument("-x", "--exclude", action="append", help="Add a file to the source exclusion list, single wildcards allowed.")
|
parser.add_argument("-x", "--exclude", action="append", help="Add a file to the source exclusion list, single wildcards allowed.")
|
||||||
parser.add_argument("-y", "--assume-yes", action="store_true", help="Assume yes on all queries, useful for scripts.")
|
parser.add_argument("-y", "--assume-yes", action="store_true", help="Assume yes on all queries, useful for scripts.")
|
||||||
parser.add_argument("--show-cfg", action="store_true", help="Show configs that would be used to run and exit successfully.")
|
parser.add_argument("--show-cfg", action="store_true", help="Show configs that would be used to run and exit successfully.")
|
||||||
|
|||||||
Reference in New Issue
Block a user