From 7897567e4ecabc46e3843612751a15dc4df014a0 Mon Sep 17 00:00:00 2001 From: Tom Finegan Date: Tue, 30 May 2017 08:55:54 -0700 Subject: [PATCH] Add dist rule to CMake build and correct behavior of the install rule. - Install only includes, libs, and aomdec/aomenc in the install rule. - Install docs and examples in addition to the above in the dist rule. BUG=aomedia:76,aomedia:375 Change-Id: If42832ebd21184e6f9bf95c3b43c6d4e05663bf2 --- CMakeLists.txt | 66 +++++++++++++++++++++++++++++++++++------- build/cmake/dist.cmake | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 build/cmake/dist.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a43eb8f3..3b27de58f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,7 +243,7 @@ if (CONFIG_AV1_DECODER) "${AOM_ROOT}/examples/inspect.c" $ $) - set(AOM_APP_TARGETS ${AOM_APP_TARGETS} inspect) + set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS} inspect) if (EMSCRIPTEN) add_preproc_definition(_POSIX_SOURCE) @@ -259,9 +259,10 @@ if (CONFIG_AV1_DECODER) endif () endif () - # Add decoder apps to app target list. - set(AOM_APP_TARGETS ${AOM_APP_TARGETS} aomdec decode_to_md5 decode_with_drops - simple_decoder) + # Maintain lists of example and app targets. + set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS} + decode_to_md5 decode_with_drops simple_decoder) + set(AOM_APP_TARGETS ${AOM_APP_TARGETS} aomdec ${AOM_DECODER_EXAMPLE_TARGETS}) endif () @@ -289,16 +290,24 @@ if (CONFIG_AV1_ENCODER) $ $) - # Add encoder apps to app target list. - set(AOM_APP_TARGETS ${AOM_APP_TARGETS} aomenc lossless_encoder set_maps - simple_encoder twopass_encoder) + # Add encoder apps and examples to target lists. + set(AOM_ENCODER_EXAMPLE_TARGETS + lossless_encoder set_maps simple_encoder twopass_encoder) + set(AOM_APP_TARGETS ${AOM_APP_TARGETS} aomenc ${AOM_ENCODER_EXAMPLE_TARGETS}) endif () +# Maintain a separate variable listing only the examples to facilitate +# installation of example programs into an examples sub directory of +# $AOM_DIST_DIR/bin when building the dist target. +set(AOM_EXAMPLE_TARGETS + ${AOM_DECODER_EXAMPLE_TARGETS} ${AOM_ENCODER_EXAMPLE_TARGETS}) + if (CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER) add_executable(aom_cx_set_ref "${AOM_ROOT}/examples/aom_cx_set_ref.c" $ $) + set(AOM_EXAMPLE_TARGETS ${AOM_EXAMPLE_TARGETS} aom_cx_set_ref) set(AOM_APP_TARGETS ${AOM_APP_TARGETS} aom_cx_set_ref) endif () @@ -374,6 +383,14 @@ if (XCODE) endif () endif () +if ("${CMAKE_GENERATOR}" MATCHES "Makefiles$" ) + # Users of the configure build expect the example targets to be built in the + # examples sub directory of the configured build directory after running make. + file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/examples") + set_target_properties(${AOM_EXAMPLE_TARGETS} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${AOM_CONFIG_DIR}/examples") +endif () + # Aomedia documentation rule. if (ENABLE_DOCS) include(FindDoxygen) @@ -420,7 +437,36 @@ install(FILES "${AOM_CONFIG_DIR}/aom.pc" install(TARGETS ${AOM_INSTALL_LIBS} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${AOM_INSTALL_BINS} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") -if (ENABLE_DOCS) - install(DIRECTORY "${AOM_CONFIG_DIR}/docs/html" - DESTINATION "${CMAKE_INSTALL_PREFIX}/docs/aom") +# Aomedia dist rule. +if (CONFIG_AV1_DECODER) + set(AOM_DIST_APPS ${AOM_DIST_APPS} $) +endif () +if (CONFIG_AV1_ENCODER) + set(AOM_DIST_APPS ${AOM_DIST_APPS} $) +endif () + +foreach (example ${AOM_EXAMPLE_TARGETS}) + list(APPEND AOM_DIST_EXAMPLES $) +endforeach () + +if (NOT AOM_DIST_DIR) + set(AOM_DIST_DIR "${AOM_CONFIG_DIR}/dist") +endif () + +add_custom_target(dist + COMMAND ${CMAKE_COMMAND} + -DAOM_ROOT=${AOM_ROOT} + -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR} + -DAOM_DIST_DIR=${AOM_DIST_DIR} + -DAOM_DIST_APPS="${AOM_DIST_APPS}" + -DAOM_DIST_EXAMPLES="${AOM_DIST_EXAMPLES}" + -DAOM_DIST_INCLUDES="${AOM_INSTALL_INCS}" + -DAOM_DIST_LIBS=$ + -DENABLE_DOCS=${ENABLE_DOCS} + -P "${AOM_ROOT}/build/cmake/dist.cmake" + DEPENDS ${AOM_INSTALL_BINS} ${AOM_INSTALL_LIBS} + ${AOM_INSTALL_INCS} ${AOM_EXAMPLE_TARGETS}) + +if (ENABLE_DOCS) + add_dependencies(dist docs) endif () diff --git a/build/cmake/dist.cmake b/build/cmake/dist.cmake new file mode 100644 index 000000000..0de68a44d --- /dev/null +++ b/build/cmake/dist.cmake @@ -0,0 +1,51 @@ +## +## Copyright (c) 2017, Alliance for Open Media. All rights reserved +## +## This source code is subject to the terms of the BSD 2 Clause License and +## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License +## was not distributed with this source code in the LICENSE file, you can +## obtain it at www.aomedia.org/license/software. If the Alliance for Open +## Media Patent License 1.0 was not distributed with this source code in the +## PATENTS file, you can obtain it at www.aomedia.org/license/patent. +## +cmake_minimum_required(VERSION 3.5) + +# Converts spaces in $in_string to semicolons and writes the output to +# $out_string. In CMake's eyes this converts the input string to a list. +function (listify_string in_string out_string) + string(REPLACE " " ";" ${out_string} ${in_string}) + set(${out_string} "${${out_string}}" PARENT_SCOPE) +endfunction () + +set(REQUIRED_ARGS "AOM_ROOT" "AOM_CONFIG_DIR" "AOM_DIST_DIR" "AOM_DIST_EXAMPLES" + "AOM_DIST_APPS" "AOM_DIST_INCLUDES" "AOM_DIST_LIBS" "ENABLE_DOCS") + +foreach (arg ${REQUIRED_ARGS}) + if ("${${arg}}" STREQUAL "") + message(FATAL_ERROR "${arg} must not be empty.") + endif () +endforeach () + +if (ENABLE_DOCS) + file(INSTALL "${AOM_CONFIG_DIR}/docs" DESTINATION "${AOM_DIST_DIR}") +endif () + +listify_string("${AOM_DIST_EXAMPLES}" "AOM_DIST_EXAMPLES") +foreach (example ${AOM_DIST_EXAMPLES}) + file(INSTALL "${example}" DESTINATION "${AOM_DIST_DIR}/bin/examples") +endforeach () + +listify_string("${AOM_DIST_APPS}" "AOM_DIST_APPS") +foreach (app ${AOM_DIST_APPS}) + file(INSTALL "${app}" DESTINATION "${AOM_DIST_DIR}/bin") +endforeach () + +listify_string("${AOM_DIST_INCLUDES}" "AOM_DIST_INCLUDES") +foreach (inc ${AOM_DIST_INCLUDES}) + file(INSTALL "${inc}" DESTINATION "${AOM_DIST_DIR}/include/aom") +endforeach () + +listify_string("${AOM_DIST_LIBS}" "AOM_DIST_LIBS") +foreach (lib ${AOM_DIST_LIBS}) + file(INSTALL "${lib}" DESTINATION "${AOM_DIST_DIR}/lib") +endforeach ()