[CMake] Automatically pick up subdirectories in llvm/tools as 'external projects...
[oota-llvm.git] / cmake / modules / AddLLVM.cmake
index 24afeea9d187c8d6a24f2be8a4bdfcb020fbd901..277914ff906a907d7c50824e1a1f180238ffddf9 100644 (file)
@@ -146,6 +146,7 @@ macro(add_llvm_external_project name)
   if("${add_llvm_external_dir}" STREQUAL "")
     set(add_llvm_external_dir ${name})
   endif()
+  list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}")
   string(REPLACE "-" "_" nameUNDERSCORE ${name})
   string(TOUPPER ${nameUNDERSCORE} nameUPPER)
   set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}"
@@ -160,6 +161,34 @@ macro(add_llvm_external_project name)
   endif()
 endmacro(add_llvm_external_project)
 
+macro(add_llvm_tool_subdirectory name)
+  list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
+  add_subdirectory(${name})
+endmacro(add_llvm_tool_subdirectory)
+
+macro(ignore_llvm_tool_subdirectory name)
+  list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
+endmacro(ignore_llvm_tool_subdirectory)
+
+function(add_llvm_implicit_external_projects)
+  set(list_of_implicit_subdirs "")
+  file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
+  foreach(dir ${sub-dirs})
+    if(IS_DIRECTORY "${dir}")
+      list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore)
+      if( tool_subdir_ignore EQUAL -1
+          AND EXISTS "${dir}/CMakeLists.txt")
+        get_filename_component(fn "${dir}" NAME)
+        list(APPEND list_of_implicit_subdirs "${fn}")
+      endif()
+    endif()
+  endforeach()
+
+  foreach(external_proj ${list_of_implicit_subdirs})
+    add_llvm_external_project("${external_proj}")
+  endforeach()
+endfunction(add_llvm_implicit_external_projects)
+
 # Generic support for adding a unittest.
 function(add_unittest test_suite test_name)
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})