The library libwebrtc
from https://github.com/cloudwebrtc/libwebrtc-build/blob/dev/CMakeLists.txt was built to be used with make; make install
and the project which wants to use the library must later use the find_package
from CMake.
I, however, want to change libwebrtc
so it can be added as a git submodule into my current project as a custom library, as, for instance, https://github.com/itay-grudev/SingleApplication which is compiled when I type: cmake ..; make into a static/dynamic library and then linked in my main application. (The Qt library example I references earlier was confusing since this is build outside of my main project and only linked to afterwards - which is not what I want). Sorry for that confusion.
To be able to do that, I think that the ExternalProject_Add
at https://github.com/cloudwebrtc/libwebrtc-build/blob/a24a5e5947658d43339d4bfd85d3f4c52fc71057/CMakeLists.txt#L100 must be changed into a add_library
call.
The problem here is that the include_directories
is used by the main project before the library has been completely built.
Question
How to rewrite libwebrtc
to be used as a simple static library with proper build dependencies so that my main project is only compiled/linked after the libwebrtc
build was finished and custom header files were generated in the CMAKE_CURRENT_BINARY_DIR
of libwebrtc
.
Or in other words, how to rewrite libwebrtc
to be used without having to call make install
for the library and then use find_package
to use that library.
The hack (which is working already)
With this hack I am already able to:
- Build the library from my parent project
- Depend on the generated header files which exist only after the
libwebrtc
has been built completely (thus, delay main project building until dependencies are meet) - Depend on the generated webrtc.a static library for the linker step
I imaging that make install
will work since libwebrtc
is statically linked.
add_dependencies(${PROJECT_NAME} libwebrtcx)
add_subdirectory(third-party/libwebrtcx)
include_directories(
${CMAKE_BINARY_DIR}/sources/third-party/libwebrtcx/include/webrtc
${CMAKE_BINARY_DIR}/sources/third-party/libwebrtcx/include/webrtc/third_party/libyuv/include/
${CMAKE_BINARY_DIR}/sources/third-party/libwebrtcx/webrtc/src/third_party/abseil-cpp
)
add_library(libwebrtc STATIC IMPORTED)
set_property(TARGET libwebrtc PROPERTY IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/sources/third-party/libwebrtcx/webrtc/src/out/Release/obj/libwebrtc.a")
target_link_libraries(${PROJECT_NAME} libwebrtc)
Note: It requires to rename the libwebrtc project to libwebrtcx and also the ExternalProject_Add
at https://github.com/cloudwebrtc/libwebrtc-build/blob/a24a5e5947658d43339d4bfd85d3f4c52fc71057/CMakeLists.txt#L100 must be renamed to libwebrtcx.
Note: It also requires to rename all CMAKE_BINARY_DIR
into CMAKE_CURRENT_BINARY_DIR
and CMAKE_SOURCE_DIR
to CMAKE_CURRENT_SOURCE_DIR
. Details can be found here: CMake: Using add_subproject with a library using Include ends up in wrong relative path