llvm.org GIT mirror llvm / 651c390
[CMake] Cleanup tools/CMakeLists.txt to take advantage of the auto-registration that was already partially working. Summary: The tools CMakeLists file already had implicit tool registration, but there were a few things off about it that needed to be altered to make it work. This change addresses all that. The changes in this patch are: * factored out canonicalizing tool names from paths to CMake variables * removed the LLVM_IMPLICIT_PROJECT_IGNORE mechanism in favor of LLVM_EXTERNAL_${nameUPPER}_BUILD which I renamed to LLVM_TOOL_${nameUPPER}_BUILD because it applies to internal and external tools * removed ignore_llvm_tool_subdirectory() in favor of just setting LLVM_TOOL_${nameUPPER}_BUILD to Off * Added create_llvm_tool_options() to resolve a bug in add_llvm_external_project() - the old LLVM_EXTERNAL_${nameUPPER}_BUILD would not work on a clean CMake directory because the option could be created after it was set in code. * Removed all but the minimum required calls to add_llvm_external_project from tools/CMakeLists.txt Reviewers: bogner, samsonov, chapuni, beanz Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10665 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241621 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 4 years ago
2 changed file(s) with 53 addition(s) and 89 deletion(s). Raw diff Collapse all Expand all
675675 set( CURRENT_LLVM_TARGET LLVM${target_name} )
676676 endmacro(add_llvm_target)
677677
678 function(canonicalize_tool_name name output)
679 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" nameStrip ${name})
680 string(REPLACE "-" "_" nameUNDERSCORE ${nameStrip})
681 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
682 set(${output} "${nameUPPER}" PARENT_SCOPE)
683 endfunction(canonicalize_tool_name)
684
678685 # Add external project that may want to be built as part of llvm such as Clang,
679686 # lld, and Polly. This adds two options. One for the source directory of the
680687 # project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
685692 if("${add_llvm_external_dir}" STREQUAL "")
686693 set(add_llvm_external_dir ${name})
687694 endif()
688 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}")
689 string(REPLACE "-" "_" nameUNDERSCORE ${name})
690 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
691 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}"
695 canonicalize_tool_name(${name} nameUPPER)
696 set(LLVM_TOOL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}"
692697 CACHE PATH "Path to ${name} source directory")
693 if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL ""
694 AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt)
695 option(LLVM_EXTERNAL_${nameUPPER}_BUILD
698 if (NOT ${LLVM_TOOL_${nameUPPER}_SOURCE_DIR} STREQUAL ""
699 AND EXISTS ${LLVM_TOOL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt)
700 option(LLVM_TOOL_${nameUPPER}_BUILD
696701 "Whether to build ${name} as part of LLVM" ON)
697 if (LLVM_EXTERNAL_${nameUPPER}_BUILD)
698 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
702 if (LLVM_TOOL_${nameUPPER}_BUILD)
703 add_subdirectory(${LLVM_TOOL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
704 set(LLVM_TOOL_${nameUPPER}_BUILD Off)
699705 endif()
700706 endif()
701707 endmacro(add_llvm_external_project)
702708
703709 macro(add_llvm_tool_subdirectory name)
704 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
710 set(LLVM_TOOL_${nameUPPER}_BUILD Off)
705711 add_subdirectory(${name})
706712 endmacro(add_llvm_tool_subdirectory)
707713
708 macro(ignore_llvm_tool_subdirectory name)
709 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
710 endmacro(ignore_llvm_tool_subdirectory)
711
712 function(add_llvm_implicit_external_projects)
714 function(create_llvm_tool_options)
715 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
716 foreach(dir ${sub-dirs})
717 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
718 canonicalize_tool_name(${dir} name)
719 option(LLVM_TOOL_${name}_BUILD
720 "Whether to build ${name} as part of LLVM" On)
721 endif()
722 endforeach()
723 endfunction(create_llvm_tool_options)
724
725 function(add_llvm_implicit_projects)
713726 set(list_of_implicit_subdirs "")
714727 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
715728 foreach(dir ${sub-dirs})
716 if(IS_DIRECTORY "${dir}")
717 list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore)
718 if( tool_subdir_ignore EQUAL -1
719 AND EXISTS "${dir}/CMakeLists.txt")
729 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
730 canonicalize_tool_name(${dir} name)
731 if (LLVM_TOOL_${name}_BUILD)
720732 get_filename_component(fn "${dir}" NAME)
721733 list(APPEND list_of_implicit_subdirs "${fn}")
722734 endif()
726738 foreach(external_proj ${list_of_implicit_subdirs})
727739 add_llvm_external_project("${external_proj}")
728740 endforeach()
729 endfunction(add_llvm_implicit_external_projects)
741 endfunction(add_llvm_implicit_projects)
730742
731743 # Generic support for adding a unittest.
732744 function(add_unittest test_suite test_name)
None add_llvm_tool_subdirectory(llvm-config)
0 # This file will recurse into all subdirectories that contain CMakeLists.txt
1 # Setting variables that match the pattern LLVM_TOOL_{NAME}_BUILD to Off will
2 # prevent traversing into a directory.
3 #
4 # The only tools that need to be explicitly added are ones that have explicit
5 # ordering requirements.
6
7 # Iterates all the subdirectories to create CMake options to enable/disable
8 # traversing each directory.
9 create_llvm_tool_options()
110
211 # Build polly before the tools: the tools link against polly when
312 # LINK_POLLY_INTO_TOOLS is set.
413 if(WITH_POLLY)
514 add_llvm_external_project(polly)
6 else(WITH_POLLY)
7 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${LLVM_MAIN_SRC_DIR}/tools/polly")
8 endif(WITH_POLLY)
9
10 if( LLVM_BUILD_LLVM_DYLIB )
11 add_llvm_tool_subdirectory(llvm-shlib)
1215 else()
13 ignore_llvm_tool_subdirectory(llvm-shlib)
16 set(LLVM_TOOL_POLLY_BUILD Off)
1417 endif()
1518
16 add_llvm_tool_subdirectory(opt)
17 add_llvm_tool_subdirectory(llvm-as)
18 add_llvm_tool_subdirectory(llvm-dis)
19 add_llvm_tool_subdirectory(llvm-mc)
20
21 add_llvm_tool_subdirectory(llc)
22 add_llvm_tool_subdirectory(llvm-ar)
23 add_llvm_tool_subdirectory(llvm-nm)
24 add_llvm_tool_subdirectory(llvm-size)
25
26 add_llvm_tool_subdirectory(llvm-cov)
27 add_llvm_tool_subdirectory(llvm-profdata)
28 add_llvm_tool_subdirectory(llvm-link)
29 add_llvm_tool_subdirectory(lli)
30
31 add_llvm_tool_subdirectory(llvm-extract)
32 add_llvm_tool_subdirectory(llvm-diff)
33 add_llvm_tool_subdirectory(macho-dump)
34 add_llvm_tool_subdirectory(llvm-objdump)
35 add_llvm_tool_subdirectory(llvm-readobj)
36 add_llvm_tool_subdirectory(llvm-rtdyld)
37 add_llvm_tool_subdirectory(llvm-dwarfdump)
38 add_llvm_tool_subdirectory(dsymutil)
39 add_llvm_tool_subdirectory(llvm-cxxdump)
40 if( LLVM_USE_INTEL_JITEVENTS )
41 add_llvm_tool_subdirectory(llvm-jitlistener)
42 else()
43 ignore_llvm_tool_subdirectory(llvm-jitlistener)
44 endif( LLVM_USE_INTEL_JITEVENTS )
45
46 add_llvm_tool_subdirectory(bugpoint)
47 add_llvm_tool_subdirectory(bugpoint-passes)
48 add_llvm_tool_subdirectory(llvm-bcanalyzer)
49 add_llvm_tool_subdirectory(llvm-stress)
50 add_llvm_tool_subdirectory(llvm-mcmarkup)
51
52 add_llvm_tool_subdirectory(verify-uselistorder)
53
54 add_llvm_tool_subdirectory(llvm-symbolizer)
55
56 add_llvm_tool_subdirectory(llvm-c-test)
57
58 add_llvm_tool_subdirectory(obj2yaml)
59 add_llvm_tool_subdirectory(yaml2obj)
60
61 add_llvm_tool_subdirectory(llvm-go)
62
63 add_llvm_tool_subdirectory(llvm-pdbdump)
64
65 if(NOT CYGWIN AND LLVM_ENABLE_PIC)
66 add_llvm_tool_subdirectory(lto)
67 add_llvm_tool_subdirectory(llvm-lto)
68 else()
69 ignore_llvm_tool_subdirectory(lto)
70 ignore_llvm_tool_subdirectory(llvm-lto)
19 if(NOT LLVM_BUILD_LLVM_DYLIB )
20 set(LLVM_TOOL_LLVM_SHLIB_BUILD Off)
7121 endif()
7222
73 add_llvm_tool_subdirectory(gold)
23 if(NOT LLVM_USE_INTEL_JITEVENTS )
24 set(LLVM_TOOL_LLVM_JITLISTENER_BUILD Off)
25 endif()
7426
75 add_llvm_external_project(clang)
76 add_llvm_external_project(llgo)
77 add_llvm_external_project(lld)
78 add_llvm_external_project(lldb)
27 if(CYGWIN OR NOT LLVM_ENABLE_PIC)
28 set(LLVM_TOOL_LTO_BUILD Off)
29 set(LLVM_TOOL_LLVM_LTO_BUILD Off)
30 endif()
7931
8032 # Automatically add remaining sub-directories containing a 'CMakeLists.txt'
8133 # file as external projects.
82 add_llvm_implicit_external_projects()
34 add_llvm_implicit_projects()
8335
8436 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)