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:
106
CMakeLists.txt
106
CMakeLists.txt
@@ -5,23 +5,17 @@
|
|||||||
## 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.
|
||||||
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
|
option(ENABLE_WEBMTS "Enables WebM PES/TS support." ON)
|
||||||
|
|
||||||
# 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.
|
|
||||||
option(ENABLE_TESTS "Enables tests." OFF)
|
option(ENABLE_TESTS "Enables tests." OFF)
|
||||||
set(GTEST_SRC_DIR "${LIBWEBM_SRC_DIR}/../googletest" CACHE PATH
|
set(GTEST_SRC_DIR "${LIBWEBM_SRC_DIR}/../googletest" CACHE PATH
|
||||||
"Path to Googletest git repository.")
|
"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.
|
# This directory is where libwebm will build googletest dependencies.
|
||||||
set(GTEST_BUILD_DIR "${CMAKE_BINARY_DIR}/googletest_build")
|
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 <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.
|
||||||
|
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.
|
# Libwebm section.
|
||||||
add_library(webm STATIC
|
add_library(webm STATIC
|
||||||
"${LIBWEBM_SRC_DIR}/hdr_util.cpp"
|
"${LIBWEBM_SRC_DIR}/hdr_util.cpp"
|
||||||
@@ -45,12 +75,12 @@ add_library(webm STATIC
|
|||||||
"${LIBWEBM_SRC_DIR}/mkvwriter.cpp"
|
"${LIBWEBM_SRC_DIR}/mkvwriter.cpp"
|
||||||
"${LIBWEBM_SRC_DIR}/mkvwriter.hpp"
|
"${LIBWEBM_SRC_DIR}/mkvwriter.hpp"
|
||||||
"${LIBWEBM_SRC_DIR}/webmids.hpp")
|
"${LIBWEBM_SRC_DIR}/webmids.hpp")
|
||||||
if(WIN32)
|
if (WIN32)
|
||||||
# Use libwebm and libwebm.lib for project and library name on Windows (instead
|
# Use libwebm and libwebm.lib for project and library name on Windows (instead
|
||||||
# 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,23 +107,25 @@ 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)
|
||||||
|
|
||||||
# webmts (PES/TS support) library section.
|
if (ENABLE_WEBMTS)
|
||||||
add_library(webmts
|
# webmts (PES/TS support) library section.
|
||||||
"${LIBWEBM_SRC_DIR}/common/libwebm_utils.cc"
|
add_library(webmts
|
||||||
"${LIBWEBM_SRC_DIR}/common/libwebm_utils.h"
|
"${LIBWEBM_SRC_DIR}/common/libwebm_utils.cc"
|
||||||
"${LIBWEBM_SRC_DIR}/webm2pes.cc"
|
"${LIBWEBM_SRC_DIR}/common/libwebm_utils.h"
|
||||||
"${LIBWEBM_SRC_DIR}/webm2pes.h"
|
"${LIBWEBM_SRC_DIR}/webm2pes.cc"
|
||||||
"${LIBWEBM_SRC_DIR}/vpxpes2ts.cc"
|
"${LIBWEBM_SRC_DIR}/webm2pes.h"
|
||||||
"${LIBWEBM_SRC_DIR}/vpxpes2ts.h")
|
"${LIBWEBM_SRC_DIR}/vpxpes2ts.cc"
|
||||||
|
"${LIBWEBM_SRC_DIR}/vpxpes2ts.h")
|
||||||
|
|
||||||
# webm2pes section.
|
# webm2pes section.
|
||||||
add_executable(webm2pes
|
add_executable(webm2pes
|
||||||
"${LIBWEBM_SRC_DIR}/webm2pes_main.cc")
|
"${LIBWEBM_SRC_DIR}/webm2pes_main.cc")
|
||||||
target_link_libraries(webm2pes LINK_PUBLIC webm webmts)
|
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)
|
||||||
|
|
||||||
add_executable(webm2pes_tests
|
if (ENABLE_WEBMTS)
|
||||||
"${LIBWEBM_SRC_DIR}/testing/test_util.cc"
|
add_executable(webm2pes_tests
|
||||||
"${LIBWEBM_SRC_DIR}/testing/test_util.h"
|
"${LIBWEBM_SRC_DIR}/testing/test_util.cc"
|
||||||
"${LIBWEBM_SRC_DIR}/testing/webm2pes_tests.cc")
|
"${LIBWEBM_SRC_DIR}/testing/test_util.h"
|
||||||
target_link_libraries(webm2pes_tests LINK_PUBLIC gtest webm webmts)
|
"${LIBWEBM_SRC_DIR}/testing/webm2pes_tests.cc")
|
||||||
endif (ENABLE_TESTS)
|
target_link_libraries(webm2pes_tests LINK_PUBLIC gtest webm webmts)
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user