Skip to content

Commit

Permalink
optimize add ADD_FILE_DEPENDS var
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Mar 31, 2024
1 parent 429a7ec commit f06db8c
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 16 deletions.
5 changes: 4 additions & 1 deletion Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ menu "Toolchain configuration"
default ""
endmenu

menu "Components configuration"
menu "SDK Components Configuration"
osource "${SDK_PATH}/components/*/Kconfig"
osource "${CUSTOM_COMPONENTS_PATH}/*/Kconfig"
endmenu
menu "Project Components Configuration"
osource "${PROJECT_PATH}/../components/*/Kconfig"
osource "${PROJECT_PATH}/*/Kconfig"
osource "${PROJECT_PATH}/components/*/Kconfig"
endmenu
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ node demo1.js

## Add command

By default we can use `python project.py run` to call [tools/run.py](./tools/run.py) file, and execute the binary file.
If you want to add commands for your SDK, just create new `py` file in tools directory, write a script and content refer to [tools/run.py](./tools/run.py).
By default we can use `python project.py run` to call [tools/cmds/run.py](./tools/run.py) file, and execute the binary file.
If you want to add commands for your SDK, just create new `py` file in tools directory, write a script and content refer to [tools/cmds/run.py](./tools/cmds/run.py).

## Online Debugging

Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ node demo1.js

## 增加新的命令

比如默认使用 `python project.py run` 命令会调用`tools/run.py`脚本来执行构建出来的可执行文件。
如果你需要给你的 SDK 增加命令,只需要创建一个新的文件,参考[tools/run.py](./tools/run.py)文件的写法即可
比如默认使用 `python project.py run` 命令会调用`tools/cmds/run.py`脚本来执行构建出来的可执行文件。
如果你需要给你的 SDK 增加命令,只需要创建一个新的文件,参考[tools/cmds/run.py](./tools/cmds/run.py)文件的写法即可

## 在线调试

Expand Down
7 changes: 7 additions & 0 deletions components/component1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ list(APPEND ADD_SRCS "src/lib1.c"

###### Add required/dependent components ######
# list(APPEND ADD_REQUIREMENTS component1)
#
# list(APPEND ADD_FILE_DEPENDS include/axx.h)
# set_property(SOURCE ${python_h_path} PROPERTY GENERATED 1)
# add_custom_command(OUTPUT include/axx.h
# COMMAND echo "" > include/axx.h
# COMMENT "Generating axx.h ..."
# )
###############################################

###### Add link search path for requirements/libs ######
Expand Down
7 changes: 7 additions & 0 deletions components/component2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ if(CONFIG_COMPONENT2_ENABLED)

###### Add required/dependent components ######
list(APPEND ADD_REQUIREMENTS component1)
#
# list(APPEND ADD_FILE_DEPENDS include/axx.h)
# set_property(SOURCE ${python_h_path} PROPERTY GENERATED 1)
# add_custom_command(OUTPUT include/axx.h
# COMMAND echo "" > include/axx.h
# COMMENT "Generating axx.h ..."
# )
###############################################

###### Add link search path for requirements/libs ######
Expand Down
7 changes: 7 additions & 0 deletions components/component3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ if(CONFIG_COMPONENT3_ENABLED)

###### Add required/dependent components ######
list(APPEND ADD_REQUIREMENTS component1)
#
# list(APPEND ADD_FILE_DEPENDS include/axx.h)
# set_property(SOURCE ${python_h_path} PROPERTY GENERATED 1)
# add_custom_command(OUTPUT include/axx.h
# COMMAND echo "" > include/axx.h
# COMMENT "Generating axx.h ..."
# )
###############################################

###### Add link search path for requirements/libs ######
Expand Down
13 changes: 13 additions & 0 deletions examples/demo1/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ endif()
if(CONFIG_COMPONENT3_ENABLED)
list(APPEND ADD_REQUIREMENTS component3)
endif()
#
# list(APPEND ADD_FILE_DEPENDS include/axx.h)
# set_property(SOURCE ${python_h_path} PROPERTY GENERATED 1)
# add_custom_command(OUTPUT include/axx.h
# COMMAND echo "" > include/axx.h
# COMMENT "Generating axx.h ..."
# )
###############################################

###### Add link search path for requirements/libs ######
Expand All @@ -43,6 +50,12 @@ endif()
# list(APPEND ADD_STATIC_LIB "lib/libtest.a")
###############################################

############ Add dynamic libs ##################
# list(APPEND ADD_DYNAMIC_LIB "lib/arch/v831/libmaix_nn.so"
# "lib/arch/v831/libmaix_cam.so"
# )
###############################################

#### Add compile option for this component ####
#### Just for this component, won't affect other
#### modules, including component that depend
Expand Down
43 changes: 33 additions & 10 deletions tools/cmake/compile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@ function(register_component)

# Add definitions public
foreach(difinition ${ADD_DEFINITIONS})
target_compile_options(${component_name} PUBLIC ${difinition})
if(${include_type} STREQUAL INTERFACE)
target_compile_options(${component_name} INTERFACE ${difinition})
target_link_options(${component_name} INTERFACE ${difinition})
else()
target_compile_options(${component_name} PUBLIC ${difinition})
target_link_options(${component_name} PUBLIC ${difinition})
endif()
endforeach()

# Add definitions private
foreach(difinition ${ADD_DEFINITIONS_PRIVATE})
target_compile_options(${component_name} PRIVATE ${difinition})
target_link_options(${component_name} PRIVATE ${difinition})
endforeach()

# Add lib search path
Expand Down Expand Up @@ -161,28 +168,43 @@ function(register_component)

# Add requirements
target_link_libraries(${component_name} ${include_type} ${ADD_REQUIREMENTS})

# Add file depends
if(ADD_FILE_DEPENDS)
add_custom_target(${component_name}_file_depends DEPENDS ${ADD_FILE_DEPENDS})
add_dependencies(${component_name} ${component_name}_file_depends)
endif()
endfunction()

function(is_path_component ret param_path)
set(res 1)
get_filename_component(abs_dir ${param_path} ABSOLUTE)

if(NOT IS_DIRECTORY "${abs_dir}")
set(res 0)
set(${ret} 0 PARENT_SCOPE)
return()
endif()

get_filename_component(base_dir ${abs_dir} NAME)
string(SUBSTRING "${base_dir}" 0 1 first_char)

if(NOT first_char STREQUAL ".")
if(NOT EXISTS "${abs_dir}/CMakeLists.txt")
set(res 0)
endif()
else()
set(res 0)
if(first_char STREQUAL ".")
set(${ret} 0 PARENT_SCOPE)
return()
endif()
if(NOT EXISTS "${abs_dir}/CMakeLists.txt")
set(${ret} 0 PARENT_SCOPE)
return()
endif()

# check if register_component in CMakeLists.txt
file(READ "${abs_dir}/CMakeLists.txt" content)
string(FIND "${content}" "register_component" find_res)
if(find_res EQUAL -1)
set(${ret} 0 PARENT_SCOPE)
return()
endif()

set(${ret} ${res} PARENT_SCOPE)
set(${ret} 1 PARENT_SCOPE)
endfunction()

function(find_components componet_dirs kconfigs configs found_main find_dir)
Expand Down Expand Up @@ -249,6 +271,7 @@ macro(project name)
find_components(components_dirs components_kconfig_files kconfig_defaults_files_args found_main ${PROJECT_SOURCE_DIR}/../components/*)
# Find components in project folder
find_components(components_dirs components_kconfig_files kconfig_defaults_files_args found_main ${PROJECT_SOURCE_DIR}/*)
find_components(components_dirs components_kconfig_files kconfig_defaults_files_args found_main ${PROJECT_SOURCE_DIR}/components/*)

if(NOT found_main)
message(FATAL_ERROR "=================\nCan not find main component(folder) in project folder!!\n=================")
Expand Down
2 changes: 1 addition & 1 deletion tools/cmake/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
exit(1)

# find extra tools
tools_dir = os.path.join(sdk_path, "tools")
tools_dir = os.path.join(sdk_path, "tools", "cmds")
sys.path.insert(1, tools_dir)
# find all .py files in tools dir
extra_tools_names = []
Expand Down
53 changes: 53 additions & 0 deletions tools/cmake/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import time
import re
import os
import subprocess

def check_all_submodule(sdk_path):
if (not os.path.exists(os.path.join(sdk_path, ".gitmodules"))) or (not os.path.exists(os.path.join(sdk_path, ".git"))):
return True, ""
with open(os.path.join(sdk_path, ".gitmodules")) as f:
content = f.read()
m = re.findall(r'path = (.*)', content)
if not m:
return True, ""
for path in m:
full_path = os.path.join(sdk_path, path)
err_msg = "Submodule {} not exists, please run `git submodule update --init --recursive` to init all submodules".format(path)
if (not os.path.exists(full_path)):
print("-- {} not exists".format(full_path))
return False, err_msg
files = os.listdir(full_path)
if ".git" not in files:
print("-- {}/.git not exists".format(full_path))
return False, err_msg
visible_files = []
for name in files:
if not name.startswith("."):
visible_files.append(name)
if len(visible_files) == 0:
print("-- {} no files".format(full_path))
return False, err_msg
# check if submodule version is the same as should be
cmd = ["git", "submodule", "status"]
p = subprocess.Popen(cmd, cwd=sdk_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = p.communicate("")
res = p.returncode
if res != 0:
print("-- git submodule status failed")
return False, err
try:
output = output.decode(encoding="utf-8" if os.name == "nt" else "utf-8")
except Exception:
output = output.decode(encoding="gbk" if os.name == "nt" else "utf-8")
lines = output.split("\n")
for line in lines:
if line.startswith("+"):
print("\n============================================")
print("-- [Warning]\n!! Submodule [{}] have changes, it maybe cause problems\nif you don't know what this means, please execute:\n git submodule update --init --recursive`\nto update submodule !".format(line.split(" ")[1]))
print("============================================\n")
time.sleep(1)
elif line.startswith("-"):
return False, "Submodule {} not exists, please run `git submodule update --init --recursive` to init all submodules".format(line.split(" ")[1])

return True, ""
File renamed without changes.
File renamed without changes.

0 comments on commit f06db8c

Please sign in to comment.