2

What would be the best approach to bring external dependencies into cross-platform CMake project? See below the problem scope and solutions I see.

Problem Scope

Let's say we have a C/C++ project with following constraints:

  • CMake is the build system;
  • Has to be built for different platforms (Desktops, Android NDK / Yocto SDK, iOS);
  • Has external dependencies built with CMake (ex. Google Test);
  • Has external non-CMake based dependencies (ex. SQLite amalgamation, Boost);
  • Not all dependencies have Git upstream (ex. SQLite is kept in fossil).

Nice to have things:

  • Dependencies are automatically downloaded, so that new devs have less steps to start coding;
  • Dependencies are configured in a way that IDE's (like CLion) can do autocomplete (without extra configuration steps to be done).

Possible Solutions

  • Git Sub-modules (not clear what to do with non-Cmake based and not kept in Git dependencies);
  • Google Repo tool (the same issues as for previous);
  • CMake ExternalProject (download, unpack and potentially patch with CMakeLists.txt during generation phase and include to project with add_subdirectory). I have created a PoC[1] based on Craig Scott's[2] answer in [3].

References

Vladimir Berlev
  • 502
  • 4
  • 16
  • 1
    You have 2 approaches with downsides and one - ExternalProject - without them. So, why do not follow the third approach? What is a **question**? – Tsyvarev Jan 11 '20 at 15:44
  • @Tsyvarev, I'm looking forward to know approaches I didn't think of. – Vladimir Berlev Jan 12 '20 at 14:45
  • Given such very generic information looking for approaches is just a "**recommendation**" question which we tend to avoid on Stack Overflow. We prefer to concentrate on a **specific problem** instead. See [help/on-topic]. – Tsyvarev Jan 12 '20 at 14:50
  • @Tsyvarev, I think the topic is quite specific (given all the constraints) but also quite conceptual. Due to the lack of clear guidance in cases like that I think the question brings a good value. – Vladimir Berlev Jan 12 '20 at 17:57
  • Actually, these "constraints" have **vague** meaning. E.g. you write "Has to be built for different platforms ... Android NDK", and comment to the answer that `FetchContent` module is not accessible in Android NDK. But is this a real problem? One could easily **ship** his/her project with `FetchContent.cmake` module **copied** from official CMake for work in old CMake versions. Then, you want to work both with CMake and non-CMake-based dependencies. But what prevents to process these two kinds dependencies **differently**? – Tsyvarev Jan 12 '20 at 19:57
  • So you question is actually about processing external dependencies in CMake project in **general**. Far **too broad** for Stack Overflow. – Tsyvarev Jan 12 '20 at 19:58

1 Answers1

1

Your PoC might work, but CMake has a built in solution for fetching external projects during the configure step. If this does not satisfy your requirements like non CMake based dependencies, you may have a look at Conan.

https://blog.conan.io/2018/06/11/Transparent-CMake-Integration.html

zer0
  • 451
  • 4
  • 10
  • FetchContent is great and elides this ugly execution step in my PoC, but seems this module is not available in CMake version shipped with Android NDK. – Vladimir Berlev Jan 12 '20 at 17:59