Add -z defs linker option when building shared lib

The -z defs linker option makes the linking of a shared library fail if
there are unresolved symbol references.

BUG=aomedia:3064

Change-Id: Ib96854a80faffff5c76a72388429307ddce72825
diff --git a/CMakeLists.txt b/CMakeLists.txt
index adf2591..df67220 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -721,6 +721,17 @@
 endif()
 
 if(BUILD_SHARED_LIBS)
+  if(NOT MSVC AND NOT APPLE)
+    # The -z defs linker option reports unresolved symbol references from object
+    # files when building a shared library.
+    if("${CMAKE_VERSION}" VERSION_LESS "3.13")
+      # target_link_options() is not available before CMake 3.13.
+      target_link_libraries(aom PRIVATE -Wl,-z,defs)
+    else()
+      target_link_options(aom PRIVATE LINKER:-z,defs)
+    endif()
+  endif()
+
   include("${AOM_ROOT}/build/cmake/exports.cmake")
   setup_exports_target()
 endif()