llvm.org GIT mirror llvm / 7fa8f24
[cmake] Clean up add_llvm_subdirectory I found the pattern of setting the project_BUILD variable to OFF after processing the project to be pretty confusing. Using global properties to explicitly keep track of whether a project has been processed or not seems much more straightforward, and it also allows us to convert the macro into a function (which is required for the early return). Factor the project+type+name combination out into a variable while I'm here, since it's used a whole bunch of times. I don't believe this should result in any functional changes. Differential Revision: https://reviews.llvm.org/D55104 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348180 91177308-0d34-0410-b5e6-96231b3b80d8 Shoaib Meenai 10 months ago
1 changed file(s) with 20 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
977977 # Custom add_subdirectory wrapper
978978 # Takes in a project name (i.e. LLVM), the subdirectory name, and an optional
979979 # path if it differs from the name.
980 macro(add_llvm_subdirectory project type name)
980 function(add_llvm_subdirectory project type name)
981981 set(add_llvm_external_dir "${ARGN}")
982982 if("${add_llvm_external_dir}" STREQUAL "")
983983 set(add_llvm_external_dir ${name})
984984 endif()
985985 canonicalize_tool_name(${name} nameUPPER)
986 set(canonical_full_name ${project}_${type}_${nameUPPER})
987 get_property(already_processed GLOBAL PROPERTY ${canonical_full_name}_PROCESSED)
988 if(already_processed)
989 return()
990 endif()
991 set_property(GLOBAL PROPERTY ${canonical_full_name}_PROCESSED YES)
992
986993 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)
987994 # Treat it as in-tree subproject.
988 option(${project}_${type}_${nameUPPER}_BUILD
995 option(${canonical_full_name}_BUILD
989996 "Whether to build ${name} as part of ${project}" On)
990997 mark_as_advanced(${project}_${type}_${name}_BUILD)
991 if(${project}_${type}_${nameUPPER}_BUILD)
998 if(${canonical_full_name}_BUILD)
992999 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir})
993 # Don't process it in add_llvm_implicit_projects().
994 set(${project}_${type}_${nameUPPER}_BUILD OFF)
9951000 endif()
9961001 else()
9971002 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
9981003 "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
9991004 CACHE PATH "Path to ${name} source directory")
1000 set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT ON)
1005 set(${canonical_full_name}_BUILD_DEFAULT ON)
10011006 if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
1002 set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF)
1007 set(${canonical_full_name}_BUILD_DEFAULT OFF)
10031008 endif()
10041009 if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF")
1005 set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF)
1006 endif()
1007 option(${project}_${type}_${nameUPPER}_BUILD
1010 set(${canonical_full_name}_BUILD_DEFAULT OFF)
1011 endif()
1012 option(${canonical_full_name}_BUILD
10081013 "Whether to build ${name} as part of LLVM"
1009 ${${project}_${type}_${nameUPPER}_BUILD_DEFAULT})
1010 if (${project}_${type}_${nameUPPER}_BUILD)
1014 ${${canonical_full_name}_BUILD_DEFAULT})
1015 if (${canonical_full_name}_BUILD)
10111016 if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
10121017 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
10131018 elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "")
10141019 message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}")
10151020 endif()
1016 # FIXME: It'd be redundant.
1017 set(${project}_${type}_${nameUPPER}_BUILD Off)
1018 endif()
1019 endif()
1020 endmacro()
1021 endif()
1022 endif()
1023 endfunction()
10211024
10221025 # Add external project that may want to be built as part of llvm such as Clang,
10231026 # lld, and Polly. This adds two options. One for the source directory of the