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

Adding cmake configuration to download roc-toolkit with branch provided via cmake variable #10

Merged
merged 11 commits into from
Jan 24, 2024
53 changes: 50 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
- cron: '0 0 * * 1'

jobs:
ubuntu:
ubuntu-systemwide-roc:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -36,5 +36,52 @@ jobs:

- name: Build tests
run: |
make build
test -e ./bin/rt-tests
mkdir build && cd build
cmake -DDOWNLOAD_ROC=OFF .. && make -j
test -e ../bin/rt-tests

ubuntu-roc-custom-path-roc:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get -y install g++ pkg-config scons ragel gengetopt \
libuv1-dev libunwind-dev libpulse-dev libsox-dev libcpputest-dev libspeexdsp-dev \
libtool intltool autoconf automake make cmake

- name: Build Roc
run: |
git clone https://github.com/roc-streaming/roc-toolkit.git /tmp/roc
scons -C /tmp/roc -Q --build-3rdparty=openfec --prefix=/tmp/roc/output
sudo scons -C /tmp/roc -Q --build-3rdparty=openfec --prefix=/tmp/roc/output install

- name: Build tests
run: |
mkdir build && cd build
cmake -DDOWNLOAD_ROC=OFF \
-DROC_INCLUDE_DIR=/tmp/roc/output/include \
-DROC_LIB_DIR=/tmp/roc/output/lib .. && make -j
test -e ../bin/rt-tests

ubuntu-download-roc:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get -y install g++ pkg-config scons ragel gengetopt \
libuv1-dev libunwind-dev libpulse-dev libsox-dev libcpputest-dev libspeexdsp-dev \
libtool intltool autoconf automake make cmake

- name: Build tests
run: |
mkdir build && cd build
cmake .. && make -j
test -e ../bin/rt-tests
53 changes: 31 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@ cmake_minimum_required(VERSION 3.5)

project(rt-tests)

include(ExternalProject)

ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
GIT_SHALLOW ON
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
INSTALL_COMMAND ""
TEST_COMMAND ""
LOG_DOWNLOAD ON
LOG_BUILD ON
)

include_directories(
"${CMAKE_CURRENT_BINARY_DIR}/googletest-src/googletest/include"
)

link_directories(
"${CMAKE_CURRENT_BINARY_DIR}/googletest-build/lib"
)
include("cmake/define_option.cmake")
include("cmake/download_googletest.cmake")

define_option(ROC_INCLUDE_DIR "" STRING "roc toolkit include directory")
define_option(ROC_LIB_DIR "" STRING "roc toolkit library directory")
define_option(DOWNLOAD_ROC ON BOOL "automatically download and build roc-toolkit")

if(DOWNLOAD_ROC)
define_option(ROC_BRANCH "master" STRING "roc-toolkit branch")
include("cmake/download_roc.cmake")
add_custom_target(download_roc DEPENDS RocLibrary)
else()
add_custom_target(download_roc) # download_roc an empty target in this case
if(NOT ROC_INCLUDE_DIR STREQUAL "")
get_filename_component(ROC_INCLUDE_DIR "${ROC_INCLUDE_DIR}" ABSOLUTE)
message(STATUS "Using ROC_INCLUDE_DIR - ${ROC_INCLUDE_DIR}")

include_directories(SYSTEM "${ROC_INCLUDE_DIR}")
endif()

if(NOT ROC_LIB_DIR STREQUAL "")
get_filename_component(ROC_LIB_DIR "${ROC_LIB_DIR}" ABSOLUTE)
message(STATUS "Using ROC_LIB_DIR - ${ROC_LIB_DIR}")

link_directories("${ROC_LIB_DIR}")
endif()

link_libraries("roc")
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down Expand Up @@ -50,14 +58,15 @@ add_executable(rt-tests
tests/test_service_quality.cpp
)

add_dependencies(rt-tests googletest)
add_dependencies(rt-tests googletest download_roc)

find_package(Threads)

target_link_libraries(rt-tests
roc
gtest
gtest_main
${CMAKE_DL_LIBS}
gavv marked this conversation as resolved.
Show resolved Hide resolved
${CMAKE_THREAD_LIBS_INIT})

add_custom_command(TARGET rt-tests POST_BUILD
Expand Down
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,68 @@ Requirements
* C++17 compiler
* CMake >= 3.0.0
* Google Test >= 1.10 (downloaded automatically)
* Roc Toolkit (should be pre-installed system-wide, see [instructions](https://roc-streaming.org/toolkit/docs/building/user_cookbook.html))
* Roc Toolkit (downloaded automatically)

Instructions
------------

Build and run:
### Simple build
When using this method, CMake will automatically download and build dependencies (Roc Toolkit). Roc will be statically linked into the modules and there is no need to install it into the system.

First install build tools:

```
sudo apt install -y \
g++ pkg-config scons ragel gengetopt \
libuv1-dev libunwind-dev \
libpulse-dev libsox-dev \
libcpputest-dev libspeexdsp-dev \
libtool intltool autoconf automake make cmake
```

Next build and run:

```
make
```

Clean build results:
To specify **roc-toolkit** branch use cmake flag `ROC_TOOLKIT_BRANCH`

```
mkdir build && cd build
cmake -DROC_TOOLKIT_BRANCH=master .. && make
```
### Additional targets

You can accomplish these additional tasks using the following targets.

To clean working build directory:

```
make clean
```

Format code:
To format code:

```
make fmt
```

### Advanced bulid

You can disable automatic downloading of roc-toolkit and build it manually.

Download, build and install Roc Toolkit into the system as described on [this page](https://roc-streaming.org/toolkit/docs/building/user_cookbook.html)

```
mkdir build && cd build
cmake -DDOWNLOAD_ROC=OFF .. && make
```
To provide custom path to roc-toolkit library and headers use flags
`ROC_INCLUDE_DIR` and `ROC_LIB_DIR`



Workflow
--------

Expand Down
22 changes: 22 additions & 0 deletions cmake/define_option.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# A custom function to create an option for the user which
# can be set via environment or provided via cmdline.
# It can be boolean or string
# Order of precedence
# 1. Command line
# 2. Environment variable
# 3. Default specified in cmake

macro(define_option ARG_NAME ARG_DEFAULT ARG_TYPE ARG_HELP)
# overwrite default from environment
set(DEFAULT_VALUE $ENV{${ARG_NAME}})
if(NOT DEFAULT_VALUE)
set(DEFAULT_VALUE "${ARG_DEFAULT}")
endif()

# register option
if(${ARG_TYPE} STREQUAL "BOOL")
option(${ARG_NAME} "${ARG_HELP}" "${DEFAULT_VALUE}")
elseif(${ARG_TYPE} STREQUAL "STRING")
set(${ARG_NAME} "${DEFAULT_VALUE}" CACHE STRING "${ARG_HELP}")
endif()
endmacro()
21 changes: 21 additions & 0 deletions cmake/download_googletest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include(ExternalProject)

ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
GIT_SHALLOW ON
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
INSTALL_COMMAND ""
TEST_COMMAND ""
LOG_DOWNLOAD ON
LOG_BUILD ON
)

include_directories(
"${CMAKE_CURRENT_BINARY_DIR}/googletest-src/googletest/include"
)

link_directories(
"${CMAKE_CURRENT_BINARY_DIR}/googletest-build/lib"
)
56 changes: 56 additions & 0 deletions cmake/download_roc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
include(ExternalProject)

if(DEFINED ENV{CI})
set(USE_LOGFILES OFF)
else()
set(USE_LOGFILES ON)
endif()

set(SCONS_CMD
scons
--prefix=${CMAKE_CURRENT_BINARY_DIR}/roc-prefix
--build-3rdparty=all
--enable-static
--disable-shared
--disable-tools
--disable-sox
--disable-openssl
--disable-libunwind
--disable-pulseaudio
--host=${CMAKE_CXX_COMPILER_TARGET}
"CC=${CMAKE_C_COMPILER}"
"CCLD=${CMAKE_C_COMPILER}"
"CXX=${CMAKE_CXX_COMPILER}"
"CXXLD=${CMAKE_CXX_COMPILER}"
"AR=${CMAKE_AR}"
"RANLIB=${CMAKE_RANLIB}"
"STRIP=${CMAKE_STRIP}"
)


ExternalProject_Add(RocLibrary
GIT_REPOSITORY "https://github.com/roc-streaming/roc-toolkit.git"
GIT_TAG origin/${ROC_BRANCH}
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/roc-src"
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/roc-prefix"
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND ""
BUILD_COMMAND ${SCONS_CMD}
INSTALL_COMMAND ${SCONS_CMD} install
TEST_COMMAND ""
LOG_DOWNLOAD ${USE_LOGFILES}
LOG_PATCH ${USE_LOGFILES}
LOG_CONFIGURE ${USE_LOGFILES}
LOG_BUILD ${USE_LOGFILES}
LOG_INSTALL ${USE_LOGFILES}
LOG_TEST ${USE_LOGFILES}
)


include_directories(
"${CMAKE_CURRENT_BINARY_DIR}/roc-prefix/include"
)

link_directories(
"${CMAKE_CURRENT_BINARY_DIR}/roc-prefix/lib/"
)
Loading