llvm.org GIT mirror llvm / 1159e42
[cmake] Canonicalize CMake booleans to 0/1 for lit interop Canonicalize all CMake booleans to 0/1 before passing them to lit, to ensure that the Python side handles all of them consistently and correctly. 0/1 is a safe choice of values that trigger the same boolean interpretation in CMake, Python and C++. Furthermore, using them without quotes improves the chance Python will explicitly fail when an incorrect value (such as ON/OFF, TRUE/FALSE, YES/NO) is accidentally passed, rather than silently misinterpreting the value. This replaces a lot of different logics spread around lit site files, attempting to partially reproduce the boolean logic used in CMake and usually silently failing when an uncommon value was used instead. In fact, some of them were never working correctly since different values were assigned in CMake and checked in Python. The alternative solution could be to create a common parser for CMake booleans in lit and use it consistently throughout the site files. However, it does not seem like the best idea to create redundant implementation of the same logic and have to follow upstream if it ever is extended to handle more values. Differential Revision: https://reviews.llvm.org/D28294 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291284 91177308-0d34-0410-b5e6-96231b3b80d8 Michal Gorny 2 years ago
9 changed file(s) with 39 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
461461 if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK)
462462 message(FATAL_ERROR "DIA SDK not found. If you have both VS 2012 and 2013 installed, you may need to uninstall the former and re-install the latter afterwards.")
463463 endif()
464
465 # Normalize to 0/1 for lit.site.cfg
466 if(LLVM_ENABLE_DIA_SDK)
467 set(LLVM_ENABLE_DIA_SDK 1)
468 else()
469 set(LLVM_ENABLE_DIA_SDK 0)
470 endif()
471464 else()
472465 set(LLVM_ENABLE_DIA_SDK 0)
473466 endif( MSVC )
10661066 endif()
10671067 endfunction()
10681068
1069 # This function canonicalize the CMake variables passed by names
1070 # from CMake boolean to 0/1 suitable for passing into Python or C++,
1071 # in place.
1072 function(llvm_canonicalize_cmake_booleans)
1073 foreach(var ${ARGN})
1074 if(${var})
1075 set(${var} 1 PARENT_SCOPE)
1076 else()
1077 set(${var} 0 PARENT_SCOPE)
1078 endif()
1079 endforeach()
1080 endfunction(llvm_canonicalize_cmake_booleans)
1081
10691082 # This function provides an automatic way to 'configure'-like generate a file
10701083 # based on a set of common and custom variables, specifically targeting the
10711084 # variables needed for the 'lit.site.cfg' files. This function bundles the
55 if not 'go' in config.root.llvm_bindings:
66 config.unsupported = True
77
8 if config.root.include_go_tests != 'ON':
8 if not config.root.include_go_tests:
99 config.unsupported = True
1010
1111 def find_executable(executable, path=None):
22 if not 'ocaml' in config.root.llvm_bindings:
33 config.unsupported = True
44
5 if config.root.have_ocaml_ounit not in ('1', 'TRUE'):
5 if not config.root.have_ocaml_ounit:
66 config.unsupported = True
0 llvm_canonicalize_cmake_booleans(
1 LLVM_TOOL_LTO_BUILD
2 HAVE_OCAMLOPT
3 HAVE_OCAML_OUNIT
4 LLVM_INCLUDE_GO_TESTS
5 LLVM_USE_INTEL_JITEVENTS
6 HAVE_LIBZ
7 HAVE_LIBXAR
8 LLVM_ENABLE_DIA_SDK
9 LLVM_ENABLE_FFI)
10
11 configure_lit_site_cfg(
112 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
213 ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
0 # These tests require foreign function calls
1 if config.enable_ffi != "ON":
1 if not config.enable_ffi:
22 config.unsupported = True
None if not config.root.llvm_use_intel_jitevents == "true":
0 if not config.root.llvm_use_intel_jitevents:
11 config.unsupported = True
22
230230 config.substitutions.append( ('%ocamlc',
231231 "%s ocamlc -cclib -L%s %s" %
232232 (config.ocamlfind_executable, llvm_lib_dir, config.ocaml_flags)) )
233 if config.have_ocamlopt in ('1', 'TRUE'):
233 if config.have_ocamlopt:
234234 config.substitutions.append( ('%ocamlopt',
235235 "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
236236 (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) )
398398 if not 'hexagon' in config.target_triple:
399399 config.available_features.add("object-emission")
400400
401 if config.have_zlib == "1":
401 if config.have_zlib:
402402 config.available_features.add("zlib")
403403 else:
404404 config.available_features.add("nozlib")
454454 config.available_features.add('ld_plugin')
455455
456456 def have_ld64_plugin_support():
457 if (config.llvm_tool_lto_build == 'OFF' or config.ld64_executable == ''):
457 if not config.llvm_tool_lto_build or config.ld64_executable == '':
458458 return False
459459
460460 ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)
1414 config.python_executable = "@PYTHON_EXECUTABLE@"
1515 config.gold_executable = "@GOLD_EXECUTABLE@"
1616 config.ld64_executable = "@LD64_EXECUTABLE@"
17 config.llvm_tool_lto_build = "@LLVM_TOOL_LTO_BUILD@"
17 config.llvm_tool_lto_build = @LLVM_TOOL_LTO_BUILD@
1818 config.ocamlfind_executable = "@OCAMLFIND@"
19 config.have_ocamlopt = "@HAVE_OCAMLOPT@"
20 config.have_ocaml_ounit = "@HAVE_OCAML_OUNIT@"
19 config.have_ocamlopt = @HAVE_OCAMLOPT@
20 config.have_ocaml_ounit = @HAVE_OCAML_OUNIT@
2121 config.ocaml_flags = "@OCAMLFLAGS@"
22 config.include_go_tests = "@LLVM_INCLUDE_GO_TESTS@"
22 config.include_go_tests = @LLVM_INCLUDE_GO_TESTS@
2323 config.go_executable = "@GO_EXECUTABLE@"
2424 config.enable_shared = @ENABLE_SHARED@
2525 config.enable_assertions = @ENABLE_ASSERTIONS@
3131 config.host_cc = "@HOST_CC@"
3232 config.host_cxx = "@HOST_CXX@"
3333 config.host_ldflags = "@HOST_LDFLAGS@"
34 config.llvm_use_intel_jitevents = "@LLVM_USE_INTEL_JITEVENTS@"
34 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
3535 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
36 config.have_zlib = "@HAVE_LIBZ@"
37 config.have_libxar = "@HAVE_LIBXAR@"
36 config.have_zlib = @HAVE_LIBZ@
37 config.have_libxar = @HAVE_LIBXAR@
3838 config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
39 config.enable_ffi = "@LLVM_ENABLE_FFI@"
39 config.enable_ffi = @LLVM_ENABLE_FFI@
4040
4141 # Support substitution of the tools_dir with user parameters. This is
4242 # used when we can't determine the tool dir at configuration time.