llvm.org GIT mirror llvm / d6dbd6b
[CMake] Automatically pick up subdirectories in llvm/tools as 'external projects' if they contain a 'CMakeLists.txt' file. Allow CMake to pick up external projects in llvm/tools without the need to modify the "llvm/tools/CMakeLists.txt" file. This makes it easier to work with projects that live in other repositories, without needing to specify each one in "llvm/tools/CMakeLists.txt". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188921 91177308-0d34-0410-b5e6-96231b3b80d8 Argyrios Kyrtzidis 6 years ago
2 changed file(s) with 73 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
145145 if("${add_llvm_external_dir}" STREQUAL "")
146146 set(add_llvm_external_dir ${name})
147147 endif()
148 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}")
148149 string(REPLACE "-" "_" nameUNDERSCORE ${name})
149150 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
150151 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}"
158159 endif()
159160 endif()
160161 endmacro(add_llvm_external_project)
162
163 macro(add_llvm_tool_subdirectory name)
164 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
165 add_subdirectory(${name})
166 endmacro(add_llvm_tool_subdirectory)
167
168 macro(ignore_llvm_tool_subdirectory name)
169 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
170 endmacro(ignore_llvm_tool_subdirectory)
171
172 function(add_llvm_implicit_external_projects)
173 set(list_of_implicit_subdirs "")
174 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
175 foreach(dir ${sub-dirs})
176 if(IS_DIRECTORY "${dir}")
177 list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore)
178 if( tool_subdir_ignore EQUAL -1
179 AND EXISTS "${dir}/CMakeLists.txt")
180 get_filename_component(fn "${dir}" NAME)
181 list(APPEND list_of_implicit_subdirs "${fn}")
182 endif()
183 endif()
184 endforeach()
185
186 foreach(external_proj ${list_of_implicit_subdirs})
187 add_llvm_external_project("${external_proj}")
188 endforeach()
189 endfunction(add_llvm_implicit_external_projects)
161190
162191 # Generic support for adding a unittest.
163192 function(add_unittest test_suite test_name)
44 if( NOT WIN32 OR MSYS OR CYGWIN )
55 # We currently require 'sed' to build llvm-config, so don't try to build it
66 # on pure Win32.
7 add_subdirectory(llvm-config)
7 add_llvm_tool_subdirectory(llvm-config)
8 else()
9 ignore_llvm_tool_subdirectory(llvm-config)
810 endif()
911
10 add_subdirectory(opt)
11 add_subdirectory(llvm-as)
12 add_subdirectory(llvm-dis)
13 add_subdirectory(llvm-mc)
12 add_llvm_tool_subdirectory(opt)
13 add_llvm_tool_subdirectory(llvm-as)
14 add_llvm_tool_subdirectory(llvm-dis)
15 add_llvm_tool_subdirectory(llvm-mc)
1416
15 add_subdirectory(llc)
16 add_subdirectory(llvm-ar)
17 add_subdirectory(llvm-nm)
18 add_subdirectory(llvm-size)
17 add_llvm_tool_subdirectory(llc)
18 add_llvm_tool_subdirectory(llvm-ar)
19 add_llvm_tool_subdirectory(llvm-nm)
20 add_llvm_tool_subdirectory(llvm-size)
1921
20 add_subdirectory(llvm-cov)
21 add_subdirectory(llvm-prof)
22 add_subdirectory(llvm-link)
23 add_subdirectory(lli)
22 add_llvm_tool_subdirectory(llvm-cov)
23 add_llvm_tool_subdirectory(llvm-prof)
24 add_llvm_tool_subdirectory(llvm-link)
25 add_llvm_tool_subdirectory(lli)
2426
25 add_subdirectory(llvm-extract)
26 add_subdirectory(llvm-diff)
27 add_subdirectory(macho-dump)
28 add_subdirectory(llvm-objdump)
29 add_subdirectory(llvm-readobj)
30 add_subdirectory(llvm-rtdyld)
31 add_subdirectory(llvm-dwarfdump)
27 add_llvm_tool_subdirectory(llvm-extract)
28 add_llvm_tool_subdirectory(llvm-diff)
29 add_llvm_tool_subdirectory(macho-dump)
30 add_llvm_tool_subdirectory(llvm-objdump)
31 add_llvm_tool_subdirectory(llvm-readobj)
32 add_llvm_tool_subdirectory(llvm-rtdyld)
33 add_llvm_tool_subdirectory(llvm-dwarfdump)
3234 if( LLVM_USE_INTEL_JITEVENTS )
33 add_subdirectory(llvm-jitlistener)
35 add_llvm_tool_subdirectory(llvm-jitlistener)
36 else()
37 ignore_llvm_tool_subdirectory(llvm-jitlistener)
3438 endif( LLVM_USE_INTEL_JITEVENTS )
3539
36 add_subdirectory(bugpoint)
37 add_subdirectory(bugpoint-passes)
38 add_subdirectory(llvm-bcanalyzer)
39 add_subdirectory(llvm-stress)
40 add_subdirectory(llvm-mcmarkup)
40 add_llvm_tool_subdirectory(bugpoint)
41 add_llvm_tool_subdirectory(bugpoint-passes)
42 add_llvm_tool_subdirectory(llvm-bcanalyzer)
43 add_llvm_tool_subdirectory(llvm-stress)
44 add_llvm_tool_subdirectory(llvm-mcmarkup)
4145
42 add_subdirectory(llvm-symbolizer)
46 add_llvm_tool_subdirectory(llvm-symbolizer)
4347
44 add_subdirectory(obj2yaml)
45 add_subdirectory(yaml2obj)
48 add_llvm_tool_subdirectory(obj2yaml)
49 add_llvm_tool_subdirectory(yaml2obj)
4650
4751 if( NOT WIN32 )
48 add_subdirectory(lto)
52 add_llvm_tool_subdirectory(lto)
53 else()
54 ignore_llvm_tool_subdirectory(lto)
4955 endif()
5056
5157 if( LLVM_ENABLE_PIC )
5258 # TODO: support other systems:
5359 if( (CMAKE_SYSTEM_NAME STREQUAL "Linux")
5460 OR (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") )
55 add_subdirectory(gold)
61 add_llvm_tool_subdirectory(gold)
62 else()
63 ignore_llvm_tool_subdirectory(gold)
5664 endif()
65 else()
66 ignore_llvm_tool_subdirectory(gold)
5767 endif()
5868
5969 add_llvm_external_project(clang)
6070
6171 if( NOT LLVM_INCLUDE_TOOLS STREQUAL "bootstrap-only" )
62 add_llvm_external_project(lld)
63 add_llvm_external_project(lldb)
64 add_llvm_external_project(polly)
72 # Automatically add remaining sub-directories containing a 'CMakeLists.txt'
73 # file as external projects.
74 add_llvm_implicit_external_projects()
6575 endif()
6676
6777 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)