llvm.org GIT mirror llvm / b903fdd
[CMake] Introduce LLVM_TARGET_TRIPLE_ENV as an option to override LLVM_DEFAULT_TARGET_TRIPLE at runtime. No behavior is changed if LLVM_TARGET_TRIPLE_ENV is blank or undefined. If LLVM_TARGET_TRIPLE_ENV is "TEST_TARGET_TRIPLE" and $TEST_TARGET_TRIPLE is not blank, llvm::sys::getDefaultTargetTriple() returns $TEST_TARGET_TRIPLE. Lit resets config.target_triple and config.environment[LLVM_TARGET_TRIPLE_ENV] to change the default target. Without changing LLVM_DEFAULT_TARGET_TRIPLE nor rebuilding, lit can be run; TEST_TARGET_TRIPLE=i686-pc-win32 bin/llvm-lit -sv path/to/test/ TEST_TARGET_TRIPLE=i686-pc-win32 ninja check-clang-tools Differential Revision: https://reviews.llvm.org/D33662 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305632 91177308-0d34-0410-b5e6-96231b3b80d8 NAKAMURA Takumi 2 years ago
5 changed file(s) with 35 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
569569 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
570570 endif()
571571
572 # Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
573 set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.")
574 mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
575
572576 # All options referred to from HandleLLVMOptions have to be specified
573577 # BEFORE this include, otherwise options will not be correctly set on
574578 # first cmake run
11321132
11331133 set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${input}\n## Do not edit!")
11341134
1135 # Override config_target_triple (and the env)
1136 if(LLVM_TARGET_TRIPLE_ENV)
1137 # This is expanded into the heading.
1138 string(CONCAT LIT_SITE_CFG_IN_HEADER "${LIT_SITE_CFG_IN_HEADER}\n\n"
1139 "import os\n"
1140 "target_env = \"${LLVM_TARGET_TRIPLE_ENV}\"\n"
1141 "config.target_triple = config.environment[target_env] = os.environ.get(target_env, \"${TARGET_TRIPLE}\")\n"
1142 )
1143
1144 # This is expanded to; config.target_triple = ""+config.target_triple+""
1145 set(TARGET_TRIPLE "\"+config.target_triple+\"")
1146 endif()
1147
11351148 configure_file(${input} ${output} @ONLY)
11361149 endfunction()
11371150
355355 /* Define if this is Win32ish platform */
356356 #cmakedefine LLVM_ON_WIN32 ${LLVM_ON_WIN32}
357357
358 /* Define if overriding target triple is enabled */
359 #cmakedefine LLVM_TARGET_TRIPLE_ENV "${LLVM_TARGET_TRIPLE_ENV}"
360
358361 /* Define if we have the Intel JIT API runtime support library */
359362 #cmakedefine01 LLVM_USE_INTEL_JITEVENTS
360363
4444 TargetTripleString += getOSVersion();
4545 }
4646
47 // Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
48 #if defined(LLVM_TARGET_TRIPLE_ENV)
49 if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV))
50 TargetTripleString = EnvTriple;
51 #endif
52
4753 return Triple::normalize(TargetTripleString);
4854 }
1717 using namespace llvm;
1818
1919 std::string sys::getDefaultTargetTriple() {
20 return Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE);
20 const char *Triple = LLVM_DEFAULT_TARGET_TRIPLE;
21
22 // Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
23 #if defined(LLVM_TARGET_TRIPLE_ENV)
24 if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV))
25 Triple = EnvTriple;
26 #endif
27
28 return Triple::normalize(Triple);
2129 }