0

I have a CMake project named proj1, which I want to use as an external project in another project, proj2. Now, the (relevant) command in proj1's CMakeLists.txt is:

install(
    TARGETS proj1
    ARCHIVE
    DESTINATION lib
    EXPORT proj1_library
    INCLUDES DESTINATION include
    CONFIGURATIONS Release RelWithDebugInfo
)

and I want to use this static library in proj2, without explicitly "guessing" where it's installed to be proj1. I want to be able to get obtain this target from proj1 (which I obtain using ExternalProject), then use it - directly or indirectly - in add_target_libraries() commands.

How should I do that? And - do I only need to make changes to proj2 or also to proj1's CMakeLists.txt?

einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

0

Exporting the targets is the right approach.

To support this, proj1 would have to generate a proj1Config.cmake in both its build tree and also in the install tree (so that a development package for proj1 can be used as a SDK [1])

I suggest you read the following section of the CMake documentation, it covers the different concepts and provides an example. See https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-packages

[1] SDK: https://en.wikipedia.org/wiki/Software_development_kit

J-Christophe
  • 1,975
  • 15
  • 13
  • Thank you, but - in SO answers it's customary to provide an in-place answer rather than a link. Can you descirbe how such a `.cmake` file is to be generated and used? Or at least give an example? – einpoklum Aug 03 '18 at 08:03