2

I'm trying to depend on a non-cmake, header-only, git library. The following seems to work:

include(ExternalProject)
ExternalProject_Add(${REPO}-external
    GIT_REPOSITORY [... path to repo ... ]
    GIT_TAG [... some git tag ... ]
    SOURCE_DIR external/${REPO}
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    CONFIGURE_COMMAND "")
add_library(${REPO} INTERFACE)
add_dependencies(${REPO} ${REPO}-external)
target_include_directories(${REPO} SYSTEM INTERFACE external/${REPO}/include)

But this seems really convoluted, and I expect that I'm just missing some basics about how to properly use this function. Is there a more direct approach?

Barry
  • 286,269
  • 29
  • 621
  • 977
  • Your approach is quite common, but there are other approaches, depending on your additional needs. What exactly seems "convoluted" here? `I'm just missing some basics about how to properly use this function.` - Which function you are talking about? – Tsyvarev Feb 28 '18 at 07:52
  • Is your project itself hosted on a Git platform? Then you could work with [Git Submodules](https://git-scm.com/docs/git-submodule). For an example see ["Basic CMake C++ project structure"](https://codereview.stackexchange.com/questions/176508/basic-cmake-c-project-structure) on Code Review. – Florian Feb 28 '18 at 08:45
  • @Tsyvarev The fact that I have this arbitrary `-external` name that I need to depend on seems weird to me. – Barry Feb 28 '18 at 13:39
  • @Florian I am not sure that git submodules have any advantages over this approach, and there are clear disadvantages. – Barry Feb 28 '18 at 13:40
  • `${REPO}-external` is a name of the *target* which performs "git clone". BTW, it is you who names it so. Once you have described the *INTERFACE* library, you may forget about this "external" name. – Tsyvarev Feb 28 '18 at 13:44
  • 1
    An alternative would be to use `execute_process()` like in my answer [here](https://stackoverflow.com/questions/48955632/finding-direct3d-12-using-cmake/48975072#48975072). – Florian Feb 28 '18 at 13:45

0 Answers0