cocos2d-x自动导入所有cpp文件到android.mk

只有Classes文件夹的情况下用下面这个足以
LOCAL_PATH := $(call my-dir)
 
include $(CLEAR_VARS)
 
LOCAL_MODULE := hellocpp_shared
 
LOCAL_MODULE_FILENAME := libhellocpp
 
FILE_LIST := hellocpp/main.cpp
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
 
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
 
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
 
include $(BUILD_SHARED_LIBRARY)
 
$(call import-module,cocos2dx)
如果Classes文件夹下有子文件夹怎么办,加文件夹呗
#FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)
#FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/datapacker/*.cpp)
#FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/platform/*.cpp)

//如果classes目录下面有子目录的话,include路径是不对的。
//可以再添加
FILE_INCLUDES := $(shell find $(LOCAL_PATH)/../../Classes -type d)
然后LOCAL_C_INCLUDES := $(FILE_INCLUDES) 就可以了。 如果文件夹多了懒得加怎么办,用下面的方法
# 遍历目录及子目录的函数
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)/%=%)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes