【发布时间】:2015-10-23 16:55:45
【问题描述】:
我的 CMake 构建系统有问题。有CMakeLists.txt 文件定义运行时或库或使用ExternalProjects_Add() 下载和构建外部代码。由于依赖关系,这些项目必须相互找到。现在我想在顶层有一个CMakeLists.txt,它可以同时构建所有这些。为了找到一个项目,是必须安装的。但是在 CMake 中配置时已经完成了查找项目。
repository
├─project
│ ├─game (Depends on engine, uses EngineConfig.cmake once installed)
│ │ ├─CMakeLists.txt
│ │ ├─include
│ │ ├─src
│ │ └─textures
│ ├─engine (Depends on boost, uses built-in FindBoost.cmake)
│ │ ├─CMakeLists.txt
│ │ ├─include
│ │ └─src
│ ├─boost (Not the source code, just an ExternalProject_Add call)
│ : └─CMakeLists.txt
│
├─build
│ ├─game
│ ├─engine
│ ├─boost (Source will be downloaded and built here)
│ : ├─download
│ ├─source
│ :
│
├─install
│ ├─game
│ │ ├─bin
│ │ └─textures
│ ├─engine
│ │ ├─include
│ │ │ └─engine
│ │ │ ├─EngineConfig.cmake (Needed to find the library)
│ │ │ :
│ │ │
│ │ └─lib
│ ├─boost (Layout is up to the external library)
│ : └─ ...
│
└─CMakeLists.txt (Calls add_subdirectory for all inside the project folder)
为每个项目运行一个 CMake 流程:使用execute_process(${CMAKE_COMMAND} ...),我可以在配置时配置和构建每个项目。但是,这意味着我总是必须在编辑代码后运行 CMake,并且无法从我为其生成项目文件的 IDE 中进行编译。
链接到 CMake 目标: 为所有外部库运行 CMake 进程是可以的,因为我不处理它们。我自己的库可以通过调用target_link_libraries() 来使用它们的目标名称。然而,链接是不够的。我的库包括外部库的目录。这些也必须提供给正在使用的项目。
如何在我的 CMake 项目中使用需要先安装的库?
【问题讨论】:
-
My own libraries could be used by calling target_link_libraries() with their target names. However, linking isn't enough...- 您能否根据您提供的项目层次结构添加该用法的示例? -
当然,例如game要使用engine。
project/engine/CMakeListst.txt使用add_library(engine ${SOURCE_FILES})声明库。然后,project/game/CMakeListst.txt用add_runtime(game ${SOURCE_FILES})声明它的可执行文件,并用target_link_libraries(game engine)将库链接到它。是这个意思吗?
标签: cmake build-system