diff --git a/port/esp32/create_examples.py b/port/esp32/create_examples.py index 733b9a1a5..b52a51874 100755 --- a/port/esp32/create_examples.py +++ b/port/esp32/create_examples.py @@ -31,6 +31,27 @@ EXAMPLE.h: $(COMPONENT_PATH)/EXAMPLE.gatt COMPONENT_EXTRA_CLEAN = EXAMPLE.h ''' +example_cmake_template = ''' +# BTstack example 'EXAMPLE' for ESP32 port +# +# Generated by TOOL +# On DATE + +# 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) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(EXAMPLE) +''' + +main_cmake_template = ''' +set(COMPONENT_SRCS "EXAMPLE.c") +set(COMPONENT_ADD_INCLUDEDIRS "") +register_component() +''' + + def create_examples(script_path, suffix): # path to examples examples_embedded = script_path + "/../../example/" @@ -75,6 +96,10 @@ def create_examples(script_path, suffix): with open(apps_folder + "Makefile", "wt") as fout: fout.write(mk_template.replace("EXAMPLE", example).replace("TOOL", script_path).replace("DATE",time.strftime("%c"))) + # create CMakeLists.txt file + with open(apps_folder + "CMakeLists.txt", "wt") as fout: + fout.write(example_cmake_template.replace("EXAMPLE", example).replace("TOOL", script_path).replace("DATE",time.strftime("%c"))) + # create main folder main_folder = apps_folder + "main/" if not os.path.exists(main_folder): @@ -92,6 +117,10 @@ def create_examples(script_path, suffix): main_component_mk = apps_folder + "/main/component.mk" shutil.copyfile(script_path + '/template/main/component.mk', main_component_mk) + # create CMakeLists.txt file + with open(apps_folder + "/main/CMakeLists.txt", "wt") as fout: + fout.write(main_cmake_template.replace("EXAMPLE", example)) + # add rules to compile gatt db if .gatt file is present gatt_path = examples_embedded + example + ".gatt" if os.path.exists(gatt_path):