diff --git a/CMakeLists.txt b/CMakeLists.txt index c282e60..653a3bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,14 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} find_package(Git REQUIRED) +set(WEBRTC_GIT_URL https://chromium.googlesource.com/external/webrtc) +set(WEBRTC_DEFAULT_HEAD 60) +set(WEBRTC_SOURCE_DIR ${CMAKE_BINARY_DIR}/webrtc/src) + include(FindLibraries) -include(Version) include(Options) +include(VersionWebRTC) +include(Version) include(TargetOsAndCpu) if (HAS_OWN_DEPOT_TOOLS) @@ -58,34 +63,25 @@ set(_WEBRTC_CMAKE_ARGS -DHAS_OWN_DEPOT_TOOLS:PATH=${HAS_OWN_DEPOT_TOOLS} -DTARGET_CPU=${TARGET_CPU} -DTARGET_OS=${TARGET_OS} - -DWEBRTC_PARENT_DIR:PATH=${CMAKE_BINARY_DIR}/webrtc) + -DWEBRTC_PARENT_DIR:PATH=${CMAKE_BINARY_DIR}/webrtc + -DWEBRTC_REVISION=${WEBRTC_REVISION}) if (BUILD_TESTS) set(_WEBRTC_CMAKE_ARGS ${_WEBRTC_CMAKE_ARGS} -DBUILD_TESTS=${BUILD_TESTS}) endif (BUILD_TESTS) -if (WEBRTC_BRANCH_HEAD) - set(_WEBRTC_CMAKE_ARGS ${_WEBRTC_CMAKE_ARGS} -DWEBRTC_BRANCH_HEAD=${WEBRTC_BRANCH_HEAD}) -endif (WEBRTC_BRANCH_HEAD) - -if (WEBRTC_REVISION) - set(_WEBRTC_CMAKE_ARGS ${_WEBRTC_CMAKE_ARGS} -DWEBRTC_REVISION=${WEBRTC_REVISION}) -endif (WEBRTC_REVISION) - ExternalProject_Add( webrtc-src DEPENDS ${_NEXT_DEPENDS} - GIT_REPOSITORY https://chromium.googlesource.com/external/webrtc PREFIX ${CMAKE_BINARY_DIR}/webrtc BINARY_DIR ${CMAKE_BINARY_DIR}/webrtc/build - DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/webrtc/src - SOURCE_DIR ${CMAKE_BINARY_DIR}/webrtc/src + SOURCE_DIR ${WEBRTC_SOURCE_DIR} STAMP_DIR ${CMAKE_BINARY_DIR}/webrtc/stamp TMP_DIR ${CMAKE_BINARY_DIR}/webrtc/tmp - PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/webrtc/CMakeLists.txt.in ${CMAKE_BINARY_DIR}/webrtc/src/CMakeLists.txt + PATCH_COMMAND "" UPDATE_COMMAND "" INSTALL_COMMAND "" diff --git a/CMakeModules/DepotTools.cmake b/CMakeModules/DepotTools.cmake index 90a8254..670dd15 100644 --- a/CMakeModules/DepotTools.cmake +++ b/CMakeModules/DepotTools.cmake @@ -4,27 +4,14 @@ endif (HAS_OWN_DEPOT_TOOLS) include(LibWebRTCExecute) -if (WEBRTC_REVISION) - libwebrtc_execute( - COMMAND ${GIT_EXECUTABLE} log -1 --format=%ci ${WEBRTC_REVISION} - OUTPUT_VARIABLE _WEBRTC_COMMIT_DATE - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - STAMPFILE webrtc-revision-commit-date - STATUS "Retrieving date for commit ${WEBRTC_REVISION}" - ERROR "Unable to find webrtc commit date at ${WEBRTC_REVISION}" - ) -elseif (WEBRTC_BRANCH_HEAD) - libwebrtc_execute( - COMMAND ${GIT_EXECUTABLE} log -1 --format=%ci - OUTPUT_VARIABLE _WEBRTC_COMMIT_DATE - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - STAMPFILE webrtc-branch-head-commit-date - STATUS "Retrieving date for ${WEBRTC_BRANCH_HEAD}" - ERROR "Unable to retrieve the commit date for ${WEBRTC_BRANCH_HEAD}" - ) -else (WEBRTC_REVISION) - message(FATAL_ERROR "-- Both WEBRTC_REVISION and WEBRTC_BRANCH_HEAD variables are undefined") -endif (WEBRTC_REVISION) +libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} log -1 --format=%ci ${WEBRTC_REVISION} + OUTPUT_VARIABLE _WEBRTC_COMMIT_DATE + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + STAMPFILE webrtc-revision-commit-date + STATUS "Retrieving date for commit ${WEBRTC_REVISION}" + ERROR "Unable to find webrtc commit date at ${WEBRTC_REVISION}" +) string(STRIP ${_WEBRTC_COMMIT_DATE} _WEBRTC_COMMIT_DATE) libwebrtc_execute( diff --git a/CMakeModules/Options.cmake b/CMakeModules/Options.cmake index caecfb6..195481e 100644 --- a/CMakeModules/Options.cmake +++ b/CMakeModules/Options.cmake @@ -6,7 +6,7 @@ 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") set(WEBRTC_REVISION "" CACHE STRING "WebRTC commit hash to checkout") -set(WEBRTC_BRANCH_HEAD "${LIBWEBRTC_WEBRTC_HEAD}" CACHE STRING "WebRTC branch head to checkout") +set(WEBRTC_BRANCH_HEAD "${WEBRTC_DEFAULT_HEAD}" CACHE STRING "WebRTC branch head to checkout") if (DEPOT_TOOLS_PATH) set(HAS_OWN_DEPOT_TOOLS 1) diff --git a/CMakeModules/Version.cmake b/CMakeModules/Version.cmake index 7d52305..28ddfa2 100644 --- a/CMakeModules/Version.cmake +++ b/CMakeModules/Version.cmake @@ -18,6 +18,6 @@ string(REGEX REPLACE "^v?[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" LIBWEBRTC_BUILD_VER set(LIBWEBRTC_API_VERSION "${LIBWEBRTC_MAJOR_VERSION}.${LIBWEBRTC_MINOR_VERSION}.${LIBWEBRTC_PATCH_VERSION}") set(LIBWEBRTC_VERSION - ${LIBWEBRTC_API_VERSION}${LIBWEBRTC_BUILD_VERSION}) + "${LIBWEBRTC_API_VERSION}${LIBWEBRTC_BUILD_VERSION}+${WEBRTC_BRANCH_HEAD}-${WEBRTC_REVISION}") -set(LIBWEBRTC_WEBRTC_HEAD refs/branch-heads/60) +message(STATUS "Building version ${LIBWEBRTC_VERSION}") diff --git a/CMakeModules/VersionWebRTC.cmake b/CMakeModules/VersionWebRTC.cmake new file mode 100644 index 0000000..75d606d --- /dev/null +++ b/CMakeModules/VersionWebRTC.cmake @@ -0,0 +1,86 @@ +include(LibWebRTCExecute) + +libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} clone --depth 1 ${WEBRTC_GIT_URL} ${WEBRTC_SOURCE_DIR} + OUTPUT_VARIABLE _WEBRTC_CLONE + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + STAMPFILE webrtc-clone + STATUS "Cloning WebRTC" + ERROR "Unable to clone WebRTC" +) + +libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} config remote.origin.fetch +refs/branch-heads/*:refs/remotes/branch-heads/* ^\\+refs/branch-heads/\\*:.*$ + OUTPUT_VARIABLE _WEBRTC_CONFIG_FETCH + WORKING_DIRECTORY ${WEBRTC_SOURCE_DIR} + STAMPFILE webrtc-config-fetch + STATUS "Setting up WebRTC branch-heads refspecs" + ERROR "Unable to setup up WebRTC branch-heads refspecs" +) + +# get WebRTC version +if (WEBRTC_REVISION) + libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} fetch origin + OUTPUT_VARIABLE _WEBRTC_FETCH + WORKING_DIRECTORY ${WEBRTC_SOURCE_DIR} + STAMPFILE webrtc-fetch + STATUS "Fetching webrtc" + ERROR "Unable to fetch webrtc" + ) + libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} checkout ${WEBRTC_REVISION} + OUTPUT_VARIABLE _WEBRTC_CHECKOUT + WORKING_DIRECTORY ${WEBRTC_SOURCE_DIR} + STAMPFILE webrtc-checkout-commit + STATUS "Checking out webrtc to commit ${WEBRTC_REVISION}" + ERROR "Unable to checkout webrtc to commit ${WEBRTC_REVISION}" + ) + libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} name-rev --refs remotes/branch-heads/* --name-only ${WEBRTC_REVISION} + OUTPUT_VARIABLE _WEBRTC_NAME_REV + WORKING_DIRECTORY ${WEBRTC_SOURCE_DIR} + STAMPFILE webrtc-name-rev + STATUS "Finding out WebRTC branch for commit ${WEBRTC_REVISION}" + ERROR "Unable to find out WebRTC branch for commit ${WEBRTC_REVISION}" + ) + string(REGEX MATCH "^branch-heads/([0-9]+).*" _MATCHES "${_WEBRTC_NAME_REV}") + if (_MATCHES) + set(WEBRTC_BRANCH_HEAD ${CMAKE_MATCH_1}) + else (_MATCHES) + message(FATAL_ERROR "-- Unable to find out WebRTC branch for commit ${WEBRTC_REVISION} in name ${_WEBRTC_NAME_REV}") + endif (_MATCHES) +elseif (WEBRTC_BRANCH_HEAD) + libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} ls-remote --exit-code ${WEBRTC_GIT_URL} refs/branch-heads/${WEBRTC_BRANCH_HEAD} + OUTPUT_VARIABLE _WEBRTC_BRANCH_HEAD_INFO + WORKING_DIRECTORY ${WEBRTC_SOURCE_DIR} + STAMPFILE webrtc-branch-head-info + STATUS "Retrieving info for WebRTC branch ${WEBRTC_BRANCH_HEAD}" + ERROR "Unable to retrieve info for WebRTC branch ${WEBRTC_BRANCH_HEAD}" + ) + string(REGEX REPLACE "^[ \t]*([0-9a-f]+)[ \t]+.*" "\\1" WEBRTC_REVISION "${_WEBRTC_BRANCH_HEAD_INFO}") + + libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} fetch origin ${WEBRTC_REVISION} + OUTPUT_VARIABLE _WEBRTC_FETCH + WORKING_DIRECTORY ${WEBRTC_SOURCE_DIR} + STAMPFILE webrtc-fetch-commit + STATUS "Fetching webrtc commit ${WEBRTC_REVISION}" + ERROR "Unable to fetch webrtc commit ${WEBRTC_REVISION}" + ) + libwebrtc_execute( + COMMAND ${GIT_EXECUTABLE} checkout ${WEBRTC_REVISION} + OUTPUT_VARIABLE _WEBRTC_CHECKOUT + WORKING_DIRECTORY ${WEBRTC_SOURCE_DIR} + STAMPFILE webrtc-checkout-commit + STATUS "Checking out webrtc to commit ${WEBRTC_REVISION}" + ERROR "Unable to checkout webrtc to commit ${WEBRTC_REVISION}" + ) +else (WEBRTC_REVISION) + message(FATAL_ERROR "-- Both WEBRTC_REVISION and WEBRTC_BRANCH_HEAD variables are undefined") +endif (WEBRTC_REVISION) + +configure_file(${CMAKE_SOURCE_DIR}/webrtc/CMakeLists.txt.in ${WEBRTC_SOURCE_DIR}/CMakeLists.txt @ONLY) + +message(STATUS "WebRTC version ${WEBRTC_BRANCH_HEAD}-${WEBRTC_REVISION}") diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 93932bb..e37a2de 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -4,6 +4,10 @@ project(sample) find_package(LibWebRTC REQUIRED) include(${LIBWEBRTC_USE_FILE}) +configure_file("config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h") + +include_directories("${CMAKE_CURRENT_BINARY_DIR}") + set(SOURCE_FILES main.cpp) add_executable(sample ${SOURCE_FILES}) target_link_libraries(sample ${LIBWEBRTC_LIBRARIES}) diff --git a/sample/config.h.in b/sample/config.h.in new file mode 100644 index 0000000..4f8039a --- /dev/null +++ b/sample/config.h.in @@ -0,0 +1,17 @@ +/* + * 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. + */ + +#define LIBWEBRTC_WEBRTC_BRANCH_HEAD @LIBWEBRTC_WEBRTC_BRANCH_HEAD@ diff --git a/sample/main.cpp b/sample/main.cpp index a073972..2af386c 100644 --- a/sample/main.cpp +++ b/sample/main.cpp @@ -24,11 +24,17 @@ #include #endif +#include "config.h" + int main(int argc, char **argv) { #ifdef WIN32 rtc::EnsureWinsockInit(); +#if LIBWEBRTC_WEBRTC_BRANCH_HEAD > 59 rtc::Win32SocketServer w32_ss; rtc::Win32Thread w32_thread(&w32_ss); +#else + rtc::Win32Thread w32_thread; +#endif rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread); #endif diff --git a/webrtc/CMakeLists.txt.in b/webrtc/CMakeLists.txt.in index b6c3874..dc94ff2 100644 --- a/webrtc/CMakeLists.txt.in +++ b/webrtc/CMakeLists.txt.in @@ -8,46 +8,6 @@ else (WIN32) find_package(PythonInterp 2.7 REQUIRED) endif (WIN32) -include(LibWebRTCExecute) - -if (WEBRTC_REVISION) - libwebrtc_execute( - COMMAND ${GIT_EXECUTABLE} checkout ${WEBRTC_REVISION} - OUTPUT_VARIABLE _WEBRTC_CHECKOUT - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - STAMPFILE webrtc-checkout-commit - STATUS "Checking out webrtc to commit ${WEBRTC_REVISION}" - ERROR "Unable to checkout webrtc to commit ${WEBRTC_REVISION}" - ) -elseif (WEBRTC_BRANCH_HEAD) - libwebrtc_execute( - COMMAND ${GIT_EXECUTABLE} config remote.origin.fetch +refs/branch-heads/*:refs/remotes/branch-heads/* ^\\+refs/branch-heads/\\*:.*$ - OUTPUT_VARIABLE _WEBRTC_CONFIG_FETCH - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - STAMPFILE webrtc-config-fetch - STATUS "Setting up branch-heads refspecs" - ERROR "Unable to add branch-heads refspec to the git config" - ) - - libwebrtc_execute( - COMMAND ${GIT_EXECUTABLE} fetch origin ${WEBRTC_BRANCH_HEAD} - OUTPUT_VARIABLE _WEBRTC_FETCH - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - STAMPFILE webrtc-fetch-branch-heads - STATUS "Fetching ${WEBRTC_BRANCH_HEAD}" - ERROR "Unable to fetch ${WEBRTC_BRANCH_HEAD}" - ) - - libwebrtc_execute( - COMMAND ${GIT_EXECUTABLE} checkout FETCH_HEAD - OUTPUT_VARIABLE _WEBRTC_CHECKOUT - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - STAMPFILE webrtc-checkout-branch-head - STATUS "Checking out ${WEBRTC_BRANCH_HEAD}" - ERROR "Unable to checkout ${WEBRTC_BRANCH_HEAD}" - ) -endif (WEBRTC_REVISION) - include(DepotTools) include(GClient) include(Environment) @@ -144,7 +104,11 @@ libwebrtc_command( DEPENDS ${_DEPENDENCIES} ) -set(_NINJA_COMMAND ninja ${NINJA_ARGS} -C ${_NINJA_BUILD_DIR} webrtc system_wrappers_default) +if (@WEBRTC_BRANCH_HEAD@ GREATER 57) + set(_NINJA_COMMAND ninja ${NINJA_ARGS} -C ${_NINJA_BUILD_DIR} webrtc system_wrappers_default) +else (@WEBRTC_BRANCH_HEAD@ GREATER 57) + set(_NINJA_COMMAND ninja ${NINJA_ARGS} -C ${_NINJA_BUILD_DIR} webrtc system_wrappers_default libjingle_peerconnection) +endif (@WEBRTC_BRANCH_HEAD@ GREATER 57) if (BUILD_TESTS) set(_NINJA_COMMAND ${_NINJA_COMMAND} webrtc_tests)