Skip to content

Commit

Permalink
Merge pull request #1278 from paullouisageneau/fix-static-deps-install
Browse files Browse the repository at this point in the history
CMake: Prevent installing static deps when building shared library
  • Loading branch information
paullouisageneau authored Oct 24, 2024
2 parents 4e95467 + 4bfb6cc commit 444e9da
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ endif()
target_compile_definitions(datachannel-static PRIVATE RTC_EXPORTS)
target_compile_definitions(datachannel-static PUBLIC RTC_STATIC)

if(NOT BUILD_SHARED_DEPS_LIBS)
if(BUILD_SHARED_LIBS AND NOT BUILD_SHARED_DEPS_LIBS)
set(BUILD_SHARED_LIBS OFF)
set(INSTALL_DEPS_LIBS OFF)
else()
set(INSTALL_DEPS_LIBS ON)
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
Expand Down Expand Up @@ -304,19 +307,20 @@ else()
endif()
add_library(Usrsctp::Usrsctp ALIAS usrsctp)

# usrsctp lacks an export set
install(TARGETS usrsctp EXPORT UsrsctpTargets)
install(EXPORT UsrsctpTargets
FILE UsrsctpTargets.cmake
NAMESPACE Usrsctp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/usrsctp
EXCLUDE_FROM_ALL)

# Fix directories
set_target_properties(usrsctp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
target_include_directories(usrsctp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/usrsctp/usrsctplib>
$<INSTALL_INTERFACE:>)
if(INSTALL_DEPS_LIBS)
# usrsctp lacks an export set
install(TARGETS usrsctp EXPORT UsrsctpTargets)
install(EXPORT UsrsctpTargets
FILE UsrsctpTargets.cmake
NAMESPACE Usrsctp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/usrsctp
EXCLUDE_FROM_ALL)
# Fix directories
set_target_properties(usrsctp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
target_include_directories(usrsctp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/usrsctp/usrsctplib>
$<INSTALL_INTERFACE:>)
endif()
endif()

target_include_directories(datachannel PUBLIC
Expand Down Expand Up @@ -376,7 +380,9 @@ else()
else()
if(NOT TARGET srtp2)
add_subdirectory(deps/libsrtp EXCLUDE_FROM_ALL)
install(TARGETS srtp2)
if(INSTALL_DEPS_LIBS)
install(TARGETS srtp2)
endif()
endif()
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_SRTP=0)
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_SRTP=0)
Expand Down Expand Up @@ -454,7 +460,9 @@ else()
target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuice)
else()
add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
install(TARGETS juice)
if(INSTALL_DEPS_LIBS)
install(TARGETS juice)
endif()
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_JUICE=0)
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_JUICE=0)
target_link_libraries(datachannel PRIVATE LibJuice::LibJuice)
Expand Down

0 comments on commit 444e9da

Please sign in to comment.