Add Subzero unit tests to CMake build.

Bug b/37478805

Change-Id: Idb44b05cea24eed8a46d267c3de9fc769ac58977
Reviewed-on: https://swiftshader-review.googlesource.com/9489
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cd43706..693e1a1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,7 @@
 option(USE_GROUP_SOURCES "Group the source files in a folder tree for Visual Studio" 1)
 
 option(BUILD_SAMPLES "Build sample programs" 1)
+option(BUILD_TESTS "Build test programs" 1)
 
 set(REACTOR_BACKEND "LLVM" CACHE STRING "JIT compiler back-end used by Reactor")
 set_property(CACHE REACTOR_BACKEND PROPERTY STRINGS LLVM Subzero)
@@ -978,3 +979,26 @@
         )
     endif()
 endif()
+
+if(BUILD_TESTS AND ${REACTOR_BACKEND} STREQUAL "Subzero")
+    set(SUBZERO_TEST_LIST
+        ${SOURCE_DIR}/Reactor/Main.cpp
+        ${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/src/gtest-all.cc
+    )
+
+    set(SUBZERO_TEST_INCLUDE_DIR
+        ${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/include
+        ${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/
+    )
+
+    add_executable(SubzeroTest ${SUBZERO_TEST_LIST})
+    set_target_properties(SubzeroTest PROPERTIES
+        INCLUDE_DIRECTORIES "${SUBZERO_TEST_INCLUDE_DIR}"
+        FOLDER "Tests"
+    )
+    if(WIN32)
+        target_link_libraries(SubzeroTest ReactorSubzero)
+    else()
+        target_link_libraries(SubzeroTest ReactorSubzero pthread dl)
+    endif()
+endif()