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