1#
2# Copyright (c) 2017, Alliance for Open Media. All rights reserved
3#
4# This source code is subject to the terms of the BSD 2 Clause License and the
5# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
6# not distributed with this source code in the LICENSE file, you can obtain it
7# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
8# License 1.0 was not distributed with this source code in the PATENTS file, you
9# can obtain it at www.aomedia.org/license/patent.
10#
11if(AOM_BUILD_CMAKE_EXPORTS_CMAKE_)
12  return()
13endif() # AOM_BUILD_CMAKE_EXPORTS_CMAKE_
14set(AOM_BUILD_CMAKE_EXPORTS_CMAKE_ 1)
15
16include("${AOM_ROOT}/build/cmake/exports_sources.cmake")
17
18# Creates the custom target which handles generation of the symbol export lists.
19function(setup_exports_target)
20  if("${AOM_TARGET_SYSTEM}" STREQUAL "Darwin")
21    set(symbol_file_ext "syms")
22  elseif("${AOM_TARGET_SYSTEM}" MATCHES "Windows\|MSYS" AND MSVC)
23    set(symbol_file_ext "def")
24  else()
25    set(symbol_file_ext "ver")
26  endif()
27
28  set(aom_sym_file "${AOM_CONFIG_DIR}/libaom.${symbol_file_ext}")
29
30  add_custom_target(generate_exports
31                    COMMAND ${CMAKE_COMMAND}
32                            -DAOM_ROOT="${AOM_ROOT}"
33                            -DAOM_CONFIG_DIR="${AOM_CONFIG_DIR}"
34                            -DAOM_TARGET_SYSTEM=${AOM_TARGET_SYSTEM}
35                            -DAOM_SYM_FILE="${aom_sym_file}"
36                            -DAOM_MSVC=${MSVC}
37                            -DAOM_XCODE=${XCODE}
38                            -DCONFIG_NAME=$<CONFIG>
39                            -DCONFIG_AV1_DECODER=${CONFIG_AV1_DECODER}
40                            -DCONFIG_AV1_ENCODER=${CONFIG_AV1_ENCODER}
41                            -DCONFIG_INSPECTION=${CONFIG_INSPECTION}
42                            -DENABLE_TESTS=${ENABLE_TESTS}
43                            -P
44                            "${AOM_ROOT}/build/cmake/generate_exports.cmake"
45                    SOURCES ${AOM_EXPORTS_SOURCES}
46                    DEPENDS ${AOM_EXPORTS_SOURCES})
47
48  # Make libaom depend on the exports file, and set flags to pick it up when
49  # creating the dylib.
50  add_dependencies(aom generate_exports)
51
52  if(APPLE)
53    set_property(TARGET aom
54                 APPEND_STRING
55                 PROPERTY LINK_FLAGS "-exported_symbols_list ${aom_sym_file}")
56  elseif(WIN32)
57    if(NOT MSVC)
58      set_property(TARGET aom
59                   APPEND_STRING
60                   PROPERTY LINK_FLAGS "-Wl,--version-script ${aom_sym_file}")
61    else()
62      set_property(TARGET aom
63                   APPEND_STRING
64                   PROPERTY LINK_FLAGS "/DEF:${aom_sym_file}")
65    endif()
66
67    # TODO(tomfinegan): Sort out the import lib situation and flags for MSVC.
68
69  else()
70    set_property(TARGET aom
71                 APPEND_STRING
72                 PROPERTY LINK_FLAGS "-Wl,--version-script,${aom_sym_file}")
73  endif()
74endfunction()
75