From 611cac5669c02e774aa5ecaf7c2959133ecb512c Mon Sep 17 00:00:00 2001 From: Tzvetan Mikov Date: Thu, 6 Feb 2020 00:30:00 -0800 Subject: [PATCH] Use internal fork of LLVM Summary: Place a fork of LLVM git rev c179d7b006348005d2da228aed4c3c251590baa3 under `external/llvh`(1) and modify the CMake build to use it. I am calling it a "fork", because it is not all of LLVM. Only the parts that are used by Hermes are included, which at this time is only parts of `libLLVMSupporrt`. Most(2) of LLVM build scripts are removed, and it is treated just as another ordinary library. (1) Why `llvh`? To be able to coexist with instances of the "real" LLVM, we must change the namespace, all public symbols containing the `llvm` string and the include directory name. `llvh` seemed as good a name as any. I also considered `llvm-h` and `h-llvm`, but the problem is that they are a superstring of `llvm` so it becomes harder to search for the `llvm` string. Note that the actual rename will happen in a follow up diff. It would be a massive patch. (2) libLLVMSupport relies on pretty elaborate feature detection scripts, which would be painful to duplicate, so for now I have preserved them under external/llvh/cmake. Unfortunately turning LLVM into an ordinary library is not enough, since we were implicitly relying on a lot of functionality provided by the LLVM build scripts. Things like setting default warning flags, easily turning exceptions on and off, etc. I attempted to replace it with Hermes equivalents, which are now provided by `cmake/Hermes.cmake`: - `add_llvm_library/tool()` is replaced by `add_hermes_library/tool()`. - Several `LLVM_xxx` variables are replaced my similar `HERMES_xxx` ones. As a result, building Hermes now requires only checking it out, and running CMake and Ninja. It is a vastly simpler process than before. == Limitations - CMake LTO and ASAN builds aren't supported yet. - The JIT requires the "real" LLVM for disassembly. Reviewed By: avp Differential Revision: D19658656 fbshipit-source-id: 5094d2af45e343973b1aab02c550a18b2bf93a06 --- API/CMakeLists.txt | 4 +- API/hermes/CMakeLists.txt | 21 +- API/hermes/synthtest/CMakeLists.txt | 2 +- CMakeLists.txt | 175 +- android/cross-compile/CrossCompile.md | 13 - android/cross-compile/config-hermes.sh | 7 +- android/cross-compile/config-llvm-clang.sh | 12 - android/cross-compile/config-llvm.sh | 12 - android/cross-compile/llvm.patch | 62 - ... toolchain-android-arm-api15-gnustl.cmake} | 4 +- cmake/modules/Hermes.cmake | 398 +++++ cmake/modules/Lit.cmake | 99 ++ external/CMakeLists.txt | 2 + external/dtoa/CMakeLists.txt | 2 +- external/llvh/CMakeLists.txt | 30 + external/llvh/cmake/config-ix.cmake | 625 +++++++ external/llvh/cmake/config.guess | 1528 +++++++++++++++++ external/llvh/cmake/modules/CheckAtomic.cmake | 106 ++ .../cmake/modules/CheckCompilerVersion.cmake | 52 + .../llvh/cmake/modules/CheckLinkerFlag.cmake | 6 + .../modules/DetermineGCCCompatible.cmake | 13 + external/llvh/cmake/modules/FindLibpfm.cmake | 23 + .../llvh/cmake/modules/GetHostTriple.cmake | 29 + .../llvh/cmake/modules/HandleLLVMStdlib.cmake | 32 + .../llvh/gen/include/llvm/IR/Attributes.inc | 520 ++++++ .../llvh/include/llvm/Config/config.h.cmake | 4 + .../{llvm-config.h => llvm-config.h.cmake} | 44 +- external/llvh/lib/CMakeLists.txt | 2 + external/llvh/lib/Demangle/CMakeLists.txt | 5 + external/llvh/lib/Support/CMakeLists.txt | 61 + .../patches}/llvm-changes-for-hermes.patch | 0 external/llvh/utils/FileCheck/CMakeLists.txt | 4 +- external/llvh/utils/count/CMakeLists.txt | 2 +- external/llvh/utils/not/CMakeLists.txt | 4 +- external/llvh/utils/unittest/CMakeLists.txt | 11 +- .../unittest/UnitTestMain/CMakeLists.txt | 9 +- external/zip/CMakeLists.txt | 2 +- first-party/fbjni/CMakeLists.txt | 4 +- lib/ADT/CMakeLists.txt | 2 +- lib/AST/CMakeLists.txt | 2 +- lib/BCGen/CMakeLists.txt | 2 +- lib/BCGen/HBC/CMakeLists.txt | 2 +- lib/CMakeLists.txt | 12 +- lib/CompilerDriver/CMakeLists.txt | 2 +- lib/ConsoleHost/CMakeLists.txt | 2 +- lib/FlowParser/CMakeLists.txt | 2 +- lib/FrontEndDefs/CMakeLists.txt | 2 +- lib/Inst/CMakeLists.txt | 2 +- lib/InternalBytecode/CMakeLists.txt | 2 +- lib/Parser/CMakeLists.txt | 4 +- lib/Platform/CMakeLists.txt | 2 +- lib/Platform/Unicode/CMakeLists.txt | 4 +- lib/Regex/CMakeLists.txt | 2 +- lib/SourceMap/CMakeLists.txt | 2 +- lib/Support/CMakeLists.txt | 2 +- lib/VM/CMakeLists.txt | 4 +- lib/VM/Instrumentation/CMakeLists.txt | 2 +- public/hermes/Public/CtorConfig.h | 16 +- tools/hbc-attribute/CMakeLists.txt | 8 +- tools/hbc-deltaprep/CMakeLists.txt | 8 +- tools/hbc-diff/CMakeLists.txt | 8 +- tools/hbcdump/CMakeLists.txt | 8 +- tools/hdb/CMakeLists.txt | 6 +- tools/hermes/CMakeLists.txt | 8 +- tools/hermesc/CMakeLists.txt | 8 +- tools/hvm-bench/CMakeLists.txt | 8 +- tools/hvm/CMakeLists.txt | 8 +- tools/jsi/CMakeLists.txt | 18 +- tools/repl/CMakeLists.txt | 8 +- tools/synth/CMakeLists.txt | 2 +- unittests/API/CMakeLists.txt | 13 +- unittests/AST/CMakeLists.txt | 4 - unittests/BCGen/CMakeLists.txt | 6 +- unittests/CMakeLists.txt | 4 +- unittests/IR/CMakeLists.txt | 6 +- unittests/Parser/CMakeLists.txt | 5 +- unittests/VMRuntime/CMakeLists.txt | 6 +- unittests/VMRuntime/JIT/CMakeLists.txt | 6 +- utils/build/build_llvm.py | 211 --- utils/build/configure.py | 19 +- utils/crosscompile_llvm.sh | 66 - utils/hermes-lit/CMakeLists.txt | 22 + utils/hermes-lit/hermes-lit.in | 11 + 83 files changed, 3785 insertions(+), 691 deletions(-) delete mode 100755 android/cross-compile/config-llvm-clang.sh delete mode 100755 android/cross-compile/config-llvm.sh delete mode 100644 android/cross-compile/llvm.patch rename android/cross-compile/{toolchain-android-clang-arm-api13-gnustl.cmake => toolchain-android-arm-api15-gnustl.cmake} (81%) create mode 100644 cmake/modules/Hermes.cmake create mode 100644 cmake/modules/Lit.cmake create mode 100644 external/llvh/CMakeLists.txt create mode 100644 external/llvh/cmake/config-ix.cmake create mode 100644 external/llvh/cmake/config.guess create mode 100644 external/llvh/cmake/modules/CheckAtomic.cmake create mode 100644 external/llvh/cmake/modules/CheckCompilerVersion.cmake create mode 100644 external/llvh/cmake/modules/CheckLinkerFlag.cmake create mode 100644 external/llvh/cmake/modules/DetermineGCCCompatible.cmake create mode 100644 external/llvh/cmake/modules/FindLibpfm.cmake create mode 100644 external/llvh/cmake/modules/GetHostTriple.cmake create mode 100644 external/llvh/cmake/modules/HandleLLVMStdlib.cmake create mode 100644 external/llvh/gen/include/llvm/IR/Attributes.inc rename external/llvh/include/llvm/Config/{llvm-config.h => llvm-config.h.cmake} (65%) create mode 100644 external/llvh/lib/CMakeLists.txt create mode 100644 external/llvh/lib/Demangle/CMakeLists.txt create mode 100644 external/llvh/lib/Support/CMakeLists.txt rename {utils/build => external/llvh/patches}/llvm-changes-for-hermes.patch (100%) delete mode 100755 utils/build/build_llvm.py delete mode 100755 utils/crosscompile_llvm.sh create mode 100644 utils/hermes-lit/CMakeLists.txt create mode 100755 utils/hermes-lit/hermes-lit.in diff --git a/API/CMakeLists.txt b/API/CMakeLists.txt index 9934ef88275..8ca492f3540 100644 --- a/API/CMakeLists.txt +++ b/API/CMakeLists.txt @@ -3,8 +3,8 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_REQUIRES_EH ON) -set(LLVM_REQUIRES_RTTI ON) +set(HERMES_ENABLE_EH ON) +set(HERMES_ENABLE_RTTI ON) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${HERMES_JSI_DIR}) diff --git a/API/hermes/CMakeLists.txt b/API/hermes/CMakeLists.txt index 33f88215ff0..c7a0a22bb61 100644 --- a/API/hermes/CMakeLists.txt +++ b/API/hermes/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_OPTIONAL_SOURCES +set(HERMES_OPTIONAL_SOURCES hermes.cpp hermes_tracing.cpp hermes_tracing_compat.cpp @@ -21,7 +21,7 @@ set(api_sources hermes_tracing_compat.cpp ) -add_llvm_library(hermesapi +add_hermes_library(hermesapi ${api_sources} LINK_LIBS jsi hermesVMRuntime) @@ -38,22 +38,19 @@ set_property(TARGET hermesapi APPEND_STRING PROPERTY set_property(TARGET hermesapi APPEND_STRING PROPERTY COMPILE_DEFINITIONS "JSI_CREATE_SHARED_LIBRARY") -set(LLVM_LINK_COMPONENTS - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) # Disable EH and RTTI for compileJS -set(LLVM_REQUIRES_EH OFF) -set(LLVM_REQUIRES_RTTI OFF) +set(HERMES_ENABLE_EH OFF) +set(HERMES_ENABLE_RTTI OFF) -add_llvm_library(compileJS STATIC CompileJS.cpp) +add_hermes_library(compileJS STATIC CompileJS.cpp) # Restore EH and RTTI (Note: At the time of writing, there is no usage of -# add_llvm_library either after this line in this file or in a sub directory. +# add_hermes_library either after this line in this file or in a sub directory. # However, the values are restored anyways for the sake of sanity.) -set(LLVM_REQUIRES_EH ON) -set(LLVM_REQUIRES_RTTI ON) +set(HERMES_ENABLE_EH ON) +set(HERMES_ENABLE_RTTI ON) add_library(libhermes SHARED ${api_sources}) target_link_libraries(libhermes diff --git a/API/hermes/synthtest/CMakeLists.txt b/API/hermes/synthtest/CMakeLists.txt index e7caafc8af8..674933e0d22 100644 --- a/API/hermes/synthtest/CMakeLists.txt +++ b/API/hermes/synthtest/CMakeLists.txt @@ -5,6 +5,6 @@ # Dummy CMakeLists to avoid a test failure -add_llvm_library(synth_test +add_hermes_library(synth_test Driver.cpp ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76bb42b6ab5..53ff5288e20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,19 +17,53 @@ if (POLICY CMP0048) cmake_policy(SET CMP0048 NEW) endif() +# find_package uses _ROOT variables. +if (POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() # Include file check macros honor CMAKE_REQUIRED_LIBRARIES. if (POLICY CMP0075) cmake_policy(SET CMP0075 NEW) endif() +# Only interpret if() arguments as variables or keywords when unquoted. +# CMake emits a warning if this is not set. +if (POLICY CMP0054) + cmake_policy(SET CMP0054 NEW) +endif() + +# Pick up a workaround for a CMake problem from LLVM r282552. +if(POLICY CMP0057) + cmake_policy(SET CMP0057 NEW) +endif() + +# Enable transitive library dependencies +if(POLICY CMP0022) + cmake_policy(SET CMP0022 NEW) +endif() + +# Don't complain about mixing plain and keyword target_link_libraries commands. +# Keyword style is when you specify whether library symbols are re-exported, +# e.g. target_link_libraries(target PRIVATE lib). +# LLVM currently uses plain-style target_link_libraries calls so we must +# allow mixing. +if (POLICY CMP0023) + cmake_policy(SET CMP0023 OLD) +endif() + + # This must be consistent with the release_version in # android/build.gradle and npm/package.json project(Hermes VERSION 0.4.0 LANGUAGES C CXX) -include(CheckCXXCompilerFlag) -include(CheckCXXSourceCompiles) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") + +set(LLVH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/llvh) + +include(Hermes) +include(Lit) set(HERMES_RELEASE_VERSION ${PROJECT_VERSION}) @@ -126,11 +160,7 @@ set(ANDROID_LINUX_PERF_PATH "" set(HERMES_MSVC_MP ON CACHE STRING "Enable /MP in MSVC for parallel builds") -# On Android we need an ABI specific version of LLVM. -# Unfortunately, the build system doesn't allow setting the -# LLVM_BUILD_DIR per ABI, so we do it here instead. if (HERMES_IS_ANDROID) - set(LLVM_BUILD_DIR "${LLVM_BUILD_BASE}-${ANDROID_ABI}") add_definitions(-DHERMES_PLATFORM_UNICODE=HERMES_PLATFORM_UNICODE_JAVA) # The toolchain passes -Wa,--noexecstack which is valid for compiling @@ -151,15 +181,6 @@ if (HERMES_IS_ANDROID) endif() endif() -# The hermes project is built using CMake and the LLVM's build system. -# It expects LLVM_SRC_DIR and LLVM_BUILD_DIR to be set. For example: -# -# cmake -G Ninja -DLLVM_BUILD_DIR=$XXX -DLLVM_SRC_DIR=$YYY -# -file(TO_CMAKE_PATH "${LLVM_BUILD_DIR}" LLVM_BUILD_DIR) -file(TO_CMAKE_PATH "${LLVM_SRC_DIR}" LLVM_SRC_DIR) -list(APPEND CMAKE_MODULE_PATH "${LLVM_BUILD_DIR}/lib/cmake/llvm/") - # Enable debug mode by default if ((NOT GENERATOR_IS_MULTI_CONFIG) AND CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE Debug) @@ -256,49 +277,16 @@ if (NOT (ANDROID_LINUX_PERF_PATH STREQUAL "")) add_definitions(-DANDROID_LINUX_PERF_PATH="${ANDROID_LINUX_PERF_PATH}") endif() -# Build the hermes compiler by default. -set(LLVM_BUILD_TOOLS ON) -# Enable warnings. -set(LLVM_ENABLE_WARNINGS ON) - -# Only interpret if() arguments as variables or keywords when unquoted. -# CMake emits a warning if this is not set. -if (POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) -endif() - if (HERMES_ENABLE_WERROR) - # Turn all warnings into errors on some compilers: - if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(LLVM_ENABLE_WERROR ON) - elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") - set(LLVM_ENABLE_WERROR ON) - elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") - # Warn. + # Turn all warnings into errors on GCC-compatible compilers. + if (GCC_COMPATIBLE) + append("-Werror" CMAKE_CXX_FLAGS CMAKE_C_FLAGS) endif() endif() # Collect all header files and add them to the IDE. file(GLOB_RECURSE ALL_HEADER_FILES "*.h") -# Pick up a workaround for a CMake problem from LLVM r282552. -if(POLICY CMP0057) - cmake_policy(SET CMP0057 NEW) -endif() -# Enable transitive library dependencies -if(POLICY CMP0022) - cmake_policy(SET CMP0022 NEW) -endif() - -# Don't complain about mixing plain and keyword target_link_libraries commands. -# Keyword style is when you specify whether library symbols are re-exported, -# e.g. target_link_libraries(target PRIVATE lib). -# LLVM currently uses plain-style target_link_libraries calls so we must -# allow mixing. -if (POLICY CMP0023) - cmake_policy(SET CMP0023 OLD) -endif() - if(HERMES_SLOW_DEBUG) # Enable HERMES_SLOW_DEBUG in Debug mode set_property(DIRECTORY APPEND PROPERTY @@ -315,17 +303,13 @@ if (NOT (GENERATOR_IS_MULTI_CONFIG OR CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_C # Enable LTO if we are not multi config generator and not a DEBUG build # and not GCC # GCC currently fails to link Hermes with LTO (see t16557748) - option(LLVM_ENABLE_LTO "Build Hermes with LTO" ON) + option(HERMES_ENABLE_LTO "Build Hermes with LTO" ON) endif() -if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR - "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") - # Supress warnings about unknown warnings - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option") - # Suppress an uninteresting warning about C++17 name mangling changes. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-noexcept-type") +if (GCC_COMPATIBLE) # Suppress uninteresting warnings about initializing ArrayRef from initializer lists. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-init-list-lifetime") + check_cxx_compiler_flag("-Winit-list-lifetime" INIT_LIST_LIFETIME_FLAG) + append_if(INIT_LIST_LIFETIME_FLAG "-Wno-init-list-lifetime" CMAKE_CXX_FLAGS) # Don't export symbols unless we explicitly say so set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") @@ -335,6 +319,8 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4200") # C4201 nonstandard extension used: nameless struct/union set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4201") + # C4530 C++ exception handler used, but unwind semantics are not enabled + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4530") # Parallelize build if (HERMES_MSVC_MP) add_definitions( /MP ) @@ -345,17 +331,6 @@ endif() # to analyze the source code of the project. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(LLVM_MAIN_SRC_DIR ${LLVM_SRC_DIR}) -include(LLVMConfig) -include(AddLLVM) -include(HandleLLVMOptions) - -include_directories("${LLVM_SRC_DIR}/include" - "${LLVM_BUILD_DIR}/include") - -link_directories("${LLVM_SRC_DIR}/lib" - "${LLVM_BUILD_DIR}/${CMAKE_CFG_INTDIR}/lib") - # Attempt to use system ICU first, if none specified. # Don't need ICU on Apple systems. if (APPLE) @@ -374,7 +349,7 @@ if (NOT ICU_FOUND) # FindICU uses ICU_ROOT variable as a hint # Include 'uc' twice for static libraries that depend on each other. - find_package(ICU 52 COMPONENTS uc i18n data uc) + find_global_package(ICU 52 COMPONENTS uc i18n data uc) if (ICU_FOUND) foreach(LIB_FILE ${ICU_LIBRARIES}) @@ -431,9 +406,9 @@ else() set(CORE_FOUNDATION "") endif() -if (CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT LLVM_BUILD_32_BITS) +if (CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT HERMES_BUILD_32_BITS) set(LIBFLOWPARSER ${CMAKE_CURRENT_SOURCE_DIR}/external/flowparser/libflowparser-mac.a) -elseif (CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT LLVM_BUILD_32_BITS) +elseif (CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT HERMES_BUILD_32_BITS) set(LIBFLOWPARSER ${CMAKE_CURRENT_SOURCE_DIR}/external/flowparser/libflowparser-linux.a) else() set(LIBFLOWPARSER "") @@ -453,14 +428,6 @@ set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11") set(HERMES_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(HERMES_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) -# Tell LLVM where to place the compiled binaries. -# -# NOTE: LLVM also uses this variable to find its own binaries, which can create -# problems. For now the only LLVM tool we need is llvm-lit, so our short term -# solution is to just hack that special case (the long term solution would be -# to stop using add_llvm_tool() for our own tools). -set(LLVM_RUNTIME_OUTPUT_INTDIR ${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) - if(EXISTS ${HERMES_SOURCE_DIR}/API/jsi) set(HERMES_JSI_DIR ${HERMES_SOURCE_DIR}/API/jsi) elseif(EXISTS ${FBSOURCE_DIR}/xplat/jsi) @@ -471,6 +438,12 @@ else() message(FATAL_ERROR "Unable to find jsi.") endif() +include_directories( + external/llvh/include + external/llvh/gen/include + ${CMAKE_CURRENT_BINARY_DIR}/external/llvh/include +) + include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -485,7 +458,7 @@ if(HERMES_IS_ANDROID) elseif(EXISTS ${FBSOURCE_DIR}/fbandroid/libraries/fbjni/cxx) set(FBJNI_PATH ${FBSOURCE_DIR}/fbandroid/libraries/fbjni) elseif(EXISTS ${HERMES_SOURCE_DIR}/../../fbandroid/libraries/fbjni/cxx) - set(FBJNI_PATH ${HERMES_SOURCE_DIR}/../../fbandroid/libraries/fbjni/cxx) + set(FBJNI_PATH ${HERMES_SOURCE_DIR}/../../fbandroid/libraries/fbjni) else() message(FATAL_ERROR "Unable to find fbjni.") endif() @@ -496,14 +469,25 @@ if(HERMES_IS_ANDROID) set(OPTIONAL_JNI_ONLOAD "-Wl,--undefined=JNI_OnLoad") endif() +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +add_subdirectory(external/llvh) +add_subdirectory(utils/hermes-lit) add_subdirectory(tools) add_subdirectory(include) add_subdirectory(lib) add_subdirectory(external) add_subdirectory(unittests) -add_subdirectory(${HERMES_JSI_DIR}/jsi ${CMAKE_CURRENT_BINARY_DIR}/jsi) add_subdirectory(API) +# Make sure JSI is compiled with PIC +set(save_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE}) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +add_subdirectory(${HERMES_JSI_DIR}/jsi ${CMAKE_CURRENT_BINARY_DIR}/jsi) +set(CMAKE_POSITION_INDEPENDENT_CODE ${save_CMAKE_POSITION_INDEPENDENT_CODE}) + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/facebook) add_subdirectory(facebook) endif() @@ -522,7 +506,6 @@ list(APPEND HERMES_TEST_DEPS hbc-attribute hbc-deltaprep hbc-diff - llvm-config ) set(HERMES_LIT_TEST_PARAMS @@ -532,15 +515,15 @@ set(HERMES_LIT_TEST_PARAMS use_flowparser=${HERMES_USE_FLOWPARSER} jit_enabled=${HERMESVM_JIT} jit_disassembler_enabled=${HERMESVM_JIT_DISASSEMBLER} - hbc_deltaprep=${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/hbc-deltaprep - FileCheck=${LLVM_BUILD_DIR}/${CMAKE_CFG_INTDIR}/bin/FileCheck - hermes=${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/hermes - hermesc=${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/hermesc - hdb=${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/hdb - hbcdump=${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/hbcdump - repl=${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/hermes-repl - hbc-deltaprep=${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/hbc-deltaprep - hbc_diff=${HERMES_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/hbc-diff + hbc_deltaprep=${HERMES_TOOLS_OUTPUT_DIR}/hbc-deltaprep + FileCheck=${HERMES_TOOLS_OUTPUT_DIR}//FileCheck + hermes=${HERMES_TOOLS_OUTPUT_DIR}/hermes + hermesc=${HERMES_TOOLS_OUTPUT_DIR}/hermesc + hdb=${HERMES_TOOLS_OUTPUT_DIR}/hdb + hbcdump=${HERMES_TOOLS_OUTPUT_DIR}/hbcdump + repl=${HERMES_TOOLS_OUTPUT_DIR}/hermes-repl + hbc-deltaprep=${HERMES_TOOLS_OUTPUT_DIR}/hbc-deltaprep + hbc_diff=${HERMES_TOOLS_OUTPUT_DIR}/hbc-diff build_mode=${HERMES_ASSUMED_BUILD_MODE_IN_LIT_TEST} exception_on_oom_enabled=${HERMESVM_EXCEPTION_ON_OOM} serialize_enabled=${HERMESVM_SERIALIZE} @@ -551,11 +534,7 @@ set(HERMES_LIT_TEST_PARAMS ubsan=OFF ) -set(LLVM_LIT_ARGS "-sv") - -# This is a hack to help LLVM find its own llvm-lit tool, since we had to set -# LLVM_RUNTIME_OUTPUT_INTDIR to our own build dir. -set(LLVM_LIT_OUTPUT_DIR ${LLVM_BUILD_DIR}/${CMAKE_CFG_INTDIR}/bin) +set(LLVH_LIT_ARGS "-sv") add_lit_testsuite(check-hermes "Running the Hermes regression tests" ${HERMES_SOURCE_DIR}/test diff --git a/android/cross-compile/CrossCompile.md b/android/cross-compile/CrossCompile.md index 5749c003ea4..10b3b394121 100644 --- a/android/cross-compile/CrossCompile.md +++ b/android/cross-compile/CrossCompile.md @@ -3,19 +3,6 @@ These are informal instructions for cross-compiling a "standalone" build of Hermes (one that doesn't use Java). -## Cross-compile LLVM - -1. Compile LLVM for host. -2. Patch LLVM with the supplied patch `llvm.patch`. -3. Edit the paths in `config-llvm.sh`. -3. Cross-compile LLVM for android: -``` -mkdir llvm_arm && cd llvm_arm -# Change this to config-llvm-clang.sh to use Clang instead of GCC -$path_to_this_directory/config-llvm.sh -ninja -``` - ## Cross-compile ICU 1. Make sure that: diff --git a/android/cross-compile/config-hermes.sh b/android/cross-compile/config-hermes.sh index 666c7713e3f..058dd04f8ae 100755 --- a/android/cross-compile/config-hermes.sh +++ b/android/cross-compile/config-hermes.sh @@ -5,8 +5,7 @@ # LICENSE file in the root directory of this source tree. cmake ~/fbsource/xplat/hermes \ - -DHERMES_FACEBOOK_BUILD=OFF -DLLVM_ENABLE_LTO=OFF \ - -DLLVM_BUILD_DIR=$PWD/../llvm_arm_clang -DLLVM_SRC_DIR=$PWD/../llvm \ + -DHERMES_FACEBOOK_BUILD=OFF \ -DCMAKE_BUILD_TYPE=MinSizeRel \ - -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-android-clang-arm-api13-gnustl.cmake \ - -DICU_ROOT=/Users/tmikov/3rd/swift-libiconv-libicu-android.git/armeabi-v7a -G Ninja + -DCMAKE_TOOLCHAIN_FILE=/opt/android_ndk/android-ndk-r15c/build/cmake/android.toolchain.cmake \ + -DICU_ROOT=/Users/tmikov/3rd/swift-libiconv-libicu-android.git/armeabi-v7a -G Ninja $* diff --git a/android/cross-compile/config-llvm-clang.sh b/android/cross-compile/config-llvm-clang.sh deleted file mode 100755 index 669a622c1e1..00000000000 --- a/android/cross-compile/config-llvm-clang.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-android-clang-arm-api13-gnustl.cmake \ - -DLLVM_TARGETS_TO_BUILD= -DCMAKE_BUILD_TYPE=MinSizeRel \ - -DLLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO=Off \ - -DLLVM_TABLEGEN=/Users/tmikov/work/hws/llvm_build/bin/llvm-tblgen \ - -DCLANG_TABLEGEN=/Users/tmikov/work/hws/llvm_build/bin/clang-tblgen \ - -GNinja ../llvm diff --git a/android/cross-compile/config-llvm.sh b/android/cross-compile/config-llvm.sh deleted file mode 100755 index 3fe5bbb5c1e..00000000000 --- a/android/cross-compile/config-llvm.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-android-arm-api13-gnustl.cmake \ - -DLLVM_TARGETS_TO_BUILD= -DCMAKE_BUILD_TYPE=MinSizeRel \ - -DLLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO=Off \ - -DLLVM_TABLEGEN=/Users/tmikov/work/hws/llvm_build/bin/llvm-tblgen \ - -DCLANG_TABLEGEN=/Users/tmikov/work/hws/llvm_build/bin/clang-tblgen \ - -GNinja ../llvm diff --git a/android/cross-compile/llvm.patch b/android/cross-compile/llvm.patch deleted file mode 100644 index 90f50b2e8e0..00000000000 --- a/android/cross-compile/llvm.patch +++ /dev/null @@ -1,62 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 3e40d7e087a..9719f8c8fc8 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -803,7 +803,7 @@ include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}) - - # when crosscompiling import the executable targets from a file - if(LLVM_USE_HOST_TOOLS) -- include(CrossCompile) -+ # include(CrossCompile) - endif(LLVM_USE_HOST_TOOLS) - if(LLVM_TARGET_IS_CROSSCOMPILE_HOST) - # Dummy use to avoid CMake Warning: Manually-specified variables were not used -diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake -index 86ce0bbcfd0..5355b06f697 100644 ---- a/cmake/modules/HandleLLVMOptions.cmake -+++ b/cmake/modules/HandleLLVMOptions.cmake -@@ -243,7 +243,7 @@ if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) - - # FIXME: CMAKE_SIZEOF_VOID_P is still 8 - add_definitions(-D_LARGEFILE_SOURCE) -- add_definitions(-D_FILE_OFFSET_BITS=64) -+ # add_definitions(-D_FILE_OFFSET_BITS=64) - endif( LLVM_BUILD_32_BITS ) - endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) - -diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt -index f59402ac4b0..8b20cec52f3 100644 ---- a/tools/llvm-config/CMakeLists.txt -+++ b/tools/llvm-config/CMakeLists.txt -@@ -65,17 +65,17 @@ endif() - # Add the dependency on the generation step. - add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH}) - --if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH) -- set(LLVM_CONFIG_PATH "${LLVM_NATIVE_BUILD}/bin/llvm-config" CACHE STRING "") -- -- add_custom_command(OUTPUT "${LLVM_CONFIG_PATH}" -- COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $ -- DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt -- WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} -- COMMENT "Building native llvm-config..." -- USES_TERMINAL) -- add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH}) -- add_dependencies(NativeLLVMConfig CONFIGURE_LLVM_NATIVE) -- -- add_dependencies(llvm-config NativeLLVMConfig) --endif() -+# if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH) -+# set(LLVM_CONFIG_PATH "${LLVM_NATIVE_BUILD}/bin/llvm-config" CACHE STRING "") -+# -+# add_custom_command(OUTPUT "${LLVM_CONFIG_PATH}" -+# COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $ -+# DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt -+# WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} -+# COMMENT "Building native llvm-config..." -+# USES_TERMINAL) -+# add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH}) -+# add_dependencies(NativeLLVMConfig CONFIGURE_LLVM_NATIVE) -+# -+# add_dependencies(llvm-config NativeLLVMConfig) -+# endif() diff --git a/android/cross-compile/toolchain-android-clang-arm-api13-gnustl.cmake b/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake similarity index 81% rename from android/cross-compile/toolchain-android-clang-arm-api13-gnustl.cmake rename to android/cross-compile/toolchain-android-arm-api15-gnustl.cmake index a05b62f602d..f49173b4aca 100644 --- a/android/cross-compile/toolchain-android-clang-arm-api13-gnustl.cmake +++ b/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake @@ -4,10 +4,10 @@ # LICENSE file in the root directory of this source tree. SET(CMAKE_SYSTEM_NAME Android) -SET(CMAKE_SYSTEM_VERSION 13) +SET(CMAKE_SYSTEM_VERSION 15) SET(CMAKE_ANDROID_ARCH_ABI armeabi-v7a) -SET(CMAKE_ANDROID_NDK /opt/android_ndk/android-ndk-r13b) +SET(CMAKE_ANDROID_NDK /opt/android_ndk/android-ndk-r15c) SET(CMAKE_ANDROID_STL_TYPE gnustl_shared) SET(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang) diff --git a/cmake/modules/Hermes.cmake b/cmake/modules/Hermes.cmake new file mode 100644 index 00000000000..ec66eb17e03 --- /dev/null +++ b/cmake/modules/Hermes.cmake @@ -0,0 +1,398 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +include(CheckCXXCompilerFlag) +include(CheckCCompilerFlag) +include(CheckCXXSourceCompiles) +include(CMakePrintHelpers) + +set(HERMES_TOOLS_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}") + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(GCC 1) + set(GCC_COMPATIBLE 1) +elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CLANG 1) + set(GCC_COMPATIBLE 1) + if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") + set(CLANG_CL 1) + endif () +endif () + +# For compatibility, CMake adds /EHsc by default for MSVC. We want to set that +# flag per target, so remove it. +if (MSVC) + string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +endif (MSVC) + +# set stack reserved size to ~10MB +if (MSVC) + # CMake previously automatically set this value for MSVC builds, but the + # behavior was changed in CMake 2.8.11 (Issue 12437) to use the MSVC default + # value (1 MB) which is not enough for some of our stack overflow tests. + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10000000") +elseif (MINGW) # FIXME: Also cygwin? + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,16777216") +endif () + +if (WIN32) + set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) + if (CYGWIN) + set(LLVM_ON_WIN32 0) + set(LLVM_ON_UNIX 1) + else (CYGWIN) + set(LLVM_ON_WIN32 1) + set(LLVM_ON_UNIX 0) + endif (CYGWIN) +else (WIN32) + if (FUCHSIA OR UNIX) + set(LLVM_ON_WIN32 0) + set(LLVM_ON_UNIX 1) + if (APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) + else () + set(LLVM_HAVE_LINK_VERSION_SCRIPT 1) + endif () + else (FUCHSIA OR UNIX) + MESSAGE(SEND_ERROR "Unable to determine platform") + endif (FUCHSIA OR UNIX) +endif (WIN32) + +function(hermes_update_compile_flags name) + get_property(sources TARGET ${name} PROPERTY SOURCES) + if ("${sources}" MATCHES "\\.c(;|$)") + set(update_src_props ON) + endif () + + set(flags "") + + if (HERMES_ENABLE_EH) + if (GCC_COMPATIBLE) + set(flags "${flags} -fexceptions") + elseif (MSVC) + set(flags "${flags} /EHsc") + endif () + else () + if (GCC_COMPATIBLE) + set(flags "${flags} -fno-exceptions") + elseif (MSVC) + set(flags "${flags} /EHs-c-") + endif () + endif () + + if (HERMES_ENABLE_RTTI) + if (GCC_COMPATIBLE) + set(flags "${flags} -frtti") + elseif (MSVC) + set(flags "${flags} /GR") + endif () + else () + if (GCC_COMPATIBLE) + set(flags "${flags} -fno-rtti") + elseif (MSVC) + set(flags "${flags} /GR-") + endif () + endif () + + if (update_src_props) + foreach (fn ${sources}) + get_filename_component(suf ${fn} EXT) + if ("${suf}" STREQUAL ".cpp") + set_property(SOURCE ${fn} APPEND_STRING PROPERTY + COMPILE_FLAGS "${flags}") + endif () + endforeach () + else () + # Update target props, since all sources are C++. + set_property(TARGET ${name} APPEND_STRING PROPERTY + COMPILE_FLAGS "${flags}") + endif () +endfunction() + +function(add_hermes_library name) + cmake_parse_arguments(ARG "" "" "LINK_LIBS" ${ARGN}) + add_library(${name} STATIC ${ARG_UNPARSED_ARGUMENTS}) + target_link_libraries(${name} ${ARG_LINK_LIBS} ${HERMES_LINK_COMPONENTS}) + set_property(TARGET ${name} PROPERTY POSITION_INDEPENDENT_CODE ON) + hermes_update_compile_flags(${name}) +endfunction(add_hermes_library) + +function(add_hermes_executable name) + cmake_parse_arguments(ARG "" "" "LINK_LIBS" ${ARGN}) + add_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) + target_link_libraries(${name} ${ARG_LINK_LIBS} ${HERMES_LINK_COMPONENTS}) + hermes_update_compile_flags(${name}) +endfunction(add_hermes_executable) + +function(add_hermes_tool name) + add_hermes_executable(${name} ${ARGN}) + + # In multi-config build systems, remove the per-config directory and let + # CMake automatically add it in the component. + if (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") + string(REPLACE ${CMAKE_CFG_INTDIR} "" HERMES_TOOLS_OUTPUT_DIR "${HERMES_TOOLS_OUTPUT_DIR}") + endif () + + set_property(TARGET ${name} PROPERTY RUNTIME_OUTPUT_DIRECTORY + "${HERMES_TOOLS_OUTPUT_DIR}") +endfunction(add_hermes_tool) + +# find_package()is not able to find packages specified with _DIR if +# CMAKE_SYSROOT or CMAKE_FIND_ROOT_PATH is set, because find_file() is being +# restricted in where it looks. +# This wrapper adds _DIR to CMAKE_FIND_ROOT_PATH so find_package() can +# find it. +macro(find_global_package name) + # If we have a CMAKE_SYSROOT or CMAKE_FIND_ROOT_PATH and _ROOT is set, + # temporarily add _ROOT to the search path + if (((NOT "${CMAKE_SYSROOT}" STREQUAL "") OR + (NOT "${CMAKE_FIND_ROOT_PATH}" STREQUAL "")) AND + (NOT "${${name}_ROOT}" STREQUAL "")) + + list(APPEND CMAKE_FIND_ROOT_PATH "${${name}_ROOT}") + find_package(${name} ${ARGN}) + list(REMOVE_AT CMAKE_FIND_ROOT_PATH -1) + + else () + + find_package(${name} ${ARGN}) + + endif () +endmacro(find_global_package) + +function(append value) + foreach (variable ${ARGN}) + set(${variable} "${${variable}} ${value}" PARENT_SCOPE) + endforeach (variable) +endfunction() + +function(append_if condition value) + if (${condition}) + foreach (variable ${ARGN}) + set(${variable} "${${variable}} ${value}" PARENT_SCOPE) + endforeach (variable) + endif () +endfunction() + +macro(add_flag_if_supported flag name) + check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}") + append_if("C_SUPPORTS_${name}" "${flag}" CMAKE_C_FLAGS) + check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}") + append_if("CXX_SUPPORTS_${name}" "${flag}" CMAKE_CXX_FLAGS) +endmacro() + +function(add_flag_or_print_warning flag name) + check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}") + check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}") + if (C_SUPPORTS_${name} AND CXX_SUPPORTS_${name}) + message(STATUS "Building with ${flag}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE) + set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${flag}" PARENT_SCOPE) + else () + message(WARNING "${flag} is not supported.") + endif () +endfunction() + + +# +# Enable warnings +# +if (XCODE) + # For Xcode enable several build settings that correspond to + # many warnings that are on by default in Clang but are + # not enabled for historical reasons. For versions of Xcode + # that do not support these options they will simply + # be ignored. + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES") + set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES") +endif () + +if (MSVC) + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0) + # For MSVC 2013, disable iterator null pointer checking in debug mode, + # especially so std::equal(nullptr, nullptr, nullptr) will not assert. + add_definitions("-D_DEBUG_POINTER_IMPL=") + endif () + + if (MSVC11) + add_definitions(-D_VARIADIC_MAX=10) + endif () + + # Add definitions that make MSVC much less annoying. + add_definitions( + # For some reason MS wants to deprecate a bunch of standard functions... + -D_CRT_SECURE_NO_DEPRECATE + -D_CRT_SECURE_NO_WARNINGS + -D_CRT_NONSTDC_NO_DEPRECATE + -D_CRT_NONSTDC_NO_WARNINGS + -D_SCL_SECURE_NO_DEPRECATE + -D_SCL_SECURE_NO_WARNINGS + ) + + # Tell MSVC to use the Unicode version of the Win32 APIs instead of ANSI. + # add_definitions( + # -DUNICODE + # -D_UNICODE + # ) + + # Turn warnings into errors. + # append("/WX" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + + # Remove unreferenced data or functions that are COMDATs, or that only have + # internal linkage. + append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + + # "Generate Intrinsic Functions". + append("/Oi" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + + # "Enforce type conversion rules". + append("/Zc:rvalueCast" CMAKE_CXX_FLAGS) + + if (NOT CLANG_CL) + set(msvc_warning_flags + # Disabled warnings. + -wd4141 # Suppress ''modifier' : used more than once' (because of __forceinline combined with inline) + -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned' + -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored' + -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data' + -wd4258 # Suppress ''var' : definition from the for loop is ignored; the definition from the enclosing scope is used' + -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data' + -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception' + -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized' + -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized' + -wd4355 # Suppress ''this' : used in base member initializer list' + -wd4456 # Suppress 'declaration of 'var' hides local variable' + -wd4457 # Suppress 'declaration of 'var' hides function parameter' + -wd4458 # Suppress 'declaration of 'var' hides class member' + -wd4459 # Suppress 'declaration of 'var' hides global declaration' + -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated' + -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible' + -wd4722 # Suppress 'function' : destructor never returns, potential memory leak + -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)' + -wd4100 # Suppress 'unreferenced formal parameter' + -wd4127 # Suppress 'conditional expression is constant' + -wd4512 # Suppress 'assignment operator could not be generated' + -wd4505 # Suppress 'unreferenced local function has been removed' + -wd4610 # Suppress ' can never be instantiated' + -wd4510 # Suppress 'default constructor could not be generated' + -wd4702 # Suppress 'unreachable code' + -wd4245 # Suppress 'signed/unsigned mismatch' + -wd4706 # Suppress 'assignment within conditional expression' + -wd4310 # Suppress 'cast truncates constant value' + -wd4701 # Suppress 'potentially uninitialized local variable' + -wd4703 # Suppress 'potentially uninitialized local pointer variable' + -wd4389 # Suppress 'signed/unsigned mismatch' + -wd4611 # Suppress 'interaction between '_setjmp' and C++ object destruction is non-portable' + -wd4805 # Suppress 'unsafe mix of type and type in operation' + -wd4204 # Suppress 'nonstandard extension used : non-constant aggregate initializer' + -wd4577 # Suppress 'noexcept used with no exception handling mode specified; termination on exception is not guaranteed' + -wd4091 # Suppress 'typedef: ignored on left of '' when no variable is declared' + # C4592 is disabled because of false positives in Visual Studio 2015 + # Update 1. Re-evaluate the usefulness of this diagnostic with Update 2. + -wd4592 # Suppress ''var': symbol will be dynamically initialized (implementation limitation) + -wd4319 # Suppress ''operator' : zero extending 'type' to 'type' of greater size' + + # Ideally, we'd like this warning to be enabled, but MSVC 2013 doesn't + # support the 'aligned' attribute in the way that clang sources requires (for + # any code that uses the LLVM_ALIGNAS macro), so this is must be disabled to + # avoid unwanted alignment warnings. + # When we switch to requiring a version of MSVC that supports the 'alignas' + # specifier (MSVC 2015?) this warning can be re-enabled. + -wd4324 # Suppress 'structure was padded due to __declspec(align())' + + # Promoted warnings. + -w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning. + + # Promoted warnings to errors. + -we4238 # Promote 'nonstandard extension used : class rvalue used as lvalue' to error. + ) + endif (NOT CLANG_CL) + foreach (flag ${msvc_warning_flags}) + append("${flag}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + endforeach (flag) +endif (MSVC) + +if (GCC_COMPATIBLE) + # Don't add -Wall for clang-cl, because it maps -Wall to -Weverything for + # MSVC compatibility. /W4 is added above instead. + if (NOT CLANG_CL) + append("-Wall" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + endif () + + append("-Wextra -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + append("-Wcast-qual" CMAKE_CXX_FLAGS) + + # Turn off missing field initializer warnings for gcc to avoid noise from + # false positives with empty {}. Turn them on otherwise (they're off by + # default for clang). + check_cxx_compiler_flag("-Wmissing-field-initializers" CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG) + if (CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG) + if (CMAKE_COMPILER_IS_GNUCXX) + append("-Wno-missing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + else () + append("-Wmissing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + endif () + endif () + + # Disable gcc's potentially uninitialized use analysis as it presents lots of + # false positives. + if (CMAKE_COMPILER_IS_GNUCXX) + check_cxx_compiler_flag("-Wmaybe-uninitialized" MAYBE_UNINITIALIZED_FLAG) + append_if(MAYBE_UNINITIALIZED_FLAG "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS) + if (NOT MAYBE_UNINITIALIZED_FLAG) + # Only recent versions of gcc make the distinction between -Wuninitialized + # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just + # turn off all uninitialized use warnings. + check_cxx_compiler_flag("-Wuninitialized" UNINITIALIZED_FLAG) + append_if(UNINITIALIZED_FLAG "-Wno-uninitialized" CMAKE_CXX_FLAGS) + endif () + endif () + + # Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires on + # LLVM's ADT classes. + check_cxx_compiler_flag("-Wclass-memaccess" CXX_SUPPORTS_CLASS_MEMACCESS_FLAG) + append_if(CXX_SUPPORTS_CLASS_MEMACCESS_FLAG "-Wno-class-memaccess" CMAKE_CXX_FLAGS) + + # The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not useful. + check_cxx_compiler_flag("-Wnoexcept-type" CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG) + append_if(CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG "-Wno-noexcept-type" CMAKE_CXX_FLAGS) + + # Check if -Wnon-virtual-dtor warns even though the class is marked final. + # If it does, don't add it. So it won't be added on clang 3.4 and older. + # This also catches cases when -Wnon-virtual-dtor isn't supported by + # the compiler at all. This flag is not activated for gcc since it will + # incorrectly identify a protected non-virtual base when there is a friend + # declaration. Don't activate this in general on Windows as this warning has + # too many false positives on COM-style classes, which are destroyed with + # Release() (PR32286). + if (NOT CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11 -Werror=non-virtual-dtor") + CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();protected: ~base();}; + class derived final : public base { public: ~derived();}; + int main() { return 0; }" + CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + append_if(CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR + "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS) + endif () + + # Enable -Wdelete-non-virtual-dtor if available. + add_flag_if_supported("-Wdelete-non-virtual-dtor" DELETE_NON_VIRTUAL_DTOR_FLAG) +endif (GCC_COMPATIBLE) diff --git a/cmake/modules/Lit.cmake b/cmake/modules/Lit.cmake new file mode 100644 index 00000000000..9e11c54b243 --- /dev/null +++ b/cmake/modules/Lit.cmake @@ -0,0 +1,99 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +set(HERMES_LIT_PATH "${HERMES_TOOLS_OUTPUT_DIR}/hermes-lit") +if (CMAKE_HOST_WIN32 AND NOT CYGWIN) + # llvm-lit needs suffix.py for multiprocess to find a main module. + set(HERMES_LIT_PATH "${HERMES_LIT_PATH}.py") +endif () + + +# A raw function to create a lit target. This is used to implement the testuite +# management functions. +function(add_lit_target target comment) + cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) + set(LIT_ARGS "${ARG_ARGS} ${LLVH_LIT_ARGS}") + separate_arguments(LIT_ARGS) + if (NOT CMAKE_CFG_INTDIR STREQUAL ".") + list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR}) + endif () + + set(LIT_COMMAND "${PYTHON_EXECUTABLE};${HERMES_LIT_PATH}") + list(APPEND LIT_COMMAND ${LIT_ARGS}) + foreach(param ${ARG_PARAMS}) + list(APPEND LIT_COMMAND --param ${param}) + endforeach() + if (ARG_UNPARSED_ARGUMENTS) + add_custom_target(${target} + COMMAND ${LIT_COMMAND} ${ARG_UNPARSED_ARGUMENTS} + COMMENT "${comment}" + USES_TERMINAL + ) + else() + add_custom_target(${target} + COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.") + message(STATUS "${target} does nothing.") + endif() + + # Add lit test dependencies. + set(llvm_utils_deps + FileCheck count not + ) + foreach(dep ${llvm_utils_deps}) + if (TARGET ${dep}) + add_dependencies(${target} ${dep}) + endif() + endforeach() + + if (ARG_DEPENDS) + add_dependencies(${target} ${ARG_DEPENDS}) + endif() + + # Tests should be excluded from "Build Solution". + set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON) +endfunction() + +# A function to add a set of lit test suites to be driven through 'check-*' targets. +function(add_lit_testsuite target comment) + cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) + + # Produce a specific suffixed check rule. + add_lit_target(${target} ${comment} + ${ARG_UNPARSED_ARGUMENTS} + PARAMS ${ARG_PARAMS} + DEPENDS ${ARG_DEPENDS} + ARGS ${ARG_ARGS} + ) +endfunction() + +function(add_unittest test_suite test_name) + # Our current version of gtest does not properly recognize C++11 support + # with MSVC, so it falls back to tr1 / experimental classes. Since LLVM + # itself requires C++11, we can safely force it on unconditionally so that + # we don't have to fight with the buggy gtest check. + add_definitions(-DGTEST_LANG_CXX11=1) + add_definitions(-DGTEST_HAS_TR1_TUPLE=0) + + include_directories(${LLVH_SOURCE_DIR}/utils/unittest/googletest/include) + include_directories(${LLVH_SOURCE_DIR}/utils/unittest/googlemock/include) + +# if (SUPPORTS_VARIADIC_MACROS_FLAG) +# list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros") +# endif () +# # Some parts of gtest rely on this GNU extension, don't warn on it. +# if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG) +# list(APPEND LLVM_COMPILE_FLAGS "-Wno-gnu-zero-variadic-macro-arguments") +# endif() + + add_hermes_executable(${test_name} ${ARGN}) + + target_link_libraries(${test_name} PRIVATE gtest_main gtest) + + add_dependencies(${test_suite} ${test_name}) + get_target_property(test_suite_folder ${test_suite} FOLDER) + if (NOT ${test_suite_folder} STREQUAL "NOTFOUND") + set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}") + endif () +endfunction() diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index f48620e60e8..d74d3610656 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,2 +1,4 @@ add_subdirectory(dtoa) add_subdirectory(zip) +# Do not include llvh - it will be included directly. +# add_subdirectory(llvh) diff --git a/external/dtoa/CMakeLists.txt b/external/dtoa/CMakeLists.txt index e3a4a6ad231..f41ad56fb12 100644 --- a/external/dtoa/CMakeLists.txt +++ b/external/dtoa/CMakeLists.txt @@ -10,7 +10,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_C_FLAGS} -Wno-parentheses -Wno-unused-label -Wno-sign-compare -Wno-implicit-fallthrough") endif() -add_llvm_library(dtoa STATIC +add_hermes_library(dtoa STATIC dtoa.c g_fmt.c locks.cpp) diff --git a/external/llvh/CMakeLists.txt b/external/llvh/CMakeLists.txt new file mode 100644 index 00000000000..1ed5ede1392 --- /dev/null +++ b/external/llvh/CMakeLists.txt @@ -0,0 +1,30 @@ +set(HERMES_LLVM True) +add_definitions(-DHERMES_LLVM) + +set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(LLVM_MAIN_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR}) +set(LLVM_BINARY_DIR ${LLVM_MAIN_BIN_DIR}) + +set(PACKAGE_NAME "LLVM") +set(PACKAGE_STRING "LLVM 8.0.0svn") +set(PACKAGE_VERSION "8.0.0svn") + +set(LLVM_ENABLE_THREADS 1) +if (LLVH_REVERSE_ITERATION) + set(LLVM_ENABLE_REVERSE_ITERATION 1) +endif () + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") +include(config-ix) + +configure_file(include/llvm/Config/config.h.cmake include/llvm/Config/config.h) +configure_file(include/llvm/Config/llvm-config.h.cmake include/llvm/Config/llvm-config.h) + +add_subdirectory(lib) +add_subdirectory(utils/FileCheck) +add_subdirectory(utils/not) +add_subdirectory(utils/count) +add_subdirectory(utils/unittest) diff --git a/external/llvh/cmake/config-ix.cmake b/external/llvh/cmake/config-ix.cmake new file mode 100644 index 00000000000..11d3540e002 --- /dev/null +++ b/external/llvh/cmake/config-ix.cmake @@ -0,0 +1,625 @@ +if( WIN32 AND NOT CYGWIN ) + # We consider Cygwin as another Unix + set(PURE_WINDOWS 1) +endif() + +include(CheckIncludeFile) +include(CheckLibraryExists) +include(CheckSymbolExists) +include(CheckFunctionExists) +include(CheckCCompilerFlag) + +include(CheckCompilerVersion) +include(HandleLLVMStdlib) + +if( UNIX AND NOT (BEOS OR HAIKU) ) + # Used by check_symbol_exists: + list(APPEND CMAKE_REQUIRED_LIBRARIES "m") +endif() +# x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly. +if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND + CMAKE_SIZEOF_VOID_P EQUAL 8 ) + list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt") +endif() + +# include checks +check_include_file(dlfcn.h HAVE_DLFCN_H) +check_include_file(errno.h HAVE_ERRNO_H) +check_include_file(fcntl.h HAVE_FCNTL_H) +check_include_file(link.h HAVE_LINK_H) +check_include_file(malloc.h HAVE_MALLOC_H) +check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H) +if( NOT PURE_WINDOWS ) + check_include_file(pthread.h HAVE_PTHREAD_H) +endif() +check_include_file(signal.h HAVE_SIGNAL_H) +check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H) +check_include_file(sys/mman.h HAVE_SYS_MMAN_H) +check_include_file(sys/param.h HAVE_SYS_PARAM_H) +check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(sys/time.h HAVE_SYS_TIME_H) +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(termios.h HAVE_TERMIOS_H) +check_include_file(unistd.h HAVE_UNISTD_H) +check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H) +check_include_file(zlib.h HAVE_ZLIB_H) +check_include_file(fenv.h HAVE_FENV_H) +check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT) +check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT) + +check_include_file(mach/mach.h HAVE_MACH_MACH_H) +check_include_file(histedit.h HAVE_HISTEDIT_H) +check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H) +if(APPLE) + include(CheckCSourceCompiles) + CHECK_C_SOURCE_COMPILES(" + static const char *__crashreporter_info__ = 0; + asm(\".desc ___crashreporter_info__, 0x10\"); + int main() { return 0; }" + HAVE_CRASHREPORTER_INFO) +endif() + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H) + if(NOT HAVE_LINUX_MAGIC_H) + # older kernels use split files + check_include_file(linux/nfs_fs.h HAVE_LINUX_NFS_FS_H) + check_include_file(linux/smb.h HAVE_LINUX_SMB_H) + endif() +endif() + +# library checks +if( NOT PURE_WINDOWS ) + check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD) + if (HAVE_LIBPTHREAD) + check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC) + check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) + check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK) + else() + # this could be Android + check_library_exists(c pthread_create "" PTHREAD_IN_LIBC) + if (PTHREAD_IN_LIBC) + check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC) + check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) + check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK) + endif() + endif() + check_library_exists(dl dlopen "" HAVE_LIBDL) + check_library_exists(rt clock_gettime "" HAVE_LIBRT) +endif() + +# Check for libpfm. +include(FindLibpfm) + +if(HAVE_LIBPTHREAD) + # We want to find pthreads library and at the moment we do want to + # have it reported as '-l' instead of '-pthread'. + # TODO: switch to -pthread once the rest of the build system can deal with it. + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + set(THREADS_HAVE_PTHREAD_ARG Off) + find_package(Threads REQUIRED) + set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) +endif() + +# Don't look for these libraries if we're using MSan, since uninstrumented third +# party code may call MSan interceptors like strlen, leading to false positives. +if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") + set(HAVE_LIBZ 0) + if(LLVM_ENABLE_ZLIB) + foreach(library z zlib_static zlib) + string(TOUPPER ${library} library_suffix) + check_library_exists(${library} compress2 "" HAVE_LIBZ_${library_suffix}) + if(HAVE_LIBZ_${library_suffix}) + set(HAVE_LIBZ 1) + set(ZLIB_LIBRARIES "${library}") + break() + endif() + endforeach() + endif() + + # Don't look for these libraries on Windows. + if (NOT PURE_WINDOWS) + # Skip libedit if using ASan as it contains memory leaks. + if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*") + check_library_exists(edit el_init "" HAVE_LIBEDIT) + else() + set(HAVE_LIBEDIT 0) + endif() + if(LLVM_ENABLE_TERMINFO) + set(HAVE_TERMINFO 0) + foreach(library tinfo terminfo curses ncurses ncursesw) + string(TOUPPER ${library} library_suffix) + check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix}) + if(HAVE_TERMINFO_${library_suffix}) + set(HAVE_TERMINFO 1) + set(TERMINFO_LIBS "${library}") + break() + endif() + endforeach() + else() + set(HAVE_TERMINFO 0) + endif() + + find_library(ICONV_LIBRARY_PATH NAMES iconv libiconv libiconv-2 c) + set(LLVM_LIBXML2_ENABLED 0) + set(LIBXML2_FOUND 0) + if((LLVM_ENABLE_LIBXML2) AND ((CMAKE_SYSTEM_NAME MATCHES "Linux") AND (ICONV_LIBRARY_PATH) OR APPLE)) + find_package(LibXml2) + if (LIBXML2_FOUND) + set(LLVM_LIBXML2_ENABLED 1) + if ((CMAKE_OSX_SYSROOT) AND (EXISTS ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})) + include_directories(${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}) + else() + include_directories(${LIBXML2_INCLUDE_DIR}) + endif() + set(LIBXML2_LIBS "xml2") + endif() + endif() + endif() +endif() + +if (LLVM_ENABLE_LIBXML2 STREQUAL "FORCE_ON" AND NOT LLVM_LIBXML2_ENABLED) + message(FATAL_ERROR "Failed to congifure libxml2") +endif() + +check_library_exists(xar xar_open "" HAVE_LIBXAR) +if(HAVE_LIBXAR) + set(XAR_LIB xar) +endif() + +# function checks +check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM) +find_package(Backtrace) +set(HAVE_BACKTRACE ${Backtrace_FOUND}) +set(BACKTRACE_HEADER ${Backtrace_HEADER}) + +# Prevent check_symbol_exists from using API that is not supported for a given +# deployment target. +check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW") +if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new") +endif() + +check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE) +check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) +check_symbol_exists(sysconf unistd.h HAVE_SYSCONF) +check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE) +check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT) +check_symbol_exists(isatty unistd.h HAVE_ISATTY) +check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS) +check_symbol_exists(futimes sys/time.h HAVE_FUTIMES) +check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE) +# AddressSanitizer conflicts with lib/Support/Unix/Signals.inc +# Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it +# (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind +# past the signal handler after an assertion failure (rdar://29866587). +if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE ) + check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK) +endif() +set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE") +check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64) +set(CMAKE_REQUIRED_DEFINITIONS "") +check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL) +check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) +check_symbol_exists(malloc_zone_statistics malloc/malloc.h + HAVE_MALLOC_ZONE_STATISTICS) +check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT) +check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN) +check_symbol_exists(pread unistd.h HAVE_PREAD) +check_symbol_exists(realpath stdlib.h HAVE_REALPATH) +check_symbol_exists(sbrk unistd.h HAVE_SBRK) +check_symbol_exists(strerror string.h HAVE_STRERROR) +check_symbol_exists(strerror_r string.h HAVE_STRERROR_R) +check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S) +check_symbol_exists(setenv stdlib.h HAVE_SETENV) +if( PURE_WINDOWS ) + check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S) + + check_function_exists(_alloca HAVE__ALLOCA) + check_function_exists(__alloca HAVE___ALLOCA) + check_function_exists(__chkstk HAVE___CHKSTK) + check_function_exists(__chkstk_ms HAVE___CHKSTK_MS) + check_function_exists(___chkstk HAVE____CHKSTK) + check_function_exists(___chkstk_ms HAVE____CHKSTK_MS) + + check_function_exists(__ashldi3 HAVE___ASHLDI3) + check_function_exists(__ashrdi3 HAVE___ASHRDI3) + check_function_exists(__divdi3 HAVE___DIVDI3) + check_function_exists(__fixdfdi HAVE___FIXDFDI) + check_function_exists(__fixsfdi HAVE___FIXSFDI) + check_function_exists(__floatdidf HAVE___FLOATDIDF) + check_function_exists(__lshrdi3 HAVE___LSHRDI3) + check_function_exists(__moddi3 HAVE___MODDI3) + check_function_exists(__udivdi3 HAVE___UDIVDI3) + check_function_exists(__umoddi3 HAVE___UMODDI3) + + check_function_exists(__main HAVE___MAIN) + check_function_exists(__cmpdi2 HAVE___CMPDI2) +endif() +if( HAVE_DLFCN_H ) + if( HAVE_LIBDL ) + list(APPEND CMAKE_REQUIRED_LIBRARIES dl) + endif() + check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN) + check_symbol_exists(dladdr dlfcn.h HAVE_DLADDR) + if( HAVE_LIBDL ) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl) + endif() +endif() + +check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC) +if( LLVM_USING_GLIBC ) + add_definitions( -D_GNU_SOURCE ) + list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") +endif() +# This check requires _GNU_SOURCE +check_symbol_exists(sched_getaffinity sched.h HAVE_SCHED_GETAFFINITY) +check_symbol_exists(CPU_COUNT sched.h HAVE_CPU_COUNT) +if (NOT PURE_WINDOWS) + if (LLVM_PTHREAD_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB}) + endif() + check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP) + check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP) + if (LLVM_PTHREAD_LIB) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB}) + endif() +endif() + +# available programs checks +function(llvm_find_program name) + string(TOUPPER ${name} NAME) + string(REGEX REPLACE "\\." "_" NAME ${NAME}) + + find_program(LLVM_PATH_${NAME} NAMES ${ARGV}) + mark_as_advanced(LLVM_PATH_${NAME}) + if(LLVM_PATH_${NAME}) + set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?") + mark_as_advanced(HAVE_${NAME}) + else(LLVM_PATH_${NAME}) + set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?") + endif(LLVM_PATH_${NAME}) +endfunction() + +if (LLVM_ENABLE_DOXYGEN) + llvm_find_program(dot) +endif () + +if( LLVM_ENABLE_FFI ) + find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR}) + if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" ) + set(FFI_HEADER ffi.h CACHE INTERNAL "") + set(HAVE_FFI_H 1 CACHE INTERNAL "") + else() + find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR}) + if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" ) + set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "") + set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "") + endif() + endif() + + if( NOT FFI_HEADER ) + message(FATAL_ERROR "libffi includes are not found.") + endif() + + find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR}) + if( NOT FFI_LIBRARY_PATH ) + message(FATAL_ERROR "libffi is not found.") + endif() + + list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH}) + list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH}) + check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL) + list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH}) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH}) +else() + unset(HAVE_FFI_FFI_H CACHE) + unset(HAVE_FFI_H CACHE) + unset(HAVE_FFI_CALL CACHE) +endif( LLVM_ENABLE_FFI ) + +# Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported. +include(CheckAtomic) + +if( LLVM_ENABLE_PIC ) + set(ENABLE_PIC 1) +else() + set(ENABLE_PIC 0) + check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG) + if(SUPPORTS_NO_PIE_FLAG) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") + endif() +endif() + +check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG) +check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments" + SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG) + +set(USE_NO_MAYBE_UNINITIALIZED 0) +set(USE_NO_UNINITIALIZED 0) + +# Disable gcc's potentially uninitialized use analysis as it presents lots of +# false positives. +if (CMAKE_COMPILER_IS_GNUCXX) + check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED) + if (HAS_MAYBE_UNINITIALIZED) + set(USE_NO_MAYBE_UNINITIALIZED 1) + else() + # Only recent versions of gcc make the distinction between -Wuninitialized + # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just + # turn off all uninitialized use warnings. + check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED) + set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED}) + endif() +endif() + +# By default, we target the host, but this can be overridden at CMake +# invocation time. +include(GetHostTriple) +get_host_triple(LLVM_INFERRED_HOST_TRIPLE) + +set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING + "Host on which LLVM binaries will run") + +if (NOT ${HERMES_LLVM}) +# Determine the native architecture. +string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH) +if( LLVM_NATIVE_ARCH STREQUAL "host" ) + string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE}) +endif () + +if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86") + set(LLVM_NATIVE_ARCH X86) +elseif (LLVM_NATIVE_ARCH STREQUAL "x86") + set(LLVM_NATIVE_ARCH X86) +elseif (LLVM_NATIVE_ARCH STREQUAL "amd64") + set(LLVM_NATIVE_ARCH X86) +elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64") + set(LLVM_NATIVE_ARCH X86) +elseif (LLVM_NATIVE_ARCH MATCHES "sparc") + set(LLVM_NATIVE_ARCH Sparc) +elseif (LLVM_NATIVE_ARCH MATCHES "powerpc") + set(LLVM_NATIVE_ARCH PowerPC) +elseif (LLVM_NATIVE_ARCH MATCHES "aarch64") + set(LLVM_NATIVE_ARCH AArch64) +elseif (LLVM_NATIVE_ARCH MATCHES "arm64") + set(LLVM_NATIVE_ARCH AArch64) +elseif (LLVM_NATIVE_ARCH MATCHES "arm") + set(LLVM_NATIVE_ARCH ARM) +elseif (LLVM_NATIVE_ARCH MATCHES "mips") + set(LLVM_NATIVE_ARCH Mips) +elseif (LLVM_NATIVE_ARCH MATCHES "xcore") + set(LLVM_NATIVE_ARCH XCore) +elseif (LLVM_NATIVE_ARCH MATCHES "msp430") + set(LLVM_NATIVE_ARCH MSP430) +elseif (LLVM_NATIVE_ARCH MATCHES "hexagon") + set(LLVM_NATIVE_ARCH Hexagon) +elseif (LLVM_NATIVE_ARCH MATCHES "s390x") + set(LLVM_NATIVE_ARCH SystemZ) +elseif (LLVM_NATIVE_ARCH MATCHES "wasm32") + set(LLVM_NATIVE_ARCH WebAssembly) +elseif (LLVM_NATIVE_ARCH MATCHES "wasm64") + set(LLVM_NATIVE_ARCH WebAssembly) +elseif (LLVM_NATIVE_ARCH MATCHES "riscv32") + set(LLVM_NATIVE_ARCH RISCV) +elseif (LLVM_NATIVE_ARCH MATCHES "riscv64") + set(LLVM_NATIVE_ARCH RISCV) +else () + message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}") +endif () + +# If build targets includes "host", then replace with native architecture. +list(FIND LLVM_TARGETS_TO_BUILD "host" idx) +if( NOT idx LESS 0 ) + list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx}) + list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH}) + list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) +endif() + +list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX) +if (NATIVE_ARCH_IDX EQUAL -1) + message(STATUS + "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code") +else () + message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}") + set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target) + set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo) + set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC) + set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter) + + # We don't have an ASM parser for all architectures yet. + if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt) + set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser) + endif () + + # We don't have an disassembler for all architectures yet. + if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt) + set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler) + endif () +endif () +endif(NOT ${HERMES_LLVM}) + +if( MSVC ) + set(SHLIBEXT ".lib") + set(stricmp "_stricmp") + set(strdup "_strdup") + + # See if the DIA SDK is available and usable. + set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK") + + # Due to a bug in MSVC 2013's installation software, it is possible + # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012 + # install directory. If this happens, the installation is corrupt + # and there's nothing we can do. It happens with enough frequency + # though that we should handle it. We do so by simply checking that + # the DIA SDK folder exists. Should this happen you will need to + # uninstall VS 2012 and then re-install VS 2013. + if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR}) + set(HAVE_DIA_SDK 1) + else() + set(HAVE_DIA_SDK 0) + endif() + + option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available." + ${HAVE_DIA_SDK}) + + if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK) + 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.") + endif() +else() + set(LLVM_ENABLE_DIA_SDK 0) +endif( MSVC ) + +# FIXME: Signal handler return type, currently hardcoded to 'void' +set(RETSIGTYPE void) + +if( LLVM_ENABLE_THREADS ) + # Check if threading primitives aren't supported on this platform + if( NOT HAVE_PTHREAD_H AND NOT WIN32 ) + set(LLVM_ENABLE_THREADS 0) + endif() +endif() + +if( LLVM_ENABLE_THREADS ) + message(STATUS "Threads enabled.") +else( LLVM_ENABLE_THREADS ) + message(STATUS "Threads disabled.") +endif() + +if (LLVM_ENABLE_ZLIB ) + # Check if zlib is available in the system. + if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ ) + set(LLVM_ENABLE_ZLIB 0) + endif() +endif() + +if (LLVM_ENABLE_DOXYGEN) + message(STATUS "Doxygen enabled.") + find_package(Doxygen REQUIRED) + + if (DOXYGEN_FOUND) + # If we find doxygen and we want to enable doxygen by default create a + # global aggregate doxygen target for generating llvm and any/all + # subprojects doxygen documentation. + if (LLVM_BUILD_DOCS) + add_custom_target(doxygen ALL) + endif() + + option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF) + if (LLVM_DOXYGEN_EXTERNAL_SEARCH) + set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.") + set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings") + endif() + endif() +else() + message(STATUS "Doxygen disabled.") +endif() + +set(LLVM_BINDINGS "") +find_program(GO_EXECUTABLE NAMES go DOC "go executable") +if(WIN32 OR NOT LLVM_ENABLE_BINDINGS) + message(STATUS "Go bindings disabled.") +else() + if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND") + message(STATUS "Go bindings disabled.") + else() + execute_process(COMMAND ${GO_EXECUTABLE} run ${PROJECT_SOURCE_DIR}/bindings/go/conftest.go + RESULT_VARIABLE GO_CONFTEST) + if(GO_CONFTEST STREQUAL "0") + set(LLVM_BINDINGS "${LLVM_BINDINGS} go") + message(STATUS "Go bindings enabled.") + else() + message(STATUS "Go bindings disabled, need at least Go 1.2.") + endif() + endif() +endif() + +find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker") +set(LLVM_BINUTILS_INCDIR "" CACHE PATH + "PATH to binutils/include containing plugin-api.h for gold plugin.") + +if(CMAKE_HOST_APPLE AND APPLE) + if(NOT CMAKE_XCRUN) + find_program(CMAKE_XCRUN NAMES xcrun) + endif() + if(CMAKE_XCRUN) + execute_process(COMMAND ${CMAKE_XCRUN} -find ld + OUTPUT_VARIABLE LD64_EXECUTABLE + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker") + endif() + + if(LD64_EXECUTABLE) + set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable") + message(STATUS "Found ld64 - ${LD64_EXECUTABLE}") + endif() +endif() + +if (NOT ${HERMES_LLVM}) +# Keep the version requirements in sync with bindings/ocaml/README.txt. +include(FindOCaml) +include(AddOCaml) +if(WIN32 OR NOT LLVM_ENABLE_BINDINGS) + message(STATUS "OCaml bindings disabled.") +else() + find_package(OCaml) + if( NOT OCAML_FOUND ) + message(STATUS "OCaml bindings disabled.") + else() + if( OCAML_VERSION VERSION_LESS "4.00.0" ) + message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.") + else() + find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL) + if( HAVE_OCAML_CTYPES ) + message(STATUS "OCaml bindings enabled.") + find_ocamlfind_package(oUnit VERSION 2 OPTIONAL) + set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml") + + set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING + "Install directory for LLVM OCaml packages") + else() + message(STATUS "OCaml bindings disabled, need ctypes >=0.4.") + endif() + endif() + endif() +endif() + +string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}") +endif(NOT ${HERMES_LLVM}) + +function(find_python_module module) + string(REPLACE "." "_" module_name ${module}) + string(TOUPPER ${module_name} module_upper) + set(FOUND_VAR PY_${module_upper}_FOUND) + + execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}" + RESULT_VARIABLE status + ERROR_QUIET) + + if(status) + set(${FOUND_VAR} 0 PARENT_SCOPE) + message(STATUS "Could NOT find Python module ${module}") + else() + set(${FOUND_VAR} 1 PARENT_SCOPE) + message(STATUS "Found Python module ${module}") + endif() +endfunction() + +set (PYTHON_MODULES + pygments + # Some systems still don't have pygments.lexers.c_cpp which was introduced in + # version 2.0 in 2014... + pygments.lexers.c_cpp + yaml + ) +foreach(module ${PYTHON_MODULES}) + find_python_module(${module}) +endforeach() + +if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND) + set (LLVM_HAVE_OPT_VIEWER_MODULES 1) +else() + set (LLVM_HAVE_OPT_VIEWER_MODULES 0) +endif() diff --git a/external/llvh/cmake/config.guess b/external/llvh/cmake/config.guess new file mode 100644 index 00000000000..ccb30f4e75e --- /dev/null +++ b/external/llvh/cmake/config.guess @@ -0,0 +1,1528 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, +# 2011 Free Software Foundation, Inc. + +timestamp='2011-08-20' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner. Please send patches (context +# diff format) to and include a ChangeLog +# entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# You can get the latest version of this script from: +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free +Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ELF__ + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + # Reset EXIT trap before exiting to avoid spurious non-zero exit code. + exitcode=$? + trap '' 0 + exit $exitcode ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + s390x:SunOS:*:*) + echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) + echo i386-pc-auroraux${UNAME_RELEASE} + exit ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + eval $set_cc_for_build + SUN_ARCH="i386" + # If there is a compiler, see if it is configured for 64-bit objects. + # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. + # This test works for both compilers. + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + SUN_ARCH="x86_64" + fi + fi + echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[4567]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep -q __LP64__ + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + UNAME_PROCESSOR=`/usr/bin/uname -p` + case ${UNAME_PROCESSOR} in + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + *:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + *:MSYS*:*) + echo ${UNAME_MACHINE}-pc-msys + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + *:Interix*:*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + authenticamd | genuineintel | EM64T) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + IA64) + echo ia64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + 8664:Windows_NT:*) + echo x86_64-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + aarch64*:Linux:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep -q ld.so.1 + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit ;; + arm*:Linux:*:*) + eval $set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + echo ${UNAME_MACHINE}-unknown-linux-gnu + else + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + echo ${UNAME_MACHINE}-unknown-linux-gnueabi + else + echo ${UNAME_MACHINE}-unknown-linux-gnueabihf + fi + fi + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + LIBC=gnu + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:* | mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef ${UNAME_MACHINE} + #undef ${UNAME_MACHINE}el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=${UNAME_MACHINE}el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=${UNAME_MACHINE} + #else + CPU= + #endif + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; + padre:Linux:*:*) + echo sparc-unknown-linux-gnu + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + ppc64le:Linux:*:*) + echo powerpc64le-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + tile*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit ;; + xtensa*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i586. + # Note: whatever this is, it MUST be the same as what config.sub + # prints for the "djgpp" host, or else GDB configury will decide that + # this is a cross-build. + echo i586-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + NCR*:*:4.2:* | MPRAS*:*:4.2:*) + OS_REL='.3' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + echo i586-pc-haiku + exit ;; + x86_64:Haiku:*:*) # Haiku running on x86_64. + echo x86_64-unknown-haiku + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + i386) + eval $set_cc_for_build + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + UNAME_PROCESSOR="x86_64" + fi + fi ;; + unknown) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NEO-?:NONSTOP_KERNEL:*:*) + echo neo-tandem-nsk${UNAME_RELEASE} + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; + i*86:AROS:*:*) + echo ${UNAME_MACHINE}-pc-aros + exit ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/external/llvh/cmake/modules/CheckAtomic.cmake b/external/llvh/cmake/modules/CheckAtomic.cmake new file mode 100644 index 00000000000..9a4cdf12a62 --- /dev/null +++ b/external/llvh/cmake/modules/CheckAtomic.cmake @@ -0,0 +1,106 @@ +# atomic builtins are required for threading support. + +INCLUDE(CheckCXXSourceCompiles) +INCLUDE(CheckLibraryExists) + +# Sometimes linking against libatomic is required for atomic ops, if +# the platform doesn't support lock-free atomics. + +function(check_working_cxx_atomics varname) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") + CHECK_CXX_SOURCE_COMPILES(" +#include +std::atomic x; +int main() { + return x; +} +" ${varname}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endfunction(check_working_cxx_atomics) + +function(check_working_cxx_atomics64 varname) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}") + CHECK_CXX_SOURCE_COMPILES(" +#include +#include +std::atomic x (0); +int main() { + uint64_t i = x.load(std::memory_order_relaxed); + return 0; +} +" ${varname}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endfunction(check_working_cxx_atomics64) + + +# This isn't necessary on MSVC, so avoid command-line switch annoyance +# by only running on GCC-like hosts. +if (LLVM_COMPILER_IS_GCC_COMPATIBLE) + # First check if atomics work without the library. + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) + # If not, check if the library exists, and atomics work with it. + if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) + check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) + if( HAVE_LIBATOMIC ) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) + if (NOT HAVE_CXX_ATOMICS_WITH_LIB) + message(FATAL_ERROR "Host compiler must support std::atomic!") + endif() + else() + message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.") + endif() + endif() +endif() + +# Check for 64 bit atomic operations. +if(MSVC) + set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) +else() + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) +endif() + +# If not, check if the library exists, and atomics work with it. +if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) + check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) + if(HAVE_CXX_LIBATOMICS64) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) + if (NOT HAVE_CXX_ATOMICS64_WITH_LIB) + message(FATAL_ERROR "Host compiler must support std::atomic!") + endif() + else() + message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.") + endif() +endif() + +## TODO: This define is only used for the legacy atomic operations in +## llvm's Atomic.h, which should be replaced. Other code simply +## assumes C++11 works. +CHECK_CXX_SOURCE_COMPILES(" +#ifdef _MSC_VER +#include +#endif +int main() { +#ifdef _MSC_VER + volatile LONG val = 1; + MemoryBarrier(); + InterlockedCompareExchange(&val, 0, 1); + InterlockedIncrement(&val); + InterlockedDecrement(&val); +#else + volatile unsigned long val = 1; + __sync_synchronize(); + __sync_val_compare_and_swap(&val, 1, 0); + __sync_add_and_fetch(&val, 1); + __sync_sub_and_fetch(&val, 1); +#endif + return 0; + } +" LLVM_HAS_ATOMICS) + +if( NOT LLVM_HAS_ATOMICS ) + message(STATUS "Warning: LLVM will be built thread-unsafe because atomic builtins are missing") +endif() diff --git a/external/llvh/cmake/modules/CheckCompilerVersion.cmake b/external/llvh/cmake/modules/CheckCompilerVersion.cmake new file mode 100644 index 00000000000..adf500ad53a --- /dev/null +++ b/external/llvh/cmake/modules/CheckCompilerVersion.cmake @@ -0,0 +1,52 @@ +# Check if the host compiler is new enough. LLVM requires at least GCC 4.8, +# MSVC 2015 (Update 3), or Clang 3.1. + +include(CheckCXXSourceCompiles) + +if(NOT DEFINED LLVM_COMPILER_CHECKED) + set(LLVM_COMPILER_CHECKED ON) + + if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) + message(FATAL_ERROR "Host GCC version must be at least 4.8!") + endif() + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1) + message(FATAL_ERROR "Host Clang version must be at least 3.1!") + endif() + + if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") + if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS 19.0) + message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=19.0") + endif() + set(CLANG_CL 1) + elseif(NOT LLVM_ENABLE_LIBCXX) + # Otherwise, test that we aren't using too old of a version of libstdc++ + # with the Clang compiler. This is tricky as there is no real way to + # check the version of libstdc++ directly. Instead we test for a known + # bug in libstdc++4.6 that is fixed in libstdc++4.7. + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++0x") + check_cxx_source_compiles(" +#include +std::atomic x(0.0f); +int main() { return (float)x; }" + LLVM_NO_OLD_LIBSTDCXX) + if(NOT LLVM_NO_OLD_LIBSTDCXX) + message(FATAL_ERROR "Host Clang must be able to find libstdc++4.8 or newer!") + endif() + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES}) + endif() + elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0) + message(FATAL_ERROR "Host Visual Studio must be at least 2015") + elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.00.24213.1) + message(WARNING "Host Visual Studio should at least be 2015 Update 3 (MSVC 19.00.24213.1)" + " due to miscompiles from earlier versions") + endif() + endif() + endif() +endif() diff --git a/external/llvh/cmake/modules/CheckLinkerFlag.cmake b/external/llvh/cmake/modules/CheckLinkerFlag.cmake new file mode 100644 index 00000000000..fe9d01a349c --- /dev/null +++ b/external/llvh/cmake/modules/CheckLinkerFlag.cmake @@ -0,0 +1,6 @@ +include(CheckCXXCompilerFlag) + +function(check_linker_flag flag out_var) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}") + check_cxx_compiler_flag("" ${out_var}) +endfunction() diff --git a/external/llvh/cmake/modules/DetermineGCCCompatible.cmake b/external/llvh/cmake/modules/DetermineGCCCompatible.cmake new file mode 100644 index 00000000000..1369ebe9d0e --- /dev/null +++ b/external/llvh/cmake/modules/DetermineGCCCompatible.cmake @@ -0,0 +1,13 @@ +# Determine if the compiler has GCC-compatible command-line syntax. + +if(NOT DEFINED LLVM_COMPILER_IS_GCC_COMPATIBLE) + if(CMAKE_COMPILER_IS_GNUCXX) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) + elseif( MSVC ) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE OFF) + elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) + elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel" ) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) + endif() +endif() diff --git a/external/llvh/cmake/modules/FindLibpfm.cmake b/external/llvh/cmake/modules/FindLibpfm.cmake new file mode 100644 index 00000000000..202bb030e38 --- /dev/null +++ b/external/llvh/cmake/modules/FindLibpfm.cmake @@ -0,0 +1,23 @@ +# CMake module for finding libpfm4. +# +# If successful, the following variables will be defined: +# HAVE_LIBPFM +# +# Libpfm can be disabled by setting LLVM_ENABLE_LIBPFM to 0. + +include(CheckIncludeFile) +include(CheckLibraryExists) + +if (LLVM_ENABLE_LIBPFM) + check_library_exists(pfm pfm_initialize "" HAVE_LIBPFM_INITIALIZE) + if(HAVE_LIBPFM_INITIALIZE) + check_include_file(perfmon/perf_event.h HAVE_PERFMON_PERF_EVENT_H) + check_include_file(perfmon/pfmlib.h HAVE_PERFMON_PFMLIB_H) + check_include_file(perfmon/pfmlib_perf_event.h HAVE_PERFMON_PFMLIB_PERF_EVENT_H) + if(HAVE_PERFMON_PERF_EVENT_H AND HAVE_PERFMON_PFMLIB_H AND HAVE_PERFMON_PFMLIB_PERF_EVENT_H) + set(HAVE_LIBPFM 1) + endif() + endif() +endif() + + diff --git a/external/llvh/cmake/modules/GetHostTriple.cmake b/external/llvh/cmake/modules/GetHostTriple.cmake new file mode 100644 index 00000000000..7b842450b72 --- /dev/null +++ b/external/llvh/cmake/modules/GetHostTriple.cmake @@ -0,0 +1,29 @@ +# Returns the host triple. +# Invokes config.guess + +function( get_host_triple var ) + if( MSVC ) + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + set( value "x86_64-pc-windows-msvc" ) + else() + set( value "i686-pc-windows-msvc" ) + endif() + elseif( MINGW AND NOT MSYS ) + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + set( value "x86_64-w64-windows-gnu" ) + else() + set( value "i686-pc-windows-gnu" ) + endif() + else( MSVC ) + set(config_guess ${LLVM_MAIN_SRC_DIR}/cmake/config.guess) + execute_process(COMMAND sh ${config_guess} + RESULT_VARIABLE TT_RV + OUTPUT_VARIABLE TT_OUT + OUTPUT_STRIP_TRAILING_WHITESPACE) + if( NOT TT_RV EQUAL 0 ) + message(FATAL_ERROR "Failed to execute ${config_guess}") + endif( NOT TT_RV EQUAL 0 ) + set( value ${TT_OUT} ) + endif( MSVC ) + set( ${var} ${value} PARENT_SCOPE ) +endfunction( get_host_triple var ) diff --git a/external/llvh/cmake/modules/HandleLLVMStdlib.cmake b/external/llvh/cmake/modules/HandleLLVMStdlib.cmake new file mode 100644 index 00000000000..a0706d8e084 --- /dev/null +++ b/external/llvh/cmake/modules/HandleLLVMStdlib.cmake @@ -0,0 +1,32 @@ +# This CMake module is responsible for setting the standard library to libc++ +# if the user has requested it. + +include(DetermineGCCCompatible) + +if(NOT DEFINED LLVM_STDLIB_HANDLED) + set(LLVM_STDLIB_HANDLED ON) + + function(append value) + foreach(variable ${ARGN}) + set(${variable} "${${variable}} ${value}" PARENT_SCOPE) + endforeach(variable) + endfunction() + + include(CheckCXXCompilerFlag) + include(CheckLinkerFlag) + if(LLVM_ENABLE_LIBCXX) + if(LLVM_COMPILER_IS_GCC_COMPATIBLE) + check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB) + check_linker_flag("-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB) + if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB) + append("-stdlib=libc++" + CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS + CMAKE_MODULE_LINKER_FLAGS) + else() + message(WARNING "Can't specify libc++ with '-stdlib='") + endif() + else() + message(WARNING "Not sure how to specify libc++ for this compiler") + endif() + endif() +endif() diff --git a/external/llvh/gen/include/llvm/IR/Attributes.inc b/external/llvh/gen/include/llvm/IR/Attributes.inc new file mode 100644 index 00000000000..28d4287cb71 --- /dev/null +++ b/external/llvh/gen/include/llvm/IR/Attributes.inc @@ -0,0 +1,520 @@ +#ifdef GET_ATTR_ENUM +#undef GET_ATTR_ENUM +Alignment, +AllocSize, +AlwaysInline, +ArgMemOnly, +Builtin, +ByVal, +Cold, +Convergent, +Dereferenceable, +DereferenceableOrNull, +InAlloca, +InReg, +InaccessibleMemOnly, +InaccessibleMemOrArgMemOnly, +InlineHint, +JumpTable, +MinSize, +Naked, +Nest, +NoAlias, +NoBuiltin, +NoCapture, +NoCfCheck, +NoDuplicate, +NoImplicitFloat, +NoInline, +NoRecurse, +NoRedZone, +NoReturn, +NoUnwind, +NonLazyBind, +NonNull, +OptForFuzzing, +OptimizeForSize, +OptimizeNone, +ReadNone, +ReadOnly, +Returned, +ReturnsTwice, +SExt, +SafeStack, +SanitizeAddress, +SanitizeHWAddress, +SanitizeMemory, +SanitizeThread, +ShadowCallStack, +Speculatable, +SpeculativeLoadHardening, +StackAlignment, +StackProtect, +StackProtectReq, +StackProtectStrong, +StrictFP, +StructRet, +SwiftError, +SwiftSelf, +UWTable, +WriteOnly, +ZExt, +#endif +#ifdef GET_ATTR_KIND_FROM_NAME +#undef GET_ATTR_KIND_FROM_NAME +static Attribute::AttrKind getAttrKindFromName(StringRef AttrName) { + return StringSwitch(AttrName) + .Case("align", Attribute::Alignment) + .Case("allocsize", Attribute::AllocSize) + .Case("alwaysinline", Attribute::AlwaysInline) + .Case("argmemonly", Attribute::ArgMemOnly) + .Case("builtin", Attribute::Builtin) + .Case("byval", Attribute::ByVal) + .Case("cold", Attribute::Cold) + .Case("convergent", Attribute::Convergent) + .Case("dereferenceable", Attribute::Dereferenceable) + .Case("dereferenceable_or_null", Attribute::DereferenceableOrNull) + .Case("inalloca", Attribute::InAlloca) + .Case("inreg", Attribute::InReg) + .Case("inaccessiblememonly", Attribute::InaccessibleMemOnly) + .Case("inaccessiblemem_or_argmemonly", Attribute::InaccessibleMemOrArgMemOnly) + .Case("inlinehint", Attribute::InlineHint) + .Case("jumptable", Attribute::JumpTable) + .Case("minsize", Attribute::MinSize) + .Case("naked", Attribute::Naked) + .Case("nest", Attribute::Nest) + .Case("noalias", Attribute::NoAlias) + .Case("nobuiltin", Attribute::NoBuiltin) + .Case("nocapture", Attribute::NoCapture) + .Case("nocf_check", Attribute::NoCfCheck) + .Case("noduplicate", Attribute::NoDuplicate) + .Case("noimplicitfloat", Attribute::NoImplicitFloat) + .Case("noinline", Attribute::NoInline) + .Case("norecurse", Attribute::NoRecurse) + .Case("noredzone", Attribute::NoRedZone) + .Case("noreturn", Attribute::NoReturn) + .Case("nounwind", Attribute::NoUnwind) + .Case("nonlazybind", Attribute::NonLazyBind) + .Case("nonnull", Attribute::NonNull) + .Case("optforfuzzing", Attribute::OptForFuzzing) + .Case("optsize", Attribute::OptimizeForSize) + .Case("optnone", Attribute::OptimizeNone) + .Case("readnone", Attribute::ReadNone) + .Case("readonly", Attribute::ReadOnly) + .Case("returned", Attribute::Returned) + .Case("returns_twice", Attribute::ReturnsTwice) + .Case("signext", Attribute::SExt) + .Case("safestack", Attribute::SafeStack) + .Case("sanitize_address", Attribute::SanitizeAddress) + .Case("sanitize_hwaddress", Attribute::SanitizeHWAddress) + .Case("sanitize_memory", Attribute::SanitizeMemory) + .Case("sanitize_thread", Attribute::SanitizeThread) + .Case("shadowcallstack", Attribute::ShadowCallStack) + .Case("speculatable", Attribute::Speculatable) + .Case("speculative_load_hardening", Attribute::SpeculativeLoadHardening) + .Case("alignstack", Attribute::StackAlignment) + .Case("ssp", Attribute::StackProtect) + .Case("sspreq", Attribute::StackProtectReq) + .Case("sspstrong", Attribute::StackProtectStrong) + .Case("strictfp", Attribute::StrictFP) + .Case("sret", Attribute::StructRet) + .Case("swifterror", Attribute::SwiftError) + .Case("swiftself", Attribute::SwiftSelf) + .Case("uwtable", Attribute::UWTable) + .Case("writeonly", Attribute::WriteOnly) + .Case("zeroext", Attribute::ZExt) + .Default(Attribute::None); +} + +#endif +#ifdef GET_ATTR_COMPAT_FUNC +#undef GET_ATTR_COMPAT_FUNC +struct EnumAttr { + static bool isSet(const Function &Fn, + Attribute::AttrKind Kind) { + return Fn.hasFnAttribute(Kind); + } + + static void set(Function &Fn, + Attribute::AttrKind Kind, bool Val) { + if (Val) + Fn.addFnAttr(Kind); + else + Fn.removeFnAttr(Kind); + } +}; + +struct StrBoolAttr { + static bool isSet(const Function &Fn, + StringRef Kind) { + auto A = Fn.getFnAttribute(Kind); + return A.getValueAsString().equals("true"); + } + + static void set(Function &Fn, + StringRef Kind, bool Val) { + Fn.addFnAttr(Kind, Val ? "true" : "false"); + } +}; + +// EnumAttr classes +struct AlignmentAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Alignment; + } +}; +struct AllocSizeAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::AllocSize; + } +}; +struct AlwaysInlineAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::AlwaysInline; + } +}; +struct ArgMemOnlyAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::ArgMemOnly; + } +}; +struct BuiltinAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Builtin; + } +}; +struct ByValAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::ByVal; + } +}; +struct ColdAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Cold; + } +}; +struct ConvergentAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Convergent; + } +}; +struct DereferenceableAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Dereferenceable; + } +}; +struct DereferenceableOrNullAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::DereferenceableOrNull; + } +}; +struct InAllocaAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::InAlloca; + } +}; +struct InRegAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::InReg; + } +}; +struct InaccessibleMemOnlyAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::InaccessibleMemOnly; + } +}; +struct InaccessibleMemOrArgMemOnlyAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::InaccessibleMemOrArgMemOnly; + } +}; +struct InlineHintAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::InlineHint; + } +}; +struct JumpTableAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::JumpTable; + } +}; +struct MinSizeAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::MinSize; + } +}; +struct NakedAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Naked; + } +}; +struct NestAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Nest; + } +}; +struct NoAliasAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoAlias; + } +}; +struct NoBuiltinAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoBuiltin; + } +}; +struct NoCaptureAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoCapture; + } +}; +struct NoCfCheckAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoCfCheck; + } +}; +struct NoDuplicateAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoDuplicate; + } +}; +struct NoImplicitFloatAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoImplicitFloat; + } +}; +struct NoInlineAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoInline; + } +}; +struct NoRecurseAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoRecurse; + } +}; +struct NoRedZoneAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoRedZone; + } +}; +struct NoReturnAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoReturn; + } +}; +struct NoUnwindAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NoUnwind; + } +}; +struct NonLazyBindAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NonLazyBind; + } +}; +struct NonNullAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::NonNull; + } +}; +struct OptForFuzzingAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::OptForFuzzing; + } +}; +struct OptimizeForSizeAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::OptimizeForSize; + } +}; +struct OptimizeNoneAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::OptimizeNone; + } +}; +struct ReadNoneAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::ReadNone; + } +}; +struct ReadOnlyAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::ReadOnly; + } +}; +struct ReturnedAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Returned; + } +}; +struct ReturnsTwiceAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::ReturnsTwice; + } +}; +struct SExtAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SExt; + } +}; +struct SafeStackAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SafeStack; + } +}; +struct SanitizeAddressAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SanitizeAddress; + } +}; +struct SanitizeHWAddressAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SanitizeHWAddress; + } +}; +struct SanitizeMemoryAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SanitizeMemory; + } +}; +struct SanitizeThreadAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SanitizeThread; + } +}; +struct ShadowCallStackAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::ShadowCallStack; + } +}; +struct SpeculatableAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::Speculatable; + } +}; +struct SpeculativeLoadHardeningAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SpeculativeLoadHardening; + } +}; +struct StackAlignmentAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::StackAlignment; + } +}; +struct StackProtectAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::StackProtect; + } +}; +struct StackProtectReqAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::StackProtectReq; + } +}; +struct StackProtectStrongAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::StackProtectStrong; + } +}; +struct StrictFPAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::StrictFP; + } +}; +struct StructRetAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::StructRet; + } +}; +struct SwiftErrorAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SwiftError; + } +}; +struct SwiftSelfAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::SwiftSelf; + } +}; +struct UWTableAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::UWTable; + } +}; +struct WriteOnlyAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::WriteOnly; + } +}; +struct ZExtAttr : EnumAttr { + static enum Attribute::AttrKind getKind() { + return llvm::Attribute::ZExt; + } +}; + +// StrBoolAttr classes +struct LessPreciseFPMADAttr : StrBoolAttr { + static StringRef getKind() { + return "less-precise-fpmad"; + } +}; +struct NoInfsFPMathAttr : StrBoolAttr { + static StringRef getKind() { + return "no-infs-fp-math"; + } +}; +struct NoJumpTablesAttr : StrBoolAttr { + static StringRef getKind() { + return "no-jump-tables"; + } +}; +struct NoNansFPMathAttr : StrBoolAttr { + static StringRef getKind() { + return "no-nans-fp-math"; + } +}; +struct ProfileSampleAccurateAttr : StrBoolAttr { + static StringRef getKind() { + return "profile-sample-accurate"; + } +}; +struct UnsafeFPMathAttr : StrBoolAttr { + static StringRef getKind() { + return "unsafe-fp-math"; + } +}; + +static inline bool hasCompatibleFnAttrs(const Function &Caller, + const Function &Callee) { + bool Ret = true; + + Ret &= isEqual(Caller, Callee); + Ret &= isEqual(Caller, Callee); + Ret &= isEqual(Caller, Callee); + Ret &= isEqual(Caller, Callee); + Ret &= isEqual(Caller, Callee); + Ret &= isEqual(Caller, Callee); + + return Ret; +} + +static inline void mergeFnAttrs(Function &Caller, + const Function &Callee) { + setOR(Caller, Callee); + setOR(Caller, Callee); + setOR(Caller, Callee); + setOR(Caller, Callee); + adjustCallerSSPLevel(Caller, Callee); + adjustCallerStackProbes(Caller, Callee); + adjustCallerStackProbeSize(Caller, Callee); + adjustMinLegalVectorWidth(Caller, Callee); + adjustNullPointerValidAttr(Caller, Callee); + setAND(Caller, Callee); + setAND(Caller, Callee); + setAND(Caller, Callee); + setAND(Caller, Callee); +} + +#endif diff --git a/external/llvh/include/llvm/Config/config.h.cmake b/external/llvh/include/llvm/Config/config.h.cmake index 55f95d57e56..89ba600db90 100644 --- a/external/llvh/include/llvm/Config/config.h.cmake +++ b/external/llvh/include/llvm/Config/config.h.cmake @@ -292,6 +292,10 @@ /* Linker version detected at compile time. */ #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" +/* Target triple LLVM will generate code for by default */ +/* Doesn't use `cmakedefine` because it is allowed to be empty. */ +#define LLVM_DEFAULT_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}" + /* Define if zlib compression is available */ #cmakedefine01 LLVM_ENABLE_ZLIB diff --git a/external/llvh/include/llvm/Config/llvm-config.h b/external/llvh/include/llvm/Config/llvm-config.h.cmake similarity index 65% rename from external/llvh/include/llvm/Config/llvm-config.h rename to external/llvh/include/llvm/Config/llvm-config.h.cmake index 3b8829cc1dd..872a31553d1 100644 --- a/external/llvh/include/llvm/Config/llvm-config.h +++ b/external/llvh/include/llvm/Config/llvm-config.h.cmake @@ -15,71 +15,71 @@ #define LLVM_CONFIG_H /* Define if LLVM_ENABLE_DUMP is enabled */ -/* #undef LLVM_ENABLE_DUMP */ +#cmakedefine LLVM_ENABLE_DUMP /* Define if we link Polly to the tools */ -/* #undef LINK_POLLY_INTO_TOOLS */ +#cmakedefine LINK_POLLY_INTO_TOOLS /* Target triple LLVM will generate code for by default */ -#define LLVM_DEFAULT_TARGET_TRIPLE "x86_64-apple-darwin18.6.0" +#cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" /* Define if threads enabled */ -#define LLVM_ENABLE_THREADS 1 +#cmakedefine01 LLVM_ENABLE_THREADS /* Has gcc/MSVC atomic intrinsics */ -#define LLVM_HAS_ATOMICS 1 +#cmakedefine01 LLVM_HAS_ATOMICS /* Host triple LLVM will be executed on */ -#define LLVM_HOST_TRIPLE "x86_64-apple-darwin18.6.0" +#cmakedefine LLVM_HOST_TRIPLE "${LLVM_HOST_TRIPLE}" /* LLVM architecture name for the native architecture, if available */ -#define LLVM_NATIVE_ARCH X86 +#cmakedefine LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH} /* LLVM name for the native AsmParser init function, if available */ -#define LLVM_NATIVE_ASMPARSER LLVMInitializeX86AsmParser +#cmakedefine LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser /* LLVM name for the native AsmPrinter init function, if available */ -#define LLVM_NATIVE_ASMPRINTER LLVMInitializeX86AsmPrinter +#cmakedefine LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter /* LLVM name for the native Disassembler init function, if available */ -#define LLVM_NATIVE_DISASSEMBLER LLVMInitializeX86Disassembler +#cmakedefine LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler /* LLVM name for the native Target init function, if available */ -#define LLVM_NATIVE_TARGET LLVMInitializeX86Target +#cmakedefine LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target /* LLVM name for the native TargetInfo init function, if available */ -#define LLVM_NATIVE_TARGETINFO LLVMInitializeX86TargetInfo +#cmakedefine LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo /* LLVM name for the native target MC init function, if available */ -#define LLVM_NATIVE_TARGETMC LLVMInitializeX86TargetMC +#cmakedefine LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC /* Define if this is Unixish platform */ -#define LLVM_ON_UNIX 1 +#cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX} /* Define if we have the Intel JIT API runtime support library */ -#define LLVM_USE_INTEL_JITEVENTS 0 +#cmakedefine01 LLVM_USE_INTEL_JITEVENTS /* Define if we have the oprofile JIT-support library */ -#define LLVM_USE_OPROFILE 0 +#cmakedefine01 LLVM_USE_OPROFILE /* Define if we have the perf JIT-support library */ -#define LLVM_USE_PERF 0 +#cmakedefine01 LLVM_USE_PERF /* Major version of the LLVM API */ -#define LLVM_VERSION_MAJOR 8 +#define LLVM_VERSION_MAJOR ${LLVM_VERSION_MAJOR} /* Minor version of the LLVM API */ -#define LLVM_VERSION_MINOR 0 +#define LLVM_VERSION_MINOR ${LLVM_VERSION_MINOR} /* Patch version of the LLVM API */ -#define LLVM_VERSION_PATCH 0 +#define LLVM_VERSION_PATCH ${LLVM_VERSION_PATCH} /* LLVM version string */ -#define LLVM_VERSION_STRING "8.0.0svn" +#define LLVM_VERSION_STRING "${PACKAGE_VERSION}" /* Whether LLVM records statistics for use with GetStatistics(), * PrintStatistics() or PrintStatisticsJSON() */ -#define LLVM_FORCE_ENABLE_STATS 0 +#cmakedefine01 LLVM_FORCE_ENABLE_STATS #endif diff --git a/external/llvh/lib/CMakeLists.txt b/external/llvh/lib/CMakeLists.txt new file mode 100644 index 00000000000..26c32e008be --- /dev/null +++ b/external/llvh/lib/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Support) +add_subdirectory(Demangle) diff --git a/external/llvh/lib/Demangle/CMakeLists.txt b/external/llvh/lib/Demangle/CMakeLists.txt new file mode 100644 index 00000000000..97f00fcb8d5 --- /dev/null +++ b/external/llvh/lib/Demangle/CMakeLists.txt @@ -0,0 +1,5 @@ +add_hermes_library(LLVHDemangle + ItaniumDemangle.cpp + MicrosoftDemangle.cpp + MicrosoftDemangleNodes.cpp +) diff --git a/external/llvh/lib/Support/CMakeLists.txt b/external/llvh/lib/Support/CMakeLists.txt new file mode 100644 index 00000000000..f1ccbf0a0cd --- /dev/null +++ b/external/llvh/lib/Support/CMakeLists.txt @@ -0,0 +1,61 @@ +add_hermes_library(LLVHSupport + APFloat.cpp + APInt.cpp + circular_raw_ostream.cpp + CommandLine.cpp + ConvertUTF.cpp + ConvertUTFWrapper.cpp + Debug.cpp + Errno.cpp + Error.cpp + ErrorHandling.cpp + FileCheck.cpp + FoldingSet.cpp + GraphWriter.cpp + Hashing.cpp + Host.cpp + InitLLVM.cpp + LineIterator.cpp + Locale.cpp + ManagedStatic.cpp + MD5.cpp + Memory.cpp + MemoryBuffer.cpp + Mutex.cpp + NativeFormatting.cpp + Path.cpp + PrettyStackTrace.cpp + Process.cpp + Program.cpp + raw_ostream.cpp + raw_os_ostream.cpp + regcomp.c + regerror.c + regfree.c + Regex.cpp + regexec.c + regstrlcpy.c + SHA1.cpp + Signals.cpp + SmallVector.cpp + SmallPtrSet.cpp + SourceMgr.cpp + Statistic.cpp + StringExtras.cpp + StringMap.cpp + StringRef.cpp + StringSaver.cpp + TargetParser.cpp + Threading.cpp + Timer.cpp + Triple.cpp + Twine.cpp + Unicode.cpp + Valgrind.cpp + Watchdog.cpp + LINK_LIBS LLVHDemangle ${TERMINFO_LIBS} +) + +if (LLVM_PTHREAD_LIB) + target_link_libraries(LLVHSupport ${LLVM_PTHREAD_LIB}) +endif() diff --git a/utils/build/llvm-changes-for-hermes.patch b/external/llvh/patches/llvm-changes-for-hermes.patch similarity index 100% rename from utils/build/llvm-changes-for-hermes.patch rename to external/llvh/patches/llvm-changes-for-hermes.patch diff --git a/external/llvh/utils/FileCheck/CMakeLists.txt b/external/llvh/utils/FileCheck/CMakeLists.txt index 32e948a1a19..55dd9ed3b11 100644 --- a/external/llvh/utils/FileCheck/CMakeLists.txt +++ b/external/llvh/utils/FileCheck/CMakeLists.txt @@ -1,5 +1,5 @@ -add_llvm_utility(FileCheck +add_hermes_tool(FileCheck FileCheck.cpp ) -target_link_libraries(FileCheck PRIVATE LLVMSupport) +target_link_libraries(FileCheck PRIVATE LLVHSupport) diff --git a/external/llvh/utils/count/CMakeLists.txt b/external/llvh/utils/count/CMakeLists.txt index 4e0d371334e..bd872ac266e 100644 --- a/external/llvh/utils/count/CMakeLists.txt +++ b/external/llvh/utils/count/CMakeLists.txt @@ -1,3 +1,3 @@ -add_llvm_utility(count +add_hermes_tool(count count.c ) diff --git a/external/llvh/utils/not/CMakeLists.txt b/external/llvh/utils/not/CMakeLists.txt index 29c7b021852..4a355a46e38 100644 --- a/external/llvh/utils/not/CMakeLists.txt +++ b/external/llvh/utils/not/CMakeLists.txt @@ -1,5 +1,5 @@ -add_llvm_utility(not +add_hermes_tool(not not.cpp ) -target_link_libraries(not PRIVATE LLVMSupport) +target_link_libraries(not PRIVATE LLVHSupport) diff --git a/external/llvh/utils/unittest/CMakeLists.txt b/external/llvh/utils/unittest/CMakeLists.txt index 5b5cbf5d745..6e76e8ce274 100644 --- a/external/llvh/utils/unittest/CMakeLists.txt +++ b/external/llvh/utils/unittest/CMakeLists.txt @@ -38,7 +38,7 @@ if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG) add_definitions("-Wno-covered-switch-default") endif() -set(LLVM_REQUIRES_RTTI 1) +set(HERMES_ENABLE_RTTI 1) add_definitions( -DGTEST_HAS_RTTI=0 ) if (NOT LLVM_ENABLE_THREADS) @@ -50,18 +50,13 @@ if (LLVM_PTHREAD_LIBRARY_PATH) list(APPEND LIBS pthread) endif() -add_llvm_library(gtest +add_hermes_library(gtest googletest/src/gtest-all.cc googlemock/src/gmock-all.cc LINK_LIBS ${LIBS} - - LINK_COMPONENTS - Support # Depends on llvm::raw_ostream - - # This is a library meant only for the build tree. - BUILDTREE_ONLY + LLVHSupport # Depends on llvm::raw_ostream ) add_subdirectory(UnitTestMain) diff --git a/external/llvh/utils/unittest/UnitTestMain/CMakeLists.txt b/external/llvh/utils/unittest/UnitTestMain/CMakeLists.txt index 32f0f25a60f..9bd7447124b 100644 --- a/external/llvh/utils/unittest/UnitTestMain/CMakeLists.txt +++ b/external/llvh/utils/unittest/UnitTestMain/CMakeLists.txt @@ -1,12 +1,9 @@ -add_llvm_library(gtest_main +add_hermes_library(gtest_main TestMain.cpp LINK_LIBS gtest - LINK_COMPONENTS - Support # Depends on llvm::cl - - # This library is not meant to be in the install tree, only the build tree. - BUILDTREE_ONLY + LINK_LIBS + LLVHSupport # Depends on llvm::cl ) diff --git a/external/zip/CMakeLists.txt b/external/zip/CMakeLists.txt index d4b5d9e1944..8b938f14526 100644 --- a/external/zip/CMakeLists.txt +++ b/external/zip/CMakeLists.txt @@ -1,2 +1,2 @@ set(SRC src/zip.c) -add_llvm_library(zip STATIC ${SRC}) +add_hermes_library(zip STATIC ${SRC}) diff --git a/first-party/fbjni/CMakeLists.txt b/first-party/fbjni/CMakeLists.txt index 6896b326f6e..6574666ba4b 100644 --- a/first-party/fbjni/CMakeLists.txt +++ b/first-party/fbjni/CMakeLists.txt @@ -5,6 +5,9 @@ project(hermesfbjni CXX) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(fbjni_SOURCES ${FBJNI_PATH}/cxx/fbjni/ByteBuffer.cpp ${FBJNI_PATH}/cxx/fbjni/OnLoad.cpp @@ -31,7 +34,6 @@ target_compile_options(hermesfbjni PRIVATE -fexceptions -O3 -Wall - -std=c++14 -frtti -ffunction-sections -DDISABLE_CPUCAP diff --git a/lib/ADT/CMakeLists.txt b/lib/ADT/CMakeLists.txt index 7288af969f9..03a2dac9996 100644 --- a/lib/ADT/CMakeLists.txt +++ b/lib/ADT/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_library(hermesADT +add_hermes_library(hermesADT CompactArray.cpp ) diff --git a/lib/AST/CMakeLists.txt b/lib/AST/CMakeLists.txt index d90d5ad436c..a4bac878a77 100644 --- a/lib/AST/CMakeLists.txt +++ b/lib/AST/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_library(hermesAST +add_hermes_library(hermesAST ASTBuilder.cpp ESTree.cpp ESTreeJSONDumper.cpp diff --git a/lib/BCGen/CMakeLists.txt b/lib/BCGen/CMakeLists.txt index 34c41b1ff25..6a88b2ad275 100644 --- a/lib/BCGen/CMakeLists.txt +++ b/lib/BCGen/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_library(hermesBackend +add_hermes_library(hermesBackend STATIC RegAlloc.cpp BCOpt.cpp diff --git a/lib/BCGen/HBC/CMakeLists.txt b/lib/BCGen/HBC/CMakeLists.txt index d0e3062a9a6..8ac697b1f6d 100644 --- a/lib/BCGen/HBC/CMakeLists.txt +++ b/lib/BCGen/HBC/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_library(hermesHBCBackend +add_hermes_library(hermesHBCBackend STATIC BackendContext.cpp HBC.cpp diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b98b813450b..abfa5e0223d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -3,9 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS support) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_library(hermesOptimizer +add_hermes_library(hermesOptimizer STATIC Optimizer/PassManager/Pipeline.cpp Optimizer/Scalar/SimplifyCFG.cpp @@ -31,7 +31,7 @@ add_llvm_library(hermesOptimizer IR/IREval.cpp ) -add_llvm_library(hermesFrontend +add_hermes_library(hermesFrontend STATIC IRGen/IRGen.cpp IRGen/ESTreeIRGen.cpp IRGen/ESTreeIRGen.h @@ -62,6 +62,6 @@ add_subdirectory(BCGen) add_subdirectory(ConsoleHost) add_subdirectory(Regex) add_subdirectory(Platform) -if(HERMESVM_USE_JS_LIBRARY_IMPLEMENTATION) - add_subdirectory(InternalBytecode) -endif() +#if(HERMESVM_USE_JS_LIBRARY_IMPLEMENTATION) +# add_subdirectory(InternalBytecode) +#endif() diff --git a/lib/CompilerDriver/CMakeLists.txt b/lib/CompilerDriver/CMakeLists.txt index aed724de80f..7664236cd28 100644 --- a/lib/CompilerDriver/CMakeLists.txt +++ b/lib/CompilerDriver/CMakeLists.txt @@ -7,7 +7,7 @@ set(source_files CompilerDriver.cpp ) -add_llvm_library(hermesCompilerDriver STATIC ${source_files} +add_hermes_library(hermesCompilerDriver STATIC ${source_files} LINK_LIBS hermesADT hermesAST diff --git a/lib/ConsoleHost/CMakeLists.txt b/lib/ConsoleHost/CMakeLists.txt index e8eb23687e0..fc7d3411ac6 100644 --- a/lib/ConsoleHost/CMakeLists.txt +++ b/lib/ConsoleHost/CMakeLists.txt @@ -9,6 +9,6 @@ set(source_files RandomSeedParser.cpp ) -add_llvm_library(hermesConsoleHost STATIC ${source_files} +add_hermes_library(hermesConsoleHost STATIC ${source_files} LINK_LIBS hermesVMRuntime hermesInstrumentation ) diff --git a/lib/FlowParser/CMakeLists.txt b/lib/FlowParser/CMakeLists.txt index 3599f3eaba5..fa6e1b13ef4 100644 --- a/lib/FlowParser/CMakeLists.txt +++ b/lib/FlowParser/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_library(hermesFlowParser +add_hermes_library(hermesFlowParser FlowParser.cpp LINK_LIBS hermesSupport diff --git a/lib/FrontEndDefs/CMakeLists.txt b/lib/FrontEndDefs/CMakeLists.txt index 1d03bda6c27..13b5378def7 100644 --- a/lib/FrontEndDefs/CMakeLists.txt +++ b/lib/FrontEndDefs/CMakeLists.txt @@ -7,4 +7,4 @@ set(source_files Builtins.cpp ) -add_llvm_library(hermesFrontEndDefs STATIC ${source_files}) +add_hermes_library(hermesFrontEndDefs STATIC ${source_files}) diff --git a/lib/Inst/CMakeLists.txt b/lib/Inst/CMakeLists.txt index 925f405f4c3..c1ab6c8febe 100644 --- a/lib/Inst/CMakeLists.txt +++ b/lib/Inst/CMakeLists.txt @@ -8,7 +8,7 @@ set(source_files InstDecode2.cpp ) -add_llvm_library(hermesInst STATIC ${source_files} +add_hermes_library(hermesInst STATIC ${source_files} LINK_LIBS hermesSupport hermesFrontEndDefs diff --git a/lib/InternalBytecode/CMakeLists.txt b/lib/InternalBytecode/CMakeLists.txt index bd0fda5306f..f0105442f8d 100644 --- a/lib/InternalBytecode/CMakeLists.txt +++ b/lib/InternalBytecode/CMakeLists.txt @@ -14,7 +14,7 @@ else() set(hermesc_EXE hermesc) endif() -add_llvm_library(hermesInternalBytecode +add_hermes_library(hermesInternalBytecode InternalBytecode.cpp ) diff --git a/lib/Parser/CMakeLists.txt b/lib/Parser/CMakeLists.txt index 994902d6789..e586f7c8098 100644 --- a/lib/Parser/CMakeLists.txt +++ b/lib/Parser/CMakeLists.txt @@ -3,9 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS support) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_library(hermesParser +add_hermes_library(hermesParser JSLexer.cpp JSONParser.cpp JSParser.cpp diff --git a/lib/Platform/CMakeLists.txt b/lib/Platform/CMakeLists.txt index c4b97dfdaf1..405d20b17cb 100644 --- a/lib/Platform/CMakeLists.txt +++ b/lib/Platform/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_library(hermesPlatform +add_hermes_library(hermesPlatform Logging.cpp ) diff --git a/lib/Platform/Unicode/CMakeLists.txt b/lib/Platform/Unicode/CMakeLists.txt index 9d2ea619fa3..97d7ffa49ab 100644 --- a/lib/Platform/Unicode/CMakeLists.txt +++ b/lib/Platform/Unicode/CMakeLists.txt @@ -11,7 +11,7 @@ set(source_files ) if(HERMES_IS_ANDROID) - add_llvm_library(hermesPlatformUnicode STATIC ${source_files} + add_hermes_library(hermesPlatformUnicode STATIC ${source_files} LINK_LIBS hermesfbjni ${CORE_FOUNDATION} @@ -19,7 +19,7 @@ if(HERMES_IS_ANDROID) set_source_files_properties(PlatformUnicodeJava.cpp PROPERTIES COMPILE_FLAGS "-frtti -fexceptions -std=c++14") else() - add_llvm_library(hermesPlatformUnicode STATIC ${source_files} + add_hermes_library(hermesPlatformUnicode STATIC ${source_files} LINK_LIBS ${CORE_FOUNDATION} ) diff --git a/lib/Regex/CMakeLists.txt b/lib/Regex/CMakeLists.txt index 088db598f96..c6bedb0a60a 100644 --- a/lib/Regex/CMakeLists.txt +++ b/lib/Regex/CMakeLists.txt @@ -8,7 +8,7 @@ set(source_files Executor.cpp ) -add_llvm_library(hermesRegex +add_hermes_library(hermesRegex STATIC ${source_files} LINK_LIBS hermesPlatformUnicode ) diff --git a/lib/SourceMap/CMakeLists.txt b/lib/SourceMap/CMakeLists.txt index 093eb1c004f..9dfcf5f69f4 100644 --- a/lib/SourceMap/CMakeLists.txt +++ b/lib/SourceMap/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_library(hermesSourceMap +add_hermes_library(hermesSourceMap SourceMap.cpp SourceMapGenerator.cpp SourceMapParser.cpp diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt index df0600b8170..22bb5377db9 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -12,7 +12,7 @@ if (ANDROID) list(APPEND link_libs log) endif() -add_llvm_library(hermesSupport +add_hermes_library(hermesSupport Allocator.cpp Base64vlq.cpp CheckedMalloc.cpp diff --git a/lib/VM/CMakeLists.txt b/lib/VM/CMakeLists.txt index 7356c5d8711..330412f205c 100644 --- a/lib/VM/CMakeLists.txt +++ b/lib/VM/CMakeLists.txt @@ -120,7 +120,7 @@ set(jit_files JIT/ExternalCalls.cpp JIT/ExternalCalls.h ) -set(LLVM_OPTIONAL_SOURCES +set(HERMES_OPTIONAL_SOURCES gcs/FillerCell.cpp gcs/GenGC.cpp gcs/MallocGC.cpp @@ -199,7 +199,7 @@ if(HERMESVM_USE_JS_LIBRARY_IMPLEMENTATION) list(APPEND link_libs hermesInternalBytecode) endif() -add_llvm_library(hermesVMRuntime STATIC ${source_files} +add_hermes_library(hermesVMRuntime STATIC ${source_files} LINK_LIBS ${link_libs} ) diff --git a/lib/VM/Instrumentation/CMakeLists.txt b/lib/VM/Instrumentation/CMakeLists.txt index 87674455e60..66e5035c226 100644 --- a/lib/VM/Instrumentation/CMakeLists.txt +++ b/lib/VM/Instrumentation/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_library(hermesInstrumentation +add_hermes_library(hermesInstrumentation STATIC PerfEventsLinux.cpp ProcessStats.cpp diff --git a/public/hermes/Public/CtorConfig.h b/public/hermes/Public/CtorConfig.h index 50f20db7a85..540f5070651 100644 --- a/public/hermes/Public/CtorConfig.h +++ b/public/hermes/Public/CtorConfig.h @@ -30,14 +30,14 @@ /// /// We can do so with the following declaration: /// -/// #define FIELDS(F) \ -/// F(int, A) \ -/// F(int, B, 42) \ -/// F(std::string, C, "hello") -/// -/// _HERMES_CTORCONFIG_STRUCT(Foo, FIELDS, { -/// A_ = std::min(A_, C_.length()); -/// }); +/// " #define FIELDS(F) \ " +/// " F(int, A) \ " +/// " F(int, B, 42) \ " +/// " F(std::string, C, "hello") " +/// " " +/// " _HERMES_CTORCONFIG_STRUCT(Foo, FIELDS, { " +/// " A_ = std::min(A_, C_.length()); " +/// " }); " /// /// N.B. /// - The definition of A does not mention any value -- meaning it is diff --git a/tools/hbc-attribute/CMakeLists.txt b/tools/hbc-attribute/CMakeLists.txt index 84bb9f5a3df..a78e33e0bcb 100644 --- a/tools/hbc-attribute/CMakeLists.txt +++ b/tools/hbc-attribute/CMakeLists.txt @@ -3,13 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(hbc-attribute +add_hermes_tool(hbc-attribute hbc-attribute.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/hbc-deltaprep/CMakeLists.txt b/tools/hbc-deltaprep/CMakeLists.txt index d0b029d43cc..50c09859494 100644 --- a/tools/hbc-deltaprep/CMakeLists.txt +++ b/tools/hbc-deltaprep/CMakeLists.txt @@ -3,13 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(hbc-deltaprep +add_hermes_tool(hbc-deltaprep hbc-deltaprep.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/hbc-diff/CMakeLists.txt b/tools/hbc-diff/CMakeLists.txt index 0c6bb83edd6..15965d3e2e9 100644 --- a/tools/hbc-diff/CMakeLists.txt +++ b/tools/hbc-diff/CMakeLists.txt @@ -3,13 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(hbc-diff +add_hermes_tool(hbc-diff hbc-diff.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/hbcdump/CMakeLists.txt b/tools/hbcdump/CMakeLists.txt index b79e393a9e4..890a87852be 100644 --- a/tools/hbcdump/CMakeLists.txt +++ b/tools/hbcdump/CMakeLists.txt @@ -3,13 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(hbcdump +add_hermes_tool(hbcdump hbcdump.cpp HBCParser.cpp ProfileAnalyzer.cpp diff --git a/tools/hdb/CMakeLists.txt b/tools/hdb/CMakeLists.txt index e94e414aa4a..e0095996c93 100644 --- a/tools/hdb/CMakeLists.txt +++ b/tools/hdb/CMakeLists.txt @@ -5,9 +5,9 @@ include_directories(${HERMES_SOURCE_DIR}/API) include_directories(${HERMES_JSI_DIR}) -set(LLVM_REQUIRES_EH ON) -set(LLVM_REQUIRES_RTTI ON) -add_llvm_tool(hdb +set(HERMES_ENABLE_EH ON) +set(HERMES_ENABLE_RTTI ON) +add_hermes_tool(hdb hdb.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/hermes/CMakeLists.txt b/tools/hermes/CMakeLists.txt index bf872aeb89b..847d434965d 100644 --- a/tools/hermes/CMakeLists.txt +++ b/tools/hermes/CMakeLists.txt @@ -3,13 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(hermes +add_hermes_tool(hermes hermes.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/hermesc/CMakeLists.txt b/tools/hermesc/CMakeLists.txt index 9c069220016..da0993dd840 100644 --- a/tools/hermesc/CMakeLists.txt +++ b/tools/hermesc/CMakeLists.txt @@ -3,13 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(hermesc +add_hermes_tool(hermesc hermesc.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/hvm-bench/CMakeLists.txt b/tools/hvm-bench/CMakeLists.txt index 234a5c459d3..409b9630521 100644 --- a/tools/hvm-bench/CMakeLists.txt +++ b/tools/hvm-bench/CMakeLists.txt @@ -3,13 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(interp-dispatch-bench +add_hermes_tool(interp-dispatch-bench interp-dispatch-bench.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/hvm/CMakeLists.txt b/tools/hvm/CMakeLists.txt index 7c6f1babf8a..bc10a2d28e6 100644 --- a/tools/hvm/CMakeLists.txt +++ b/tools/hvm/CMakeLists.txt @@ -3,13 +3,9 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(hvm +add_hermes_tool(hvm hvm.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/jsi/CMakeLists.txt b/tools/jsi/CMakeLists.txt index d523e7aa024..319a622a78b 100644 --- a/tools/jsi/CMakeLists.txt +++ b/tools/jsi/CMakeLists.txt @@ -6,20 +6,14 @@ include_directories(${HERMES_SOURCE_DIR}/API) include_directories(${HERMES_JSI_DIR}) -add_llvm_tool(hermes-jsi +set(HERMES_ENABLE_EH ON) +set(CXX_STANDARD 14) +set(CXX_STANDARD_REQUIRED ON) + +add_hermes_tool(hermes-jsi jsi.cpp ${ALL_HEADER_FILES} + LINK_LIBS hermesapi ) -set_target_properties(hermes-jsi PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - ) -set_property(TARGET hermes-jsi APPEND_STRING PROPERTY - COMPILE_FLAGS " -fexceptions" - ) - -target_link_libraries(hermes-jsi - hermesapi - ) diff --git a/tools/repl/CMakeLists.txt b/tools/repl/CMakeLists.txt index 9a86f42d86d..594640ee18c 100644 --- a/tools/repl/CMakeLists.txt +++ b/tools/repl/CMakeLists.txt @@ -15,13 +15,9 @@ configure_file(ReplConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/ReplConfig.h include_directories(${CMAKE_CURRENT_BINARY_DIR}) -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) -add_llvm_tool(hermes-repl +add_hermes_tool(hermes-repl repl.cpp ${ALL_HEADER_FILES} ) diff --git a/tools/synth/CMakeLists.txt b/tools/synth/CMakeLists.txt index f37bc4d1d55..f1e421f0aa6 100644 --- a/tools/synth/CMakeLists.txt +++ b/tools/synth/CMakeLists.txt @@ -3,7 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -add_llvm_tool(synth +add_hermes_tool(synth synth.cpp ) diff --git a/unittests/API/CMakeLists.txt b/unittests/API/CMakeLists.txt index 7f7eaaa12b5..96171d996b0 100644 --- a/unittests/API/CMakeLists.txt +++ b/unittests/API/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # When compiling multiple libraries, put this here so that we can use a file in # not all the libraries. -set(LLVM_OPTIONAL_SOURCES +set(HERMES_OPTIONAL_SOURCES APITest.cpp APITestFactory.cpp APILeanTest.cpp @@ -20,17 +20,14 @@ set(LLVM_OPTIONAL_SOURCES TrackIOTest.cpp ) -set(LLVM_LINK_COMPONENTS - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) # Build SegmentTestCompile without EH and RTTI -add_llvm_library(SegmentTestCompile STATIC SegmentTestCompile.cpp) +add_hermes_library(SegmentTestCompile STATIC SegmentTestCompile.cpp) # Turn on EH and RTTI for APITests -set(LLVM_REQUIRES_EH ON) -set(LLVM_REQUIRES_RTTI ON) +set(HERMES_ENABLE_EH ON) +set(HERMES_ENABLE_RTTI ON) # For some reason (bug?) add_unittest() is clearing LLVM_REQUIRES_RTTI, so # we need to set this one. set(LLVM_ENABLE_RTTI ON) diff --git a/unittests/AST/CMakeLists.txt b/unittests/AST/CMakeLists.txt index 4f6fb012e49..26fb7580c2d 100644 --- a/unittests/AST/CMakeLists.txt +++ b/unittests/AST/CMakeLists.txt @@ -3,10 +3,6 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Core - ) - set(ASTSources JSONTest.cpp ESTreeTest.cpp diff --git a/unittests/BCGen/CMakeLists.txt b/unittests/BCGen/CMakeLists.txt index b0290946c95..aa569661656 100644 --- a/unittests/BCGen/CMakeLists.txt +++ b/unittests/BCGen/CMakeLists.txt @@ -3,11 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) set(BCSources BytecodeFileFormatTest.cpp diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 865a3d66353..17e85137628 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -8,9 +8,9 @@ set_target_properties(HermesUnitTests PROPERTIES FOLDER "Tests") function(add_hermes_unittest test_dirname) add_unittest(HermesUnitTests ${test_dirname} ${ARGN}) - # gtest uses LLVMSupport, so LLVMSupport needs to be listed after gtest on + # gtest uses LLVHSupport, so LLVHSupport needs to be listed after gtest on # the link line. - target_link_libraries(${test_dirname} LLVMSupport) + target_link_libraries(${test_dirname} LLVHSupport) target_compile_definitions(${test_dirname} PUBLIC UNIT_TEST) endfunction() diff --git a/unittests/IR/CMakeLists.txt b/unittests/IR/CMakeLists.txt index f46dde11f42..b707b356d71 100644 --- a/unittests/IR/CMakeLists.txt +++ b/unittests/IR/CMakeLists.txt @@ -3,11 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) set(IRSources BasicBlockTest.cpp diff --git a/unittests/Parser/CMakeLists.txt b/unittests/Parser/CMakeLists.txt index b42f1c99fb1..2b100842c25 100644 --- a/unittests/Parser/CMakeLists.txt +++ b/unittests/Parser/CMakeLists.txt @@ -3,10 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) set(ParserSources JSLexerTest.cpp diff --git a/unittests/VMRuntime/CMakeLists.txt b/unittests/VMRuntime/CMakeLists.txt index b4e2b4dc61e..eb7400c7c95 100644 --- a/unittests/VMRuntime/CMakeLists.txt +++ b/unittests/VMRuntime/CMakeLists.txt @@ -3,11 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) set(RTSources AlignedHeapSegmentTest.cpp diff --git a/unittests/VMRuntime/JIT/CMakeLists.txt b/unittests/VMRuntime/JIT/CMakeLists.txt index ab19ab1839d..02f3efc2a89 100644 --- a/unittests/VMRuntime/JIT/CMakeLists.txt +++ b/unittests/VMRuntime/JIT/CMakeLists.txt @@ -3,11 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -set(LLVM_LINK_COMPONENTS - Analysis - Core - Support - ) +set(HERMES_LINK_COMPONENTS LLVHSupport) set(JITSources ExecHeapTest.cpp diff --git a/utils/build/build_llvm.py b/utils/build/build_llvm.py deleted file mode 100755 index 154cb7d1d65..00000000000 --- a/utils/build/build_llvm.py +++ /dev/null @@ -1,211 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -from __future__ import absolute_import, division, print_function, unicode_literals - -import os -import platform -import subprocess -import sys - -from common import ( - build_dir_suffix, - common_cmake_flags, - get_parser, - is_visual_studio, - run_command, - which, -) - - -# It references the commit day so we can shallow clone -# and still manage to checkout this specific revision. -# NOTE: The revision date must be before the actual -# commit date. -_LLVM_REV = "c179d7b006348005d2da228aed4c3c251590baa3" -_LLVM_REV_DATE = "2018-10-07" - - -def parse_args(): - parser = get_parser() - parser.add_argument("llvm_src_dir", type=str, nargs="?", default="llvm") - parser.add_argument("llvm_build_dir", type=str, nargs="?", default="llvm_build") - parser.add_argument("--target", "-t", action="append", default=[]) - args = parser.parse_args() - args.llvm_src_dir = os.path.realpath(args.llvm_src_dir) - args.llvm_build_dir = os.path.realpath(args.llvm_build_dir) - args.build_type = args.build_type or ("MinSizeRel" if args.distribute else "Debug") - args.llvm_build_dir += build_dir_suffix(args) - return args - - -def build_git_command(http_proxy): - # Otherwise, trust that the user has git on the path. - command = [which("git")] - if http_proxy: - command += ["-c", "http.proxy={}".format(http_proxy)] - if platform.system() == "Windows": - command += ["-c", "core.filemode=false"] - command += ["-c", "core.autocrlf=false"] - return command - - -def clone_and_patch_llvm(args): - git = build_git_command(args.http_proxy) - if not os.path.exists(args.llvm_src_dir): - # If the directory doesn't exist, clone LLVM there. - print("Cloning LLVM into {}".format(args.llvm_src_dir)) - run_command( - git - + [ - "clone", - "--shallow-since", - _LLVM_REV_DATE, - "https://github.com/llvm-mirror/llvm.git", - args.llvm_src_dir, - ], - retries=3, - ) - - # Checkout a specific revision in LLVM. - run_command(git + ["checkout", _LLVM_REV], cwd=args.llvm_src_dir) - - # Check that the respository is clean. - try: - run_command(git + ["diff-index", "--quiet", "HEAD"], cwd=args.llvm_src_dir) - except subprocess.CalledProcessError: - raise Exception("llvm dir is dirty (contains uncommitted changes)") - - # Apply small edits to LLVM from patch files. - run_command( - git - + [ - "apply", - "--ignore-space-change", - "--ignore-whitespace", - os.path.join( - os.path.dirname(os.path.realpath(__file__)), - "llvm-changes-for-hermes.patch", - ), - ], - cwd=args.llvm_src_dir, - ) - - # Commit the patch. - run_command( - git - + [ - "-c", - "user.name=nobody", - "-c", - "user.email='nobody@example.com'", - "commit", - "-a", - "-m", - "Patch by Hermes build script", - ], - cwd=args.llvm_src_dir, - ) - - -def main(): - args = parse_args() - - print("Source Dir: {}".format(args.llvm_src_dir)) - print("Using Build system: {}".format(args.build_system)) - print("Build Dir: {}".format(args.llvm_build_dir)) - print("Build Type: {}".format(args.build_type)) - - clone_and_patch_llvm(args) - - cmake_flags = ( - args.cmake_flags.split() - + common_cmake_flags() - + ["-DLLVM_TARGETS_TO_BUILD=", "-DCMAKE_BUILD_TYPE={}".format(args.build_type)] - ) - if args.is_32_bit: - cmake_flags += ["-DLLVM_BUILD_32_BITS=On"] - if platform.system() == "Windows": - if platform.machine().endswith("64") and is_visual_studio(args.build_system): - cmake_flags += ["-Thost=x64"] - cmake_flags += ["-DLLVM_INCLUDE_EXAMPLES=Off"] - if args.enable_asan: - cmake_flags += ["-DLLVM_USE_SANITIZER=Address"] - cmake_flags += ["-DLLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO=Off"] - - if args.target_platform.startswith("iphone"): - cmake_flags += [ - "-DCMAKE_C_FLAGS=-miphoneos-version-min=8.0", - "-DCMAKE_CXX_FLAGS=-miphoneos-version-min=8.0", - "-DCMAKE_TOOLCHAIN_FILE={}".format( - os.path.join(args.llvm_src_dir, "cmake", "platforms", "iOS.cmake") - ), - "-DLLVM_BUILD_RUNTIME=Off", - "-DLLVM_INCLUDE_TESTS=Off", - "-DLLVM_INCLUDE_EXAMPLES=Off", - "-DLLVM_ENABLE_BACKTRACES=Off", - "-DLLVM_INCLUDE_UTILS=Off", - "-DLLVM_ENABLE_TERMINFO=Off", - ] - if args.target_platform == "iphoneos": - cmake_flags += ["-DCMAKE_OSX_ARCHITECTURES=armv7;arm64"] - elif args.target_platform == "iphonesimulator": - xcode_sysroot = subprocess.check_output( - [which("xcodebuild"), "-version", "-sdk", "iphonesimulator", "Path"] - ) - cmake_flags += [ - "-DCMAKE_OSX_ARCHITECTURES=x86_64", - "-DCMAKE_OSX_SYSROOT={}".format(xcode_sysroot), - ] - elif args.target_platform == "macosx": - cmake_flags += [ - "-DCMAKE_C_FLAGS=-mmacosx-version-min=10.9", - "-DCMAKE_CXX_FLAGS=-mmacosx-version-min=10.9", - ] - - try: - os.mkdir(args.llvm_build_dir) - except OSError: - # It's alright if the file already exists. - pass - - print("CMake flags: {}".format(" ".join(cmake_flags))) - cmake = which("cmake") - # Print the CMake version to assist in diagnosing issues. - print( - "CMake version:\n{}".format( - subprocess.check_output([cmake, "--version"], stderr=subprocess.STDOUT) - ) - ) - - run_command( - [cmake, "-G", args.build_system, args.llvm_src_dir] + cmake_flags, - env=os.environ, - cwd=args.llvm_build_dir, - ) - # MSBuild needs retries to handle an unexplainable linker error: LNK1000. - # Retry the build in case of failures. - tries = 3 - for i in range(tries): - try: - build_cmd = [cmake, "--build", args.llvm_build_dir] - for target in args.target: - build_cmd += ["--target", target] - if args.distribute and is_visual_studio(args.build_system): - build_cmd += ["--config", "Release"] - run_command(build_cmd, env=os.environ) - break - except subprocess.CalledProcessError as e: - if i == tries - 1: - # If all retries failed, re-throw the last exception - raise - else: - print("Exec failed: {}\nRetrying...".format(str(e))) - continue - - -if __name__ == "__main__": - main() diff --git a/utils/build/configure.py b/utils/build/configure.py index acb8e91c381..45bc0b5a407 100755 --- a/utils/build/configure.py +++ b/utils/build/configure.py @@ -79,13 +79,14 @@ def main(): args.cmake_flags.split() + common_cmake_flags() + [ - "-DLLVM_BUILD_DIR=" + args.llvm_build_dir, - "-DLLVM_SRC_DIR=" + args.llvm_src_dir, - "-DCMAKE_BUILD_TYPE=" + args.build_type, + # "-DLLVM_BUILD_DIR=" + args.llvm_build_dir, + # "-DLLVM_SRC_DIR=" + args.llvm_src_dir, + "-DCMAKE_BUILD_TYPE=" + + args.build_type ] ) - if args.is_32_bit: - cmake_flags += ["-DLLVM_BUILD_32_BITS=On"] + # if args.is_32_bit: + # cmake_flags += ["-DLLVM_BUILD_32_BITS=On"] if ( platform.system() == "Windows" @@ -93,10 +94,10 @@ def main(): and is_visual_studio(args.build_system) ): cmake_flags += ["-Thost=x64"] - if not args.distribute: - cmake_flags += ["-DLLVM_ENABLE_ASSERTIONS=On"] - if args.enable_asan: - cmake_flags += ["-DLLVM_USE_SANITIZER=Address"] + # if not args.distribute: + # cmake_flags += ["-DLLVM_ENABLE_ASSERTIONS=On"] + # if args.enable_asan: + # cmake_flags += ["-DLLVM_USE_SANITIZER=Address"] if args.opcode_stats: cmake_flags += ["-DHERMESVM_PROFILER_OPCODE=On"] if args.basic_block_profiler: diff --git a/utils/crosscompile_llvm.sh b/utils/crosscompile_llvm.sh deleted file mode 100755 index 6bcd7ba1342..00000000000 --- a/utils/crosscompile_llvm.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -set -e - -die() { - echo "$*" - exit 1 -} - -[ -n "$HERMES_WS_DIR" ] || die "HERMES_WS_DIR unset" -cd "$HERMES_WS_DIR" - -[ -d "$ANDROID_NDK" ] || - die "Android NDK does not exist (\$ANDROID_NDK=$ANDROID_NDK)" - -[ -d "$ANDROID_SDK" ] || - die "Android SDK does not exist (\$ANDROID_SDK=$ANDROID_SDK)" - -[ -d "hermes/" ] || die "Can't find hermes/ in $PWD" -[ -d "llvm/" ] || die "Can't find llvm/ in $PWD" -[ -d "llvm_build/" ] || die "Can't find llvm_build. Did you build_llvm.py?" - -if [ ! -e 'llvm/hermes' ] -then - ( - cd llvm - git apply ../hermes/android/cross-compile/llvm.patch - echo "Patched by $0" > hermes - ) -fi - -for abi in "armeabi-v7a" "arm64-v8a" "x86_64" "x86" -do - ( - mkdir -p "llvm-$abi" - cd "llvm-$abi" - # shellcheck disable=SC2191 # Allow literal = in array elements - cmd=( - cmake -G Ninja "$HERMES_WS_DIR/llvm" - -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" - -DCMAKE_CXX_FLAGS="-fvisibility=hidden" - -DANDROID_PLATFORM="android-16" - -DANDROID_ABI="$abi" - -DANDROID_NDK="$ANDROID_NDK" - -DANDROID_STL="c++_shared" - -DANDROID_PIE="True" - -DLLVM_TARGETS_TO_BUILD= - -DCMAKE_BUILD_TYPE=MinSizeRel - -DLLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO=Off - -DLLVM_TABLEGEN="$HERMES_WS_DIR/llvm_build/bin/llvm-tblgen" - ) - - printf '%q ' "${cmd[@]}" - echo - "${cmd[@]}" - - # The build does not complete successfully, - # so just build what we need for now. - ninja libLLVM{Analysis,Core,Support,Demangle,Object}.a - ) -done - diff --git a/utils/hermes-lit/CMakeLists.txt b/utils/hermes-lit/CMakeLists.txt new file mode 100644 index 00000000000..e031cb484f8 --- /dev/null +++ b/utils/hermes-lit/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# If we have a multi-configuration build system, we create a copy of llvm-lit in +# every directory. +if (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") + foreach (BUILD_MODE ${CMAKE_CONFIGURATION_TYPES}) + string(REPLACE ${CMAKE_CFG_INTDIR} ${BUILD_MODE} bi ${HERMES_LIT_PATH}) + configure_file( + hermes-lit.in + ${bi} + ) + endforeach () +else () + set(BUILD_MODE "${CMAKE_BUILD_MODE}") + configure_file( + hermes-lit.in + ${HERMES_LIT_PATH} + ) +endif () diff --git a/utils/hermes-lit/hermes-lit.in b/utils/hermes-lit/hermes-lit.in new file mode 100755 index 00000000000..9c4ba5b3f5a --- /dev/null +++ b/utils/hermes-lit/hermes-lit.in @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import os +import sys + +# Make sure we can find the lit package. +sys.path.insert(0, os.path.join("@LLVH_SOURCE_DIR@", 'utils', 'lit')) + +if __name__=='__main__': + from lit.main import main + main({})