From e19d73321d0230a0e3cca2758457e4d0e3b7d1f9 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Wed, 14 Feb 2024 16:20:59 -0800 Subject: [PATCH] build: Only ever build static or shared libraries, but never both (#1343) Closes #1341 --- packager/CMakeLists.txt | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/packager/CMakeLists.txt b/packager/CMakeLists.txt index a0f8810aa2..243a1efdab 100644 --- a/packager/CMakeLists.txt +++ b/packager/CMakeLists.txt @@ -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