diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d8401db1b..b267dd359b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,3 +24,4 @@ enable_testing() # Subdirectories with their own CMakeLists.txt add_subdirectory(packager) +add_subdirectory(link-test) diff --git a/link-test/CMakeLists.txt b/link-test/CMakeLists.txt new file mode 100644 index 0000000000..92e54748f7 --- /dev/null +++ b/link-test/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright 2023 Google LLC. All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + +# If we're building a shared library, make sure it works. We only do this for +# a shared library because the static library won't wrap the third-party +# dependencies like absl. +if(LIBPACKAGER_SHARED) + # Install the library and headers to a temporary location. + set(TEST_INSTALL_DIR ${CMAKE_BINARY_DIR}/test-install) + + add_custom_target(test-install ALL + DEPENDS mpd_generator packager libpackager + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND + ${CMAKE_COMMAND} --install . --prefix ${TEST_INSTALL_DIR} --config "$") + + # Then try to build a very simplistic test app to prove that we can include + # the headers and link the library. + add_executable(packager_link_test test.cc) + add_dependencies(packager_link_test test-install) + target_link_directories(packager_link_test PRIVATE ${TEST_INSTALL_DIR}/lib) + target_include_directories(packager_link_test PRIVATE ${TEST_INSTALL_DIR}/include) + if(NOT MSVC) + target_link_libraries(packager_link_test -lpackager) + else() + target_link_libraries(packager_link_test ${TEST_INSTALL_DIR}/lib/libpackager.lib) + endif() +endif() diff --git a/link-test/README.md b/link-test/README.md new file mode 100644 index 0000000000..d1b5ec212a --- /dev/null +++ b/link-test/README.md @@ -0,0 +1,5 @@ +# Link test for libpackager + +This is a dummy application to test linking libpackager. It gives us a build +target that validates our install target works and that our public headers (in +`../include/packager/...`) are complete and self-contained. diff --git a/link-test/test.cc b/link-test/test.cc new file mode 100644 index 0000000000..f46e6dd99a --- /dev/null +++ b/link-test/test.cc @@ -0,0 +1,35 @@ +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +// This is a simple app to test linking against a shared libpackager on all +// platforms. It's not meant to do anything useful at all. + +#include +#include + +#include + +int main(int argc, char** argv) { + // Unused. Silence warnings. + (void)argc; + (void)argv; + + // Print the packager version. + std::cout << "Packager v" + shaka::Packager::GetLibraryVersion() + "\n"; + + // Don't bother filling these out. Just make sure it links. + shaka::PackagingParams packaging_params; + std::vector stream_descriptors; + + // This will fail. + shaka::Packager packager; + shaka::Status status = + packager.Initialize(packaging_params, stream_descriptors); + + // Just print the status to make sure we can do that in a custom app. + std::cout << status.ToString() + "\n"; + return 0; +} diff --git a/packager/CMakeLists.txt b/packager/CMakeLists.txt index 29e9661f23..59e1f1f0b5 100644 --- a/packager/CMakeLists.txt +++ b/packager/CMakeLists.txt @@ -6,6 +6,9 @@ # Packager CMake build file. +# Include a module to define standard install directories. +include(GNUInstallDirs) + # Build static libs by default, or shared if LIBPACKAGER_SHARED is defined. if(LIBPACKAGER_SHARED) add_definitions(-DSHARED_LIBRARY_BUILD) @@ -114,6 +117,10 @@ target_link_libraries(libpackager string_utils version ) +# Avoid liblibpackager on Windows: +if(NOT MSVC) + set_property(TARGET libpackager PROPERTY OUTPUT_NAME packager) +endif() add_executable(packager app/ad_cue_generator_flags.cc @@ -183,3 +190,14 @@ target_link_libraries(packager_test gmock gtest gtest_main) + +configure_file(packager.pc.in packager.pc @ONLY) + + +install(TARGETS mpd_generator packager libpackager + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(DIRECTORY ../include/packager + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +install(FILES tools/pssh/pssh-box.py DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES ${CMAKE_BINARY_DIR}/packager/packager.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/packager/common.gypi b/packager/common.gypi deleted file mode 100644 index 31e68d21c0..0000000000 --- a/packager/common.gypi +++ /dev/null @@ -1,149 +0,0 @@ -# Copyright 2014 Google LLC. All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd -# -# This file contains common settings for building packager components. - -{ - 'variables': { - 'variables': { - 'shaka_code%': 0, - # musl is a lightweight C standard library used in Alpine Linux. - 'musl%': 0, - # This is a flag from build/common.gypi to allow linker warnings. - # This may be necessary with static_link_binaries=1. - 'disable_fatal_linker_warnings%': '0', - 'libpackager_type%': 'static_library', - 'static_link_binaries%': '0', - }, - - 'shaka_code%': '<(shaka_code)', - 'musl%': '<(musl)', - 'disable_fatal_linker_warnings%': '<(disable_fatal_linker_warnings)', - 'libpackager_type%': '<(libpackager_type)', - 'static_link_binaries%': '<(static_link_binaries)', - - 'conditions': [ - ['shaka_code==1', { - # This enable warnings and warnings-as-errors. - 'chromium_code': 1, - }], - # These are some Chromium build settings that are normally keyed off of - # component=="shared_library". We don't use component=="shared_library" - # because it would result in a shared lib for every single component, but - # we still need these settings for a shared library build of libpackager - # on Windows. - ['libpackager_type=="shared_library"', { - # Make sure we use a dynamic CRT to avoid issues with std::string in - # the library API on Windows. - 'win_release_RuntimeLibrary': '2', # 2 = /MD (nondebug DLL) - 'win_debug_RuntimeLibrary': '3', # 3 = /MDd (debug DLL) - # Skip the Windows allocator shim on Windows. Using this with a shared - # library results in build errors. - 'win_use_allocator_shim': 0, - }], - ], - }, - 'target_defaults': { - 'defines': [ - # These defines make the contents of base/mac/foundation_util.h compile - # against the standard OSX SDK, by renaming Chrome's opaque type and - # using the real OSX type. This was not necessary before we switched - # away from using hermetic copies of clang and the sysroot to build. - 'OpaqueSecTrustRef=__SecACL', - 'OpaqueSecTrustedApplicationRef=__SecTrustedApplication', - ], - 'conditions': [ - ['shaka_code==1', { - 'include_dirs': [ - '.', - '..', - ], - 'cflags': [ - # This is triggered by logging macros. - '-Wno-implicit-fallthrough', - # Triggered by unit tests, which override things in mocks. gmock - # doesn't mark them as override. An upgrade may help. TODO: try - # upgrading gmock. - '-Wno-inconsistent-missing-override', - # Triggered by base/time/time.h when using clang, but NOT on Mac. - '-Wno-implicit-const-int-float-conversion', - ], - 'xcode_settings': { - 'WARNING_CFLAGS': [ - # This is triggered by logging macros. - '-Wno-implicit-fallthrough', - # Triggered by unit tests, which override things in mocks. gmock - # doesn't mark them as override. An upgrade may help. TODO: try - # upgrading gmock. - '-Wno-inconsistent-missing-override', - ], - }, - # TODO(kqyang): Fix these msvs warnings. - 'msvs_disabled_warnings': [ - 4125, # Decimal digit terminates octal escape sequence, e.g. "\709". - 4819, # The file contains a character that cannot be represented in - # the current code page. It typically happens when compiling - # the code in CJK environment if there is non-ASCII characters - # in the file. - 4251, # Warnings about private std::string in Status in a shared - # library config on Windows. - ], - }, { - # We do not have control over non-shaka code. Disable some warnings to - # make build pass. - 'cflags': [ - '-Wno-error', - ], - 'variables': { - 'clang_warning_flags': [ - '-Wno-error', - ], - }, - 'xcode_settings': { - 'WARNING_CFLAGS': [ - '-Wno-error', - ], - }, - 'msvs_disabled_warnings': [ - 4819, # The file contains a character that cannot be represented in - # the current code page. It typically happens when compiling - # the code in CJK environment if there is non-ASCII characters - # in the file. - ], - }], - ['musl==1', { - 'defines': [ - # musl is not uClibc but is similar to uClibc that a minimal feature - # set is supported. One of Shaka Packager's dependencies, Chromium - # base uses __UCLIBC__ flag to disable some features, which needs to - # be disabled for musl too. - '__UCLIBC__', - ], - 'cflags!': [ - # Do not treat warnings as errors on musl as there is a hard-coded - # warning in musl's sys/errno.h. - '-Werror', - ], - }], - ['static_link_binaries==1', { - 'conditions': [ - ['OS=="linux"', { - 'defines': [ - # Even when we are not using musl or uClibc, pretending to use - # uClibc on Linux is the only way to disable certain Chromium - # base features, such as hooking into malloc. Hooking into - # malloc, in turn, fails when we are linking statically. - '__UCLIBC__', - ], - }], - ], - 'ldflags': [ - '-static', - ], - }], - ], - }, -} diff --git a/packager/packager.pc.in b/packager/packager.pc.in new file mode 100644 index 0000000000..1e20cd4f48 --- /dev/null +++ b/packager/packager.pc.in @@ -0,0 +1,18 @@ +# Copyright (c) 2021-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD3 license found in the +# LICENSE file in the root directory of this source tree. + +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ + +Requires: +Libs: -L${libdir} -lpackager +Cflags: -I${includedir}