From 8a01b5c85fdb452f1b5d197e3e0ec301189f04e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 18 Jan 2019 10:29:53 +0900 Subject: [PATCH] Support decentralized build dependency declaration (#2865) This commit allows each sub-project to declare its build dependencies. Signed-off-by: Jonghyun Park --- contrib/CMakeLists.txt | 47 +++++++++++++++++++++++++++++++++++------- contrib/enco/requires.cmake | 5 +++++ contrib/tflchef/requires.cmake | 1 + 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 contrib/enco/requires.cmake create mode 100644 contrib/tflchef/requires.cmake diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index d786690..7b27004 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -1,3 +1,42 @@ +# TODO Validate the argument of "requires" +function(get_project_build_order VAR) + # This file will describe the dependencies among projects + set(DEPS_FILE "${CMAKE_CURRENT_BINARY_DIR}/contrib.deps") + + # Remove .deps file + file(REMOVE "${DEPS_FILE}") + + # Let's create .deps file + list_subdirectories(PROJECT_DIRS) + + foreach(PROJECT_DIR IN ITEMS ${PROJECT_DIRS}) + set(SUCC "${PROJECT_DIR}") + set(REQUIRES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_DIR}/requires.cmake") + + macro(require PRED) + file(APPEND "${DEPS_FILE}" "${PRED} ${SUCC}\n") + endmacro(require) + + file(APPEND "${DEPS_FILE}" "${SUCC} ${SUCC}\n") + if(EXISTS "${REQUIRES_FILE}") + include(${REQUIRES_FILE}) + endif(EXISTS "${REQUIRES_FILE}") + endforeach(PROJECT_DIR) + + # NOTE "tsort" is a part of the POSIX.1 standard. + # + # Reference: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/tsort.html + execute_process(COMMAND tsort "${DEPS_FILE}" + OUTPUT_VARIABLE ORDER + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # Remove newline characters + # TODO Check which one (UNIX_COMMAND or WINDOWS_COMMAND) is correct + separate_arguments(ORDER UNIX_COMMAND ${ORDER}) + + set(${VAR} "${ORDER}" PARENT_SCOPE) +endfunction(get_project_build_order) + function(add_nncc_contrib_directory DIR) string(TOUPPER ${DIR} PREFIX) @@ -9,13 +48,7 @@ function(add_nncc_contrib_directory DIR) endfunction(add_nncc_contrib_directory) function(add_nncc_contrib_directories) - # NOTE Add caffegen, nnkit, ann and tflchef before enco as enco's test framework depends on these projects - add_nncc_contrib_directory(caffegen) - add_nncc_contrib_directory(nnkit) - add_nncc_contrib_directory(ann) - add_nncc_contrib_directory(tflchef) # tflchef uses nni of nnkit as a tool - - list_subdirectories(PROJECT_DIRS EXCLUDES caffegen nnkit ann tflchef) + get_project_build_order(PROJECT_DIRS) foreach(PROJECT_DIR IN ITEMS ${PROJECT_DIRS}) add_nncc_contrib_directory(${PROJECT_DIR}) diff --git a/contrib/enco/requires.cmake b/contrib/enco/requires.cmake new file mode 100644 index 0000000..ba46319 --- /dev/null +++ b/contrib/enco/requires.cmake @@ -0,0 +1,5 @@ +require("coco") +require("caffegen") +require("tflchef") +require("ann") +require("nnkit") diff --git a/contrib/tflchef/requires.cmake b/contrib/tflchef/requires.cmake new file mode 100644 index 0000000..edef24a --- /dev/null +++ b/contrib/tflchef/requires.cmake @@ -0,0 +1 @@ +require("nnkit") -- 2.7.4