Expand cmake assembler support.

- Stop acting as if Yasm is the only assembler.
- Kill generation and report error when yasm is not found for x86
  and x86_64 (remove the generic fallback).
- Use $AOM_AS_FLAGS to pass assembler specific flags.
- Add include guard in aom_optimization.cmake.

BUG=https://bugs.chromium.org/p/aomedia/issues/detail?id=76

Change-Id: Ic68d6c81071c24a8ceb6806d04ab8959be97d876
diff --git a/build/cmake/aom_configure.cmake b/build/cmake/aom_configure.cmake
index 31f826e..1a0bad4 100644
--- a/build/cmake/aom_configure.cmake
+++ b/build/cmake/aom_configure.cmake
@@ -27,6 +27,7 @@
 string(STRIP "${AOM_CMAKE_CONFIG}" AOM_CMAKE_CONFIG)
 
 include("${AOM_ROOT}/build/cmake/aom_config_defaults.cmake")
+include("${AOM_ROOT}/build/cmake/aom_optimization.cmake")
 include("${AOM_ROOT}/build/cmake/compiler_flags.cmake")
 include("${AOM_ROOT}/build/cmake/compiler_tests.cmake")
 
@@ -80,11 +81,16 @@
 endif ()
 
 if ("${AOM_TARGET_CPU}" STREQUAL "x86" OR "${AOM_TARGET_CPU}" STREQUAL "x86_64")
-  find_program(YASM_EXECUTABLE yasm $ENV{YASM_PATH})
-  if (NOT YASM_EXECUTABLE)
-    message(WARNING "Unable to find yasm, using generic as target CPU.")
-    set(AOM_TARGET_CPU "generic")
+  # TODO(tomfinegan): Support nasm at least as well as the existing build
+  # system.
+  find_program(AS_EXECUTABLE yasm $ENV{YASM_PATH})
+  if (NOT AS_EXECUTABLE)
+    message(FATAL_ERROR "Unable to find yasm. To build without optimizations, "
+            "add -DAOM_TARGET_CPU=generic to your cmake command line.")
   endif ()
+  get_asm_obj_format("objformat")
+  set(AOM_AS_FLAGS -f ${objformat} ${AOM_AS_FLAGS})
+  string(STRIP "${AOM_AS_FLAGS}" AOM_AS_FLAGS)
 endif ()
 
 include("${AOM_ROOT}/build/cmake/targets/${AOM_TARGET_CPU}.cmake")
diff --git a/build/cmake/aom_optimization.cmake b/build/cmake/aom_optimization.cmake
index 72abd5d..b2c6498 100644
--- a/build/cmake/aom_optimization.cmake
+++ b/build/cmake/aom_optimization.cmake
@@ -8,6 +8,8 @@
 ## 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.
 ##
+if (NOT AOM_BUILD_CMAKE_AOM_OPTIMIZATION_CMAKE_)
+set(AOM_BUILD_CMAKE_AOM_OPTIMIZATION_CMAKE_ 1)
 
 # Translate $flag to one which MSVC understands, and write the new flag to the
 # variable named by $translated_flag (or unset it, when MSVC needs no flag).
@@ -112,15 +114,12 @@
   # consumers of the AOM cmake build.
   add_library(${lib_name} STATIC ${${asm_sources}})
 
-  get_asm_obj_format("objformat")
-
   foreach (asm_source ${${asm_sources}})
     get_filename_component(asm_source_name "${asm_source}" NAME)
     set(asm_object "${asm_lib_obj_dir}/${asm_source_name}.o")
     add_custom_command(OUTPUT "${asm_object}"
-                       COMMAND ${YASM_EXECUTABLE}
+                       COMMAND ${AS_EXECUTABLE}
                        ARGS ${AOM_AS_FLAGS}
-                            -f ${objformat}
                             -I${AOM_ROOT} -I${AOM_CONFIG_DIR}
                             -o "${asm_object}" "${asm_source}"
                        DEPENDS "${asm_source}"
@@ -148,3 +147,5 @@
   list(APPEND AOM_LIB_TARGETS ${lib_name})
   set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
 endfunction ()
+
+endif ()  # AOM_BUILD_CMAKE_AOM_OPTIMIZATION_CMAKE_