summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShoaib Meenai <smeenai@fb.com>2018-12-03 20:05:11 +0000
committerShoaib Meenai <smeenai@fb.com>2018-12-03 20:05:11 +0000
commitf75f88d090c46a7fd9da3c966678e19f2c301a55 (patch)
treeeb5ea4f3458ca34b9e5cec16ac9eb902f2646f92
parenta79303d9a6a67ca2472471959ec2d636a56adb27 (diff)
downloadbcm5719-llvm-f75f88d090c46a7fd9da3c966678e19f2c301a55.tar.gz
bcm5719-llvm-f75f88d090c46a7fd9da3c966678e19f2c301a55.zip
[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 llvm-svn: 348180
-rw-r--r--llvm/cmake/modules/AddLLVM.cmake31
1 files changed, 17 insertions, 14 deletions
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 3e2f4f98a97..c68ec5cbb80 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -978,47 +978,50 @@ endfunction(canonicalize_tool_name)
# Custom add_subdirectory wrapper
# Takes in a project name (i.e. LLVM), the subdirectory name, and an optional
# path if it differs from the name.
-macro(add_llvm_subdirectory project type name)
+function(add_llvm_subdirectory project type name)
set(add_llvm_external_dir "${ARGN}")
if("${add_llvm_external_dir}" STREQUAL "")
set(add_llvm_external_dir ${name})
endif()
canonicalize_tool_name(${name} nameUPPER)
+ set(canonical_full_name ${project}_${type}_${nameUPPER})
+ get_property(already_processed GLOBAL PROPERTY ${canonical_full_name}_PROCESSED)
+ if(already_processed)
+ return()
+ endif()
+ set_property(GLOBAL PROPERTY ${canonical_full_name}_PROCESSED YES)
+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt)
# Treat it as in-tree subproject.
- option(${project}_${type}_${nameUPPER}_BUILD
+ option(${canonical_full_name}_BUILD
"Whether to build ${name} as part of ${project}" On)
mark_as_advanced(${project}_${type}_${name}_BUILD)
- if(${project}_${type}_${nameUPPER}_BUILD)
+ if(${canonical_full_name}_BUILD)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir})
- # Don't process it in add_llvm_implicit_projects().
- set(${project}_${type}_${nameUPPER}_BUILD OFF)
endif()
else()
set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR
"${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}"
CACHE PATH "Path to ${name} source directory")
- set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT ON)
+ set(${canonical_full_name}_BUILD_DEFAULT ON)
if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
- set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF)
+ set(${canonical_full_name}_BUILD_DEFAULT OFF)
endif()
if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF")
- set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF)
+ set(${canonical_full_name}_BUILD_DEFAULT OFF)
endif()
- option(${project}_${type}_${nameUPPER}_BUILD
+ option(${canonical_full_name}_BUILD
"Whether to build ${name} as part of LLVM"
- ${${project}_${type}_${nameUPPER}_BUILD_DEFAULT})
- if (${project}_${type}_${nameUPPER}_BUILD)
+ ${${canonical_full_name}_BUILD_DEFAULT})
+ if (${canonical_full_name}_BUILD)
if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR})
add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "")
message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}")
endif()
- # FIXME: It'd be redundant.
- set(${project}_${type}_${nameUPPER}_BUILD Off)
endif()
endif()
-endmacro()
+endfunction()
# Add external project that may want to be built as part of llvm such as Clang,
# lld, and Polly. This adds two options. One for the source directory of the
OpenPOWER on IntegriCloud