0

Lets say I have two CMake projects - an ExternalProject E and my current project P. E provides two ways to interface with it - It creates a pkg-config file and .cmake file. I wish to use either of these two options to for using E in P.

In P's build, I need to achieve the following steps:

  1. Build E
  2. Install E. This step would create pkg-config files (E.pc) or CMake exported targets file (ETargets.cmake)
  3. Use E.pc or ETargets.cmake in P for including E's headers and linking against E's libraries.

I couldn't get my build to work with following options:

  1. include(ETargets.cmake) in P's CMakeLists.txt. This doesn't work since ETargets.cmake is not present at configure time.
  2. I didn't find a way to extract information in E.pc from CMakeLists.txt in CMake's documentation.
  3. add_custom_command and add_custom_target route detailed here for dealing with generated files. This might/might not work, but either way it will introduce lot of boiler plate in my build.

Only solutions I can find are

  1. Install E manually and then use .cmake or .pc files in P (detailed in answers here).
  2. Manually scavenging through directory installed by E to find required libraries. (detailed here).

Both the solutions outsource some work to outside of CMake build hence are not satisfactory.

  • I am assuming you have you thought about using `ExternalProject_Add`? https://cmake.org/cmake/help/latest/module/ExternalProject.html – Cinder Biscuits Sep 17 '19 at 14:38
  • ExternalProject_Add(E) builds project E at build time. Therefore, .cmake and .pc files cannot be used to configure P (Point 1 in options I tried). – Aravind Nujella Sep 17 '19 at 15:19
  • 1
    So you need to build and install E project at *configure* time of the A project. For that, you may use plain `execute_process`. Alternatively you may use project E via `add_subdirectory` in the project A. – Tsyvarev Sep 17 '19 at 16:19

0 Answers0