build: Only ever build static or shared libraries, but never both (#1343)

Closes #1341
This commit is contained in:
Joey Parrish 2024-02-14 16:20:59 -08:00 committed by GitHub
parent 1f71fa0a0e
commit e19d73321d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 26 deletions

View File

@ -112,36 +112,23 @@ set(libpackager_deps
)
# A static library target is always built.
add_library(libpackager_static STATIC ${libpackager_sources})
target_link_libraries(libpackager_static ${libpackager_deps})
# And always installed as libpackager.a / libpackager.lib:
if(NOT MSVC)
set_property(TARGET libpackager_static PROPERTY OUTPUT_NAME packager)
if(BUILD_SHARED_LIBS)
add_library(libpackager SHARED ${libpackager_sources})
target_link_libraries(libpackager ${libpackager_deps})
target_compile_definitions(libpackager PUBLIC SHAKA_IMPLEMENTATION)
else()
set_property(TARGET libpackager_static PROPERTY OUTPUT_NAME libpackager)
add_library(libpackager STATIC ${libpackager_sources})
target_link_libraries(libpackager ${libpackager_deps})
endif()
# A shared library target is conditional (default OFF):
if(BUILD_SHARED_LIBS)
add_library(libpackager_shared SHARED ${libpackager_sources})
target_link_libraries(libpackager_shared ${libpackager_deps})
target_compile_definitions(libpackager_shared PUBLIC SHAKA_IMPLEMENTATION)
# And always installed as libpackager.so / libpackager.dll:
if(NOT MSVC)
set_property(TARGET libpackager_shared PROPERTY OUTPUT_NAME packager)
else()
set_property(TARGET libpackager_shared PROPERTY OUTPUT_NAME libpackager)
endif()
# If we're building a shared library, this is what the "libpackager" target
# aliases to.
add_library(libpackager ALIAS libpackager_shared)
# The library is always installed as
# libpackager.so / libpackager.dll / libpackager.a / libpackager.lib:
if(NOT MSVC)
# The "lib" prefix is implied outside of MSVC.
set_property(TARGET libpackager PROPERTY OUTPUT_NAME packager)
else()
# If we're not building a shared library, the "libpackager" target aliases to
# the static library.
add_library(libpackager ALIAS libpackager_static)
set_property(TARGET libpackager PROPERTY OUTPUT_NAME libpackager)
endif()
add_executable(packager
@ -256,7 +243,7 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pssh-box-protos
# The static library isn't usable as a standalone because it doesn't include
# its static dependencies (zlib, absl, etc).
if(BUILD_SHARED_LIBS)
install(TARGETS libpackager_shared)
install(TARGETS libpackager)
install(DIRECTORY ../include/packager
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/packager.pc