Skip to content

Commit 3ead49b

Browse files
committed
Optimize construct order
1 parent 942057a commit 3ead49b

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

project_include.cmake

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,29 @@ function(convert_arduino_libraries_to_components)
5151
endif()
5252
endforeach()
5353

54+
# Start CMakeLists.txt generation
55+
file(WRITE ${component_cmakelist} "idf_component_register(")
56+
5457
# Sources are not compiled only if precompiled=full and precompiled library for our target exists
55-
file(WRITE ${component_cmakelist} "idf_component_register(SRCS ")
5658
if(NOT precompiled STREQUAL "full" OR NOT EXISTS "${src_dir}/${IDF_TARGET}/lib${child}.a")
59+
file(APPEND ${component_cmakelist} "SRCS ")
5760
file(GLOB_RECURSE src_files "${src_dir}/*.c" "${src_dir}/*.cpp")
5861
foreach(src_file ${src_files})
5962
string(REPLACE "${child_dir}/" "" src_file "${src_file}")
6063
file(APPEND ${component_cmakelist} "\"${src_file}\" ")
6164
endforeach()
62-
else()
63-
file(APPEND ${component_cmakelist} "\"\" ")
6465
endif()
66+
# Add src folder to includes
67+
file(APPEND ${component_cmakelist} "INCLUDE_DIRS \"src\" ")
68+
69+
# Add component requires
6570
file(APPEND ${component_cmakelist} "PRIV_REQUIRES ${arduino_component_name} ${main_component_name})\n")
6671

72+
# Add any custom LD_FLAGS, if defined
73+
if(NOT "${ldflags}" STREQUAL "")
74+
file(APPEND ${component_cmakelist} "target_link_libraries(\${COMPONENT_TARGET} INTERFACE \"${ldflags}\")\n")
75+
endif()
76+
6777
# If this lib has precompiled libs and they match our target, get them
6878
if((precompiled STREQUAL "true" OR precompiled STREQUAL "full") AND IS_DIRECTORY "${src_dir}/${IDF_TARGET}")
6979
file(GLOB_RECURSE lib_files "${src_dir}/${IDF_TARGET}/lib*.a")
@@ -73,14 +83,6 @@ function(convert_arduino_libraries_to_components)
7383
endforeach()
7484
endif()
7585

76-
# Add src folder to includes
77-
file(APPEND ${component_cmakelist} "target_include_directories(\${COMPONENT_TARGET} PUBLIC \"src\")\n")
78-
79-
# Add any custom LD_FLAGS, if defined
80-
if(NOT "${ldflags}" STREQUAL "")
81-
file(APPEND ${component_cmakelist} "target_link_libraries(\${COMPONENT_TARGET} INTERFACE \"${ldflags}\")\n")
82-
endif()
83-
8486
message(STATUS "Created IDF component for ${child}")
8587
else()
8688
message(STATUS "Processing 1.0 compatible library '${child}' in '${libs_dir_abs}'")
@@ -102,18 +104,17 @@ function(convert_arduino_libraries_to_components)
102104
endforeach()
103105
endif()
104106

105-
# Require arduino and main components to suceed in compilation
106-
file(APPEND ${component_cmakelist} "PRIV_REQUIRES ${arduino_component_name} ${main_component_name})\n")
107-
108107
# Add root folder to includes
109-
file(APPEND ${component_cmakelist} "target_include_directories(\${COMPONENT_TARGET} PUBLIC \".\"")
108+
file(APPEND ${component_cmakelist} "INCLUDE_DIRS \".\" ")
110109

111110
# Add the utility folder to includes if it exists
112111
if(IS_DIRECTORY "${utility_dir}")
113-
file(APPEND ${component_cmakelist} " \"utility\"")
112+
file(APPEND ${component_cmakelist} "\"utility\" ")
114113
endif()
114+
115+
# Require arduino and main components to suceed in compilation
116+
file(APPEND ${component_cmakelist} "PRIV_REQUIRES ${arduino_component_name} ${main_component_name})\n")
115117

116-
file(APPEND ${component_cmakelist} ")\n")
117118
message(STATUS "Created IDF component for ${child}")
118119
endif()
119120
else()

0 commit comments

Comments
 (0)