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
32 changes: 30 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,40 @@ ExternalProject_Add(googletest
LOG_BUILD ON
)
gavv marked this conversation as resolved.
Show resolved Hide resolved

include("cmake/define_option.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)
include("cmake/download_roc.cmake")
else()
gavv marked this conversation as resolved.
Show resolved Hide resolved
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()

include_directories(
"${CMAKE_CURRENT_BINARY_DIR}/googletest-src/googletest/include"
#"${CMAKE_CURRENT_BINARY_DIR}/roc-toolkit-src/src/public_api/include"
)

link_directories(
"${CMAKE_CURRENT_BINARY_DIR}/googletest-build/lib"
#"${CMAKE_CURRENT_BINARY_DIR}/roc-toolkit-src/bin/x86_64-pc-linux-gnu/"
)
gavv marked this conversation as resolved.
Show resolved Hide resolved

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -50,12 +78,12 @@ add_executable(rt-tests
tests/test_service_quality.cpp
)

add_dependencies(rt-tests googletest)
add_dependencies(rt-tests googletest roc)

find_package(Threads)

target_link_libraries(rt-tests
roc
-l:libroc.a
gavv marked this conversation as resolved.
Show resolved Hide resolved
gtest
gtest_main
${CMAKE_THREAD_LIBS_INIT})
Expand Down
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,30 @@ 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 \
gcc g++ \
make \
libtool intltool m4 autoconf automake \
meson libsndfile-dev \
cmake \
scons \
git \
wget \
python3
gavv marked this conversation as resolved.
Show resolved Hide resolved
```

Next build and run:

```
make
Expand All @@ -62,6 +80,28 @@ Format code:
make fmt
```
gavv marked this conversation as resolved.
Show resolved Hide resolved

To specify **roc-toolkit** branch use cmake flag `ROC_TOOLKIT_BRANCH`

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

### 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()
57 changes: 57 additions & 0 deletions cmake/download_roc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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}"
Copy link
Member

Choose a reason for hiding this comment

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

I think we should uncomment it to allow cross-compiling.

Here is the code that detects CMAKE_CXX_COMPILER_TARGET if it's empty: https://github.com/roc-streaming/roc-pulse/blob/main/cmake/setup_toolchain.cmake (starting from else(TOOLCHAIN_PREFIX)).

That code also allows using TOOLCHAIN_PREFIX option, which I think can be useful for rt-tests too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uncommented these lines, but I am not sure what needs to be done for cross compilation. Can this be done in a separate PR?

Copy link
Member

Choose a reason for hiding this comment

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

Sure thing.

I've created a separate issue for cross-compilation: #11

Feel free to pick it up or ignore it.

)

define_option(ROC_TOOLKIT_BRANCH "master" STRING "roc-toolkit branch")

ExternalProject_Add(roc
GIT_REPOSITORY "https://github.com/roc-streaming/roc-toolkit.git"
GIT_TAG origin/${ROC_TOOLKIT_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