From b3d30a5998d6ad05a228e57fb6a5c8539604babd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Tue, 2 May 2023 10:59:59 +0300 Subject: [PATCH 1/4] build: Add CMake options for disabling tests and examples --- BUILDING.md | 8 ++++++ CMakeLists.txt | 19 +++++++++++--- cmake/FindDependencies.cmake | 50 +++++++++++++++++------------------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 5964880..6f28bab 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -120,6 +120,14 @@ cmake -DDISABLE_WERROR=1 .. Creation of an issue on Github that describes these warnings is also appreciated. +## Not building examples or tests + +By default, uvgRTP configures both examples and tests as additional targets to build. If this is undesirable, you can disable their configuration with following CMake parameters: + +``` +cmake -DUVGRTP_DISABLE_TESTS=1 -UVGRTP_DISABLE_EXAMPLES=1 .. +``` + ## Release commit (for devs) The release commit can be specified in CMake. This slightly changes how the version is printed. This feature is mostly useful for distributing release versions. Use the following command: diff --git a/CMakeLists.txt b/CMakeLists.txt index 8165197..ba995e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,12 +15,18 @@ project(uvgrtp include(GNUInstallDirs) -include(cmake/FindDependencies.cmake) -include(cmake/Versioning.cmake) + option(DISABLE_CRYPTO "Do not build uvgRTP with crypto enabled" OFF) option(DISABLE_PRINTS "Do not print anything from uvgRTP" OFF) option(DISABLE_WERROR "Ignore compiler warnings" OFF) +option(UVGRTP_DISABLE_TESTS "Do not build unit tests" OFF) +option(UVGRTP_DISABLE_EXAMPLES "Do not build examples" OFF) + +include(cmake/FindDependencies.cmake) +include(cmake/Versioning.cmake) + + add_library(${PROJECT_NAME}) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION "${PROJECT_VERSION_MAJOR}" @@ -236,8 +242,13 @@ if(APPLE) target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Security") endif() -add_subdirectory(examples EXCLUDE_FROM_ALL) -add_subdirectory(test EXCLUDE_FROM_ALL) +if (NOT UVGRTP_DISABLE_EXAMPLES) + add_subdirectory(examples EXCLUDE_FROM_ALL) +endif() + +if (NOT UVGRTP_DISABLE_TESTS) + add_subdirectory(test EXCLUDE_FROM_ALL) +endif() # # Install diff --git a/cmake/FindDependencies.cmake b/cmake/FindDependencies.cmake index df4814a..068c30b 100644 --- a/cmake/FindDependencies.cmake +++ b/cmake/FindDependencies.cmake @@ -1,30 +1,26 @@ -# -# PThread -# -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package( Threads REQUIRED ) +if (NOT UVGRTP_DISABLE_TESTS) + # PThread + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + set(THREADS_PREFER_PTHREAD_FLAG TRUE) + find_package( Threads REQUIRED ) -# -# Git -# -find_package(Git) + # Git + find_package(Git) -# -# GTest / GMock -# -include(FetchContent) -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.11.0 -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + # GTest / GMock + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.11.0 + ) + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) -add_library(GTest::GMock ALIAS gmock) -add_library(GTest::GMockMain ALIAS gmock_main) -add_library(GTest::GTest ALIAS gtest) -add_library(GTest::GTestMain ALIAS gtest_main) + FetchContent_MakeAvailable(googletest) + add_library(GTest::GMock ALIAS gmock) + add_library(GTest::GMockMain ALIAS gmock_main) + add_library(GTest::GTest ALIAS gtest) + add_library(GTest::GTestMain ALIAS gtest_main) +endif() From 03ee03cd0711b530011ab2d3f36ed67211668ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Tue, 2 May 2023 13:29:33 +0300 Subject: [PATCH 2/4] build: Add option to download Crypto++ headers to CMake --- CMakeLists.txt | 14 +++++++++++--- cmake/CryptoHeaders.cmake | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 cmake/CryptoHeaders.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ba995e1..26a5f43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ option(DISABLE_WERROR "Ignore compiler warnings" OFF) option(UVGRTP_DISABLE_TESTS "Do not build unit tests" OFF) option(UVGRTP_DISABLE_EXAMPLES "Do not build examples" OFF) +option(UVGRTP_DOWNLOAD_CRYPTO "Download headers for Crypto++ if they are missing" OFF) include(cmake/FindDependencies.cmake) include(cmake/Versioning.cmake) @@ -222,9 +223,6 @@ if (UNIX) if(CRYPTOPP_FOUND) list(APPEND UVGRTP_CXX_FLAGS ${CRYPTOPP_CFLAGS_OTHER}) list(APPEND UVGRTP_LINKER_FLAGS ${CRYPTOPP_LDFLAGS}) - else() - message("libcrypto++ not found. Encryption will be disabled") - list(APPEND UVGRTP_CXX_FLAGS "-D__RTP_NO_CRYPTO__") endif() endif() @@ -238,6 +236,16 @@ if (UNIX) endif(PkgConfig_FOUND) endif (UNIX) +if (NOT CRYPTOPP_FOUND AND UVGRTP_DOWNLOAD_CRYPTO) + include(cmake/CryptoHeaders.cmake) + list(APPEND UVGRTP_CXX_FLAGS ${CRYPTOPP_CFLAGS_OTHER}) + list(APPEND UVGRTP_LINKER_FLAGS ${CRYPTOPP_LDFLAGS}) +elseif(NOT CRYPTOPP_FOUND AND UNIX) + # In Visual Studio, we want to leave user the option to add Crypto++ headers manually + message("libcrypto++ not found. Encryption will be disabled") + list(APPEND UVGRTP_CXX_FLAGS "-D__RTP_NO_CRYPTO__") +endif() + if(APPLE) target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Security") endif() diff --git a/cmake/CryptoHeaders.cmake b/cmake/CryptoHeaders.cmake new file mode 100644 index 0000000..3b72b94 --- /dev/null +++ b/cmake/CryptoHeaders.cmake @@ -0,0 +1,18 @@ +include(FetchContent) + +message(STATUS "Downloading Crypto++ headers") + +FetchContent_Declare(cryptopp + URL https://github.com/weidai11/cryptopp/releases/download/CRYPTOPP_8_7_0/cryptopp870.zip + URL_HASH SHA256=d0d3a28fcb5a1f6ed66b3adf57ecfaed234a7e194e42be465c2ba70c744538dd + DOWNLOAD_EXTRACT_TIMESTAMP ON +) + +FetchContent_MakeAvailable(cryptopp) + +file(GLOB CRYPTOPP_HEADERS "${cryptopp_SOURCE_DIR}/*.h") +file(MAKE_DIRECTORY ${cryptopp_SOURCE_DIR}/include/cryptopp) +file(COPY ${CRYPTOPP_HEADERS} DESTINATION ${cryptopp_SOURCE_DIR}/include/cryptopp) + +include_directories(${cryptopp_SOURCE_DIR}/include) + From aeaa71e6b4455c458c6a21bfe36f6eab5cad338a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Wed, 3 May 2023 12:43:10 +0300 Subject: [PATCH 3/4] build: Rename CMake flags to new format Upending UVGRTP to each CMake option makes it less likely to conflict between other libraries built at the same time. Added also some backwards compatibility for old options. --- BUILDING.md | 10 +++++----- CMakeLists.txt | 33 ++++++++++++++++++++++++++------- cmake/Versioning.cmake | 5 ++--- examples/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 6f28bab..c432d46 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -28,7 +28,7 @@ cmake .. Alternatively, if you want to disable Crypto++, use command: ``` -cmake -DDISABLE_CRYPTO=1 .. +cmake -DUVGRTP_DISABLE_CRYPTO=1 .. ``` If you are using MinGW for your compilation, add the generate parameter the generate the MinGW build configuration: @@ -107,7 +107,7 @@ You can also use `pkg-config` to get the flags. It is possible to silence all prints coming from uvgRTP by enabling following parameter: ``` -cmake -DDISABLE_PRINTS=1 .. +cmake -DUVGRTP_DISABLE_PRINTS=1 .. ``` ## Allow compiler warnings by disabling Werror @@ -115,7 +115,7 @@ cmake -DDISABLE_PRINTS=1 .. If the compiler warnings are causing your build to fail without you making any modifications, you may use this option to disable the `-Werror`-flag: ``` -cmake -DDISABLE_WERROR=1 .. +cmake -DUVGRTP_DISABLE_WERROR=1 .. ``` Creation of an issue on Github that describes these warnings is also appreciated. @@ -125,7 +125,7 @@ Creation of an issue on Github that describes these warnings is also appreciated By default, uvgRTP configures both examples and tests as additional targets to build. If this is undesirable, you can disable their configuration with following CMake parameters: ``` -cmake -DUVGRTP_DISABLE_TESTS=1 -UVGRTP_DISABLE_EXAMPLES=1 .. +cmake -DUVGRTP_DISABLE_TESTS=1 -DUVGRTP_DISABLE_EXAMPLES=1 .. ``` ## Release commit (for devs) @@ -133,6 +133,6 @@ cmake -DUVGRTP_DISABLE_TESTS=1 -UVGRTP_DISABLE_EXAMPLES=1 .. The release commit can be specified in CMake. This slightly changes how the version is printed. This feature is mostly useful for distributing release versions. Use the following command: ``` -cmake -DRELEASE_COMMIT=1 .. +cmake -DUVGRTP_RELEASE_COMMIT=1 .. ``` diff --git a/CMakeLists.txt b/CMakeLists.txt index 26a5f43..b5a70d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,14 +16,33 @@ project(uvgrtp include(GNUInstallDirs) -option(DISABLE_CRYPTO "Do not build uvgRTP with crypto enabled" OFF) -option(DISABLE_PRINTS "Do not print anything from uvgRTP" OFF) -option(DISABLE_WERROR "Ignore compiler warnings" OFF) +option(UVGRTP_DISABLE_CRYPTO "Do not build uvgRTP with crypto enabled" OFF) +option(UVGRTP_DISABLE_PRINTS "Do not print anything from uvgRTP" OFF) +option(UVGRTP_DISABLE_WERROR "Ignore compiler warnings" OFF) option(UVGRTP_DISABLE_TESTS "Do not build unit tests" OFF) option(UVGRTP_DISABLE_EXAMPLES "Do not build examples" OFF) option(UVGRTP_DOWNLOAD_CRYPTO "Download headers for Crypto++ if they are missing" OFF) +option(UVGRTP_RELEASE_COMMIT "Explicitly say that this is a release version in version prints" OFF) + +# obsolete, do not use +option(DISABLE_CRYPTO "Do not build uvgRTP with crypto enabled" OFF) +option(DISABLE_PRINTS "Do not print anything from uvgRTP" OFF) +option(DISABLE_WERROR "Ignore compiler warnings" OFF) + +# offer some backwards compatibility for old flags +if (DISABLE_CRYPTO) + set(UVGRTP_DISABLE_CRYPTO ON) +endif() +if (DISABLE_PRINTS) + set(UVGRTP_DISABLE_PRINTS ON) +endif() +if (DISABLE_WERROR) + set(UVGRTP_DISABLE_WERROR ON) +endif() + + include(cmake/FindDependencies.cmake) include(cmake/Versioning.cmake) @@ -168,19 +187,19 @@ endif() if(MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /Zc:__cplusplus /W4) else() - if (DISABLE_WERROR) + if (UVGRTP_DISABLE_WERROR) target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic) else () target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror) endif() endif() -if (DISABLE_CRYPTO) +if (UVGRTP_DISABLE_CRYPTO) list(APPEND UVGRTP_CXX_FLAGS "-D__RTP_NO_CRYPTO__") target_compile_definitions(${PROJECT_NAME} PRIVATE __RTP_NO_CRYPTO__) endif() -if (DISABLE_PRINTS) +if (UVGRTP_DISABLE_PRINTS) list(APPEND UVGRTP_CXX_FLAGS "-D__RTP_SILENT__") target_compile_definitions(${PROJECT_NAME} PRIVATE __RTP_SILENT__) endif() @@ -218,7 +237,7 @@ if (UNIX) endif(NOT DEFINED ENV{PKG_CONFIG_PATH}) # Find crypto++ - if(NOT DISABLE_CRYPTO) + if(NOT UVGRTP_DISABLE_CRYPTO) pkg_search_module(CRYPTOPP libcrypto++ cryptopp) if(CRYPTOPP_FOUND) list(APPEND UVGRTP_CXX_FLAGS ${CRYPTOPP_CFLAGS_OTHER}) diff --git a/cmake/Versioning.cmake b/cmake/Versioning.cmake index 6b6d7a6..65fb8fe 100644 --- a/cmake/Versioning.cmake +++ b/cmake/Versioning.cmake @@ -17,8 +17,7 @@ if(uvgrtp_GIT_HASH) SET(uvgrtp_GIT_HASH "${uvgrtp_GIT_HASH}") endif() -option(RELEASE_COMMIT "Create a release version" OFF) -if(RELEASE_COMMIT) +if(UVGRTP_RELEASE_COMMIT) set (LIBRARY_VERSION ${PROJECT_VERSION}) elseif(uvgrtp_GIT_HASH) set (LIBRARY_VERSION ${PROJECT_VERSION} + "-" + ${uvgrtp_GIT_HASH}) @@ -36,7 +35,7 @@ target_include_directories(${PROJECT_NAME}_version PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ) -if (RELEASE_COMMIT) +if (UVGRTP_RELEASE_COMMIT) target_compile_definitions(${PROJECT_NAME}_version PRIVATE RTP_RELEASE_COMMIT) endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a959bfd..fe45489 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -30,7 +30,7 @@ target_sources(sync_sender PRIVATE sync_sender.cc) target_sources(sync_receiver PRIVATE sync_receiver.cc) # set crypto++ to be linked in examples if available -if (NOT DISABLE_CRYPTO AND CRYPTOPP_FOUND) +if (NOT UVGRTP_DISABLE_CRYPTO AND CRYPTOPP_FOUND) if(MSVC) set(CRYPTOPP_LIB_NAME "cryptlib") else() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3bccd5c..411a445 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -19,7 +19,7 @@ target_sources(${PROJECT_NAME} PRIVATE target_include_directories(${PROJECT_NAME} PRIVATE $) # set crypto++ to be linked in tests if available -if (NOT DISABLE_CRYPTO AND CRYPTOPP_FOUND) +if (NOT UVGRTP_DISABLE_CRYPTO AND CRYPTOPP_FOUND) if(MSVC) set(CRYPTOPP_LIB_NAME "cryptlib") else() From 9216f4bbeebb55827f58ffd5bd509bd70ea355ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Wed, 3 May 2023 12:43:51 +0300 Subject: [PATCH 4/4] build: Set default CMake options so werror is disabled --- CMakeLists.txt | 2 +- CONTRIBUTING.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5a70d6..0cf2c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ include(GNUInstallDirs) option(UVGRTP_DISABLE_CRYPTO "Do not build uvgRTP with crypto enabled" OFF) option(UVGRTP_DISABLE_PRINTS "Do not print anything from uvgRTP" OFF) -option(UVGRTP_DISABLE_WERROR "Ignore compiler warnings" OFF) +option(UVGRTP_DISABLE_WERROR "Ignore compiler warnings" ON) option(UVGRTP_DISABLE_TESTS "Do not build unit tests" OFF) option(UVGRTP_DISABLE_EXAMPLES "Do not build examples" OFF) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fb50782..e4402d0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,7 @@ When issuing a pull request (PR) to uvgRTP. Please consider the following aspect ### PR code - Should compile both on with newest GCC, MinGW and MSVC. We can help with testing if needed. - Try to avoid code duplication +- Try to avoid unnecessary compiler warnings ### Version history - Try to keep commits small and limited to improving one specific aspect of uvgRTP