1# Copyright 2021 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15cmake_policy(SET CMP0012 NEW) 16cmake_policy(SET CMP0048 NEW) 17project(ruy CXX) 18cmake_minimum_required(VERSION 3.13) # Copied from IREE 19set(CMAKE_CXX_STANDARD 14) 20 21 22 23if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) 24 set(RUY_IS_TOPLEVEL TRUE) 25 set(RUY_MINIMAL_BUILD_DEFAULT_VALUE OFF) 26else() 27 set(RUY_IS_TOPLEVEL FALSE) 28 set(RUY_MINIMAL_BUILD_DEFAULT_VALUE ON) 29endif() 30 31option(RUY_MINIMAL_BUILD "Disable ruy's tests, examples, etc. Build only ruy public libraries." ${RUY_MINIMAL_BUILD_DEFAULT_VALUE}) 32if (NOT RUY_MINIMAL_BUILD) 33 enable_testing() 34endif() 35 36option(RUY_PROFILER "Enable ruy's built-in profiler (harms performance)" OFF) 37 38include(cmake/ruy_add_all_subdirs.cmake) 39include(cmake/ruy_cc_library.cmake) 40include(cmake/ruy_cc_binary.cmake) 41include(cmake/ruy_cc_test.cmake) 42 43# Skip cpuinfo if it was already generated, which can happen when ruy is 44# a subdirectory in a wider project that already uses cpuinfo. 45if (NOT TARGET cpuinfo) 46 # Test if the third_party/cpuinfo submodule was checked out before 47 # adding that subdirectory, so we can do more helpful things below in the 48 # else() block when it's not. 49 set(RUY_CPUINFO_CMAKELISTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cpuinfo/CMakeLists.txt") 50 if (EXISTS "${RUY_CPUINFO_CMAKELISTS_FILE}") 51 # Disabling cpuinfo's tests and benchmarks to prevent a copy of its 52 # googletest dependency getting downloaded into a 'deps' directory in the 53 # source tree! 54 set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE) 55 set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "" FORCE) 56 set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "" FORCE) 57 add_subdirectory("third_party/cpuinfo" EXCLUDE_FROM_ALL) 58 else() 59 # third_party/cpuinfo is not checked out. That could be intentional when 60 # ruy is a subdirectory in a wider project that is already providing 61 # the cpuinfo target. Maybe that wider project's CMakeLists is ordered 62 # in such a way that cpuinfo gets generated after ruy. In that case, 63 # it's helpful that we continue silently. In the worst case if the cpuinfo 64 # target never gets defined, ruy will fail to compile. 65 # On the other hand, if ruy is the top-level project here (not part of a 66 # wider project) then nothing will define the cpuinfo target for us, 67 # so we will definitely fail to compile, so we may as well fail right here. 68 if (RUY_IS_TOPLEVEL) 69 message(FATAL_ERROR "This file does not exist:\n${RUY_CPUINFO_CMAKELISTS_FILE}\n" 70 "That typically means that the git submodules of the ruy " 71 "repository haven't been checked out. Try this in the ruy " 72 "git directory:\n git submodule update --init") 73 endif() 74 endif() 75endif() 76 77# googletest is only needed for tests. Projects embedding ruy as a subdirectory 78# and not needing to build ruy tests may proceed without a local checkout of 79# third_party/googletest. 80if (NOT RUY_MINIMAL_BUILD 81 AND NOT TARGET gtest 82 AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/CMakeLists.txt") 83 add_subdirectory("third_party/googletest" EXCLUDE_FROM_ALL) 84endif() 85 86add_subdirectory("ruy") 87 88if (NOT RUY_MINIMAL_BUILD) 89 add_subdirectory("example") 90endif() 91