【发布时间】:2014-05-15 17:16:36
【问题描述】:
我正在开发一个项目,该项目由 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”,即加密库的头文件。这似乎建设得很好。对此的任何想法也非常感谢!
【问题讨论】: