# 获取当前目录下的所有目录 file(GLOB directories RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) foreach(dir ${directories}) if (DEFINED ENABLE_PROJECT) list(FIND ENABLE_PROJECT ${dir} PROJECT) if(NOT PROJECT EQUAL -1) if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir}) if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt") add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir}) else () message("Can't find dir: " "${CMAKE_SOURCE_DIR}/${dir}/CMakeLists.txt") endif () endif () endif() else() if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir}) if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt") add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir}) else () message("Can't find dir: " "${CMAKE_SOURCE_DIR}/${dir}/CMakeLists.txt") endif () endif () endif () endforeach()