Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake build improvements #441

Open
wants to merge 93 commits into
base: develop
Choose a base branch
from
Open

CMake build improvements #441

wants to merge 93 commits into from

Conversation

stefankiesz
Copy link
Contributor

@stefankiesz stefankiesz commented Feb 28, 2024

What was changed?
Build improvements including the following:

  • BUILD_DEPENDENCIES will now only use dependency libraries built from source. They can also be individually specified to use system-installed when BUILD_DEPENDENCIES is on with library-specific flags
  • Building the samples can be turned off via BUILD_SAMPLES flag
  • Added comments throughout the CMakeLists file
  • The Windows CI job now moves the repo into a short directory incase exceeding path length causes any issues in the future
  • No longer need to run cmake .. twice for M1 CI tests
  • Replaced "local-openssl" CI jobs with "system-openssl" jobs which now use a BUILD_CRYPTO flag to determine whether to build from source rather than the now removed LOCAL_OPENSSL_BUILD flag
  • Added Mac OS "system-deps" tests which set BUILD_DEPENDENCIES to FALSE and use only system-installed libraries
    • Note: GTest must be built from source when using GCC compiler on Mac because the system's CLANG-compiled GTest is not compatible with GCC-compiled libraries

Why was it changed?
The SDK build can be very inconsistent when we use find_package and pkg_check_modules for project-built-from-source dependencies. Sometimes they find the system-installed libraries instead of the ones this project builds from source, and this has been the cause for some CI build failures. These commands are no longer used when building the dependencies from source along with the project because setting the known include/header and library directories is sufficient - these are both always in our open-source folder that is generated during the build configuration cmake .. stage.

These kind of build issues were also experienced when building locally on Mac, specifically when there was a rouge version of KVS PIC SDK installed in the usr/local/lib default system library directory and when there was already an openssl library installed via HomeBrew.


How was it changed?
This project's CMakeLists.txt and CI jobs were modified as described in the above sections.


What testing was done for the changes?

  • Built and ran this SDK solo and as dependency for Producer CPP and WebRTC SDKs locally on Intel Mac and M2 Mac, and on a Windows EC2 instance
    • otool -L <library>.dylib was used with the local M2 Mac build to verify that Producer C SDK's dependencies and the Producer C SDK itself when built as a dependency for the above SDKs were not linked to duplicate dependency libraries
  • Built and ran this SDK with BUILD_DEPENDENCIES off on Mac
  • The CI for this repo, Producer CPP, and WebRTC C were run to verify all tests are passing
  • Note: Producer CPP SDK has some small changes necessary for this Producer C to work, but WebRTC C SDK is compatible unmodified

Draft PR for Producer CPP tests: awslabs/amazon-kinesis-video-streams-producer-sdk-cpp#1154
Draft PR for WebRTC C tests: awslabs/amazon-kinesis-video-streams-webrtc-sdk-c#1952


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link

codecov-commenter commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.76%. Comparing base (7f9ff95) to head (eb156ac).

❗ Current head eb156ac differs from pull request most recent head 58da8fe. Consider uploading reports for the commit 58da8fe to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #441      +/-   ##
===========================================
- Coverage    63.93%   63.76%   -0.18%     
===========================================
  Files           32       32              
  Lines         5077     5078       +1     
===========================================
- Hits          3246     3238       -8     
- Misses        1831     1840       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stefankiesz stefankiesz marked this pull request as ready for review March 8, 2024 23:41
@stefankiesz stefankiesz marked this pull request as draft March 8, 2024 23:42
@@ -1,3 +1,4 @@
REM NOTE: May need to replace "Enterprise" with "Community" int the below command
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: int -> in

@stefankiesz
Copy link
Contributor Author

Something to consider:

link_directories should generally be avoided in modern CMake projects, as it can lead to unexpected behavior and is less flexible compared to using target_link_libraries with absolute or relative paths.

message(${CC_NAME})
if(${CC_NAME} MATCHES ".*gcc-.*")
build_dependency(gtest)
endif()
endif()

find_package(PkgConfig REQUIRED)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: PkgConfig probably does not need to be checked for on Windows.

Copy link
Contributor

@disa6302 disa6302 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet to review the rest. But publishing first half.

project(KinesisVideoProducerC VERSION 1.5.1 LANGUAGES C)

set(KINESIS_VIDEO_PRODUCER_C_MAJOR_VERSION 1)
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}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a CI for this and also add a verification step in the CI to confirm the generated libraries are in fact static? Similar to this:
https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-c/blob/develop/.github/workflows/ci.yml#L801-L805

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be ${CMAKE_CURRENT_SOURCE_DIR}? Did we test webrtc with this build to confirm it works and does not break existing behavior if OPEN_SRC_INSTALL_PREFIX is not set?

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. For future enhancements, let us see if we can mask these behind a BUILD_ONLY overarching flag. Similar to how AWS SDK does: https://github.com/aws/aws-sdk-cpp/blob/main/docs/CMake_Parameters.md#build_only

set(BUILD_ARGS -DBUILD_STATIC=${BUILD_STATIC}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DOPENSSL_DIR=${OPEN_SRC_INSTALL_PREFIX}
-DUSE_OPENSSL=${USE_OPENSSL}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants