我正在开发一个由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”,这是加密库的头文件 . 这看起来很好 . 对此的任何想法也非常感谢!