Add C++11 detection to cmake file.

Disable test and webmts targets when not C++11 and/or
std::unique_ptr are unavailable.

BUG=https://bugs.chromium.org/p/webm/issues/detail?id=1136

Change-Id: I717631bc6adea90c91e59862378328089e9aeec6
This commit is contained in:
Tom Finegan
2016-02-24 10:03:37 -08:00
parent 9b89187db0
commit 777247b505

View File

@@ -5,14 +5,52 @@
## tree. An additional intellectual property rights grant can be found ## tree. An additional intellectual property rights grant can be found
## in the file PATENTS. All contributing project authors may ## in the file PATENTS. All contributing project authors may
## be found in the AUTHORS file in the root of the source tree. ## be found in the AUTHORS file in the root of the source tree.
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 3.2)
project(LIBWEBM) project(LIBWEBM CXX)
include("${CMAKE_CURRENT_SOURCE_DIR}/build/msvc_runtime.cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/build/msvc_runtime.cmake")
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
set(LIBWEBM_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(LIBWEBM_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
# Enable C++11 support. # Build/test configuration flags. Defined here for visibility.
option(ENABLE_WEBMTS "Enables WebM PES/TS support." ON)
option(ENABLE_TESTS "Enables tests." OFF)
set(GTEST_SRC_DIR "${LIBWEBM_SRC_DIR}/../googletest" CACHE PATH
"Path to Googletest git repository.")
# This directory is where libwebm will build googletest dependencies.
set(GTEST_BUILD_DIR "${CMAKE_BINARY_DIR}/googletest_build")
if (ENABLE_TESTS OR ENABLE_WEBMTS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAVE_CXX11)
if (HAVE_CXX11)
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
endif ()
endif ()
endif ()
if (MSVC OR HAVE_CXX11)
# C++11 compile tests.
check_cxx_source_compiles("
#include <memory>
int main(int argc, const char* argv[]) {
std::unique_ptr<int> ptr;
(void)ptr;
return 0;
}"
HAVE_UNIQUE_PTR)
endif ()
if (NOT HAVE_UNIQUE_PTR)
set(ENABLE_TESTS OFF)
set(ENABLE_WEBMTS OFF)
message(WARNING "std::unique_ptr not supported, tests and webmts disabled.")
endif ()
# Turn up the warning levels. # Turn up the warning levels.
if (MSVC) if (MSVC)
@@ -21,14 +59,6 @@ else ()
set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
endif () endif ()
# Test configuration flags. Defined here for visibility.
option(ENABLE_TESTS "Enables tests." OFF)
set(GTEST_SRC_DIR "${LIBWEBM_SRC_DIR}/../googletest" CACHE PATH
"Path to Googletest git repository.")
# This directory is where libwebm will build googletest dependencies.
set(GTEST_BUILD_DIR "${CMAKE_BINARY_DIR}/googletest_build")
# Libwebm section. # Libwebm section.
add_library(webm STATIC add_library(webm STATIC
"${LIBWEBM_SRC_DIR}/hdr_util.cpp" "${LIBWEBM_SRC_DIR}/hdr_util.cpp"
@@ -50,7 +80,7 @@ if(WIN32)
# webm and webm.lib). # webm and webm.lib).
set_target_properties(webm PROPERTIES PROJECT_LABEL libwebm) set_target_properties(webm PROPERTIES PROJECT_LABEL libwebm)
set_target_properties(webm PROPERTIES PREFIX lib) set_target_properties(webm PROPERTIES PREFIX lib)
endif(WIN32) endif ()
include_directories("${LIBWEBM_SRC_DIR}") include_directories("${LIBWEBM_SRC_DIR}")
@@ -77,6 +107,7 @@ add_executable(vttdemux
"${LIBWEBM_SRC_DIR}/webvttparser.h") "${LIBWEBM_SRC_DIR}/webvttparser.h")
target_link_libraries(vttdemux LINK_PUBLIC webm) target_link_libraries(vttdemux LINK_PUBLIC webm)
if (ENABLE_WEBMTS)
# webmts (PES/TS support) library section. # webmts (PES/TS support) library section.
add_library(webmts add_library(webmts
"${LIBWEBM_SRC_DIR}/common/libwebm_utils.cc" "${LIBWEBM_SRC_DIR}/common/libwebm_utils.cc"
@@ -94,6 +125,7 @@ target_link_libraries(webm2pes LINK_PUBLIC webm webmts)
# webm2ts section. # webm2ts section.
add_executable(webm2ts "${LIBWEBM_SRC_DIR}/vpxpes2ts_main.cc") add_executable(webm2ts "${LIBWEBM_SRC_DIR}/vpxpes2ts_main.cc")
target_link_libraries(webm2ts LINK_PUBLIC webm webmts) target_link_libraries(webm2ts LINK_PUBLIC webm webmts)
endif ()
if (ENABLE_TESTS) if (ENABLE_TESTS)
add_subdirectory("${GTEST_SRC_DIR}" "${GTEST_BUILD_DIR}") add_subdirectory("${GTEST_SRC_DIR}" "${GTEST_BUILD_DIR}")
@@ -111,10 +143,12 @@ if (ENABLE_TESTS)
"${LIBWEBM_SRC_DIR}/testing/test_util.h") "${LIBWEBM_SRC_DIR}/testing/test_util.h")
target_link_libraries(parser_tests LINK_PUBLIC gtest webm) target_link_libraries(parser_tests LINK_PUBLIC gtest webm)
if (ENABLE_WEBMTS)
add_executable(webm2pes_tests add_executable(webm2pes_tests
"${LIBWEBM_SRC_DIR}/testing/test_util.cc" "${LIBWEBM_SRC_DIR}/testing/test_util.cc"
"${LIBWEBM_SRC_DIR}/testing/test_util.h" "${LIBWEBM_SRC_DIR}/testing/test_util.h"
"${LIBWEBM_SRC_DIR}/testing/webm2pes_tests.cc") "${LIBWEBM_SRC_DIR}/testing/webm2pes_tests.cc")
target_link_libraries(webm2pes_tests LINK_PUBLIC gtest webm webmts) target_link_libraries(webm2pes_tests LINK_PUBLIC gtest webm webmts)
endif (ENABLE_TESTS) endif ()
endif ()