Add ExtendCMakeFunction module and add_subdirectories function (#3912)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 7 Dec 2018 07:15:23 +0000 (16:15 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 7 Dec 2018 07:15:23 +0000 (16:15 +0900)
- 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 <hseok82.oh@samsung.com>
CMakeLists.txt
cmake/modules/ExtendCMakeFunction.cmake [new file with mode: 0644]
libs/CMakeLists.txt

index b24100e..e643a5e 100644 (file)
@@ -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 (file)
index 0000000..06b7c76
--- /dev/null
@@ -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)
index 176631c..99d2028 100644 (file)
@@ -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()