Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Build] Simplify the integration of external backends
- Loading branch information
1 parent
da1e9f6
commit 241d4e9
Showing
10 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# Copyright (c) 2019-present, Facebook, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# A function to add a test to be driven through the 'check' target. | ||
# Unlike the 'test' target, the 'check' target rebuilds the executables | ||
# before invoking the tests. | ||
|
||
# Returns the name of the backend enabling. | ||
MACRO(getBackendEnableVariable result backend_dir_name) | ||
string(TOUPPER "GLOW_WITH_${backend_dir_name}" ${result}) | ||
ENDMACRO() | ||
|
||
|
||
# Macro to be called at top level. | ||
MACRO(ExternalBackendsInit) | ||
# External backends | ||
set(EXTERNAL_BACKENDS_DIR ${GLOW_SOURCE_DIR}/externalbackends) | ||
include_directories(${EXTERNAL_BACKENDS_DIR}) | ||
getSubDirList(SUBDIRS ${EXTERNAL_BACKENDS_DIR}) | ||
|
||
FOREACH(child ${SUBDIRS}) | ||
# Add an option for the backend. The backend is enabled by default. | ||
# The user can disable it by setting the right variable to OFF. | ||
getBackendEnableVariable(backend_enable_variable ${child}) | ||
option(${backend_enable_variable} "Build the ${child} backend" ON) | ||
# define BACKEND_ROOT_<upper case backend name> | ||
string(TOUPPER "BACKEND_ROOT_${child}" BACKEND_ROOT_NAME) | ||
set(${BACKEND_ROOT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/externalbackends/${child}) | ||
|
||
# Verbosing | ||
message(STATUS "Detected external backend '${child}'") | ||
message(STATUS " -> Backend '${child}' can be disabled by setting ${backend_enable_variable}=OFF") | ||
message(STATUS " -> Backend '${child}' specific variables:") | ||
message(STATUS " - ${backend_enable_variable} = ${${backend_enable_variable}}") | ||
message(STATUS " - ${BACKEND_ROOT_NAME} = ${${BACKEND_ROOT_NAME}}") | ||
if (${backend_enable_variable}) | ||
message(STATUS " -> Backend '${child}' ENABLED") | ||
add_definitions(-D${backend_enable_variable}=1) | ||
else() | ||
message(STATUS " -> Backend '${child}' DISABLED") | ||
endif() | ||
|
||
# Handle the backend only when activated | ||
if (${backend_enable_variable}) | ||
# If the backend has a global CMakefile, include it. | ||
if(EXISTS "${EXTERNAL_BACKENDS_DIR}/${child}/CMakeLists.txt") | ||
include("${EXTERNAL_BACKENDS_DIR}/${child}/CMakeLists.txt") | ||
else() | ||
message(STATUS "External backend '${child}' has no global CMakeLists.txt") | ||
endif() | ||
endif() | ||
ENDFOREACH() | ||
ENDMACRO() | ||
|
||
# Macro to register external backends. | ||
MACRO(ExternalBackendsRegister) | ||
getSubDirList(SUBDIRS ${GLOW_SOURCE_DIR}/externalbackends) | ||
FOREACH(child ${SUBDIRS}) | ||
getBackendEnableVariable(backend_enable_variable ${child}) | ||
# Handle the backend only when activated | ||
if (${backend_enable_variable}) | ||
# If the backend has a 'Backends' sub-directory, add it. | ||
if(EXISTS ${EXTERNAL_BACKENDS_DIR}/${child}/Backends) | ||
message("Adding external ${child} backend.") | ||
set(EXTERNAL_BACKEND_NAME ${child}Backend) | ||
add_subdirectory(${EXTERNAL_BACKENDS_DIR}/${child}/Backends EXT_${EXTERNAL_BACKEND_NAME}) | ||
else() | ||
message(FATAL_ERROR "External backend '${child}' has no 'Backends' sub-directory (${EXTERNAL_BACKENDS_DIR}/${child}/Backends)") | ||
endif() | ||
endif() | ||
ENDFOREACH() | ||
ENDMACRO() | ||
|
||
# Macro to register backend specific nodes and instructions. | ||
MACRO(ExternalBackendsClassGen) | ||
getSubDirList(SUBDIRS ${GLOW_SOURCE_DIR}/externalbackends) | ||
FOREACH(child ${SUBDIRS}) | ||
getBackendEnableVariable(backend_enable_variable ${child}) | ||
# Handle the backend only when activated | ||
if (${backend_enable_variable}) | ||
# If the backend has a 'ClassGen' sub-directory, add it. | ||
if(EXISTS ${EXTERNAL_BACKENDS_DIR}/${child}/ClassGen) | ||
add_subdirectory(${EXTERNAL_BACKENDS_DIR}/${child}/ClassGen EXT_${child}) | ||
else() | ||
message(STATUS "External backend '${child}' has no 'ClassGen' sub-directory") | ||
endif() | ||
endif() | ||
ENDFOREACH() | ||
ENDMACRO() | ||
|
||
# Macro to add external backends tests. | ||
MACRO(ExternalBackendsTest) | ||
getSubDirList(SUBDIRS ${GLOW_SOURCE_DIR}/externalbackends) | ||
FOREACH(child ${SUBDIRS}) | ||
getBackendEnableVariable(backend_enable_variable ${child}) | ||
# Handle the backend only when activated | ||
if (${backend_enable_variable}) | ||
# If the backend has a 'Tests' sub-directory, add it. | ||
if(EXISTS "${EXTERNAL_BACKENDS_DIR}/${child}/Tests") | ||
add_subdirectory("${EXTERNAL_BACKENDS_DIR}/${child}/Tests" EXT_${child}) | ||
else() | ||
message(STATUS "External backend '${child}' has no 'Tests' sub-directory") | ||
endif() | ||
endif() | ||
ENDFOREACH() | ||
ENDMACRO() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This directory is intended to contain external backends. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters