2
votes

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).

1

1 Answers

1
votes

You don't need to include the .cmake file.

After your add_executable for the game executable, add the following assuming your game engines target name is Game:

target_link_libraries(Game Engine)

cmake will do all the magic behind the scenes making sure that the engine is built before the game and then link the game to the engine for you.