Skip to content

Instantly share code, notes, and snippets.

@YcSmile
Last active March 13, 2019 13:12
Show Gist options
  • Save YcSmile/4bfab348b53e1a7e2f5916f3b96315b8 to your computer and use it in GitHub Desktop.
Save YcSmile/4bfab348b53e1a7e2f5916f3b96315b8 to your computer and use it in GitHub Desktop.
[CMake 批量添加工程]CMake批量添加工程 #CMake #批量Cmake工程
#批量添加子文件工程
cmake_minimum_required(VERSION 3.5)
# 工程名称
project(DataStruct)
# 检索 CMAKE_SOURCE_DIR 下子文件夹名称
file(GLOB folders RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/*)
# 遍历子文件夹
foreach(subDir ${folders})
#if("${subDir}" MATCHES "^[u4e00-u9fa5]+") # 使用正则来匹配固定格式
# 判断是否是文件夹
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/${subDir})
# 检索所与子文件夹下的 c cc文件
file(GLOB subSrc ${CMAKE_SOURCE_DIR}/${subDir}/*.cc ${CMAKE_SOURCE_DIR}/${subDir}/*.c )
# 判断子文件下源文件是否为空
if (NOT "${subSrc}" STREQUAL "")
message(STATUS "Add Exe-" ${subDir}.exe)
#
# STRING(REGEX REPLACE ".+/(.+)\\..*" "\\1" FILE_NAME ${subSrc})
# 子文件夹名为bin文件名
add_executable(${subDir}.exe ${subSrc})
endif()
endif()
endforeach(subDir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment