diff --git a/.travis.yml b/.travis.yml index 86d9225..6a4644d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index accb32c..ffee487 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakeModules/Options.cmake b/CMakeModules/Options.cmake index 1585d77..caecfb6 100644 --- a/CMakeModules/Options.cmake +++ b/CMakeModules/Options.cmake @@ -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") diff --git a/README.md b/README.md index 7181dd2..030aee6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/appveyor.yml b/appveyor.yml index 224d413..a8aaca1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt new file mode 100644 index 0000000..93932bb --- /dev/null +++ b/sample/CMakeLists.txt @@ -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) diff --git a/sample/main.cpp b/sample/main.cpp new file mode 100644 index 0000000..a660fcd --- /dev/null +++ b/sample/main.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 Axel Isouard + * + * 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 +#include +#include + +#ifdef WIN32 +#include +#include +#include +#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 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; +}