Commit d46b4d30 authored by Tom Finegan's avatar Tom Finegan

Add Emscripten support to the CMake build.

Supporting Emscripten requires modification of all uses of the
target_link_libraries() function to match the form
of the target_link_libraries() call in Emscripten.cmake.

The AOM_LIB_LINK_TYPE variable has been added to allow for
flexibility on the libaom side when using toolchains that
behave similarly to Emscripten.cmake wrt
target_link_libaries().

To use CMake for an Emscripten build, first install Emscripten, then:
$ cmake path/to/aom -DCMAKE_TOOLCHAIN_FILE=path/to/Emscripten.cmake -DAOM_TARGET_CPU=generic

BUG=aomedia:76,aomedia:468

Change-Id: I22c7df7912ecfdbc2a52180086b205cc8dcfc0c6
parent 0f50dcd4
......@@ -225,7 +225,7 @@ if (CONFIG_ANALYZER)
"${AOM_ROOT}/examples/analyzer.cc"
$<TARGET_OBJECTS:aom_common_app_util>
$<TARGET_OBJECTS:aom_decoder_app_util>)
target_link_libraries(analyzer PUBLIC ${wxWidgets_LIBRARIES})
target_link_libraries(analyzer ${AOM_LIB_LINK_TYPE} ${wxWidgets_LIBRARIES})
set(AOM_APP_TARGETS ${AOM_APP_TARGETS} analyzer)
endif ()
......@@ -255,11 +255,24 @@ add_executable(simple_decoder
$<TARGET_OBJECTS:aom_decoder_app_util>)
if (CONFIG_INSPECTION)
add_executable(inspect
"${AOM_ROOT}/examples/inspect.c"
$<TARGET_OBJECTS:aom_common_app_util>
$<TARGET_OBJECTS:aom_decoder_app_util>)
set(AOM_APP_TARGETS ${AOM_APP_TARGETS} inspect)
add_executable(inspect
"${AOM_ROOT}/examples/inspect.c"
$<TARGET_OBJECTS:aom_common_app_util>
$<TARGET_OBJECTS:aom_decoder_app_util>)
set(AOM_APP_TARGETS ${AOM_APP_TARGETS} inspect)
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")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
# Default to -O3 when no build type specified.
add_compiler_flag_if_supported("-O3")
endif ()
em_link_post_js(inspect "${AOM_ROOT}/tools/inspect-post.js")
endif ()
endif ()
add_executable(simple_encoder
......@@ -278,7 +291,7 @@ set(AOM_APP_TARGETS ${AOM_APP_TARGETS} aom_cx_set_ref aomdec aomenc
simple_encoder twopass_encoder)
foreach (aom_app ${AOM_APP_TARGETS})
target_link_libraries(${aom_app} PUBLIC aom)
target_link_libraries(${aom_app} ${AOM_LIB_LINK_TYPE} aom)
endforeach ()
if (CONFIG_LIBYUV)
......@@ -321,7 +334,7 @@ endif ()
if (HAVE_PTHREAD_H AND CONFIG_MULTITHREAD)
find_package(Threads)
foreach (app_target ${AOM_APP_TARGETS})
target_link_libraries(${app_target} PUBLIC Threads::Threads)
target_link_libraries(${app_target} ${AOM_LIB_LINK_TYPE} Threads::Threads)
endforeach ()
endif ()
......
......@@ -207,6 +207,13 @@ if (NOT MSVC)
aom_pop_var(CMAKE_REQUIRED_LIBRARIES)
endif()
set(AOM_LIB_LINK_TYPE PUBLIC)
if (EMSCRIPTEN)
# Avoid CMake generation time errors resulting from collisions with the form
# of target_link_libraries() used by Emscripten.cmake.
unset(AOM_LIB_LINK_TYPE)
endif ()
# Generate aom_config templates.
set(aom_config_asm_template "${AOM_CONFIG_DIR}/aom_config.asm.cmake")
set(aom_config_h_template "${AOM_CONFIG_DIR}/aom_config.h.cmake")
......
......@@ -141,7 +141,7 @@ function (add_asm_library lib_name asm_sources dependent_target)
"void ${lib_name}_dummy_function(void) {}\n")
target_sources(${lib_name} PUBLIC ${dummy_c_file})
target_link_libraries(${dependent_target} PRIVATE ${lib_name})
target_link_libraries(${dependent_target} ${AOM_LIB_LINK_TYPE} ${lib_name})
# Add the new lib target to the global list of aom library targets.
list(APPEND AOM_LIB_TARGETS ${lib_name})
......
......@@ -275,12 +275,12 @@ function (setup_aom_test_targets)
endif ()
endif ()
target_link_libraries(test_libaom PUBLIC aom gtest)
target_link_libraries(test_libaom ${AOM_LIB_LINK_TYPE} aom gtest)
add_executable(test_intra_pred_speed
${AOM_TEST_INTRA_PRED_SPEED_SOURCES}
$<TARGET_OBJECTS:aom_common_app_util>)
target_link_libraries(test_intra_pred_speed PUBLIC aom gtest)
target_link_libraries(test_intra_pred_speed ${AOM_LIB_LINK_TYPE} aom gtest)
if (CONFIG_LIBYUV)
target_sources(test_libaom PUBLIC $<TARGET_OBJECTS:yuv>)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment