Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Prevent installing static deps when building shared library #1278

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading