llvm.org GIT mirror llvm / 8d539b5
[CMake] Cleanup tools/CMakeLists.txt to take advantage of the auto-registration that was already partially working. Summary: This change re-lands r241621, with an additional fix that was required to allow tool sources to live outside the llvm checkout. It also no longer renames LLVM_EXTERNAL_*_SOURCE_DIR. This change was reverted in r241663, because it renamed several variables of the format LLVM_EXTERNAL_*_* to LLVM_TOOL_*_*. Original 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 Differential Revision: http://reviews.llvm.org/D10665 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242059 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 4 years ago
2 changed file(s) with 86 addition(s) and 91 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}"
692 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
696 "Whether to build ${name} as part of LLVM" ON)
697 if (LLVM_EXTERNAL_${nameUPPER}_BUILD)
695 canonicalize_tool_name(${name} nameUPPER)
696 if (LLVM_TOOL_${nameUPPER}_BUILD)
697 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)
698 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir})
699 set(LLVM_TOOL_${nameUPPER}_BUILD Off)
700 elseif(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR)
701 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
702 "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
703 CACHE PATH "Path to ${name} source directory")
704 mark_as_advanced(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR)
698705 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
706 set(LLVM_TOOL_${nameUPPER}_BUILD Off)
699707 endif()
700708 endif()
701709 endmacro(add_llvm_external_project)
702710
703711 macro(add_llvm_tool_subdirectory name)
704 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
705 add_subdirectory(${name})
712 add_llvm_external_project(${name})
706713 endmacro(add_llvm_tool_subdirectory)
707714
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)
715 function(get_project_name_from_src_var var output)
716 string(REGEX MATCH "LLVM_EXTERNAL_(.*)_SOURCE_DIR"
717 MACHED_TOOL "${var}")
718 if(MACHED_TOOL)
719 set(${output} ${CMAKE_MATCH_1} PARENT_SCOPE)
720 else()
721 set(${output} PARENT_SCOPE)
722 endif()
723 endfunction()
724
725 function(create_llvm_tool_options)
726 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
727 foreach(dir ${sub-dirs})
728 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
729 canonicalize_tool_name(${dir} name)
730 option(LLVM_TOOL_${name}_BUILD
731 "Whether to build ${name} as part of LLVM" On)
732 mark_as_advanced(LLVM_TOOL_${name}_BUILD)
733 endif()
734 endforeach()
735 get_cmake_property(variableNames VARIABLES)
736 foreach (variableName ${variableNames})
737 get_project_name_from_src_var(${variableName} projectName)
738 if(projectName)
739 option(LLVM_TOOL_${projectName}_BUILD
740 "Whether to build ${name} as part of LLVM" On)
741 mark_as_advanced(LLVM_TOOL_${name}_BUILD)
742 endif()
743 endforeach()
744 endfunction(create_llvm_tool_options)
745
746 function(add_llvm_implicit_projects)
713747 set(list_of_implicit_subdirs "")
714748 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
715749 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")
750 if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
751 canonicalize_tool_name(${dir} name)
752 if (LLVM_TOOL_${name}_BUILD)
720753 get_filename_component(fn "${dir}" NAME)
721754 list(APPEND list_of_implicit_subdirs "${fn}")
722755 endif()
723756 endif()
724757 endforeach()
725758
759 get_cmake_property(variableNames VARIABLES)
760 foreach (variableName ${variableNames})
761 get_project_name_from_src_var(${variableName} projectName)
762 if(projectName)
763 string(TOLOWER ${projectName} projectName)
764 list(APPEND list_of_implicit_subdirs ${projectName})
765 endif()
766 endforeach()
767
768 list(REMOVE_DUPLICATES list_of_implicit_subdirs)
726769 foreach(external_proj ${list_of_implicit_subdirs})
727770 add_llvm_external_project("${external_proj}")
728771 endforeach()
729 endfunction(add_llvm_implicit_external_projects)
772 endfunction(add_llvm_implicit_projects)
730773
731774 # Generic support for adding a unittest.
732775 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)