From 9f9fe4f855e2ccff13da4ae3d4d2037de44499c3 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Thu, 29 Feb 2024 15:19:41 -0800 Subject: [PATCH] Add CMakeLists.txt to run GTEST for runtime/kernel/test Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned] --- CMakeLists.txt | 15 +++++++++++++++ runtime/kernel/test/CMakeLists.txt | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 runtime/kernel/test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 3666b3e832a..a878b1a3529 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,6 +134,9 @@ option(EXECUTORCH_BUILD_EXTENSION_MODULE option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL "Build the extension/runner_util directory" OFF) +# Build gtest +option(EXECUTORCH_BUILD_GTEST "Build GTEST" OFF) + if(NOT BUCK2) set(BUCK2 buck2) endif() @@ -429,5 +432,17 @@ if(EXECUTORCH_BUILD_PYBIND) install(TARGETS portable_lib LIBRARY DESTINATION executorch/extension/pybindings) endif() + +if(EXECUTORCH_BUILD_GTEST) + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + ) + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) + add_subdirectory(runtime/kernel/test) +endif() # Print all summary executorch_print_configuration_summary() diff --git a/runtime/kernel/test/CMakeLists.txt b/runtime/kernel/test/CMakeLists.txt new file mode 100644 index 00000000000..c94ea24079f --- /dev/null +++ b/runtime/kernel/test/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# ### Editing this file ### +# +# This file should be formatted with +# ~~~ +# cmake-format --first-comment-is-literal=True CMakeLists.txt +# ~~~ +# It should also be cmake-lint clean. +# +enable_testing() + +add_executable( + make_boxed_from_unboxed_functor_test + make_boxed_from_unboxed_functor_test.cpp +) +target_link_libraries( + make_boxed_from_unboxed_functor_test + executorch + GTest::gtest_main +) + +include(GoogleTest) +gtest_discover_tests(make_boxed_from_unboxed_functor_test)