From 7d62838f65479b5db9befdcab607651210cf3d40 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Fri, 7 Dec 2018 16:15:23 +0900 Subject: [PATCH] Add ExtendCMakeFunction module and add_subdirectories function (#3912) - Add ExtendCMakeFunction module to simplify cmake - Introduce add_subdirectories function to support adding all subdirectories at once. (It's comes from nncc repo) - Use add_subdirectories function in libs Signed-off-by: Hyeongseok Oh --- CMakeLists.txt | 2 ++ cmake/modules/ExtendCMakeFunction.cmake | 27 +++++++++++++++++++++++++++ libs/CMakeLists.txt | 9 ++++----- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 cmake/modules/ExtendCMakeFunction.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b24100e..e643a5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,8 @@ if(OBS_BUILD) add_definitions(-DOBS_BUILD) endif(OBS_BUILD) +nnfw_include(ExtendCMakeFunction) + # TODO For now Android build is being enabled incrementally so not all subdirectories are added yet. # However we are going to have the same subdirectories with other OS eventually. if("${TARGET_OS}" STREQUAL "android") diff --git a/cmake/modules/ExtendCMakeFunction.cmake b/cmake/modules/ExtendCMakeFunction.cmake new file mode 100644 index 0000000..06b7c76 --- /dev/null +++ b/cmake/modules/ExtendCMakeFunction.cmake @@ -0,0 +1,27 @@ +function(list_subdirectories OUTPUT_VARIABLE) + cmake_parse_arguments(ARG "" "" "EXCLUDES" ${ARGN}) + + file(GLOB PROJECT_FILES + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "*/CMakeLists.txt") + + foreach(PROJECT_FILE IN ITEMS ${PROJECT_FILES}) + get_filename_component(PROJECT_DIR ${PROJECT_FILE} DIRECTORY) + list(FIND ARG_EXCLUDES ${PROJECT_DIR} PROJECT_INDEX) + if(${PROJECT_INDEX} EQUAL -1) + list(APPEND PROJECT_LIST ${PROJECT_DIR}) + endif(${PROJECT_INDEX} EQUAL -1) + endforeach(PROJECT_FILE) + + set(${OUTPUT_VARIABLE} ${PROJECT_LIST} PARENT_SCOPE) +endfunction(list_subdirectories) + +function(add_subdirectories) + cmake_parse_arguments(ARG "" "" "EXCLUDES" ${ARGN}) + + list_subdirectories(PROJECT_DIRS EXCLUDES ${ARG_EXCLUDES}) + + foreach(PROJECT_DIR IN ITEMS ${PROJECT_DIRS}) + add_subdirectory(${PROJECT_DIR}) + endforeach(PROJECT_DIR) +endfunction(add_subdirectories) diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 176631c..99d2028 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,5 +1,4 @@ -add_subdirectory(util) -add_subdirectory(support) -add_subdirectory(ARMComputeEx) -add_subdirectory(cpp14) -add_subdirectory(nnapi) +# Add all subdirectories. +# Each library in sub-directory must have it's own CMakeLists.txt +# to build library's binaries or to support interface. +add_subdirectories() -- 2.7.4