0%

android自动添加文件到android-mk

1
2
3
LOCAL_SRC_FILES := hellocpp/main.cpp \  
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp

换成

1
2
3
FILE_LIST := hellocpp/main.cpp    
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

另外一种方法:

1
2
3
4
5
6
7
8
9
10
11
#遍历目录及子目录的函数  
define walk
$(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e)))
endef

#遍历Classes目录
ALLFILES = $(call walk, $(LOCAL_PATH)/../../Classes)
FILE_LIST := hellocpp/main.cpp
#从所有文件中提取出所有.cpp文件
FILE_LIST += $(filter %.cpp, $(ALLFILES))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
给作者打赏,鼓励TA抓紧创作!