|
| 1 | +# Copyright (c) 2019-present, Facebook, Inc. |
| 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 | +# http://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 | + |
| 15 | +# A function to add a test to be driven through the 'check' target. |
| 16 | +# Unlike the 'test' target, the 'check' target rebuilds the executables |
| 17 | +# before invoking the tests. |
| 18 | + |
| 19 | +# Returns the name of the backend enabling. |
| 20 | +MACRO(getBackendEnableVariable result backend_dir_name) |
| 21 | + string(TOUPPER "GLOW_WITH_${backend_dir_name}" ${result}) |
| 22 | +ENDMACRO() |
| 23 | + |
| 24 | + |
| 25 | +# Macro to be called at top level. |
| 26 | +MACRO(ExternalBackendsInit) |
| 27 | +# External backends |
| 28 | +set(EXTERNAL_BACKENDS_DIR ${GLOW_SOURCE_DIR}/externalbackends) |
| 29 | +include_directories(${EXTERNAL_BACKENDS_DIR}) |
| 30 | +getSubDirList(SUBDIRS ${EXTERNAL_BACKENDS_DIR}) |
| 31 | + |
| 32 | +FOREACH(child ${SUBDIRS}) |
| 33 | + # Add an option for the backend. The backend is enabled by default. |
| 34 | + # The user can disable it by setting the right variable to OFF. |
| 35 | + getBackendEnableVariable(backend_enable_variable ${child}) |
| 36 | + option(${backend_enable_variable} "Build the ${child} backend" ON) |
| 37 | + # define BACKEND_ROOT_<upper case backend name> |
| 38 | + string(TOUPPER "BACKEND_ROOT_${child}" BACKEND_ROOT_NAME) |
| 39 | + set(${BACKEND_ROOT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/externalbackends/${child}) |
| 40 | + |
| 41 | + # Verbosing |
| 42 | + message(STATUS "Detected external backend '${child}'") |
| 43 | + message(STATUS " -> Backend '${child}' can be disabled by setting ${backend_enable_variable}=OFF") |
| 44 | + message(STATUS " -> Backend '${child}' specific variables:") |
| 45 | + message(STATUS " - ${backend_enable_variable} = ${${backend_enable_variable}}") |
| 46 | + message(STATUS " - ${BACKEND_ROOT_NAME} = ${${BACKEND_ROOT_NAME}}") |
| 47 | + if (${backend_enable_variable}) |
| 48 | + message(STATUS " -> Backend '${child}' ENABLED") |
| 49 | + add_definitions(-D${backend_enable_variable}=1) |
| 50 | + else() |
| 51 | + message(STATUS " -> Backend '${child}' DISABLED") |
| 52 | + endif() |
| 53 | + |
| 54 | + # Handle the backend only when activated |
| 55 | + if (${backend_enable_variable}) |
| 56 | + # If the backend has a global CMakefile, include it. |
| 57 | + if(EXISTS "${EXTERNAL_BACKENDS_DIR}/${child}/CMakeLists.txt") |
| 58 | + include("${EXTERNAL_BACKENDS_DIR}/${child}/CMakeLists.txt") |
| 59 | + else() |
| 60 | + message(STATUS "External backend '${child}' has no global CMakeLists.txt") |
| 61 | + endif() |
| 62 | + endif() |
| 63 | +ENDFOREACH() |
| 64 | +ENDMACRO() |
| 65 | + |
| 66 | +# Macro to register external backends. |
| 67 | +MACRO(ExternalBackendsRegister) |
| 68 | +getSubDirList(SUBDIRS ${GLOW_SOURCE_DIR}/externalbackends) |
| 69 | +FOREACH(child ${SUBDIRS}) |
| 70 | + getBackendEnableVariable(backend_enable_variable ${child}) |
| 71 | + # Handle the backend only when activated |
| 72 | + if (${backend_enable_variable}) |
| 73 | + # If the backend has a 'Backends' sub-directory, add it. |
| 74 | + if(EXISTS ${EXTERNAL_BACKENDS_DIR}/${child}/Backends) |
| 75 | + message("Adding external ${child} backend.") |
| 76 | + set(EXTERNAL_BACKEND_NAME ${child}Backend) |
| 77 | + add_subdirectory(${EXTERNAL_BACKENDS_DIR}/${child}/Backends EXT_${EXTERNAL_BACKEND_NAME}) |
| 78 | + else() |
| 79 | + message(FATAL_ERROR "External backend '${child}' has no 'Backends' sub-directory (${EXTERNAL_BACKENDS_DIR}/${child}/Backends)") |
| 80 | + endif() |
| 81 | + endif() |
| 82 | +ENDFOREACH() |
| 83 | +ENDMACRO() |
| 84 | + |
| 85 | +# Macro to register backend specific nodes and instructions. |
| 86 | +MACRO(ExternalBackendsClassGen) |
| 87 | +getSubDirList(SUBDIRS ${GLOW_SOURCE_DIR}/externalbackends) |
| 88 | +FOREACH(child ${SUBDIRS}) |
| 89 | + getBackendEnableVariable(backend_enable_variable ${child}) |
| 90 | + # Handle the backend only when activated |
| 91 | + if (${backend_enable_variable}) |
| 92 | + # If the backend has a 'ClassGen' sub-directory, add it. |
| 93 | + if(EXISTS ${EXTERNAL_BACKENDS_DIR}/${child}/ClassGen) |
| 94 | + add_subdirectory(${EXTERNAL_BACKENDS_DIR}/${child}/ClassGen EXT_${child}) |
| 95 | + else() |
| 96 | + message(STATUS "External backend '${child}' has no 'ClassGen' sub-directory") |
| 97 | + endif() |
| 98 | + endif() |
| 99 | +ENDFOREACH() |
| 100 | +ENDMACRO() |
| 101 | + |
| 102 | +# Macro to add external backends tests. |
| 103 | +MACRO(ExternalBackendsTest) |
| 104 | +getSubDirList(SUBDIRS ${GLOW_SOURCE_DIR}/externalbackends) |
| 105 | +FOREACH(child ${SUBDIRS}) |
| 106 | + getBackendEnableVariable(backend_enable_variable ${child}) |
| 107 | + # Handle the backend only when activated |
| 108 | + if (${backend_enable_variable}) |
| 109 | + # If the backend has a 'Tests' sub-directory, add it. |
| 110 | + if(EXISTS "${EXTERNAL_BACKENDS_DIR}/${child}/Tests") |
| 111 | + add_subdirectory("${EXTERNAL_BACKENDS_DIR}/${child}/Tests" EXT_${child}) |
| 112 | + else() |
| 113 | + message(STATUS "External backend '${child}' has no 'Tests' sub-directory") |
| 114 | + endif() |
| 115 | + endif() |
| 116 | +ENDFOREACH() |
| 117 | +ENDMACRO() |
| 118 | + |
0 commit comments