0


cmake 遍历目录并加入工程

一、cmake 遍历目录并加入工程

CMAKE_MINIMUM_REQUIRED(VERSION 3.17.5)
GET_FILENAME_COMPONENT(MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
PROJECT(${MODULE_NAME})

file(GLOB_RECURSE SRC_LIST *.cpp)
list(FILTER SRC_LIST EXCLUDE REGEX "autotest")

exec_program("find ${PROJECT_SOURCE_DIR}/ -maxdepth 1 -mindepth 1 -type d | xargs -n 1 basename | xargs" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE DIR_STRING)
set(DIR_LIST ${DIR_STRING})
separate_arguments(DIR_LIST)
list(LENGTH DIR_LIST LIST_LENGTH)
message("LIST_LENGTH=${LIST_LENGTH}, DIR_LIST=${DIR_LIST}")

INCLUDE_DIRECTORIES(
./
${DIR_LIST}
../
../resource/
../frame/
../database/
../proxyapi/
../dirapi/
../fightapi/
../matchapi/
../rankapi/
../mailapi/
../eventapi/
../socialapi/
../partyapi/
../commentapi/
../familyapi/
../payapi/
../../include/
)

LINK_DIRECTORIES(
../resource/
../frame/
../database/
../oss/
../proxyapi/
../dirapi/
../fightapi/
../matchapi/
../rankapi/
../mailapi/
../eventapi/
../socialapi/
../partyapi/
../commentapi/
../familyapi/
../payapi/
../../lib/
)

SET(LIB_LIST ${LIB_LIST} resource frame database oss tss swift proxyapi dirapi fightapi matchapi rankapi mailapi eventapi socialapi partyapi idipapi commentapi familyapi payapi)

ADD_EXECUTABLE(${MODULE_NAME} ${SRC_LIST})
TARGET_LINK_LIBRARIES(${MODULE_NAME} ${LIB_LIST})

二、添加当前目录为项目名称

CMAKE_MINIMUM_REQUIRED(VERSION 3.17.5)
GET_FILENAME_COMPONENT(MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
PROJECT(${MODULE_NAME})

AUX_SOURCE_DIRECTORY(. SRC_LIST)

INCLUDE_DIRECTORIES(
../
../resource/
../frame/
../database/
../../include/
)

ADD_LIBRARY(${MODULE_NAME} ${SRC_LIST})

标签:

本文转载自: https://blog.csdn.net/markqian86/article/details/118303470
版权归原作者 markqian86 所有, 如有侵权,请联系我们删除。

“cmake 遍历目录并加入工程”的评论:

还没有评论