cmake编译多个文件夹_CMake:使用静态库在一个项目中构建多个可执行文件

我正在开发一个由3个服务器可执行文件和一个共享代码库组成的项目 . 我希望它是跨平台的,所以我使用CMake(因为Xcode很痛苦)来处理构建过程 . 我在设置CMakeLists时遇到问题,以便在构建可执行文件时可以从同一级别的目录中包含库 .

这是目录结构(和CMake文件):

tethealla2.0/

CMakeLists.txt

libtethealla/

CMakeLists.txt

encryption/

utils/

patch_server/

CMakeLists.txt

login_server/

CMakeLists.txt

ship_server/

CMakeLists.txt

我的顶级CMake(tethealla2.0 / CMakeLists.txt,仅包含应编译的子项目):

project(tethealla CXX)

cmake_minimum_required(VERSION 2.6)

add_subdirectory(libtethealla)

add_subdirectory(patch_server)

tethealla2.0 / libtethealla / CMakeLists.txt,它生成一个静态库:

project(Libtethealla C)

cmake_minimum_required(VERSION 2.6)

include_directories(encryption)

set(ENC_DR encryption/)

set(ENCRYPTION_SOURCES

${ENC_DR}/psobb-crypt.c

${ENC_DR}/psogc-crypt.c

${ENC_DR}/psobb-crypt.c

${ENC_DR}/encryption.c

)

add_library(tethealla STATIC ${ENCRYPTION_SOURCES})

到目前为止tethealla2.0 / patch_server / CMakeLists.txt:

project(patch_server CXX)

cmake_minimum_required(VERSION 2.6)

add_executable(server main.cc)

target_link_libraries(server tethealla)

因此,如果我从顶层构建它更有意义,因为tethealla2.0 / CMakeLists.txt将继承每个子目录中的目标,而patch_server中的目标将可以访问tethealla库 . 但是我想要的是能够从这些子目录中构建以生成Xcode项目,以便我可以单独处理/重新编译它们 . 为此,我需要能够访问libtethealla / build目录(CMake输出)以从patch_server访问libtethealla.a库 . 这可能吗?

另外注意,即使在顶级目录的构建中,我在patch_server中的源也不能包含“encryption.h”,这是加密库的头文件 . 这看起来很好 . 对此的任何想法也非常感谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值