0

I'm trying to download a dependency from GitHub, build it, and link to it.

# External dependency
ExternalProject_Add(libdatachannel
    GIT_REPOSITORY      git@github.com:paullouisageneau/libdatachannel.git
    GIT_TAG             v0.18.0
    GIT_PROGRESS        TRUE
    GIT_SHALLOW         TRUE
)


# My library - actual main target
add_library(
    test
    SHARED
    src/main/cpp/test.cpp # and so on
)

add_dependencies(test libdatachannel)

Now libdatachannel uses CMake. But it does not build a static variant by default, using EXCLUDE_FROM_ALL:

https://github.com/paullouisageneau/libdatachannel/blob/v0.18.0/CMakeLists.txt#L237

Question 1 - how can I build this custom target inside libdatachannel - datachannel-static?

Question 2 - how can I set include paths for accessing datachannel includes from my test library - as well as link to the static version of datachannel?

Question 3 - Libdatachannel's readme file here

https://github.com/paullouisageneau/libdatachannel/blob/v0.18.0/BUILDING.md

mentions that "The CMake build exports the targets with namespace LibDataChannel::LibDataChannel and LibDataChannel::LibDataChannelStatic to link the library from another CMake project".

I'm not sure how to use these custom targets exported by libdatachannel in my project.

I tried this, but got errors from cmake:

target_link_libraries(plugin PRIVATE LibDataChannel::LibDataChannelStatic)

I'm running the top level CMake project as part of an Android build which uses Gradle and specific stanzas to invoke CMake.

starball
  • 20,030
  • 7
  • 43
  • 238
  • "how can I build this custom target" - You could specify for `ExternalProject_Add` call the exact command for building the project. E.g. `BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} datachannel-static`. "how can I set include paths ..." - [that question](https://stackoverflow.com/questions/15175318/cmake-how-to-build-external-projects-and-include-their-targets) and its answers contain possible ways for use library which is built via ExternalProject. – Tsyvarev Dec 25 '22 at 09:35
  • "The CMake build exports the targets ..." - This is for the case when libdatachannel project is build alongside with the consuming project, that is included via `add_subdirectory` or FetchContent functionality. `ExternalProject_Add` builds libdatachannel project in separate environment, so its targets are not accessible to the main project. – Tsyvarev Dec 25 '22 at 09:37

0 Answers0