2

I am new to CMake and have been trying to structure my project so that I build a shared library (game engine) that can then be linked to one or more executables (games). My directory structure is as follows:

- build
- engine
- - include
- - source
- game
- - include
- - source
- resources
- scripts

I have managed to install the shared library with the command:

install(TARGETS Engine
  EXPORT Engine
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib)
install(EXPORT Engine DESTINATION lib)

This creates the following file: build/engine/CMakeFiles/Export/lib/Engine.cmake

How can I include this file so that I can link my Engine library with my Game executable? I had hoped that it was just a case of using find_package(Engine REQUIRED).

4

1 回答 1

1

您不需要包含 .cmake 文件。

在您add_executable的游戏可执行文件之后,假设您的游戏引擎目标名称为 Game,添加以下内容:

target_link_libraries(Game Engine)

cmake 将在幕后完成所有魔法,确保引擎在游戏之前构建,然后为您将游戏链接到引擎。

于 2013-10-15T01:17:42.767 回答