summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/CMakeLists.txt4
-rw-r--r--llvm/cmake/modules/AddLLVM.cmake13
-rw-r--r--llvm/include/llvm/Config/config.h.cmake3
-rw-r--r--llvm/lib/Support/Unix/Host.inc6
-rw-r--r--llvm/lib/Support/Windows/Host.inc10
5 files changed, 35 insertions, 1 deletions
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 431785d3dd0..f929b652080 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -570,6 +570,10 @@ if (LLVM_BUILD_STATIC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
+# Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
+set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.")
+mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
+
# All options referred to from HandleLLVMOptions have to be specified
# BEFORE this include, otherwise options will not be correctly set on
# first cmake run
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index e011bb40275..2b54bdbf290 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1133,6 +1133,19 @@ function(configure_lit_site_cfg input output)
set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${input}\n## Do not edit!")
+ # Override config_target_triple (and the env)
+ if(LLVM_TARGET_TRIPLE_ENV)
+ # This is expanded into the heading.
+ string(CONCAT LIT_SITE_CFG_IN_HEADER "${LIT_SITE_CFG_IN_HEADER}\n\n"
+ "import os\n"
+ "target_env = \"${LLVM_TARGET_TRIPLE_ENV}\"\n"
+ "config.target_triple = config.environment[target_env] = os.environ.get(target_env, \"${TARGET_TRIPLE}\")\n"
+ )
+
+ # This is expanded to; config.target_triple = ""+config.target_triple+""
+ set(TARGET_TRIPLE "\"+config.target_triple+\"")
+ endif()
+
configure_file(${input} ${output} @ONLY)
endfunction()
diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake
index 8df15ef9702..1289551f073 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -356,6 +356,9 @@
/* Define if this is Win32ish platform */
#cmakedefine LLVM_ON_WIN32 ${LLVM_ON_WIN32}
+/* Define if overriding target triple is enabled */
+#cmakedefine LLVM_TARGET_TRIPLE_ENV "${LLVM_TARGET_TRIPLE_ENV}"
+
/* Define if we have the Intel JIT API runtime support library */
#cmakedefine01 LLVM_USE_INTEL_JITEVENTS
diff --git a/llvm/lib/Support/Unix/Host.inc b/llvm/lib/Support/Unix/Host.inc
index 457217125a2..0ba6a25aa19 100644
--- a/llvm/lib/Support/Unix/Host.inc
+++ b/llvm/lib/Support/Unix/Host.inc
@@ -45,5 +45,11 @@ std::string sys::getDefaultTargetTriple() {
TargetTripleString += getOSVersion();
}
+ // Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
+#if defined(LLVM_TARGET_TRIPLE_ENV)
+ if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV))
+ TargetTripleString = EnvTriple;
+#endif
+
return Triple::normalize(TargetTripleString);
}
diff --git a/llvm/lib/Support/Windows/Host.inc b/llvm/lib/Support/Windows/Host.inc
index fe89fe0aad8..7e196cf0ce1 100644
--- a/llvm/lib/Support/Windows/Host.inc
+++ b/llvm/lib/Support/Windows/Host.inc
@@ -18,5 +18,13 @@
using namespace llvm;
std::string sys::getDefaultTargetTriple() {
- return Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE);
+ const char *Triple = LLVM_DEFAULT_TARGET_TRIPLE;
+
+ // Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
+#if defined(LLVM_TARGET_TRIPLE_ENV)
+ if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV))
+ Triple = EnvTriple;
+#endif
+
+ return Triple::normalize(Triple);
}
OpenPOWER on IntegriCloud