@@ -152,23 +152,30 @@ def collect_src_files():
152
152
]
153
153
154
154
155
+ def normalize_path (path ):
156
+ project_dir = env .subst ("$PROJECT_DIR" )
157
+ if project_dir in path :
158
+ path = path .replace (project_dir , "${CMAKE_SOURCE_DIR}" )
159
+ return to_unix_path (path )
160
+
161
+
155
162
def create_default_project_files ():
156
163
root_cmake_tpl = """cmake_minimum_required(VERSION 3.16.0)
157
164
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
158
165
project(%s)
159
166
"""
160
- prj_cmake_tpl = """# Warning! This code was automatically generated for projects
167
+ prj_cmake_tpl = """# This file was automatically generated for projects
161
168
# without default 'CMakeLists.txt' file.
162
169
163
- set(app_sources
164
- %s)
170
+ FILE(GLOB_RECURSE app_sources %s/*.*)
165
171
166
172
idf_component_register(SRCS ${app_sources})
167
173
"""
168
174
169
175
if not listdir (join (env .subst ("$PROJECT_SRC_DIR" ))):
170
- # create an empty file to make CMake happy during first init
171
- open (join (env .subst ("$PROJECT_SRC_DIR" ), "empty.c" ), "a" ).close ()
176
+ # create a default main file to make CMake happy during first init
177
+ with open (join (env .subst ("$PROJECT_SRC_DIR" ), "main.c" ), "w" ) as fp :
178
+ fp .write ("void app_main() {}" )
172
179
173
180
project_dir = env .subst ("$PROJECT_DIR" )
174
181
if not isfile (join (project_dir , "CMakeLists.txt" )):
@@ -178,8 +185,10 @@ def create_default_project_files():
178
185
project_src_dir = env .subst ("$PROJECT_SRC_DIR" )
179
186
if not isfile (join (project_src_dir , "CMakeLists.txt" )):
180
187
with open (join (project_src_dir , "CMakeLists.txt" ), "w" ) as fp :
181
- fp .write (prj_cmake_tpl % "" .join (
182
- '\t "%s"\n ' % to_unix_path (f ) for f in collect_src_files ()))
188
+ fp .write (
189
+ prj_cmake_tpl
190
+ % normalize_path (env .subst ("$PROJECT_SRC_DIR" ))
191
+ )
183
192
184
193
185
194
def get_cmake_code_model (src_dir , build_dir , extra_args = None ):
0 commit comments