(#23): Add sample target, build it and run it

This commit is contained in:
Axel Isouard 2017-03-27 13:28:37 +02:00
parent 941688e7fc
commit 9f324642f5
7 changed files with 107 additions and 2 deletions

View file

@ -63,7 +63,7 @@ install:
- git submodule update
- mkdir out
- cd out
- cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DTARGET_CPU=$TARGET_CPU ..
- cmake -DBUILD_SAMPLE=1 -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DCMAKE_INSTALL_PREFIX=. -DTARGET_CPU=$TARGET_CPU ..
script:
- make -j 4 package

View file

@ -115,6 +115,18 @@ ExternalProject_Add(
-DWEBRTC_SOURCE_DIR:PATH=${CMAKE_BINARY_DIR}/webrtc/src/webrtc
)
if (BUILD_SAMPLE)
ExternalProject_Add(
sample
DEPENDS libwebrtc
SOURCE_DIR ${CMAKE_SOURCE_DIR}/sample
INSTALL_COMMAND ""
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
)
endif (BUILD_SAMPLE)
include(Install)
include(Package)

View file

@ -1,6 +1,7 @@
#
# Options, flags
option(BUILD_TESTS "Build test binaries" OFF)
option(BUILD_SAMPLE "Build sample" OFF)
set(DEPOT_TOOLS_PATH "" CACHE STRING "Path to your own depot_tools directory")
set(NINJA_ARGS "" CACHE STRING "Ninja arguments to pass before compiling WebRTC")
set(GN_EXTRA_ARGS "" CACHE STRING "Extra gn gen arguments to pass before generating build files")

View file

@ -191,6 +191,10 @@ perform cross-compiling.
Generate Red Hat package, defaults to OFF, available under Linux only.
- **BUILD_SAMPLE**
Build an executable located inside the `sample` folder.
- **DEPOT_TOOLS_PATH**
Set this variable to your own `depot_tools` directory. This will prevent

View file

@ -20,7 +20,7 @@ before_build:
- cd c:\projects\libwebrtc
- if "%platform%"=="x86" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015
- if "%platform%"=="x64" set CMAKE_GENERATOR_NAME=Visual Studio 14 2015 Win64
- cmake -G "%CMAKE_GENERATOR_NAME%" -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=c:\projects\libwebrtc .
- cmake -G "%CMAKE_GENERATOR_NAME%" -DBUILD_SAMPLE=1 -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=c:\projects\libwebrtc .
artifacts:
- path: libwebrtc-0.0.1-rc.4-win-x86.zip

21
sample/CMakeLists.txt Normal file
View file

@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.3)
project(sample)
find_package(LibWebRTC REQUIRED)
include(${LIBWEBRTC_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(sample ${SOURCE_FILES})
target_link_libraries(sample ${LIBWEBRTC_LIBRARIES})
set(_STAMP_FILE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/check-sample-done)
add_custom_command(
OUTPUT ${_STAMP_FILE}
COMMENT "Run generated sample"
COMMAND sample
COMMAND ${CMAKE_COMMAND} -E touch ${_STAMP_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(check-sample ALL DEPENDS ${_STAMP_FILE})
add_dependencies(check-sample sample)

67
sample/main.cpp Normal file
View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2017 Axel Isouard <axel@isouard.fr>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <webrtc/api/peerconnectioninterface.h>
#include <webrtc/base/ssladapter.h>
#include <webrtc/base/thread.h>
#ifdef WIN32
#include <webrtc/base/win32socketinit.h>
#include <webrtc/base/win32socketserver.h>
#include <Windows.h>
#endif
int main(int argc, char **argv) {
#ifdef WIN32
rtc::EnsureWinsockInit();
rtc::Win32Thread w32_thread;
rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
#endif
rtc::InitializeSSL();
rtc::InitRandom(rtc::Time());
rtc::ThreadManager::Instance()->WrapCurrentThread();
rtc::Thread *signalingThread = new rtc::Thread();
rtc::Thread *workerThread = new rtc::Thread();
signalingThread->SetName("signaling_thread", NULL);
workerThread->SetName("worker_thread", NULL);
if (!signalingThread->Start() || !workerThread->Start()) {
return 1;
}
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcFactory =
webrtc::CreatePeerConnectionFactory(signalingThread,
workerThread,
NULL, NULL, NULL);
pcFactory = NULL;
if (rtc::ThreadManager::Instance()->CurrentThread() == signalingThread) {
rtc::ThreadManager::Instance()->SetCurrentThread(NULL);
}
signalingThread->Stop();
workerThread->Stop();
delete signalingThread;
delete workerThread;
rtc::CleanupSSL();
return 0;
}