summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorBrian Gesiak <modocache@gmail.com>2017-07-19 18:37:02 +0000
committerBrian Gesiak <modocache@gmail.com>2017-07-19 18:37:02 +0000
commit0e8fd92a7221d1255dc2beaf2e3ed6743870ccc6 (patch)
tree9ad830b5d0ea82355b5b24753e23929c702e5842 /cmake
parentdba60ce821fb360874d1b4cad96c0b0592e9479f (diff)
[cmake] GetSVN.cmake takes a list of arguments
Summary: GetSVN.cmake currently takes one or two pairs of <source directory path, name>, then attempts to get the remote repository URL and source control revision of the repositories at those one or two paths. It takes two pairs in order for Clang to get the revision of both itself, and its dependency LLVM. For projects that rely upon both LLVM and Clang (Apple's Swift is one example, but there are others), GetSVN.cmake is used to fetch *three* revisions: Swift, Clang, and LLVM. To support this use case, change GetSVN.cmake: instead of taking one or two pairs (specified via `FIRST_SOURCE_DIR`/`FIRST_NAME`, have it take a list of pairs (`SOURCE_DIRS`/`NAMES`). In order to allow Clang to migrate, have GetSVN.cmake support both sets of arguments for now. The old arguments can be removed once Clang begins using the new arguments, and Swift can follow when it updates its copy of LLVM. Test Plan: 1. Perform a clean build of Clang, verify that `clang --version` still prints the correct LLVM and Clang revision information. 2. Modify Clang's CMake to use the new arguments, then perform another clean build. `clang --version` should still print the correct revision information. Reviewers: jordan_rose, beanz, probinson Subscribers: echristo, chapuni, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D35132 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308507 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/GetSVN.cmake50
1 files changed, 38 insertions, 12 deletions
diff --git a/cmake/modules/GetSVN.cmake b/cmake/modules/GetSVN.cmake
index d512bd292cf..0a673b908f1 100644
--- a/cmake/modules/GetSVN.cmake
+++ b/cmake/modules/GetSVN.cmake
@@ -1,17 +1,15 @@
# CMake project that writes Subversion revision information to a header.
#
# Input variables:
-# FIRST_SOURCE_DIR - First source directory
-# FIRST_NAME - The macro prefix for the first repository's info
-# SECOND_SOURCE_DIR - Second source directory (opt)
-# SECOND_NAME - The macro prefix for the second repository's info (opt)
-# HEADER_FILE - The header file to write
+# SOURCE_DIRS - A list of source directories.
+# NAMES - A list of macro prefixes for each of the source directories.
+# HEADER_FILE - The header file to write
#
-# The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION,
-# and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and
-# "SECOND" are substituted with the names specified in the input variables.
+# The output header will contain macros <NAME>_REPOSITORY and <NAME>_REVISION,
+# where "<NAME>" and is substituted with the names specified in the input
+# variables, for each of the SOURCE_DIRS given.
-# Chop off cmake/modules/GetSVN.cmake
+# Chop off cmake/modules/GetSVN.cmake
get_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH)
get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
@@ -103,9 +101,37 @@ function(append_info name path)
"#define ${name}_REPOSITORY \"${repository}\"\n")
endfunction()
-append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}")
-if(DEFINED SECOND_SOURCE_DIR)
- append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}")
+function(validate_inputs source_dirs names)
+ list(LENGTH source_dirs source_dirs_length)
+ list(LENGTH names names_length)
+ if (NOT source_dirs_length EQUAL names_length)
+ message(FATAL_ERROR
+ "GetSVN.cmake takes two arguments: a list of source directories, "
+ "and a list of names. Expected two lists must be of equal length, "
+ "but got ${source_dirs_length} source directories and "
+ "${names_length} names.")
+ endif()
+endfunction()
+
+if (DEFINED SOURCE_DIRS AND DEFINED NAMES)
+ validate_inputs("${SOURCE_DIRS}" "${NAMES}")
+
+ list(LENGTH SOURCE_DIRS source_dirs_length)
+ math(EXPR source_dirs_max_index ${source_dirs_length}-1)
+ foreach(index RANGE ${source_dirs_max_index})
+ list(GET SOURCE_DIRS ${index} source_dir)
+ list(GET NAMES ${index} name)
+ append_info(${name} ${source_dir})
+ endforeach()
+endif()
+
+# Allow -DFIRST_SOURCE_DIR arguments until Clang migrates to the new
+# -DSOURCE_DIRS argument.
+if(DEFINED FIRST_SOURCE_DIR)
+ append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}")
+ if(DEFINED SECOND_SOURCE_DIR)
+ append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}")
+ endif()
endif()
# Copy the file only if it has changed.