Merge pull request #198 from jrsnen/more_cmake_options

Add more options to uvgRTP CMake
This commit is contained in:
tampsa 2023-05-03 15:31:34 +03:00 committed by GitHub
commit 6d5b3ad9af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 107 additions and 47 deletions

View File

@ -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,16 +115,24 @@ 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.
## 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 -DUVGRTP_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:
```
cmake -DRELEASE_COMMIT=1 ..
cmake -DUVGRTP_RELEASE_COMMIT=1 ..
```

View File

@ -15,12 +15,38 @@ project(uvgrtp
include(GNUInstallDirs)
include(cmake/FindDependencies.cmake)
include(cmake/Versioning.cmake)
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" ON)
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)
add_library(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES
SOVERSION "${PROJECT_VERSION_MAJOR}"
@ -161,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()
@ -211,14 +237,11 @@ 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})
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()
@ -232,12 +255,27 @@ 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()
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

View File

@ -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

18
cmake/CryptoHeaders.cmake Normal file
View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -19,7 +19,7 @@ target_sources(${PROJECT_NAME} PRIVATE
target_include_directories(${PROJECT_NAME} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>)
# 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()