diff --git a/.github/build_windows.bat b/.github/build_windows.bat index 836e44c00..5f8fb8413 100644 --- a/.github/build_windows.bat +++ b/.github/build_windows.bat @@ -1,3 +1,4 @@ +REM NOTE: May need to replace "Enterprise" with "Community" int the below command call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" mkdir build cd build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22a8bb264..8419befc5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: - master jobs: clang-format-check: - runs-on: macos-11 + runs-on: macos-latest steps: - name: Clone repository uses: actions/checkout@v3 @@ -24,20 +24,19 @@ jobs: bash scripts/check-clang.sh mac-os-build-gcc: - runs-on: macos-12 + runs-on: macos-latest permissions: id-token: write contents: read env: - CC: /usr/local/bin/gcc-13 - CXX: /usr/local/bin/g++-13 + CC: gcc-13 + CXX: g++-13 AWS_KVS_LOG_LEVEL: 2 steps: - name: Clone repository uses: actions/checkout@v3 - name: Build repository run: | - brew install pkgconfig brew unlink openssl # it seems the libcurl is trying to access this openssl despite explicitly setting it to our build mkdir build && cd build cmake .. --trace -DBUILD_TEST=TRUE @@ -55,7 +54,7 @@ jobs: ./tst/producer_test mac-os-build-clang: - runs-on: macos-11 + runs-on: macos-latest env: AWS_KVS_LOG_LEVEL: 2 permissions: @@ -66,7 +65,6 @@ jobs: uses: actions/checkout@v3 - name: Build repository run: | - brew install pkgconfig brew unlink openssl # it seems the libcurl is trying to access this openssl despite explicitly setting it to our build mkdir build && cd build cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE @@ -95,10 +93,9 @@ jobs: uses: actions/checkout@v3 - name: Build repository run: | - brew install pkgconfig brew unlink openssl # it seems the libcurl is trying to access this openssl despite explicitly setting it to our build mkdir build && cd build - sh -c 'cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE -DCMAKE_C_COMPILER=$(brew --prefix llvm@15)/bin/clang -DCMAKE_CXX_COMPILER=$(brew --prefix llvm@15)/bin/clang++;cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE -DCMAKE_C_COMPILER=$(brew --prefix llvm@15)/bin/clang -DCMAKE_CXX_COMPILER=$(brew --prefix llvm@15)/bin/clang++' + cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE -DCMAKE_C_COMPILER=$(brew --prefix llvm@15)/bin/clang -DCMAKE_CXX_COMPILER=$(brew --prefix llvm@15)/bin/clang++ make - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1-node16 @@ -112,14 +109,14 @@ jobs: cd build ./tst/producer_test - mac-os-build-gcc-local-openssl: - runs-on: macos-11 + mac-os-build-gcc-system-openssl: + runs-on: macos-latest permissions: id-token: write contents: read env: - CC: /usr/local/bin/gcc-13 - CXX: /usr/local/bin/g++-13 + CC: gcc-13 + CXX: g++-13 AWS_KVS_LOG_LEVEL: 2 LDFLAGS: -L/usr/local/opt/openssl@3/lib CPPFLAGS: -I/usr/local/opt/openssl@3/include @@ -131,7 +128,7 @@ jobs: run: | brew info openssl mkdir build && cd build - cmake .. -DBUILD_TEST=TRUE -DLOCAL_OPENSSL_BUILD=ON + cmake .. -DBUILD_TEST=TRUE -DBUILD_CRYPTO=FALSE make - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1-node16 @@ -145,7 +142,7 @@ jobs: cd build ./tst/producer_test - mac-os-build-clang-local-openssl: + mac-os-build-clang-system-openssl: runs-on: macos-latest env: AWS_KVS_LOG_LEVEL: 2 @@ -160,9 +157,10 @@ jobs: uses: actions/checkout@v3 - name: Build repository run: | + brew install googletest brew info openssl mkdir build && cd build - cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE -DLOCAL_OPENSSL_BUILD=ON + cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE -DBUILD_CRYPTO=FALSE make - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1-node16 @@ -176,6 +174,52 @@ jobs: cd build ./tst/producer_test + # Producer is not compatible with latest CURL, so build only, don't run tests. + mac-os-build-gcc-system-deps: + runs-on: macos-latest + permissions: + id-token: write + contents: read + env: + CC: gcc-13 + CXX: g++-13 + AWS_KVS_LOG_LEVEL: 2 + LDFLAGS: -L/usr/local/opt/openssl@3/lib + CPPFLAGS: -I/usr/local/opt/openssl@3/include + OPENSSL_ROOT_DIR: /usr/local/opt/openssl@3/ + steps: + - name: Clone repository + uses: actions/checkout@v3 + - name: Build repository + run: | + brew install googletest + brew info openssl + mkdir build && cd build + cmake .. -DBUILD_TEST=TRUE -DBUILD_DEPENDENCIES=FALSE + make + + # Producer is not compatible with latest CURL, so build only, don't run tests. + mac-os-build-clang-system-deps: + runs-on: macos-latest + env: + AWS_KVS_LOG_LEVEL: 2 + LDFLAGS: -L/usr/local/opt/openssl@3/lib + CPPFLAGS: -I/usr/local/opt/openssl@3/include + OPENSSL_ROOT_DIR: /usr/local/opt/openssl@3/ + permissions: + id-token: write + contents: read + steps: + - name: Clone repository + uses: actions/checkout@v3 + - name: Build repository + run: | + brew install googletest + brew info openssl + mkdir build && cd build + cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE -DBUILD_DEPENDENCIES=FALSE + make + ubuntu-os-gcc-build-lws-mbedtls: runs-on: ubuntu-20.04 env: @@ -391,13 +435,18 @@ jobs: steps: - name: Clone repository uses: actions/checkout@v3 + - name: Move cloned repo # to shorten path length for Windows OS + run: | + git config --system core.longpaths true + mkdir C:\amazon-kinesis-video-streams-producer-c + Move-Item -Path "D:\a\amazon-kinesis-video-streams-producer-c\amazon-kinesis-video-streams-producer-c\*" -Destination "C:\amazon-kinesis-video-streams-producer-c" - name: Install dependencies run: | choco install nasm strawberryperl - name: Build repository run: | - $env:Path += ';C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Strawberry\c\bin;C:\Program Files\NASM;D:\a\amazon-kinesis-video-streams-producer-c\amazon-kinesis-video-streams-producer-c\open-source\lib;D:\a\amazon-kinesis-video-streams-producer-c\amazon-kinesis-video-streams-producer-c\open-source\bin' - git config --system core.longpaths true + $env:Path += ';C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Strawberry\c\bin;C:\Program Files\NASM;C:\amazon-kinesis-video-streams-producer-c\open-source\lib;C:\amazon-kinesis-video-streams-producer-c\open-source\bin' + cd C:\amazon-kinesis-video-streams-producer-c .github/build_windows.bat - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1-node16 @@ -408,8 +457,8 @@ jobs: role-duration-seconds: 10800 - name: Run tests run: | - $env:Path += ';C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Strawberry\c\bin;C:\Program Files\NASM;D:\a\amazon-kinesis-video-streams-producer-c\amazon-kinesis-video-streams-producer-c\open-source\lib;D:\a\amazon-kinesis-video-streams-producer-c\amazon-kinesis-video-streams-producer-c\open-source\bin' - & "D:\a\amazon-kinesis-video-streams-producer-c\amazon-kinesis-video-streams-producer-c\build\tst\producer_test.exe" --gtest_filter="-ProducerFunctionalityTest.pressure_on_buffer_duration_fail_new_connection_at_token_rotation" + $env:Path += ';C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Strawberry\c\bin;C:\Program Files\NASM;C:\amazon-kinesis-video-streams-producer-c\open-source\lib;C:\amazon-kinesis-video-streams-producer-c\open-source\bin' + & "C:\amazon-kinesis-video-streams-producer-c\build\tst\producer_test.exe" --gtest_filter="-ProducerFunctionalityTest.pressure_on_buffer_duration_fail_new_connection_at_token_rotation" arm64-cross-compilation: runs-on: ubuntu-20.04 @@ -430,6 +479,7 @@ jobs: cmake .. -DBUILD_TEST=TRUE -DBUILD_OPENSSL_PLATFORM=linux-generic64 make file libcproducer.so + linux-aarch64-cross-compilation: runs-on: ubuntu-20.04 env: @@ -449,6 +499,7 @@ jobs: cmake .. -DBUILD_TEST=TRUE -DBUILD_OPENSSL_PLATFORM=linux-aarch64 make file libcproducer.so + arm32-cross-compilation: runs-on: ubuntu-20.04 env: diff --git a/.gitignore b/.gitignore index 47291ff12..da7209d13 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ cmake-build-release/ open-source outputs dependency/ -cmake-build-producerc/ \ No newline at end of file +cmake-build-producerc/ +.vscode/settings.json diff --git a/CMake/Dependencies/libcurl-CMakeLists.txt b/CMake/Dependencies/libcurl-CMakeLists.txt index 74e44b520..4248dafc3 100644 --- a/CMake/Dependencies/libcurl-CMakeLists.txt +++ b/CMake/Dependencies/libcurl-CMakeLists.txt @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.6.3) project(libcurl-download LANGUAGES C) -find_program(MAKE_EXE NAMES make) - if (DEFINED CMAKE_OSX_SYSROOT AND NOT CMAKE_OSX_SYSROOT STREQUAL "") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isysroot${CMAKE_OSX_SYSROOT}") endif() diff --git a/CMake/Dependencies/libopenssl-CMakeLists.txt b/CMake/Dependencies/libopenssl-CMakeLists.txt index fbe3d41a2..7f52e3619 100644 --- a/CMake/Dependencies/libopenssl-CMakeLists.txt +++ b/CMake/Dependencies/libopenssl-CMakeLists.txt @@ -18,9 +18,9 @@ else() endif() if (DEFINED BUILD_OPENSSL_PLATFORM AND NOT BUILD_OPENSSL_PLATFORM STREQUAL OFF) - SET(CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/build/src/project_libopenssl/Configure ${OPENSSL_EXTRA} --prefix=${OPEN_SRC_INSTALL_PREFIX} --openssldir=${OPEN_SRC_INSTALL_PREFIX} ${BUILD_OPENSSL_PLATFORM} -Wno-nullability-completeness -Wno-expansion-to-defined) + SET(CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/build/src/project_libopenssl/Configure ${OPENSSL_EXTRA} --prefix=${OPEN_SRC_INSTALL_PREFIX} ${BUILD_OPENSSL_PLATFORM} -Wno-nullability-completeness -Wno-expansion-to-defined) else() - SET(CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/build/src/project_libopenssl/config ${OPENSSL_EXTRA} --prefix=${OPEN_SRC_INSTALL_PREFIX} --openssldir=${OPEN_SRC_INSTALL_PREFIX} -Wno-nullability-completeness -Wno-expansion-to-defined) + SET(CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/build/src/project_libopenssl/config ${OPENSSL_EXTRA} --prefix=${OPEN_SRC_INSTALL_PREFIX} -Wno-nullability-completeness -Wno-expansion-to-defined) endif() endif() diff --git a/CMake/Dependencies/libwebsockets-CMakeLists.txt b/CMake/Dependencies/libwebsockets-CMakeLists.txt index 3ada49e4b..995d08257 100644 --- a/CMake/Dependencies/libwebsockets-CMakeLists.txt +++ b/CMake/Dependencies/libwebsockets-CMakeLists.txt @@ -45,4 +45,4 @@ ExternalProject_Add(project_libwebsockets -DOPENSSL_ROOT_DIR=${OPENSSL_DIR} BUILD_ALWAYS TRUE TEST_COMMAND "" -) +) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e984c8d27..89f10931a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.6.3) + +# Include custom utilites. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}") include(Utilities) + project(KinesisVideoProducerC VERSION 1.5.1 LANGUAGES C) set(KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION 1) @@ -8,22 +11,29 @@ set(KINESIS_VIDEO_PRODUCER_C_MINOR_VERSION 5) set(KINESIS_VIDEO_PRODUCER_C_PATCH_VERSION 1) set(KINESIS_VIDEO_PRODUCER_C_VERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION}.${KINESIS_VIDEO_PRODUCER_C_MINOR_VERSION}.${KINESIS_VIDEO_PRODUCER_C_PATCH_VERSION}) -include(GNUInstallDirs) +set(SUPPORTED_CRYPTO_LIBRARIES "{OpenSSL, MbedTLS}") +# Set CMAKE_INSTALL_ directories based on GNU standard. +include(GNUInstallDirs) # User Flags option(ADD_MUCLIBC "Add -muclibc c flag" OFF) -option(BUILD_STATIC "Static build" OFF) -option(BUILD_DEPENDENCIES "Whether or not to build depending libraries from source" ON) option(USE_OPENSSL "Use openssl as crypto library" ON) option(USE_MBEDTLS "Use mbedtls as crypto library" OFF) -option(BUILD_COMMON_LWS "Whether or not to build ProducerC libwebsockets common library" OFF) -option(BUILD_COMMON_CURL "Whether or not to build ProducerC curl common library" ON) +option(BUILD_STATIC "Static build" OFF) +option(BUILD_DEPENDENCIES "Whether to build dependency libraries from source" ON) # This is a master OFF switch, none will be built if off, but if it is ON, some can be specified to be not built +option(BUILD_COMMON_LWS "Whether to build ProducerC libwebsockets common library" OFF) +option(BUILD_COMMON_CURL "Whether to build ProducerC curl common library" ON) option(BUILD_OPENSSL_PLATFORM "If buildng OpenSSL what is the target platform" OFF) -option(LOCAL_OPENSSL_BUILD "Whether or not to use local OpenSSL build" OFF) +option(BUILD_CRYPTO "Whether to build OpenSSL or MbedTLS, if not, will use system-installed version" ON) +option(BUILD_LWS "Whether to build LibWebSockets, if not, will use system-installed version" ON) +option(BUILD_CURL "Whether to build CURL library, if not, will use system-installed version" ON) +option(BUILD_KVS_PIC "Whether to build PIC SDK, else will use system-installed version" ON) +option(BUILD_SAMPLES "Whether to build Producer C samples" ON) option(CONSTRAINED_DEVICE "Change pthread stack size" OFF) -# Developer Flags + +# Maintainer Flags option(BUILD_TEST "Build the testing tree." OFF) option(CODE_COVERAGE "Enable coverage reporting" OFF) option(COMPILER_WARNINGS "Enable all compiler warnings." OFF) @@ -34,152 +44,210 @@ option(UNDEFINED_BEHAVIOR_SANITIZER "Build with UndefinedBehaviorSanitizer." OFF option(ALIGNED_MEMORY_MODEL "Aligned memory model ONLY." OFF) option(SET_SSL_CALLBACKS "Set SSL thread and lock callbacks." OFF) -set(TYPE_OF_LIB SHARED) +# TODO: Use target_include_directories to not give headers to WHOLE project +# - Print out the dependencies for each target via command line and verify there are no duplicate libraries being linked + + if (BUILD_STATIC) set(TYPE_OF_LIB STATIC) +else() + set(TYPE_OF_LIB SHARED) endif() -set(CMAKE_MACOSX_RPATH TRUE) - -get_filename_component(ROOT "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE) - -add_definitions(-DVERSION_STRING=\"${PROJECT_VERSION}\") - if(CONSTRAINED_DEVICE) - add_definitions(-DCONSTRAINED_DEVICE) + add_definitions(-DCONSTRAINED_DEVICE) endif() +set(CMAKE_MACOSX_RPATH TRUE) +add_definitions(-DVERSION_STRING=\"${PROJECT_VERSION}\") + +# Set where to build this project. if(NOT KINESIS_VIDEO_PRODUCER_C_SRC) - if(DEFINED ENV{KINESIS_VIDEO_PRODUCER_C_SRC}) - set(KINESIS_VIDEO_PRODUCER_C_SRC $ENV{KINESIS_VIDEO_PRODUCER_C_SRC}) - else() - set(KINESIS_VIDEO_PRODUCER_C_SRC "${CMAKE_CURRENT_SOURCE_DIR}") - endif() + if(DEFINED ENV{KINESIS_VIDEO_PRODUCER_C_SRC}) + set(KINESIS_VIDEO_PRODUCER_C_SRC $ENV{KINESIS_VIDEO_PRODUCER_C_SRC}) + else() + set(KINESIS_VIDEO_PRODUCER_C_SRC "${CMAKE_CURRENT_SOURCE_DIR}") + endif() endif() - message(STATUS "Kinesis Video Producer path is ${KINESIS_VIDEO_PRODUCER_C_SRC}") +# NOTE: The windows CI build has CMAKE_BUILD_TYPE set to debug, probably due to MSVC environment, TODO: look into this +# Default to release build if unspecified. if(NOT CMAKE_BUILD_TYPE) - message(STATUS "Setting CMAKE_BUILD_TYPE to Release by default") - set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) + message(STATUS "Setting CMAKE_BUILD_TYPE to Release by default") + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) +else() + message(STATUS "CMAKE_BUILD_TYPE is set to: ${CMAKE_BUILD_TYPE}") endif() + +# Fetch and build 3rd-party dependencies if specified. if(BUILD_DEPENDENCIES) + message(STATUS "Begin building dependencies.") + + # Set directory where to build the dependencies. if (NOT OPEN_SRC_INSTALL_PREFIX) - set(OPEN_SRC_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/open-source) + set(OPEN_SRC_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/open-source) set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${OPEN_SRC_INSTALL_PREFIX}/lib/pkgconfig") set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${OPEN_SRC_INSTALL_PREFIX}) endif() + # Create the dependency directory if it doesn't exist. if(NOT EXISTS ${OPEN_SRC_INSTALL_PREFIX}) file(MAKE_DIRECTORY ${OPEN_SRC_INSTALL_PREFIX}) endif() - message(STATUS "Begin building dependencies.") - + # Verify only one of SUPPORTED_CRYPTO_LIBRARIES are selected. set(SSL_OPTIONS USE_OPENSSL USE_MBEDTLS) - count_true(ENABLED_SSL_OPTION_COUNT - ${SSL_OPTIONS}) - + count_true(ENABLED_SSL_OPTION_COUNT ${SSL_OPTIONS}) if(ENABLED_SSL_OPTION_COUNT GREATER "1") message(FATAL_ERROR "Only one of ${SSL_OPTIONS} can be enabled") endif() - if(NOT LOCAL_OPENSSL_BUILD) - message(STATUS "Building non-local OpenSSL") + # If building the specified crypto library from source + if(BUILD_CRYPTO) if(USE_OPENSSL) - set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC} - -DBUILD_OPENSSL_PLATFORM=${BUILD_OPENSSL_PLATFORM}) + message(STATUS "Building OpenSSL") + set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC} -DBUILD_OPENSSL_PLATFORM=${BUILD_OPENSSL_PLATFORM}) build_dependency(openssl ${BUILD_ARGS}) elseif(USE_MBEDTLS) + message(STATUS "Building MbedTLS") set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}) build_dependency(mbedtls ${BUILD_ARGS}) else() - message(FATAL_ERROR "No crypto library selected.") + message(FATAL_ERROR "No crypto library selected. Please specify one of the following: " ${SUPPORTED_CRYPTO_LIBRARIES}) endif() endif() - if (BUILD_COMMON_LWS) + # If building KVS Producer C Common Curl, build curl. + if (BUILD_COMMON_CURL AND BUILD_CURL) set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DOPENSSL_DIR=${OPEN_SRC_INSTALL_PREFIX} - -DUSE_OPENSSL=${USE_OPENSSL} -DUSE_MBEDTLS=${USE_MBEDTLS}) - build_dependency(websockets ${BUILD_ARGS}) + build_dependency(curl ${BUILD_ARGS}) endif() - if (BUILD_COMMON_CURL) + # If building KVS Producer C Common LWS, build libwebsockets. + # NOTE: This version of LWS does not build succesfully on Mac due to a LWS bug. + if (BUILD_COMMON_LWS AND BUILD_LWS) set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DUSE_OPENSSL=${USE_OPENSSL} + -DOPENSSL_DIR=${OPEN_SRC_INSTALL_PREFIX} -DUSE_MBEDTLS=${USE_MBEDTLS}) - build_dependency(curl ${BUILD_ARGS}) - + build_dependency(websockets ${BUILD_ARGS}) endif() + # If building KVS Producer C tests, build gtest. if(BUILD_TEST) build_dependency(gtest) endif() message(STATUS "Finished building dependencies.") + +# GTest MUST be built if using GCC compiler because Mac system-built GTest uses Clang. +# Clang-built GTest is not compatible with GCC-built libraries. This check expects the +# CC env var to be set in the following format: "export CC=/gcc-". +# We currently only test with BUILD_DEPENDENCIES=OFF on Mac CI. +elseif(BUILD_TEST AND APPLE AND DEFINED ENV{CC}) + # Set directory where to build the dependencies. + if (NOT OPEN_SRC_INSTALL_PREFIX) + set(OPEN_SRC_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/open-source) + set(ENV{PKG_CONFIG_PATH} + "$ENV{PKG_CONFIG_PATH}:${OPEN_SRC_INSTALL_PREFIX}/lib/pkgconfig") + set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${OPEN_SRC_INSTALL_PREFIX}) + endif() + + # Create the dependency directory if it doesn't exist. + if(NOT EXISTS ${OPEN_SRC_INSTALL_PREFIX}) + file(MAKE_DIRECTORY ${OPEN_SRC_INSTALL_PREFIX}) + endif() + + # Check if CC env var starts with "gcc". + string(STRIP $ENV{CC} CC_NAME) + message(${CC_NAME}) + if(${CC_NAME} MATCHES ".*gcc-.*") + build_dependency(gtest) + endif() endif() find_package(PkgConfig REQUIRED) -############# Check system for kvspic ############# +message("CMAKE_PREFIX_PATH : ${CMAKE_PREFIX_PATH}") #TODO: Remove this. -pkg_check_modules(KVSPIC libkvspicUtils) -if(KVSPIC_FOUND) - set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${KVSPIC_INCLUDE_DIRS}) - link_directories(${KVSPIC_LIBRARY_DIRS}) -else() - ############# fetch repos that we need do add_subdirectory ############ - # repos that we will build using add_subdirectory will be stored in this path + +############# Checking system for kvspic ############# + +# TODO: Remove this comment in final cleanup. +# NOTE: this is possibly a breaking change, if not specified, system PIC will not be used. +# Prev behavior: look for system PIC if not found, build PIC. +# Now: is BUILD_KVS_PIC ? build PIC, else find system PIC - if system PIC not found, fail build +# TODO: Leave a note in the PIC file libkvspic.pc.cmake that the below comments/messages must be updated +# if we change "prefix=" from CMAKE_INSTALL_PREFIX. (CMAKE_INSTALL_PREFIX = usr/local). +if(BUILD_KVS_PIC) + # KVS PIC will live in the DEPENDENCY_DOWNLOAD_PATH. + # TODO: Double check all the below is correct/necessary. set(DEPENDENCY_DOWNLOAD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/dependency) set(BUILD_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}) fetch_repo(kvspic ${BUILD_ARGS}) add_subdirectory("${DEPENDENCY_DOWNLOAD_PATH}/libkvspic/kvspic-src") file(GLOB PIC_HEADERS "${pic_project_SOURCE_DIR}/src/*/include") include_directories("${PIC_HEADERS}") +else() + # TODO: test this already-installed case + # Finding PIC on system using the libcproducer.pc.cmake file. + pkg_check_modules(KVS_PIC kvspic) + if(KVS_PIC_FOUND) + message("Found system KVS PIC located: ${KVS_PIC_PREFIX}") + set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${KVS_PIC_UTILS_INCLUDE_DIRS}) + link_directories(${KVS_PIC_LIBRARY_DIRS}) + else() + message(FATAL_ERROR "Could not find system KVS PIC. PkgConfig searched in: ${KVS_PIC_INCLUDE_DIRS} \ + Please check PIC installation or set BUILD_KVS_PIC to TRUE to build PIC with this project.") + endif() - ############# fetch repos that we need do add_subdirectory done ############ + pkg_check_modules(KVS_PIC_UTILS libkvspicUtils) + if(KVS_PIC_UTILS_FOUND) + message("Found system KVS PIC Utils located: ${KVS_PIC_UTILS_PREFIX}") + set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${KVS_PIC_UTILS_INCLUDE_DIRS}) + link_directories(${KVS_PIC_UTILS_LIBRARY_DIRS}) + else() + message(FATAL_ERROR "Could not find system KVS PIC Utils. PkgConfig searched in: ${KVS_PIC_UTILS_INCLUDE_DIRS} \ + Please check PIC installation or set BUILD_KVS_PIC to TRUE to build PIC with this project.") + endif() endif() -############# Check system for kvspic done ############# +############# Done checking system for kvspic ############# -############# find dependent libraries ############ -find_package(Threads) -set(OPEN_SRC_INCLUDE_DIRS ${LIBKVSPIC_INCLUDE_DIRS}) +############# Finding 3rd-party dependencies if not built from source ############ + +# TODO: shouldn't this be "required" ? +find_package(Threads) -if(USE_OPENSSL) - find_package(OpenSSL) - if(NOT OPENSSL_FOUND AND NOT BUILD_DEPENDENCIES) - message(FATAL_ERROR "OpenSSL is not found. Make sure to export PKG_CONFIG_PATH to where OpenSSL's pc file is") +if(NOT BUILD_DEPENDENCIES OR NOT BUILD_CRYPTO) + if(USE_OPENSSL) + find_package(OpenSSL REQUIRED) + include_directories(${OPENSSL_INCLUDE_DIR}) + elseif(USE_MBEDTLS) + find_package(MbedTLS REQUIRED) + else() + message(FATAL_ERROR "No crypto library selected. Please specify one of the following: " ${SUPPORTED_CRYPTO_LIBRARIES}) endif() - set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR}) -elseif(USE_MBEDTLS) - find_package(MbedTLS REQUIRED) - set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIRS}) -else() - message(FATAL_ERROR "No crypto library selected.") endif() -if(BUILD_COMMON_CURL) +if((NOT BUILD_DEPENDENCIES OR NOT BUILD_CURL) AND BUILD_COMMON_CURL) if (WIN32) find_package(CURL REQUIRED) - set(CURL_LIBRARIES CURL::libcurl) else() pkg_check_modules(CURL REQUIRED libcurl) + set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS}) + link_directories(${CURL_LIBRARY_DIRS}) endif() - - set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS}) - link_directories(${CURL_LIBRARY_DIRS}) endif() -if (BUILD_COMMON_LWS) +if((NOT BUILD_DEPENDENCIES OR NOT BUILD_LWS) AND BUILD_COMMON_LWS) if (WIN32) find_package(LIBWEBSOCKETS REQUIRED PATHS ${OPEN_SRC_INSTALL_PREFIX}) else() @@ -190,8 +258,12 @@ if (BUILD_COMMON_LWS) link_directories(${LIBWEBSOCKETS_LIBRARY_DIRS}) endif() -############# find dependent libraries end ############ +############# Done finding 3rd-party dependencies if not built from source ############ + +# Configure bitness. +# TODO: Note, these variables are never used, in C, CPP, WebRTC SDKs. Not in cmake and not in source files. +# Confirm whether we need these. if(CMAKE_SIZEOF_VOID_P STREQUAL 4) message(STATUS "Bitness 32 bits") set(KINESIS_VIDEO_BUILD_BITNESS "x86") @@ -206,17 +278,24 @@ else() message(FATAL_ERROR "Unknown bitness") endif() + +# TODO: Figure out what is going on in here and add comments. if(${CMAKE_C_COMPILER_ID} MATCHES "GNU|Clang") + # Enable compiler to genarate "Positin Independent Code". set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - + + # Note: muclib is a standard C library alternative to glibc. if(ADD_MUCLIBC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -muclibc") endif() + # Set compiler flags for code coverage check and enable debug mode. if(CODE_COVERAGE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fprofile-arcs -ftest-coverage") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") endif() + + # Set compiler flags for appropriate sanitizer checks and enable debug mode. function(enableSanitizer SANITIZER) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fsanitize=${SANITIZER} -fno-omit-frame-pointer" PARENT_SCOPE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fsanitize=${SANITIZER} -fno-omit-frame-pointer -fno-optimize-sibling-calls" PARENT_SCOPE) @@ -236,18 +315,26 @@ if(${CMAKE_C_COMPILER_ID} MATCHES "GNU|Clang") endif() endif() +# Silence warnings for Windows builds. if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) endif() +# Producer C source files are seperated by Common, LWS, Curl, and Producer related code. file(GLOB KVS_COMMON_SOURCE_FILES_BASE "src/source/Common/*.c") file(GLOB KVS_COMMON_SOURCE_FILES_LWS "src/source/Common/Lws/*.c") file(GLOB KVS_COMMON_SOURCE_FILES_CURL "src/source/Common/Curl/*.c") file(GLOB PRODUCER_C_SOURCE_FILES "src/source/*.c") +set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${OPEN_SRC_INSTALL_PREFIX}/include) + include_directories(${KINESIS_VIDEO_PRODUCER_C_SRC}/src/include) include_directories(${OPEN_SRC_INCLUDE_DIRS}) +link_directories(${OPEN_SRC_INSTALL_PREFIX}/lib) # Unix intsalls libraries into /lib directory +link_directories(${OPEN_SRC_INSTALL_PREFIX}/bin) # Windows may install libraries into /bin directory + + if(ALIGNED_MEMORY_MODEL) add_definitions(-DALIGNED_MEMORY_MODEL) endif() @@ -257,113 +344,125 @@ if(SET_SSL_CALLBACKS) endif() -# use openssl by default -set(CPRODUCER_COMMON_TLS_OPTION KVS_USE_OPENSSL) - -set(PRODUCER_CRYPTO_LIBRARY - OpenSSL::Crypto - OpenSSL::SSL) -if (USE_MBEDTLS) - set(CPRODUCER_COMMON_TLS_OPTION KVS_USE_MBEDTLS) - set(PRODUCER_CRYPTO_LIBRARY - MbedTLS - MbedCrypto) +# Set which crypto libraries to link with (OpenSSL or MbedTLS). +if (USE_OPENSSL) + set(CPRODUCER_COMMON_TLS_OPTION KVS_USE_OPENSSL) + if(WIN32) + set(PRODUCER_CRYPTO_LIBRARIES + ${OPEN_SRC_INSTALL_PREFIX}/lib/libssl.lib + ${OPEN_SRC_INSTALL_PREFIX}/lib/libcrypto.lib) + else() + if(BUILD_DEPENDENCIES AND BUILD_CRYPTO) + set(PRODUCER_CRYPTO_LIBRARIES ssl crypto) + else() + set(PRODUCER_CRYPTO_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) + endif() + endif() +elseif(USE_MBEDTLS) + set(CPRODUCER_COMMON_TLS_OPTION KVS_USE_MBEDTLS) + if(WIN32) + set(PRODUCER_CRYPTO_LIBRARIES + ${OPEN_SRC_INSTALL_PREFIX}/lib/mbedtls.lib + ${OPEN_SRC_INSTALL_PREFIX}/lib/mbedcrypto.lib) + else() + set(PRODUCER_CRYPTO_LIBRARIES mbedtls mbedcrypto) + endif() endif() +# Note: This install instruction is necessary for KSV WebRTC SDK to find Producer C headers. install( DIRECTORY ${KINESIS_VIDEO_PRODUCER_C_SRC}/src/include DESTINATION .) +# Create KVS Common LWS library, link its dependecies, and define its installation. if(BUILD_COMMON_LWS) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/libkvsCommonLws.pc.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonLws.pc" @ONLY) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/libkvsCommonLws.pc.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonLws.pc" @ONLY) + + if (WIN32) + add_library(kvsCommonLws STATIC ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_LWS}) + else() + add_library(kvsCommonLws ${TYPE_OF_LIB} ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_LWS}) + endif() + target_compile_definitions(kvsCommonLws PRIVATE KVS_BUILD_WITH_LWS ${CPRODUCER_COMMON_TLS_OPTION}) + if(NOT BUILD_STATIC) + set_target_properties(kvsCommonLws PROPERTIES VERSION ${KINESIS_VIDEO_PRODUCER_C_VERSION} SOVERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION}) + endif() - if (WIN32) - add_library(kvsCommonLws STATIC ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_LWS}) - else() - add_library(kvsCommonLws ${TYPE_OF_LIB} ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_LWS}) - endif() - target_compile_definitions(kvsCommonLws PRIVATE KVS_BUILD_WITH_LWS ${CPRODUCER_COMMON_TLS_OPTION}) - if(NOT BUILD_STATIC) - set_target_properties(kvsCommonLws PROPERTIES VERSION ${KINESIS_VIDEO_PRODUCER_C_VERSION} SOVERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION}) - endif() - target_link_libraries(kvsCommonLws - ${PRODUCER_CRYPTO_LIBRARY} - ${LIBWEBSOCKETS_LIBRARIES} - kvspicUtils) - - install( - TARGETS kvsCommonLws - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonLws.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + target_link_libraries(kvsCommonLws ${PRODUCER_CRYPTO_LIBRARIES} ${LIBWEBSOCKETS_LIBRARIES} kvspicUtils) + + install( + TARGETS kvsCommonLws + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonLws.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endif() +# Create KVS Producer C Common Curl library, link its dependecies, and define its installation. +# Build KVS Producer C samples and tests if specified. if(BUILD_COMMON_CURL) - # producer only uses curl right now - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/libkvsCommonCurl.pc.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonCurl.pc" @ONLY) - - if(BUILD_STATIC) - # Curl will enable ZLIB as part of its build if it finds - # the package. We need to therefore link it for static builds. - find_package(ZLIB) - if(ZLIB_FOUND) - list(APPEND CURL_LIBRARIES z) - endif() - endif() + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/libkvsCommonCurl.pc.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonCurl.pc" @ONLY) - if (WIN32) - add_library(kvsCommonCurl STATIC ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_CURL}) - else() - add_library(kvsCommonCurl ${TYPE_OF_LIB} ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_CURL}) - endif() - target_compile_definitions(kvsCommonCurl PRIVATE KVS_BUILD_WITH_CURL ${CPRODUCER_COMMON_TLS_OPTION}) - if(NOT BUILD_STATIC) - set_target_properties(kvsCommonCurl PROPERTIES VERSION ${KINESIS_VIDEO_PRODUCER_C_VERSION} SOVERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION}) - endif() - target_link_libraries(kvsCommonCurl - kvspicUtils - ${CURL_LIBRARIES} - ${PRODUCER_CRYPTO_LIBRARY}) - - install( - TARGETS kvsCommonCurl - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/libkvsCommonCurl.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") - - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/libcproducer.pc.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/libcproducer.pc" @ONLY) - - if (WIN32) - add_library(cproducer STATIC ${PRODUCER_C_SOURCE_FILES}) - else() - add_library(cproducer ${TYPE_OF_LIB} ${PRODUCER_C_SOURCE_FILES}) - endif() - if(NOT BUILD_STATIC) - set_target_properties(cproducer PROPERTIES VERSION ${KINESIS_VIDEO_PRODUCER_C_VERSION} SOVERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION}) + if(WIN32) + set(CURL_LIBRARIES ${OPEN_SRC_INSTALL_PREFIX}/lib/libcurl-d_imp.lib) + else() + set(CURL_LIBRARIES curl) + endif() + + if(BUILD_STATIC) + # Curl will enable ZLIB as part of its build if it finds + # the package. We need to therefore link it for static builds. + find_package(ZLIB) + if(ZLIB_FOUND) + list(APPEND CURL_LIBRARIES z) endif() - target_link_libraries(cproducer PUBLIC kvsCommonCurl kvspic) + endif() + + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/libcproducer.pc.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/libcproducer.pc" @ONLY) - install( - TARGETS cproducer - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/libcproducer.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + if (WIN32) + add_library(cproducer STATIC ${PRODUCER_C_SOURCE_FILES} ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_CURL}) + else() + add_library(cproducer ${TYPE_OF_LIB} ${PRODUCER_C_SOURCE_FILES} ${KVS_COMMON_SOURCE_FILES_BASE} ${KVS_COMMON_SOURCE_FILES_CURL}) + endif() + if(NOT BUILD_STATIC) + set_target_properties(cproducer PROPERTIES VERSION ${KINESIS_VIDEO_PRODUCER_C_VERSION} SOVERSION ${KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION}) + endif() + + target_compile_definitions(cproducer PRIVATE KVS_BUILD_WITH_CURL ${CPRODUCER_COMMON_TLS_OPTION}) + + # TODO: Remove debug messages, this one and others. + message("CURL_LIBRARIES: ${CURL_LIBRARIES}") + message("PRODUCER_CRYPTO_LIBRARIES: ${PRODUCER_CRYPTO_LIBRARIES}") + + # TODO: Make this work with mbedtls on Windows + # Note: The linker is not able to find the .lib files on Windows without the full path, + # even when they are present and in the LIBPATH search path. + target_link_libraries(cproducer + PUBLIC kvspic + PRIVATE ${CURL_LIBRARIES} ${PRODUCER_CRYPTO_LIBRARIES}) + # TODO: Remove debug messages, this one and others. + message("CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}") + + install( + TARGETS cproducer + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/libcproducer.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + + if(BUILD_SAMPLES) add_executable(kvsVideoOnlyRealtimeStreamingSample ${KINESIS_VIDEO_PRODUCER_C_SRC}/samples/KvsVideoOnlyRealtimeStreamingSample.c) target_link_libraries(kvsVideoOnlyRealtimeStreamingSample cproducer) @@ -375,8 +474,9 @@ if(BUILD_COMMON_CURL) add_executable(kvsAudioOnlyStreamingSample ${KINESIS_VIDEO_PRODUCER_C_SRC}/samples/KvsAudioOnlyStreamingSample.c) target_link_libraries(kvsAudioOnlyStreamingSample cproducer) + endif() - if (BUILD_TEST) - add_subdirectory(tst) - endif() -endif() + if(BUILD_TEST) + add_subdirectory(tst) + endif() +endif() \ No newline at end of file diff --git a/tst/CMakeLists.txt b/tst/CMakeLists.txt index 50e3c738a..de374ff6e 100644 --- a/tst/CMakeLists.txt +++ b/tst/CMakeLists.txt @@ -7,6 +7,7 @@ set(KINESIS_VIDEO_PRODUCER_C_SRC "${CMAKE_CURRENT_SOURCE_DIR}/..") if (OPEN_SRC_INSTALL_PREFIX) find_package(GTest REQUIRED PATHS ${OPEN_SRC_INSTALL_PREFIX}) + set(GTEST_INCLUDE_DIRS ${OPEN_SRC_INSTALL_PREFIX}/include) else() find_package(GTest REQUIRED) endif()