Improve support for AOMAnalyzer in the CMake build.
- Add utility function for appending link flags to targets.
- Use it to set linker only opts for emscripten inspect target.
- Update README.md with emscripten instructions.
- Build everything with -O3 when no build type is specified.
Change-Id: I69a2083369d2880335a8162132f190377a4a85fb
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 604642e..ed824d4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -254,14 +254,17 @@
if (EMSCRIPTEN)
add_preproc_definition(_POSIX_SOURCE)
- add_compiler_flag_if_supported("-s TOTAL_MEMORY=134217728")
- add_compiler_flag_if_supported("-s MODULARIZE=1")
- add_compiler_flag_if_supported("-s EXPORT_NAME=\"\'DecoderModule\'\"")
- add_compiler_flag_if_supported("--memory-init-file 0")
+ append_link_flag_to_target("inspect" "-s TOTAL_MEMORY=134217728")
+ append_link_flag_to_target("inspect" "-s MODULARIZE=1")
+ append_link_flag_to_target("inspect"
+ "-s EXPORT_NAME=\"\'DecoderModule\'\"")
+ append_link_flag_to_target("inspect" "--memory-init-file 0")
+
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
# Default to -O3 when no build type specified.
- add_compiler_flag_if_supported("-O3")
+ append_compiler_flag("-O3")
endif ()
+
em_link_post_js(inspect "${AOM_ROOT}/tools/inspect-post.js")
endif ()
endif ()
diff --git a/README.md b/README.md
index 1c12841..74d4bf7 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,8 @@
recent version of [nasm](http://www.nasm.us/).
5. Building the documentation requires [doxygen](http://doxygen.org).
6. Building the unit tests requires [Python](https://www.python.org/).
+ 7. Emscripten builds require the portable
+ [EMSDK](https://kripken.github.io/emscripten-site/index.html).
### Basic build
@@ -115,6 +117,49 @@
$ cmake path/to/aom -G Xcode
+### Emscripten builds
+
+Building the AV1 codec library with Emscripten is supported. Typically this is
+used to hook into the AOMAnalyzer GUI application. These instructions focus on
+using the inspector with AOMAnalyzer, but all tools can be built with
+Emscripten.
+
+It is assumed here that you have already downloaded and installed the EMSDK,
+installed and activated at least one toolchain, and setup your environment
+appropriately using the emsdk\_env script.
+
+1. Download [AOMAnalyzer](https://people.xiph.org/~mbebenita/analyzer/).
+
+2. Configure the build:
+
+~~~
+ $ cmake path/to/aom \
+ -DENABLE_CCACHE=1 \
+ -DAOM_TARGET_CPU=generic \
+ -DENABLE_DOCS=0 \
+ -DCONFIG_ACCOUNTING=1 \
+ -DCONFIG_INSPECTION=1 \
+ -DCONFIG_MULTITHREAD=0 \
+ -DCONFIG_RUNTIME_CPU_DETECT=0 \
+ -DCONFIG_UNIT_TESTS=0 \
+ -DCONFIG_WEBM_IO=0 \
+ -DCMAKE_TOOLCHAIN_FILE=path/to/emsdk-portable/.../Emscripten.cmake
+~~~
+
+3. Build it: run make if that's your generator of choice:
+
+~~~
+ $ make inspect
+~~~
+
+4. Run the analyzer:
+
+~~~
+ # inspect.js is in the examples sub directory of the directory in which you
+ # executed cmake.
+ $ path/to/AOMAnalyzer path/to/examples/inspect.js path/to/av1/input/file
+~~~
+
## Testing the AV1 codec
@@ -198,3 +243,4 @@
Bug reports can be filed in the Alliance for Open Media
[issue tracker](https://bugs.chromium.org/p/aomedia/issues/list).
+
diff --git a/build/cmake/compiler_flags.cmake b/build/cmake/compiler_flags.cmake
index c9fc69b..ee6d12b 100644
--- a/build/cmake/compiler_flags.cmake
+++ b/build/cmake/compiler_flags.cmake
@@ -220,4 +220,25 @@
endif ()
endfunction ()
+# Adds $flag to the link flags for $target.
+function (append_link_flag_to_target target flags)
+ unset(target_link_flags)
+ get_target_property(target_link_flags ${target} LINK_FLAGS)
+
+ if (target_link_flags)
+ unset(link_flag_found)
+ string(FIND "${target_link_flags}" "${flags}" link_flag_found)
+
+ if (NOT ${link_flag_found} EQUAL -1)
+ return()
+ endif ()
+
+ set(target_link_flags "${target_link_flags} ${flags}")
+ else ()
+ set(target_link_flags "${flags}")
+ endif ()
+
+ set_target_properties(${target} PROPERTIES LINK_FLAGS ${target_link_flags})
+endfunction ()
+
endif () # AOM_BUILD_CMAKE_COMPILER_FLAGS_CMAKE_