diff options
author | bjacob <benoitjacob@google.com> | 2021-01-23 04:23:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-23 04:23:42 +0300 |
commit | 2887692065c38ef6617f423feafc6b69dd0a0681 (patch) | |
tree | c8da7077e6a2fa57f9646ba1a9ab4a145718aed1 | |
parent | 09827c89612fdb3b7adef229d9b057bbe61a8d31 (diff) |
Allow late definitions of cpuinfo but only when ruy is a subdir. (#250)
-rw-r--r-- | CMakeLists.txt | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 55e3397..98d480d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,13 @@ project(ruy CXX) cmake_minimum_required(VERSION 3.13) # Copied from IREE set(CMAKE_CXX_STANDARD 14) + + if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) + set(RUY_IS_TOPLEVEL TRUE) set(RUY_MINIMAL_BUILD_DEFAULT_VALUE OFF) else() + set(RUY_IS_TOPLEVEL FALSE) set(RUY_MINIMAL_BUILD_DEFAULT_VALUE ON) endif() @@ -36,14 +40,38 @@ include(cmake/ruy_cc_library.cmake) include(cmake/ruy_cc_binary.cmake) include(cmake/ruy_cc_test.cmake) +# Skip cpuinfo if it was already generated, which can happen when ruy is +# a subdirectory in a wider project that already uses cpuinfo. if (NOT TARGET cpuinfo) - # Disabling cpuinfo's tests and benchmarks to prevent a copy of its - # googletest dependency getting downloaded into a 'deps' directory in the - # source tree! - set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE) - set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "" FORCE) - set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "" FORCE) - add_subdirectory("third_party/cpuinfo" EXCLUDE_FROM_ALL) + # Test if the third_party/cpuinfo submodule was checked out before + # adding that subdirectory, so we can do more helpful things below in the + # else() block when it's not. + set(RUY_CPUINFO_CMAKELISTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cpuinfo/CMakeLists.txt") + if (EXISTS "${RUY_CPUINFO_CMAKELISTS_FILE}") + # Disabling cpuinfo's tests and benchmarks to prevent a copy of its + # googletest dependency getting downloaded into a 'deps' directory in the + # source tree! + set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE) + set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "" FORCE) + set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "" FORCE) + add_subdirectory("third_party/cpuinfo" EXCLUDE_FROM_ALL) + else() + # third_party/cpuinfo is not checked out. That could be intentional when + # ruy is a subdirectory in a wider project that is already providing + # the cpuinfo target. Maybe that wider project's CMakeLists is ordered + # in such a way that cpuinfo gets generated after ruy. In that case, + # it's helpful that we continue silently. In the worst case if the cpuinfo + # target never gets defined, ruy will fail to compile. + # On the other hand, if ruy is the top-level project here (not part of a + # wider project) then nothing will define the cpuinfo target for us, + # so we will definitely fail to compile, so we may as well fail right here. + if (RUY_IS_TOPLEVEL) + message(FATAL_ERROR "This file does not exist:\n${RUY_CPUINFO_CMAKELISTS_FILE}\n" + "That typically means that the git submodules of the ruy " + "repository haven't been checked out. Try this in the ruy " + "git directory:\n git submodule update --init") + endif() + endif() endif() # googletest is only needed for tests. Projects embedding ruy as a subdirectory |