From 777247b505b7fabf83e9da4f0a37038b4b5f8cf3 Mon Sep 17 00:00:00 2001 From: Tom Finegan Date: Wed, 24 Feb 2016 10:03:37 -0800 Subject: [PATCH] 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 --- CMakeLists.txt | 106 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 453d001..7adf409 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,23 +5,17 @@ ## tree. An additional intellectual property rights grant can be found ## in the file PATENTS. All contributing project authors may ## be found in the AUTHORS file in the root of the source tree. -cmake_minimum_required(VERSION 2.8) -project(LIBWEBM) +cmake_minimum_required(VERSION 3.2) +project(LIBWEBM CXX) include("${CMAKE_CURRENT_SOURCE_DIR}/build/msvc_runtime.cmake") +include(CheckCXXCompilerFlag) +include(CheckCXXSourceCompiles) + set(LIBWEBM_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -# Enable C++11 support. -set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE) - -# Turn up the warning levels. -if(MSVC) - set(CMAKE_CXX_FLAGS "/W4 ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE) -else () - set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE) -endif() - -# Test configuration flags. Defined here for visibility. +# 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.") @@ -29,6 +23,42 @@ set(GTEST_SRC_DIR "${LIBWEBM_SRC_DIR}/../googletest" CACHE PATH # 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) + endif () + endif () +endif () + +if (MSVC OR HAVE_CXX11) + # C++11 compile tests. + check_cxx_source_compiles(" + #include + int main(int argc, const char* argv[]) { + std::unique_ptr 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. +if (MSVC) + set(CMAKE_CXX_FLAGS "/W4 ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE) +else () + set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE) +endif () + # Libwebm section. add_library(webm STATIC "${LIBWEBM_SRC_DIR}/hdr_util.cpp" @@ -45,12 +75,12 @@ add_library(webm STATIC "${LIBWEBM_SRC_DIR}/mkvwriter.cpp" "${LIBWEBM_SRC_DIR}/mkvwriter.hpp" "${LIBWEBM_SRC_DIR}/webmids.hpp") -if(WIN32) +if (WIN32) # Use libwebm and libwebm.lib for project and library name on Windows (instead # webm and webm.lib). set_target_properties(webm PROPERTIES PROJECT_LABEL libwebm) set_target_properties(webm PROPERTIES PREFIX lib) -endif(WIN32) +endif () include_directories("${LIBWEBM_SRC_DIR}") @@ -77,23 +107,25 @@ add_executable(vttdemux "${LIBWEBM_SRC_DIR}/webvttparser.h") target_link_libraries(vttdemux LINK_PUBLIC webm) -# webmts (PES/TS support) library section. -add_library(webmts - "${LIBWEBM_SRC_DIR}/common/libwebm_utils.cc" - "${LIBWEBM_SRC_DIR}/common/libwebm_utils.h" - "${LIBWEBM_SRC_DIR}/webm2pes.cc" - "${LIBWEBM_SRC_DIR}/webm2pes.h" - "${LIBWEBM_SRC_DIR}/vpxpes2ts.cc" - "${LIBWEBM_SRC_DIR}/vpxpes2ts.h") +if (ENABLE_WEBMTS) + # webmts (PES/TS support) library section. + add_library(webmts + "${LIBWEBM_SRC_DIR}/common/libwebm_utils.cc" + "${LIBWEBM_SRC_DIR}/common/libwebm_utils.h" + "${LIBWEBM_SRC_DIR}/webm2pes.cc" + "${LIBWEBM_SRC_DIR}/webm2pes.h" + "${LIBWEBM_SRC_DIR}/vpxpes2ts.cc" + "${LIBWEBM_SRC_DIR}/vpxpes2ts.h") -# webm2pes section. -add_executable(webm2pes - "${LIBWEBM_SRC_DIR}/webm2pes_main.cc") -target_link_libraries(webm2pes LINK_PUBLIC webm webmts) + # webm2pes section. + add_executable(webm2pes + "${LIBWEBM_SRC_DIR}/webm2pes_main.cc") + target_link_libraries(webm2pes LINK_PUBLIC webm webmts) -# webm2ts section. -add_executable(webm2ts "${LIBWEBM_SRC_DIR}/vpxpes2ts_main.cc") -target_link_libraries(webm2ts LINK_PUBLIC webm webmts) + # webm2ts section. + add_executable(webm2ts "${LIBWEBM_SRC_DIR}/vpxpes2ts_main.cc") + target_link_libraries(webm2ts LINK_PUBLIC webm webmts) +endif () if (ENABLE_TESTS) add_subdirectory("${GTEST_SRC_DIR}" "${GTEST_BUILD_DIR}") @@ -111,10 +143,12 @@ if (ENABLE_TESTS) "${LIBWEBM_SRC_DIR}/testing/test_util.h") target_link_libraries(parser_tests LINK_PUBLIC gtest webm) - add_executable(webm2pes_tests - "${LIBWEBM_SRC_DIR}/testing/test_util.cc" - "${LIBWEBM_SRC_DIR}/testing/test_util.h" - "${LIBWEBM_SRC_DIR}/testing/webm2pes_tests.cc") - target_link_libraries(webm2pes_tests LINK_PUBLIC gtest webm webmts) -endif (ENABLE_TESTS) + if (ENABLE_WEBMTS) + add_executable(webm2pes_tests + "${LIBWEBM_SRC_DIR}/testing/test_util.cc" + "${LIBWEBM_SRC_DIR}/testing/test_util.h" + "${LIBWEBM_SRC_DIR}/testing/webm2pes_tests.cc") + target_link_libraries(webm2pes_tests LINK_PUBLIC gtest webm webmts) + endif () +endif ()