From a760fde7530e71989a235432ad9d66154cfc06e9 Mon Sep 17 00:00:00 2001 From: "Jesse L. Zamora" Date: Sun, 22 Jun 2025 13:29:15 -0400 Subject: [PATCH 1/3] Remove cross-compile patch for Swift - Not needed when building with cmake, it can be added again if building with build-script --- recipes-devtools/swift/swift-stdlib.bb | 1 - .../PR75367-buildbot-cross-compile.diff | 204 ------------------ 2 files changed, 205 deletions(-) delete mode 100644 recipes-devtools/swift/swift-stdlib/PR75367-buildbot-cross-compile.diff diff --git a/recipes-devtools/swift/swift-stdlib.bb b/recipes-devtools/swift/swift-stdlib.bb index 8dcbdab..7ba7039 100644 --- a/recipes-devtools/swift/swift-stdlib.bb +++ b/recipes-devtools/swift/swift-stdlib.bb @@ -17,7 +17,6 @@ SRC_URI = "\ git://github.com/swiftlang/swift-experimental-string-processing.git;protocol=https;name=stringproc;tag=swift-${SWIFT_VERSION}-RELEASE;nobranch=1;destsuffix=swift-experimental-string-processing; \ git://github.com/swiftlang/swift-syntax.git;protocol=https;name=syntax;tag=swift-${SWIFT_VERSION}-RELEASE;nobranch=1;destsuffix=swift-syntax; \ file://llvm-cmake-modules \ - file://PR75367-buildbot-cross-compile.diff \ " S = "${WORKDIR}/swift" diff --git a/recipes-devtools/swift/swift-stdlib/PR75367-buildbot-cross-compile.diff b/recipes-devtools/swift/swift-stdlib/PR75367-buildbot-cross-compile.diff deleted file mode 100644 index 57a39a5..0000000 --- a/recipes-devtools/swift/swift-stdlib/PR75367-buildbot-cross-compile.diff +++ /dev/null @@ -1,204 +0,0 @@ -From 90cf1f6c6da49d60539b6c499f75deada2ce0fe9 Mon Sep 17 00:00:00 2001 -From: "Jesse L. Zamora" -Date: Thu, 18 Jul 2024 21:20:11 -0400 -Subject: [PATCH 1/5] Add patch for cross compiling using swift build scripts - ---- - .../swift_build_support/swift_build_support/products/product.py | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/utils/swift_build_support/swift_build_support/products/product.py b/utils/swift_build_support/swift_build_support/products/product.py -index ababc351f95ee..f664bc38bb2cc 100644 ---- a/utils/swift_build_support/swift_build_support/products/product.py -+++ b/utils/swift_build_support/swift_build_support/products/product.py -@@ -373,7 +373,7 @@ def get_linux_target_components(self, arch): - def get_linux_sysroot(self, platform, arch): - if not self.is_cross_compile_target('{}-{}'.format(platform, arch)): - return None -- sysroot_arch, abi = self.get_linux_target_components(arch) -+ sysroot_arch, _, abi = self.get_linux_target_components(arch) - # $ARCH-$PLATFORM-$ABI - # E.x.: aarch64-linux-gnu - sysroot_dirname = '{}-{}-{}'.format(sysroot_arch, platform, abi) - -From 2e3bde3d3dcf8c7104bfb331b51b64659818a4e7 Mon Sep 17 00:00:00 2001 -From: "Jesse L. Zamora" -Date: Thu, 18 Jul 2024 21:20:32 -0400 -Subject: [PATCH 2/5] Add patch for CXX interop when cross compiling with - external sysroot - ---- - cmake/modules/SwiftConfigureSDK.cmake | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/cmake/modules/SwiftConfigureSDK.cmake b/cmake/modules/SwiftConfigureSDK.cmake -index 2b7dbbdbb801a..81cc831a418ba 100644 ---- a/cmake/modules/SwiftConfigureSDK.cmake -+++ b/cmake/modules/SwiftConfigureSDK.cmake -@@ -360,7 +360,7 @@ macro(configure_sdk_unix name architectures) - # depending on the architecture, so having a single value is the only - # possibility right now. - set(SWIFT_SDK_${prefix}_CXX_OVERLAY_SWIFT_COMPILE_FLAGS -- -Xcc --gcc-toolchain=/usr -+ -Xcc --gcc-toolchain=${CMAKE_SYSROOT}/usr - CACHE STRING "Extra flags for compiling the C++ overlay") - - set(_default_threading_package "pthreads") - -From b9615d81134f718103e926d7d509207999a7ab6d Mon Sep 17 00:00:00 2001 -From: "Jesse L. Zamora" -Date: Thu, 18 Jul 2024 21:21:18 -0400 -Subject: [PATCH 3/5] Add build preset for cross compiling for linux-armv7 with - external sysroot - ---- - utils/build-presets.ini | 71 +++++++++++++++++++++++++++++++++++++++++ - utils/build-script-impl | 4 +++ - 2 files changed, 75 insertions(+) - -diff --git a/utils/build-presets.ini b/utils/build-presets.ini -index 2e83a50dbbe9a..0e724fc9edb0e 100644 ---- a/utils/build-presets.ini -+++ b/utils/build-presets.ini -@@ -1092,6 +1092,77 @@ lit-args=-v - indexstore-db=0 - sourcekit-lsp=0 - -+[preset: buildbot_linux_crosscompile_armv7,llvm] -+release -+reconfigure -+ -+# Disable features -+build-swift-tools=0 -+ -+# Skip rules -+skip-build-cmark -+skip-early-swift-driver -+skip-early-swiftsyntax -+skip-build-llvm -+skip-build-swift -+ -+build-subdir=buildbot_linux_armv7 -+ -+[preset: buildbot_linux_crosscompile_armv7,stdlib,corelibs] -+mixin-preset=stdlib_base_standalone -+release -+reconfigure -+ -+install-swift -+install-swiftsyntax -+foundation -+libdispatch -+xctest -+install-foundation -+install-libdispatch -+install-xctest -+ -+# NOTE: Backtracing does not cross compile for armv7 currently -+swift-enable-backtracing=0 -+swift-stdlib-supports-backtrace-reporting=0 -+ -+swift-install-components=autolink-driver;compiler;clang-builtin-headers;libexec;stdlib;swift-remote-mirror;sdk-overlay;dev -+build-swift-static-stdlib -+build-swift-static-sdk-overlay -+ -+# Cross compilation -+skip-local-build -+cross-compile-hosts=linux-armv7 -+cross-compile-deps-path=%(sysroot)s -+cross-compile-append-host-target-to-destdir=False -+ -+build-subdir=buildbot_linux_armv7 -+ -+# Custom flags for cross compilation -+extra-cmake-options= -+ -DCMAKE_SYSROOT=%(sysroot)s -+ -DCMAKE_C_FLAGS="-w -fuse-ld=lld -target armv7-unknown-linux-gnueabihf --sysroot=%(sysroot)s" -+ -DCMAKE_CXX_FLAGS="-w -fuse-ld=lld -target armv7-unknown-linux-gnueabihf --sysroot=%(sysroot)s" -+ -DCMAKE_ASM_FLAGS="-target armv7-unknown-linux-gnueabihf --sysroot=%(sysroot)s" -+ -+# Set Swift flags to cross compile deps for armv7 -+common-swift-flags="-use-ld=lld -target armv7-unknown-linux-gnueabihf -resource-dir %(workspace_dir)s/build/buildbot_linux_armv7/swift-linux-armv7/lib/swift -sdk %(sysroot)s" -+ -+# Use lld for building Swift, set extra flags and sysroot paths -+swift-cmake-options= -+ -DSWIFT_USE_LINKER=lld -+ -DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=ON -+ -DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=ON -+ -DSWIFT_SDK_LINUX_ARCH_armv7_PATH=%(sysroot)s -+ -+install-prefix=/usr -+ -+# Path to the root of the installation filesystem. -+install-destdir=%(install_destdir)s -+ -+# Path to the .tar.gz package we would create. -+installable-package=%(installable_package)s -+ - [preset: buildbot_linux_armv7] - release - llbuild -diff --git a/utils/build-script-impl b/utils/build-script-impl -index 902fc8e7518c1..df8af112c36fa 100755 ---- a/utils/build-script-impl -+++ b/utils/build-script-impl -@@ -1465,6 +1465,10 @@ function common_swift_flags() { - echo "error: a module cache path has not been set" - exit 1 - fi -+ -+ # Remove quotes from COMMON_SWIFT_FLAGS before using it -+ COMMON_SWIFT_FLAGS=`echo ${COMMON_SWIFT_FLAGS} | xargs` -+ - echo -n "${SWIFT_FLAGS[@]} ${COMMON_SWIFT_FLAGS} -module-cache-path \"${module_cache}\" " - } - - -From 417c40a83230ce98d45b8041e835c378452aa4cf Mon Sep 17 00:00:00 2001 -From: "Jesse L. Zamora" -Date: Fri, 19 Jul 2024 14:14:02 -0400 -Subject: [PATCH 4/5] Add default preset for sysroot param - ---- - utils/build_swift/tests/build_swift/test_presets.py | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/utils/build_swift/tests/build_swift/test_presets.py b/utils/build_swift/tests/build_swift/test_presets.py -index 495d8aa99812f..98bf476ec993a 100644 ---- a/utils/build_swift/tests/build_swift/test_presets.py -+++ b/utils/build_swift/tests/build_swift/test_presets.py -@@ -44,6 +44,7 @@ - 'ndk_path': '/path/to/ndk', - 'arm_dir': '/path/to/arm', - 'toolchain_path': '/tmp/toolchain', -+ 'sysroot': '/path/to/sysroot' - } - - SAMPLE_PRESET = """ - -From eacaa7ed4ad6c2b710a5f76be132391153e87ce9 Mon Sep 17 00:00:00 2001 -From: "Jesse L. Zamora" -Date: Fri, 19 Jul 2024 14:31:00 -0400 -Subject: [PATCH 5/5] Add missing Swift modules to armv7 build through cmake - flags - ---- - utils/build-presets.ini | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/utils/build-presets.ini b/utils/build-presets.ini -index 0e724fc9edb0e..a654c2b6d262a 100644 ---- a/utils/build-presets.ini -+++ b/utils/build-presets.ini -@@ -1153,6 +1153,11 @@ swift-cmake-options= - -DSWIFT_USE_LINKER=lld - -DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=ON - -DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=ON -+ -DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=ON -+ -DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=ON -+ -DSWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES=ON -+ -DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION=ON -+ -DSWIFT_ENABLE_SYNCHRONIZATION=ON - -DSWIFT_SDK_LINUX_ARCH_armv7_PATH=%(sysroot)s - - install-prefix=/usr From 3ba234d8d0e239783f0803f8e291be7501802bbb Mon Sep 17 00:00:00 2001 From: "Jesse L. Zamora" Date: Sun, 22 Jun 2025 15:05:18 -0400 Subject: [PATCH 2/3] Remove llvm cmake files, instead grab llvm-project and configure it - We point LLVM_DIR to the build directory for those llvm cmake files. --- recipes-devtools/swift/swift-stdlib.bb | 22 +- .../llvm-cmake-modules/AddLLVM.cmake | 2494 ----------------- .../CheckCompilerVersion.cmake | 110 - .../CheckProblematicConfigurations.cmake | 19 - .../llvm-cmake-modules/CrossCompile.cmake | 134 - .../DetermineGCCCompatible.cmake | 13 - .../HandleLLVMOptions.cmake | 1419 ---------- .../llvm-cmake-modules/HandleLLVMStdlib.cmake | 54 - .../llvm-cmake-modules/LLVM-Config.cmake | 350 --- .../LLVMCheckLinkerFlag.cmake | 28 - .../llvm-cmake-modules/LLVMConfig.cmake | 144 - .../llvm-cmake-modules/LLVMConfig.cmake.in | 170 -- .../LLVMConfigExtensions.cmake | 1 - .../LLVMDistributionSupport.cmake | 291 -- .../LLVMExports-release.cmake | 9 - .../llvm-cmake-modules/LLVMExports.cmake | 90 - .../LLVMExternalProjectUtils.cmake | 405 --- .../LLVMInstallSymlink.cmake | 26 - .../LLVMProcessSources.cmake | 122 - .../llvm-cmake-modules/SetTargetTriple.cmake | 13 - .../llvm-cmake-modules/TableGen.cmake | 216 -- 21 files changed, 17 insertions(+), 6113 deletions(-) delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/AddLLVM.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CheckCompilerVersion.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CheckProblematicConfigurations.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CrossCompile.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/DetermineGCCCompatible.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/HandleLLVMOptions.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/HandleLLVMStdlib.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVM-Config.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMCheckLinkerFlag.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfig.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfig.cmake.in delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfigExtensions.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMDistributionSupport.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExports-release.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExports.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExternalProjectUtils.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMInstallSymlink.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMProcessSources.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/SetTargetTriple.cmake delete mode 100644 recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/TableGen.cmake diff --git a/recipes-devtools/swift/swift-stdlib.bb b/recipes-devtools/swift/swift-stdlib.bb index 7ba7039..be8ca75 100644 --- a/recipes-devtools/swift/swift-stdlib.bb +++ b/recipes-devtools/swift/swift-stdlib.bb @@ -12,11 +12,11 @@ PV = "${SWIFT_VERSION}+git${SRCPV}" SRCREV_FORMAT = "swift_libdispatch_stringproc_syntax" SRC_URI = "\ + git://github.com/swiftlang/llvm-project.git;protocol=https;name=llvm-project;tag=swift-${SWIFT_VERSION}-RELEASE;nobranch=1;destsuffix=llvm-project; \ git://github.com/swiftlang/swift.git;protocol=https;name=swift;tag=swift-${SWIFT_VERSION}-RELEASE;nobranch=1;destsuffix=swift; \ git://github.com/swiftlang/swift-corelibs-libdispatch.git;protocol=https;name=libdispatch;tag=swift-${SWIFT_VERSION}-RELEASE;nobranch=1;destsuffix=libdispatch; \ git://github.com/swiftlang/swift-experimental-string-processing.git;protocol=https;name=stringproc;tag=swift-${SWIFT_VERSION}-RELEASE;nobranch=1;destsuffix=swift-experimental-string-processing; \ git://github.com/swiftlang/swift-syntax.git;protocol=https;name=syntax;tag=swift-${SWIFT_VERSION}-RELEASE;nobranch=1;destsuffix=swift-syntax; \ - file://llvm-cmake-modules \ " S = "${WORKDIR}/swift" @@ -46,6 +46,8 @@ addtask fix_gcc_install_dir before do_configure after do_prepare_recipe_sysroot do_configure() { export SDKROOT=${STAGING_DIR_TARGET} + export LLVM_SRCDIR=${WORKDIR}/llvm-project + export LLVM_BUILDDIR=${LLVM_SRCDIR}/build export SWIFT_SRCDIR=${S} export SWIFT_NATIVE_PATH=${STAGING_DIR_NATIVE}/usr/bin export CC=${STAGING_DIR_NATIVE}/usr/bin/clang @@ -54,8 +56,18 @@ do_configure() { export CXX=${STAGING_DIR_NATIVE}/usr/bin/clang++ export CXXFLAGS="${SWIFT_CXX_FLAGS}" - mkdir -p ${HOST_LLVM_PATH}/cmake/llvm - cp ${WORKDIR}/llvm-cmake-modules/* ${HOST_LLVM_PATH}/cmake/llvm + rm -rf ${LLVM_BUILDDIR} + mkdir -p ${LLVM_BUILDDIR} + + # Configure the llvm project to get the cmake files generated, so we can point + # LLVM_DIR to this folder + cmake -S ${LLVM_SRCDIR}/llvm -B ${LLVM_BUILDDIR} -G Ninja \ + -DCMAKE_INSTALL_PREFIX=${STAGING_DIR_NATIVE}/usr/lib \ + -DCMAKE_C_COMPILER=${SWIFT_NATIVE_PATH}/clang \ + -DCMAKE_CXX_COMPILER=${SWIFT_NATIVE_PATH}/clang++ \ + -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \ + -DLLVM_ENABLE_PROJECTS="llvm" \ + -DCMAKE_BUILD_TYPE=Release rm -rf ${SWIFT_BUILDDIR} mkdir -p ${SWIFT_BUILDDIR} @@ -93,8 +105,8 @@ set(BUILD_TESTING OFF) set(BUILD_SHARED_LIBS ON) set(LLVM_USE_LINKER lld) -set(LLVM_DIR ${HOST_LLVM_PATH}/cmake/llvm) -set(LLVM_BUILD_LIBRARY_DIR ${HOST_LLVM_PATH}) +set(LLVM_DIR ${LLVM_BUILDDIR}/lib/cmake/llvm) +set(LLVM_BUILD_LIBRARY_DIR ${LLVM_BUILDDIR}) set(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN ON) set(SWIFT_USE_LINKER lld) diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/AddLLVM.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/AddLLVM.cmake deleted file mode 100644 index 9e1c055..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/AddLLVM.cmake +++ /dev/null @@ -1,2494 +0,0 @@ -include(GNUInstallDirs) -include(LLVMDistributionSupport) -include(LLVMProcessSources) -include(LLVM-Config) -include(DetermineGCCCompatible) - -function(llvm_update_compile_flags name) - get_property(sources TARGET ${name} PROPERTY SOURCES) - if("${sources}" MATCHES "\\.c(;|$)") - set(update_src_props ON) - endif() - - list(APPEND LLVM_COMPILE_CFLAGS " ${LLVM_COMPILE_FLAGS}") - - # LLVM_REQUIRES_EH is an internal flag that individual targets can use to - # force EH - if(LLVM_REQUIRES_EH OR LLVM_ENABLE_EH) - if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI)) - message(AUTHOR_WARNING "Exception handling requires RTTI. Enabling RTTI for ${name}") - set(LLVM_REQUIRES_RTTI ON) - endif() - if(MSVC) - list(APPEND LLVM_COMPILE_FLAGS "/EHsc") - endif() - else() - if(LLVM_COMPILER_IS_GCC_COMPATIBLE) - list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions") - if(LLVM_ENABLE_UNWIND_TABLES) - list(APPEND LLVM_COMPILE_FLAGS "-funwind-tables") - else() - list(APPEND LLVM_COMPILE_FLAGS "-fno-unwind-tables") - list(APPEND LLVM_COMPILE_FLAGS "-fno-asynchronous-unwind-tables") - endif() - elseif(MSVC) - list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0) - list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL") - list(APPEND LLVM_COMPILE_FLAGS "-qnoeh") - endif() - endif() - - # LLVM_REQUIRES_RTTI is an internal flag that individual - # targets can use to force RTTI - set(LLVM_CONFIG_HAS_RTTI YES CACHE INTERNAL "") - if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI)) - set(LLVM_CONFIG_HAS_RTTI NO CACHE INTERNAL "") - list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0) - if (LLVM_COMPILER_IS_GCC_COMPATIBLE) - list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti") - elseif (MSVC) - list(APPEND LLVM_COMPILE_FLAGS "/GR-") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL") - list(APPEND LLVM_COMPILE_FLAGS "-qnortti") - endif () - elseif(MSVC) - list(APPEND LLVM_COMPILE_FLAGS "/GR") - endif() - - # Assume that; - # - LLVM_COMPILE_FLAGS is list. - # - PROPERTY COMPILE_FLAGS is string. - string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}") - string(REPLACE ";" " " target_compile_cflags " ${LLVM_COMPILE_CFLAGS}") - - 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 "${target_compile_flags}") - endif() - if("${suf}" STREQUAL ".c") - set_property(SOURCE ${fn} APPEND_STRING PROPERTY - COMPILE_FLAGS "${target_compile_cflags}") - endif() - endforeach() - else() - # Update target props, since all sources are C++. - set_property(TARGET ${name} APPEND_STRING PROPERTY - COMPILE_FLAGS "${target_compile_flags}") - endif() - - set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS}) -endfunction() - -function(add_llvm_symbol_exports target_name export_file) - if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(native_export_file "${target_name}.exports") - add_custom_command(OUTPUT ${native_export_file} - COMMAND sed -e "s/^/_/" < ${export_file} > ${native_export_file} - DEPENDS ${export_file} - VERBATIM - COMMENT "Creating export file for ${target_name}") - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-exported_symbols_list,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"") - elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX") - # FIXME: `-Wl,-bE:` bypasses whatever handling there is in the build - # compiler driver to defer to the specified export list. - set(native_export_file "${export_file}") - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-bE:${export_file}") - elseif(LLVM_HAVE_LINK_VERSION_SCRIPT) - # Gold and BFD ld require a version script rather than a plain list. - set(native_export_file "${target_name}.exports") - # FIXME: Don't write the "local:" line on OpenBSD. - # in the export file, also add a linker script to version LLVM symbols (form: LLVM_N.M) - add_custom_command(OUTPUT ${native_export_file} - COMMAND "${Python3_EXECUTABLE}" "-c" - "import sys; \ - lines = [' ' + l.rstrip() for l in sys.stdin] + [' local: *;']; \ - print('LLVM_${LLVM_VERSION_MAJOR} {'); \ - print(' global:') if len(lines) > 1 else None; \ - print(';\\n'.join(lines) + '\\n};')" - < ${export_file} > ${native_export_file} - DEPENDS ${export_file} - VERBATIM - COMMENT "Creating export file for ${target_name}") - if (${LLVM_LINKER_IS_SOLARISLD}) - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-M,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"") - else() - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,--version-script,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"") - endif() - elseif(WIN32) - set(native_export_file "${target_name}.def") - - add_custom_command(OUTPUT ${native_export_file} - COMMAND "${Python3_EXECUTABLE}" -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))" - < ${export_file} > ${native_export_file} - DEPENDS ${export_file} - VERBATIM - COMMENT "Creating export file for ${target_name}") - set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") - if(MSVC) - # cl.exe or clang-cl, i.e. MSVC style command line interface - set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"") - elseif(CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") - # clang in msvc mode, calling a link.exe/lld-link style linker - set(export_file_linker_flag "-Wl,/DEF:\"${export_file_linker_flag}\"") - elseif(MINGW) - # ${export_file_linker_flag}, which is the plain file name, works as is - # when passed to the compiler driver, which then passes it on to the - # linker as an input file. - set(export_file_linker_flag "\"${export_file_linker_flag}\"") - else() - message(FATAL_ERROR "Unsupported Windows toolchain") - endif() - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " ${export_file_linker_flag}") - endif() - - add_custom_target(${target_name}_exports DEPENDS ${native_export_file}) - set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc") - - get_property(srcs TARGET ${target_name} PROPERTY SOURCES) - foreach(src ${srcs}) - get_filename_component(extension ${src} EXT) - if(extension STREQUAL ".cpp") - set(first_source_file ${src}) - break() - endif() - endforeach() - - # Force re-linking when the exports file changes. Actually, it - # forces recompilation of the source file. The LINK_DEPENDS target - # property only works for makefile-based generators. - # FIXME: This is not safe because this will create the same target - # ${native_export_file} in several different file: - # - One where we emitted ${target_name}_exports - # - One where we emitted the build command for the following object. - # set_property(SOURCE ${first_source_file} APPEND PROPERTY - # OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}) - - set_property(DIRECTORY APPEND - PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file}) - - add_dependencies(${target_name} ${target_name}_exports) - - # Add dependency to *_exports later -- CMake issue 14747 - list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports) - set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE) -endfunction(add_llvm_symbol_exports) - -if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32) - # Detect what linker we have here. - if(APPLE) - # Linkers with ld64-compatible flags. - set(version_flag "-Wl,-v") - else() - # Linkers with BFD ld-compatible flags. - set(version_flag "-Wl,--version") - endif() - - if (CMAKE_HOST_WIN32) - set(DEVNULL "NUL") - else() - set(DEVNULL "/dev/null") - endif() - - if(LLVM_USE_LINKER) - set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} ${version_flag} -o ${DEVNULL}) - else() - separate_arguments(flags UNIX_COMMAND "${CMAKE_EXE_LINKER_FLAGS}") - set(command ${CMAKE_C_COMPILER} ${flags} ${version_flag} -o ${DEVNULL}) - endif() - execute_process( - COMMAND ${command} - OUTPUT_VARIABLE stdout - ERROR_VARIABLE stderr - ) - - if(APPLE) - if("${stderr}" MATCHES "PROGRAM:ld") - set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "") - set(LLVM_LINKER_IS_APPLE YES CACHE INTERNAL "") - message(STATUS "Linker detection: Apple") - elseif("${stderr}" MATCHES "^LLD" OR - "${stdout}" MATCHES "^LLD") - set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "") - set(LLVM_LINKER_IS_LLD YES CACHE INTERNAL "") - message(STATUS "Linker detection: lld") - else() - set(LLVM_LINKER_DETECTED NO CACHE INTERNAL "") - message(STATUS "Linker detection: unknown") - endif() - else() - if("${stdout}" MATCHES "^mold") - set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "") - set(LLVM_LINKER_IS_MOLD YES CACHE INTERNAL "") - message(STATUS "Linker detection: mold") - elseif("${stdout}" MATCHES "GNU gold") - set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "") - set(LLVM_LINKER_IS_GOLD YES CACHE INTERNAL "") - message(STATUS "Linker detection: GNU Gold") - elseif("${stdout}" MATCHES "^LLD") - set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "") - set(LLVM_LINKER_IS_LLD YES CACHE INTERNAL "") - message(STATUS "Linker detection: LLD") - elseif("${stdout}" MATCHES "GNU ld") - set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "") - set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "") - message(STATUS "Linker detection: GNU ld") - elseif("${stderr}" MATCHES "Solaris Link Editors" OR - "${stdout}" MATCHES "Solaris Link Editors") - set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "") - set(LLVM_LINKER_IS_SOLARISLD YES CACHE INTERNAL "") - message(STATUS "Linker detection: Solaris ld") - else() - set(LLVM_LINKER_DETECTED NO CACHE INTERNAL "") - message(STATUS "Linker detection: unknown") - endif() - endif() -endif() - -function(add_link_opts target_name) - # Newer lld defaults to no-undefined-version, which we don't expect - if(LLVM_LINKER_IS_LLD) - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-undefined-version") - endif() - - get_llvm_distribution(${target_name} in_distribution in_distribution_var) - if(NOT in_distribution) - # Don't LTO optimize targets that aren't part of any distribution. - if (LLVM_ENABLE_LTO) - # We may consider avoiding LTO altogether by using -fembed-bitcode - # and teaching the linker to select machine code from .o files, see - # https://lists.llvm.org/pipermail/llvm-dev/2021-April/149843.html - if((UNIX OR MINGW) AND LINKER_IS_LLD) - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,--lto-O0") - elseif(LINKER_IS_LLD_LINK) - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " /opt:lldlto=0") - elseif(APPLE AND NOT uppercase_LLVM_ENABLE_LTO STREQUAL "THIN") - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-mllvm,-O0") - endif() - endif() - endif() - - # Don't use linker optimizations in debug builds since it slows down the - # linker in a context where the optimizations are not important. - if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - if(NOT LLVM_NO_DEAD_STRIP) - if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # ld64's implementation of -dead_strip breaks tools that use plugins. - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-dead_strip") - elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") - # Support for ld -z discard-unused=sections was only added in - # Solaris 11.4. - include(LLVMCheckLinkerFlag) - llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED) - if (LINKER_SUPPORTS_Z_DISCARD_UNUSED) - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-z,discard-unused=sections") - endif() - elseif(NOT MSVC AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX|OS390") - # TODO Revisit this later on z/OS. - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,--gc-sections") - endif() - else() #LLVM_NO_DEAD_STRIP - if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-bnogc") - endif() - endif() - endif() - - if(ARG_SUPPORT_PLUGINS AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-brtl") - endif() -endfunction(add_link_opts) - -# Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}. -# Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, -# or a certain builder, for eaxample, msbuild.exe, would be confused. -function(set_output_directory target) - cmake_parse_arguments(ARG "" "BINARY_DIR;LIBRARY_DIR" "" ${ARGN}) - - # module_dir -- corresponding to LIBRARY_OUTPUT_DIRECTORY. - # It affects output of add_library(MODULE). - if(WIN32 OR CYGWIN) - # DLL platform - set(module_dir ${ARG_BINARY_DIR}) - else() - set(module_dir ${ARG_LIBRARY_DIR}) - endif() - if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") - foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER "${build_mode}" CONFIG_SUFFIX) - if(ARG_BINARY_DIR) - string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINARY_DIR}) - set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi}) - endif() - if(ARG_LIBRARY_DIR) - string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBRARY_DIR}) - set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) - endif() - if(module_dir) - string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${module_dir}) - set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi}) - endif() - endforeach() - else() - if(ARG_BINARY_DIR) - set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ARG_BINARY_DIR}) - endif() - if(ARG_LIBRARY_DIR) - set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBRARY_DIR}) - endif() - if(module_dir) - set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${module_dir}) - endif() - endif() -endfunction() - -# If on Windows and building with MSVC, add the resource script containing the -# VERSIONINFO data to the project. This embeds version resource information -# into the output .exe or .dll. -# TODO: Enable for MinGW Windows builds too. -# -function(add_windows_version_resource_file OUT_VAR) - set(sources ${ARGN}) - if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc) - if(EXISTS ${resource_file}) - set(sources ${sources} ${resource_file}) - source_group("Resource Files" ${resource_file}) - set(windows_resource_file ${resource_file} PARENT_SCOPE) - endif() - endif(MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - - set(${OUT_VAR} ${sources} PARENT_SCOPE) -endfunction(add_windows_version_resource_file) - -# set_windows_version_resource_properties(name resource_file... -# VERSION_MAJOR int -# Optional major version number (defaults to LLVM_VERSION_MAJOR) -# VERSION_MINOR int -# Optional minor version number (defaults to LLVM_VERSION_MINOR) -# VERSION_PATCHLEVEL int -# Optional patchlevel version number (defaults to LLVM_VERSION_PATCH) -# VERSION_STRING -# Optional version string (defaults to PACKAGE_VERSION) -# PRODUCT_NAME -# Optional product name string (defaults to "LLVM") -# ) -function(set_windows_version_resource_properties name resource_file) - cmake_parse_arguments(ARG - "" - "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME" - "" - ${ARGN}) - - if (NOT DEFINED ARG_VERSION_MAJOR) - if (${LLVM_VERSION_MAJOR}) - set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) - else() - set(ARG_VERSION_MAJOR 0) - endif() - endif() - - if (NOT DEFINED ARG_VERSION_MINOR) - if (${LLVM_VERSION_MINOR}) - set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR}) - else() - set(ARG_VERSION_MINOR 0) - endif() - endif() - - if (NOT DEFINED ARG_VERSION_PATCHLEVEL) - if (${LLVM_VERSION_PATCH}) - set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH}) - else() - set(ARG_VERSION_PATCHLEVEL 0) - endif() - endif() - - if (NOT DEFINED ARG_VERSION_STRING) - if (${PACKAGE_VERSION}) - set(ARG_VERSION_STRING ${PACKAGE_VERSION}) - else() - set(ARG_VERSION_STRING 0) - endif() - endif() - - if (NOT DEFINED ARG_PRODUCT_NAME) - set(ARG_PRODUCT_NAME "LLVM") - endif() - - set_property(SOURCE ${resource_file} - PROPERTY COMPILE_FLAGS /nologo) - set_property(SOURCE ${resource_file} - PROPERTY COMPILE_DEFINITIONS - "RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}" - "RC_VERSION_FIELD_2=${ARG_VERSION_MINOR}" - "RC_VERSION_FIELD_3=${ARG_VERSION_PATCHLEVEL}" - "RC_VERSION_FIELD_4=0" - "RC_FILE_VERSION=\"${ARG_VERSION_STRING}\"" - "RC_INTERNAL_NAME=\"${name}\"" - "RC_PRODUCT_NAME=\"${ARG_PRODUCT_NAME}\"" - "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"") -endfunction(set_windows_version_resource_properties) - -# llvm_add_library(name sources... -# SHARED;STATIC -# STATIC by default w/o BUILD_SHARED_LIBS. -# SHARED by default w/ BUILD_SHARED_LIBS. -# OBJECT -# Also create an OBJECT library target. Default if STATIC && SHARED. -# MODULE -# Target ${name} might not be created on unsupported platforms. -# Check with "if(TARGET ${name})". -# DISABLE_LLVM_LINK_LLVM_DYLIB -# Do not link this library to libLLVM, even if -# LLVM_LINK_LLVM_DYLIB is enabled. -# OUTPUT_NAME name -# Corresponds to OUTPUT_NAME in target properties. -# DEPENDS targets... -# Same semantics as add_dependencies(). -# LINK_COMPONENTS components... -# Same as the variable LLVM_LINK_COMPONENTS. -# LINK_LIBS lib_targets... -# Same semantics as target_link_libraries(). -# ADDITIONAL_HEADERS -# May specify header files for IDE generators. -# SONAME -# Should set SONAME link flags and create symlinks -# NO_INSTALL_RPATH -# Suppress default RPATH settings in shared libraries. -# PLUGIN_TOOL -# The tool (i.e. cmake target) that this plugin will link against -# COMPONENT_LIB -# This is used to specify that this is a component library of -# LLVM which means that the source resides in llvm/lib/ and it is a -# candidate for inclusion into libLLVM.so. -# ) -function(llvm_add_library name) - cmake_parse_arguments(ARG - "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB" - "OUTPUT_NAME;PLUGIN_TOOL;ENTITLEMENTS;BUNDLE_PATH" - "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS" - ${ARGN}) - list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS}) - if(ARG_ADDITIONAL_HEADERS) - # Pass through ADDITIONAL_HEADERS. - set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS}) - endif() - if(ARG_OBJLIBS) - set(ALL_FILES ${ARG_OBJLIBS}) - else() - llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS}) - endif() - - if(ARG_MODULE) - if(ARG_SHARED OR ARG_STATIC) - message(WARNING "MODULE with SHARED|STATIC doesn't make sense.") - endif() - # Plugins that link against a tool are allowed even when plugins in general are not - if(NOT LLVM_ENABLE_PLUGINS AND NOT (ARG_PLUGIN_TOOL AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)) - message(STATUS "${name} ignored -- Loadable modules not supported on this platform.") - return() - endif() - else() - if(ARG_PLUGIN_TOOL) - message(WARNING "PLUGIN_TOOL without MODULE doesn't make sense.") - endif() - if(BUILD_SHARED_LIBS AND NOT ARG_STATIC) - set(ARG_SHARED TRUE) - endif() - if(NOT ARG_SHARED) - set(ARG_STATIC TRUE) - endif() - endif() - - # Generate objlib - if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT) - # Generate an obj library for both targets. - set(obj_name "obj.${name}") - add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL - ${ALL_FILES} - ) - llvm_update_compile_flags(${obj_name}) - if(CMAKE_GENERATOR STREQUAL "Xcode") - set(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/Dummy.c) - file(WRITE ${DUMMY_FILE} "// This file intentionally empty\n") - set_property(SOURCE ${DUMMY_FILE} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-empty-translation-unit") - endif() - set(ALL_FILES "$" ${DUMMY_FILE}) - - # Do add_dependencies(obj) later due to CMake issue 14747. - list(APPEND objlibs ${obj_name}) - - # Bring in the target include directories from our original target. - target_include_directories(${obj_name} PRIVATE $) - - set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries") - if(ARG_DEPENDS) - add_dependencies(${obj_name} ${ARG_DEPENDS}) - endif() - # Treat link libraries like PUBLIC dependencies. LINK_LIBS might - # result in generating header files. Add a dependendency so that - # the generated header is created before this object library. - if(ARG_LINK_LIBS) - cmake_parse_arguments(LINK_LIBS_ARG - "" - "" - "PUBLIC;PRIVATE" - ${ARG_LINK_LIBS}) - foreach(link_lib ${LINK_LIBS_ARG_PUBLIC}) - if(LLVM_PTHREAD_LIB) - # Can't specify a dependence on -lpthread - if(NOT ${link_lib} STREQUAL ${LLVM_PTHREAD_LIB}) - add_dependencies(${obj_name} ${link_lib}) - endif() - else() - add_dependencies(${obj_name} ${link_lib}) - endif() - endforeach() - endif() - endif() - - if(ARG_SHARED AND ARG_STATIC) - # static - set(name_static "${name}_static") - if(ARG_OUTPUT_NAME) - set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}") - endif() - # DEPENDS has been appended to LLVM_COMMON_LIBS. - llvm_add_library(${name_static} STATIC - ${output_name} - OBJLIBS ${ALL_FILES} # objlib - LINK_LIBS ${ARG_LINK_LIBS} - LINK_COMPONENTS ${ARG_LINK_COMPONENTS} - ) - - # Bring in the target link info from our original target. - target_link_directories(${name_static} PRIVATE $) - target_link_libraries(${name_static} PRIVATE $) - - # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY. - set(ARG_STATIC) - endif() - - if(ARG_MODULE) - add_library(${name} MODULE ${ALL_FILES}) - elseif(ARG_SHARED) - add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) - add_library(${name} SHARED ${ALL_FILES}) - else() - add_library(${name} STATIC ${ALL_FILES}) - endif() - - if(ARG_COMPONENT_LIB) - set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE) - set_property(GLOBAL APPEND PROPERTY LLVM_COMPONENT_LIBS ${name}) - endif() - - if(NOT ARG_NO_INSTALL_RPATH) - if(ARG_MODULE OR ARG_SHARED) - llvm_setup_rpath(${name}) - endif() - endif() - - setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS}) - - if(DEFINED windows_resource_file) - set_windows_version_resource_properties(${name} ${windows_resource_file}) - set(windows_resource_file ${windows_resource_file} PARENT_SCOPE) - endif() - - set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) - # $ doesn't require compile flags. - if(NOT obj_name) - llvm_update_compile_flags(${name}) - endif() - add_link_opts( ${name} ) - if(ARG_OUTPUT_NAME) - set_target_properties(${name} - PROPERTIES - OUTPUT_NAME ${ARG_OUTPUT_NAME} - ) - endif() - - if(ARG_MODULE) - set_target_properties(${name} PROPERTIES - PREFIX "" - SUFFIX ${LLVM_PLUGIN_EXT} - ) - endif() - - if(ARG_SHARED) - if(MSVC) - set_target_properties(${name} PROPERTIES - PREFIX "" - ) - endif() - - # Set SOVERSION on shared libraries that lack explicit SONAME - # specifier, on *nix systems that are not Darwin. - if(UNIX AND NOT APPLE AND NOT ARG_SONAME) - set_target_properties(${name} - PROPERTIES - # Since 4.0.0, the ABI version is indicated by the major version - SOVERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX} - VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}) - endif() - endif() - - if(ARG_MODULE OR ARG_SHARED) - # Do not add -Dname_EXPORTS to the command-line when building files in this - # target. Doing so is actively harmful for the modules build because it - # creates extra module variants, and not useful because we don't use these - # macros. - set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) - - if (LLVM_EXPORTED_SYMBOL_FILE) - add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) - endif() - endif() - - if(ARG_SHARED) - if(NOT APPLE AND ARG_SONAME) - get_target_property(output_name ${name} OUTPUT_NAME) - if(${output_name} STREQUAL "output_name-NOTFOUND") - set(output_name ${name}) - endif() - set(library_name ${output_name}-${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}) - set(api_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}) - set_target_properties(${name} PROPERTIES OUTPUT_NAME ${library_name}) - if(UNIX) - llvm_install_library_symlink(${api_name} ${library_name} SHARED - COMPONENT ${name}) - llvm_install_library_symlink(${output_name} ${library_name} SHARED - COMPONENT ${name}) - endif() - endif() - endif() - - if(ARG_STATIC) - set(libtype PUBLIC) - else() - # We can use PRIVATE since SO knows its dependent libs. - set(libtype PRIVATE) - endif() - - if(ARG_MODULE AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS AND ARG_PLUGIN_TOOL AND (WIN32 OR CYGWIN)) - # On DLL platforms symbols are imported from the tool by linking against it. - set(llvm_libs ${ARG_PLUGIN_TOOL}) - elseif (NOT ARG_COMPONENT_LIB) - if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) - set(llvm_libs LLVM) - else() - llvm_map_components_to_libnames(llvm_libs - ${ARG_LINK_COMPONENTS} - ${LLVM_LINK_COMPONENTS} - ) - endif() - else() - # Components have not been defined explicitly in CMake, so add the - # dependency information for this library through their name, and let - # LLVMBuildResolveComponentsLink resolve the mapping. - # - # It would be nice to verify that we have the dependencies for this library - # name, but using get_property(... SET) doesn't suffice to determine if a - # property has been set to an empty value. - set_property(TARGET ${name} PROPERTY LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS} ${LLVM_LINK_COMPONENTS}) - - # This property is an internal property only used to make sure the - # link step applied in LLVMBuildResolveComponentsLink uses the same - # property as the target_link_libraries call below. - set_property(TARGET ${name} PROPERTY LLVM_LIBTYPE ${libtype}) - endif() - - target_link_libraries(${name} ${libtype} - ${ARG_LINK_LIBS} - ${lib_deps} - ${llvm_libs} - ) - - if(LLVM_COMMON_DEPENDS) - add_dependencies(${name} ${LLVM_COMMON_DEPENDS}) - # Add dependencies also to objlibs. - # CMake issue 14747 -- add_dependencies() might be ignored to objlib's user. - foreach(objlib ${objlibs}) - add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS}) - endforeach() - endif() - - if(ARG_SHARED OR ARG_MODULE) - llvm_externalize_debuginfo(${name}) - llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH}) - endif() - # clang and newer versions of ninja use high-resolutions timestamps, - # but older versions of libtool on Darwin don't, so the archive will - # often get an older timestamp than the last object that was added - # or updated. To fix this, we add a custom command to touch archive - # after it's been built so that ninja won't rebuild it unnecessarily - # the next time it's run. - if(ARG_STATIC AND LLVM_TOUCH_STATIC_LIBRARIES) - add_custom_command(TARGET ${name} - POST_BUILD - COMMAND touch ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX} - ) - endif() -endfunction() - -function(add_llvm_install_targets target) - cmake_parse_arguments(ARG "" "COMPONENT;PREFIX;SYMLINK" "DEPENDS" ${ARGN}) - if(ARG_COMPONENT) - set(component_option -DCMAKE_INSTALL_COMPONENT="${ARG_COMPONENT}") - endif() - if(ARG_PREFIX) - set(prefix_option -DCMAKE_INSTALL_PREFIX="${ARG_PREFIX}") - endif() - - set(file_dependencies) - set(target_dependencies) - foreach(dependency ${ARG_DEPENDS}) - if(TARGET ${dependency}) - list(APPEND target_dependencies ${dependency}) - else() - list(APPEND file_dependencies ${dependency}) - endif() - endforeach() - - add_custom_target(${target} - DEPENDS ${file_dependencies} - COMMAND "${CMAKE_COMMAND}" - ${component_option} - ${prefix_option} - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" - USES_TERMINAL) - set_target_properties(${target} PROPERTIES FOLDER "Component Install Targets") - add_custom_target(${target}-stripped - DEPENDS ${file_dependencies} - COMMAND "${CMAKE_COMMAND}" - ${component_option} - ${prefix_option} - -DCMAKE_INSTALL_DO_STRIP=1 - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" - USES_TERMINAL) - set_target_properties(${target}-stripped PROPERTIES FOLDER "Component Install Targets (Stripped)") - if(target_dependencies) - add_dependencies(${target} ${target_dependencies}) - add_dependencies(${target}-stripped ${target_dependencies}) - endif() - - if(ARG_SYMLINK) - add_dependencies(${target} install-${ARG_SYMLINK}) - add_dependencies(${target}-stripped install-${ARG_SYMLINK}-stripped) - endif() -endfunction() - -# Define special targets that behave like a component group. They don't have any -# source attached but other components can add themselves to them. If the -# component supports is a Target and it supports JIT compilation, HAS_JIT must -# be passed. One can use ADD_TO_COMPONENT option from add_llvm_component_library -# to link extra component into an existing group. -function(add_llvm_component_group name) - cmake_parse_arguments(ARG "HAS_JIT" "" "LINK_COMPONENTS" ${ARGN}) - add_custom_target(${name}) - if(ARG_HAS_JIT) - set_property(TARGET ${name} PROPERTY COMPONENT_HAS_JIT ON) - endif() - if(ARG_LINK_COMPONENTS) - set_property(TARGET ${name} PROPERTY LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS}) - endif() -endfunction() - -# An LLVM component is a cmake target with the following cmake properties -# eventually set: -# - LLVM_COMPONENT_NAME: the name of the component, which can be the name of -# the associated library or the one specified through COMPONENT_NAME -# - LLVM_LINK_COMPONENTS: a list of component this component depends on -# - COMPONENT_HAS_JIT: (only for group component) whether this target group -# supports JIT compilation -# Additionnaly, the ADD_TO_COMPONENT option make it possible to add this -# component to the LLVM_LINK_COMPONENTS of . -function(add_llvm_component_library name) - cmake_parse_arguments(ARG - "" - "COMPONENT_NAME;ADD_TO_COMPONENT" - "" - ${ARGN}) - add_llvm_library(${name} COMPONENT_LIB ${ARG_UNPARSED_ARGUMENTS}) - string(REGEX REPLACE "^LLVM" "" component_name ${name}) - set_property(TARGET ${name} PROPERTY LLVM_COMPONENT_NAME ${component_name}) - - if(ARG_COMPONENT_NAME) - set_property(GLOBAL PROPERTY LLVM_COMPONENT_NAME_${ARG_COMPONENT_NAME} ${component_name}) - endif() - - if(ARG_ADD_TO_COMPONENT) - set_property(TARGET ${ARG_ADD_TO_COMPONENT} APPEND PROPERTY LLVM_LINK_COMPONENTS ${component_name}) - endif() - -endfunction() - -macro(add_llvm_library name) - cmake_parse_arguments(ARG - "SHARED;BUILDTREE_ONLY;MODULE;INSTALL_WITH_TOOLCHAIN" - "" - "" - ${ARGN}) - if(ARG_MODULE) - llvm_add_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS}) - elseif( BUILD_SHARED_LIBS OR ARG_SHARED ) - llvm_add_library(${name} SHARED ${ARG_UNPARSED_ARGUMENTS}) - else() - llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS}) - endif() - - # Libraries that are meant to only be exposed via the build tree only are - # never installed and are only exported as a target in the special build tree - # config file. - if (NOT ARG_BUILDTREE_ONLY AND NOT ARG_MODULE) - set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} ) - set(in_llvm_libs YES) - endif() - - if (ARG_MODULE AND NOT TARGET ${name}) - # Add empty "phony" target - add_custom_target(${name}) - elseif( EXCLUDE_FROM_ALL ) - set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) - elseif(ARG_BUILDTREE_ONLY) - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) - else() - if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN) - if(in_llvm_libs) - set(umbrella UMBRELLA llvm-libraries) - else() - set(umbrella) - endif() - - get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) - install(TARGETS ${name} - ${export_to_llvmexports} - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} - ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) - - if (NOT LLVM_ENABLE_IDE) - add_llvm_install_targets(install-${name} - DEPENDS ${name} - COMPONENT ${name}) - endif() - endif() - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) - endif() - if (ARG_MODULE) - set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") - else() - set_target_properties(${name} PROPERTIES FOLDER "Libraries") - endif() -endmacro(add_llvm_library name) - -macro(generate_llvm_objects name) - cmake_parse_arguments(ARG "GENERATE_DRIVER" "" "DEPENDS" ${ARGN}) - - llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ) - - list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS}) - - # Generate objlib - if(LLVM_ENABLE_OBJLIB OR (ARG_GENERATE_DRIVER AND LLVM_TOOL_LLVM_DRIVER_BUILD)) - # Generate an obj library for both targets. - set(obj_name "obj.${name}") - add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL - ${ALL_FILES} - ) - llvm_update_compile_flags(${obj_name}) - set(ALL_FILES "$") - if(ARG_DEPENDS) - add_dependencies(${obj_name} ${ARG_DEPENDS}) - endif() - - set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries") - endif() - - if (ARG_GENERATE_DRIVER) - string(REPLACE "-" "_" TOOL_NAME ${name}) - foreach(path ${CMAKE_MODULE_PATH}) - if(EXISTS ${path}/llvm-driver-template.cpp.in) - configure_file( - ${path}/llvm-driver-template.cpp.in - ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp) - break() - endif() - endforeach() - - list(APPEND ALL_FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp) - - if (LLVM_TOOL_LLVM_DRIVER_BUILD - AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS) - ) - set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_COMPONENTS ${LLVM_LINK_COMPONENTS}) - set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_DEPS ${ARG_DEPENDS} ${LLVM_COMMON_DEPENDS}) - set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_OBJLIBS "${obj_name}") - - set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOLS ${name}) - set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${name} ${name}) - target_link_libraries(${obj_name} ${LLVM_PTHREAD_LIB}) - llvm_config(${obj_name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} ) - endif() - endif() -endmacro() - -macro(add_llvm_executable name) - cmake_parse_arguments(ARG - "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS" - "ENTITLEMENTS;BUNDLE_PATH" - "" - ${ARGN}) - generate_llvm_objects(${name} ${ARG_UNPARSED_ARGUMENTS}) - add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) - - if(XCODE) - # Note: the dummy.cpp source file provides no definitions. However, - # it forces Xcode to properly link the static library. - list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp") - endif() - - if( EXCLUDE_FROM_ALL ) - add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) - else() - add_executable(${name} ${ALL_FILES}) - endif() - - setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS}) - - if(NOT ARG_NO_INSTALL_RPATH) - llvm_setup_rpath(${name}) - elseif(NOT "${LLVM_LOCAL_RPATH}" STREQUAL "") - # Enable BUILD_WITH_INSTALL_RPATH unless CMAKE_BUILD_RPATH is set. - if("${CMAKE_BUILD_RPATH}" STREQUAL "") - set_property(TARGET ${name} PROPERTY BUILD_WITH_INSTALL_RPATH ON) - endif() - - set_property(TARGET ${name} PROPERTY INSTALL_RPATH "${LLVM_LOCAL_RPATH}") - endif() - - if(DEFINED windows_resource_file) - set_windows_version_resource_properties(${name} ${windows_resource_file}) - endif() - - # $ doesn't require compile flags. - if(NOT LLVM_ENABLE_OBJLIB) - llvm_update_compile_flags(${name}) - endif() - - if (ARG_SUPPORT_PLUGINS AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") - set(LLVM_NO_DEAD_STRIP On) - endif() - - add_link_opts( ${name} ) - - # Do not add -Dname_EXPORTS to the command-line when building files in this - # target. Doing so is actively harmful for the modules build because it - # creates extra module variants, and not useful because we don't use these - # macros. - set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) - - if (LLVM_EXPORTED_SYMBOL_FILE) - add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) - endif(LLVM_EXPORTED_SYMBOL_FILE) - - if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) - set(USE_SHARED USE_SHARED) - endif() - - set(EXCLUDE_FROM_ALL OFF) - set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) - llvm_config( ${name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} ) - if( LLVM_COMMON_DEPENDS ) - add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) - foreach(objlib ${obj_name}) - add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS}) - endforeach() - endif( LLVM_COMMON_DEPENDS ) - - if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO) - llvm_externalize_debuginfo(${name}) - endif() - if (LLVM_PTHREAD_LIB) - # libpthreads overrides some standard library symbols, so main - # executable must be linked with it in order to provide consistent - # API for all shared libaries loaded by this executable. - target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB}) - endif() - - if(HAVE_LLVM_LIBC) - target_link_libraries(${name} PRIVATE llvmlibc) - endif() - - llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH}) -endmacro(add_llvm_executable name) - -# add_llvm_pass_plugin(name [NO_MODULE] ...) -# Add ${name} as an llvm plugin. -# If option LLVM_${name_upper}_LINK_INTO_TOOLS is set to ON, the plugin is registered statically. -# Otherwise a pluggable shared library is registered. -# -# If NO_MODULE is specified, when option LLVM_${name_upper}_LINK_INTO_TOOLS is set to OFF, -# only an object library is built, and no module is built. This is specific to the Polly use case. -# -# The SUBPROJECT argument contains the LLVM project the plugin belongs -# to. If set, the plugin will link statically by default it if the -# project was enabled. -function(add_llvm_pass_plugin name) - cmake_parse_arguments(ARG - "NO_MODULE" "SUBPROJECT" "" - ${ARGN}) - - string(TOUPPER ${name} name_upper) - - # Enable the plugin by default if it was explicitly enabled by the user. - # Note: If was set to "all", LLVM's CMakeLists.txt replaces it with a - # list of all projects, counting as explicitly enabled. - set(link_into_tools_default OFF) - if (ARG_SUBPROJECT AND LLVM_TOOL_${name_upper}_BUILD) - set(link_into_tools_default ON) - endif() - option(LLVM_${name_upper}_LINK_INTO_TOOLS "Statically link ${name} into tools (if available)" ${link_into_tools_default}) - - # If we statically link the plugin, don't use llvm dylib because we're going - # to be part of it. - if(LLVM_${name_upper}_LINK_INTO_TOOLS) - list(APPEND ARG_UNPARSED_ARGUMENTS DISABLE_LLVM_LINK_LLVM_DYLIB) - endif() - - if(LLVM_${name_upper}_LINK_INTO_TOOLS) - list(REMOVE_ITEM ARG_UNPARSED_ARGUMENTS BUILDTREE_ONLY) - # process_llvm_pass_plugins takes care of the actual linking, just create an - # object library as of now - add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS}) - target_compile_definitions(${name} PRIVATE LLVM_${name_upper}_LINK_INTO_TOOLS) - set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS LLVM_LINK_INTO_TOOLS) - if (TARGET intrinsics_gen) - add_dependencies(obj.${name} intrinsics_gen) - endif() - if (TARGET omp_gen) - add_dependencies(obj.${name} omp_gen) - endif() - if (TARGET acc_gen) - add_dependencies(obj.${name} acc_gen) - endif() - set_property(GLOBAL APPEND PROPERTY LLVM_STATIC_EXTENSIONS ${name}) - elseif(NOT ARG_NO_MODULE) - add_llvm_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS}) - else() - add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS}) - endif() - message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})") - -endfunction(add_llvm_pass_plugin) - -# process_llvm_pass_plugins([GEN_CONFIG]) -# -# Correctly set lib dependencies between plugins and tools, based on tools -# registered with the ENABLE_PLUGINS option. -# -# if GEN_CONFIG option is set, also generate X Macro file for extension -# handling. It provides a HANDLE_EXTENSION(extension_namespace, ExtensionProject) -# call for each extension allowing client code to define -# HANDLE_EXTENSION to have a specific code be run for each extension. -# -function(process_llvm_pass_plugins) - cmake_parse_arguments(ARG - "GEN_CONFIG" "" "" - ${ARGN}) - - if(ARG_GEN_CONFIG) - get_property(LLVM_STATIC_EXTENSIONS GLOBAL PROPERTY LLVM_STATIC_EXTENSIONS) - else() - include(LLVMConfigExtensions) - endif() - - # Add static plugins to the Extension component - foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) - set_property(TARGET LLVMExtensions APPEND PROPERTY LINK_LIBRARIES ${llvm_extension}) - set_property(TARGET LLVMExtensions APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension}) - endforeach() - - # Eventually generate the extension headers, and store config to a cmake file - # for usage in third-party configuration. - if(ARG_GEN_CONFIG) - - ## Part 1: Extension header to be included whenever we need extension - # processing. - if(NOT DEFINED LLVM_INSTALL_PACKAGE_DIR) - message(FATAL_ERROR "LLVM_INSTALL_PACKAGE_DIR must be defined and writable. GEN_CONFIG should only be passe when building LLVM proper.") - endif() - # LLVM_INSTALL_PACKAGE_DIR might be absolute, so don't reuse below. - string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}") - set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm") - file(WRITE - "${llvm_cmake_builddir}/LLVMConfigExtensions.cmake" - "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") - install(FILES - ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake - DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} - COMPONENT cmake-exports) - - set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") - file(WRITE "${ExtensionDef}.tmp" "//extension handlers\n") - foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) - file(APPEND "${ExtensionDef}.tmp" "HANDLE_EXTENSION(${llvm_extension})\n") - endforeach() - file(APPEND "${ExtensionDef}.tmp" "#undef HANDLE_EXTENSION\n") - - # only replace if there's an actual change - execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${ExtensionDef}.tmp" - "${ExtensionDef}") - file(REMOVE "${ExtensionDef}.tmp") - - ## Part 2: Extension header that captures each extension dependency, to be - # used by llvm-config. - set(ExtensionDeps "${LLVM_BINARY_DIR}/tools/llvm-config/ExtensionDependencies.inc") - - # Max needed to correctly size the required library array. - set(llvm_plugin_max_deps_length 0) - foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) - get_property(llvm_plugin_deps TARGET ${llvm_extension} PROPERTY LINK_LIBRARIES) - list(LENGTH llvm_plugin_deps llvm_plugin_deps_length) - if(llvm_plugin_deps_length GREATER llvm_plugin_max_deps_length) - set(llvm_plugin_max_deps_length ${llvm_plugin_deps_length}) - endif() - endforeach() - - list(LENGTH LLVM_STATIC_EXTENSIONS llvm_static_extension_count) - file(WRITE - "${ExtensionDeps}.tmp" - "#include \n\ - struct ExtensionDescriptor {\n\ - const char* Name;\n\ - const char* RequiredLibraries[1 + 1 + ${llvm_plugin_max_deps_length}];\n\ - };\n\ - std::array AvailableExtensions{\n") - - foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) - get_property(llvm_plugin_deps TARGET ${llvm_extension} PROPERTY LINK_LIBRARIES) - - file(APPEND "${ExtensionDeps}.tmp" "ExtensionDescriptor{\"${llvm_extension}\", {") - foreach(llvm_plugin_dep ${llvm_plugin_deps}) - # Turn library dependency back to component name, if possible. - # That way llvm-config can avoid redundant dependencies. - STRING(REGEX REPLACE "^-l" "" plugin_dep_name ${llvm_plugin_dep}) - STRING(REGEX MATCH "^LLVM" is_llvm_library ${plugin_dep_name}) - if(is_llvm_library) - STRING(REGEX REPLACE "^LLVM" "" plugin_dep_name ${plugin_dep_name}) - STRING(TOLOWER ${plugin_dep_name} plugin_dep_name) - endif() - file(APPEND "${ExtensionDeps}.tmp" "\"${plugin_dep_name}\", ") - endforeach() - - # Self + mandatory trailing null, because the number of RequiredLibraries differs between extensions. - file(APPEND "${ExtensionDeps}.tmp" \"${llvm_extension}\", "nullptr}},\n") - endforeach() - file(APPEND "${ExtensionDeps}.tmp" "};\n") - - # only replace if there's an actual change - execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${ExtensionDeps}.tmp" - "${ExtensionDeps}") - file(REMOVE "${ExtensionDeps}.tmp") - endif() -endfunction() - -function(export_executable_symbols target) - if (LLVM_EXPORTED_SYMBOL_FILE) - # The symbol file should contain the symbols we want the executable to - # export - set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) - elseif (LLVM_EXPORT_SYMBOLS_FOR_PLUGINS) - # Extract the symbols to export from the static libraries that the - # executable links against. - set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) - set(exported_symbol_file ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${target}.symbols) - # We need to consider not just the direct link dependencies, but also the - # transitive link dependencies. Do this by starting with the set of direct - # dependencies, then the dependencies of those dependencies, and so on. - get_target_property(new_libs ${target} LINK_LIBRARIES) - set(link_libs ${new_libs}) - while(NOT "${new_libs}" STREQUAL "") - foreach(lib ${new_libs}) - if(TARGET ${lib}) - get_target_property(lib_type ${lib} TYPE) - if("${lib_type}" STREQUAL "STATIC_LIBRARY") - list(APPEND static_libs ${lib}) - else() - list(APPEND other_libs ${lib}) - endif() - get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES) - foreach(transitive_lib ${transitive_libs}) - if(TARGET ${transitive_lib} AND NOT ${transitive_lib} IN_LIST link_libs) - list(APPEND newer_libs ${transitive_lib}) - list(APPEND link_libs ${transitive_lib}) - endif() - endforeach(transitive_lib) - endif() - endforeach(lib) - set(new_libs ${newer_libs}) - set(newer_libs "") - endwhile() - list(REMOVE_DUPLICATES static_libs) - if (MSVC) - set(mangling microsoft) - else() - set(mangling itanium) - endif() - get_host_tool_path(llvm-nm LLVM_NM llvm_nm_exe llvm_nm_target) - get_host_tool_path(llvm-readobj LLVM_READOBJ llvm_readobj_exe llvm_readobj_target) - add_custom_command(OUTPUT ${exported_symbol_file} - COMMAND "${Python3_EXECUTABLE}" - ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py - --mangling=${mangling} ${static_libs} - -o ${exported_symbol_file} - --nm=${llvm_nm_exe} - --readobj=${llvm_readobj_exe} - WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR} - DEPENDS ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py - ${static_libs} ${llvm_nm_target} ${llvm_readobj_target} - VERBATIM - COMMENT "Generating export list for ${target}") - add_llvm_symbol_exports( ${target} ${exported_symbol_file} ) - # If something links against this executable then we want a - # transitive link against only the libraries whose symbols - # we aren't exporting. - set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${other_libs}") - # The default import library suffix that cmake uses for cygwin/mingw is - # ".dll.a", but for clang.exe that causes a collision with libclang.dll, - # where the import libraries of both get named libclang.dll.a. Use a suffix - # of ".exe.a" to avoid this. - if(CYGWIN OR MINGW) - set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".exe.a") - endif() - elseif(NOT (WIN32 OR CYGWIN)) - # On Windows auto-exporting everything doesn't work because of the limit on - # the size of the exported symbol table, but on other platforms we can do - # it without any trouble. - set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) - if (APPLE) - set_property(TARGET ${target} APPEND_STRING PROPERTY - LINK_FLAGS " -rdynamic") - endif() - endif() -endfunction() - -# Export symbols if LLVM plugins are enabled. -function(export_executable_symbols_for_plugins target) - if(LLVM_ENABLE_PLUGINS OR LLVM_EXPORT_SYMBOLS_FOR_PLUGINS) - export_executable_symbols(${target}) - endif() -endfunction() - -if(NOT LLVM_TOOLCHAIN_TOOLS) - set (LLVM_TOOLCHAIN_TOOLS - llvm-ar - llvm-cov - llvm-cxxfilt - llvm-dwp - llvm-ranlib - llvm-lib - llvm-ml - llvm-nm - llvm-objcopy - llvm-objdump - llvm-pdbutil - llvm-rc - llvm-readobj - llvm-size - llvm-strings - llvm-strip - llvm-profdata - llvm-symbolizer - # symlink version of some of above tools that are enabled by - # LLVM_INSTALL_BINUTILS_SYMLINKS. - addr2line - ar - c++filt - ranlib - nm - objcopy - objdump - readelf - size - strings - strip - ) - # Build llvm-mt if libxml2 is enabled. Can be used by runtimes. - if (LLVM_ENABLE_LIBXML2) - list(APPEND LLVM_TOOLCHAIN_TOOLS llvm-mt) - endif() -endif() - -macro(llvm_add_tool project name) - cmake_parse_arguments(ARG "DEPENDS;GENERATE_DRIVER" "" "" ${ARGN}) - if( NOT LLVM_BUILD_TOOLS ) - set(EXCLUDE_FROM_ALL ON) - endif() - if(ARG_GENERATE_DRIVER - AND LLVM_TOOL_LLVM_DRIVER_BUILD - AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS) - ) - generate_llvm_objects(${name} ${ARGN}) - add_custom_target(${name} DEPENDS llvm-driver) - else() - add_llvm_executable(${name} ${ARGN}) - - if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) - if( LLVM_BUILD_TOOLS ) - get_target_export_arg(${name} LLVM export_to_llvmexports) - install(TARGETS ${name} - ${export_to_llvmexports} - RUNTIME DESTINATION ${${project}_TOOLS_INSTALL_DIR} - COMPONENT ${name}) - - if (NOT LLVM_ENABLE_IDE) - add_llvm_install_targets(install-${name} - DEPENDS ${name} - COMPONENT ${name}) - endif() - endif() - endif() - if( LLVM_BUILD_TOOLS ) - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) - endif() - set_target_properties(${name} PROPERTIES FOLDER "Tools") - endif() -endmacro(llvm_add_tool project name) - -macro(add_llvm_tool name) - llvm_add_tool(LLVM ${ARGV}) -endmacro() - - -macro(add_llvm_example name) - if( NOT LLVM_BUILD_EXAMPLES ) - set(EXCLUDE_FROM_ALL ON) - endif() - add_llvm_executable(${name} ${ARGN}) - if( LLVM_BUILD_EXAMPLES ) - install(TARGETS ${name} RUNTIME DESTINATION "${LLVM_EXAMPLES_INSTALL_DIR}") - endif() - set_target_properties(${name} PROPERTIES FOLDER "Examples") -endmacro(add_llvm_example name) - -macro(add_llvm_example_library name) - if( NOT LLVM_BUILD_EXAMPLES ) - set(EXCLUDE_FROM_ALL ON) - add_llvm_library(${name} BUILDTREE_ONLY ${ARGN}) - else() - add_llvm_library(${name} ${ARGN}) - endif() - - set_target_properties(${name} PROPERTIES FOLDER "Examples") -endmacro(add_llvm_example_library name) - -# This is a macro that is used to create targets for executables that are needed -# for development, but that are not intended to be installed by default. -macro(add_llvm_utility name) - if ( NOT LLVM_BUILD_UTILS ) - set(EXCLUDE_FROM_ALL ON) - endif() - - add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN}) - set_target_properties(${name} PROPERTIES FOLDER "Utils") - if ( ${name} IN_LIST LLVM_TOOLCHAIN_UTILITIES OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) - if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) - get_target_export_arg(${name} LLVM export_to_llvmexports) - install(TARGETS ${name} - ${export_to_llvmexports} - RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR} - COMPONENT ${name}) - - if (NOT LLVM_ENABLE_IDE) - add_llvm_install_targets(install-${name} - DEPENDS ${name} - COMPONENT ${name}) - endif() - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) - elseif(LLVM_BUILD_UTILS) - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) - endif() - endif() -endmacro(add_llvm_utility name) - -macro(add_llvm_fuzzer name) - cmake_parse_arguments(ARG "" "DUMMY_MAIN" "" ${ARGN}) - if( LLVM_LIB_FUZZING_ENGINE ) - set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN}) - add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) - target_link_libraries(${name} PRIVATE ${LLVM_LIB_FUZZING_ENGINE}) - set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") - elseif( LLVM_USE_SANITIZE_COVERAGE ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer") - set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN}) - add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) - set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") - elseif( ARG_DUMMY_MAIN ) - add_llvm_executable(${name} ${ARG_DUMMY_MAIN} ${ARG_UNPARSED_ARGUMENTS}) - set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") - endif() -endmacro() - -macro(add_llvm_target target_name) - include_directories(BEFORE - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}) - add_llvm_component_library(LLVM${target_name} ${ARGN}) - set( CURRENT_LLVM_TARGET LLVM${target_name} ) -endmacro(add_llvm_target) - -function(canonicalize_tool_name name output) - string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" nameStrip ${name}) - string(REPLACE "-" "_" nameUNDERSCORE ${nameStrip}) - string(TOUPPER ${nameUNDERSCORE} nameUPPER) - set(${output} "${nameUPPER}" PARENT_SCOPE) -endfunction(canonicalize_tool_name) - -# Custom add_subdirectory wrapper -# Takes in a project name (i.e. LLVM), the subdirectory name, and an optional -# path if it differs from the name. -function(add_llvm_subdirectory project type name) - set(add_llvm_external_dir "${ARGN}") - if("${add_llvm_external_dir}" STREQUAL "") - set(add_llvm_external_dir ${name}) - endif() - canonicalize_tool_name(${name} nameUPPER) - set(canonical_full_name ${project}_${type}_${nameUPPER}) - get_property(already_processed GLOBAL PROPERTY ${canonical_full_name}_PROCESSED) - if(already_processed) - return() - endif() - set_property(GLOBAL PROPERTY ${canonical_full_name}_PROCESSED YES) - - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt) - # Treat it as in-tree subproject. - option(${canonical_full_name}_BUILD - "Whether to build ${name} as part of ${project}" On) - mark_as_advanced(${project}_${type}_${name}_BUILD) - if(${canonical_full_name}_BUILD) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir}) - endif() - else() - set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR - "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" - CACHE PATH "Path to ${name} source directory") - set(${canonical_full_name}_BUILD_DEFAULT ON) - if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}) - set(${canonical_full_name}_BUILD_DEFAULT OFF) - endif() - if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF") - set(${canonical_full_name}_BUILD_DEFAULT OFF) - endif() - option(${canonical_full_name}_BUILD - "Whether to build ${name} as part of LLVM" - ${${canonical_full_name}_BUILD_DEFAULT}) - if (${canonical_full_name}_BUILD) - if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}) - add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir}) - elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "") - message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}") - endif() - endif() - endif() -endfunction() - -# Add external project that may want to be built as part of llvm such as Clang, -# lld, and Polly. This adds two options. One for the source directory of the -# project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to -# enable or disable building it with everything else. -# Additional parameter can be specified as the name of directory. -macro(add_llvm_external_project name) - add_llvm_subdirectory(LLVM TOOL ${name} ${ARGN}) -endmacro() - -macro(add_llvm_tool_subdirectory name) - add_llvm_external_project(${name}) -endmacro(add_llvm_tool_subdirectory) - -function(get_project_name_from_src_var var output) - string(REGEX MATCH "LLVM_EXTERNAL_(.*)_SOURCE_DIR" - MACHED_TOOL "${var}") - if(MACHED_TOOL) - set(${output} ${CMAKE_MATCH_1} PARENT_SCOPE) - else() - set(${output} PARENT_SCOPE) - endif() -endfunction() - -function(create_subdirectory_options project type) - file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*") - foreach(dir ${sub-dirs}) - if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt") - canonicalize_tool_name(${dir} name) - option(${project}_${type}_${name}_BUILD - "Whether to build ${name} as part of ${project}" On) - mark_as_advanced(${project}_${type}_${name}_BUILD) - endif() - endforeach() -endfunction(create_subdirectory_options) - -function(create_llvm_tool_options) - create_subdirectory_options(LLVM TOOL) -endfunction(create_llvm_tool_options) - -function(llvm_add_implicit_projects project) - set(list_of_implicit_subdirs "") - file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*") - foreach(dir ${sub-dirs}) - if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt") - canonicalize_tool_name(${dir} name) - # I don't like special casing things by order, but the llvm-driver ends up - # linking the object libraries from all the tools that opt-in, so adding - # it separately at the end is probably the simplest case. - if("${name}" STREQUAL "LLVM_DRIVER") - continue() - endif() - if (${project}_TOOL_${name}_BUILD) - get_filename_component(fn "${dir}" NAME) - list(APPEND list_of_implicit_subdirs "${fn}") - endif() - endif() - endforeach() - - foreach(external_proj ${list_of_implicit_subdirs}) - add_llvm_subdirectory(${project} TOOL "${external_proj}" ${ARGN}) - endforeach() -endfunction(llvm_add_implicit_projects) - -function(add_llvm_implicit_projects) - llvm_add_implicit_projects(LLVM) -endfunction(add_llvm_implicit_projects) - -# Generic support for adding a unittest. -function(add_unittest test_suite test_name) - if( NOT LLVM_BUILD_TESTS ) - set(EXCLUDE_FROM_ALL ON) - endif() - - 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() - - if (NOT DEFINED LLVM_REQUIRES_RTTI) - set(LLVM_REQUIRES_RTTI OFF) - endif() - - list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream - add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN}) - - # The runtime benefits of LTO don't outweight the compile time costs for tests. - if(LLVM_ENABLE_LTO) - if((UNIX OR MINGW) AND LINKER_IS_LLD) - set_property(TARGET ${test_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,--lto-O0") - elseif(LINKER_IS_LLD_LINK) - set_property(TARGET ${test_name} APPEND_STRING PROPERTY - LINK_FLAGS " /opt:lldlto=0") - elseif(APPLE AND NOT uppercase_LLVM_ENABLE_LTO STREQUAL "THIN") - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-mllvm,-O0") - endif() - endif() - - target_link_options(${test_name} PRIVATE "${LLVM_UNITTEST_LINK_FLAGS}") - - set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) - set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir}) - # libpthreads overrides some standard library symbols, so main - # executable must be linked with it in order to provide consistent - # API for all shared libaries loaded by this executable. - target_link_libraries(${test_name} PRIVATE llvm_gtest_main llvm_gtest ${LLVM_PTHREAD_LIB}) - - add_dependencies(${test_suite} ${test_name}) - get_target_property(test_suite_folder ${test_suite} FOLDER) - if (test_suite_folder) - set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}") - endif () -endfunction() - -# Use for test binaries that call llvm::getInputFileDirectory(). Use of this -# is discouraged. -function(add_unittest_with_input_files test_suite test_name) - set(LLVM_UNITTEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - configure_file( - ${LLVM_MAIN_SRC_DIR}/unittests/unittest.cfg.in - ${CMAKE_CURRENT_BINARY_DIR}/llvm.srcdir.txt) - - add_unittest(${test_suite} ${test_name} ${ARGN}) -endfunction() - -# Generic support for adding a benchmark. -function(add_benchmark benchmark_name) - if( NOT LLVM_BUILD_BENCHMARKS ) - set(EXCLUDE_FROM_ALL ON) - endif() - - add_llvm_executable(${benchmark_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN}) - set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) - set_output_directory(${benchmark_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir}) - set_property(TARGET ${benchmark_name} PROPERTY FOLDER "Utils") - target_link_libraries(${benchmark_name} PRIVATE benchmark) -endfunction() - -# This function canonicalize the CMake variables passed by names -# from CMake boolean to 0/1 suitable for passing into Python or C++, -# in place. -function(llvm_canonicalize_cmake_booleans) - foreach(var ${ARGN}) - if(${var}) - set(${var} 1 PARENT_SCOPE) - else() - set(${var} 0 PARENT_SCOPE) - endif() - endforeach() -endfunction(llvm_canonicalize_cmake_booleans) - -macro(set_llvm_build_mode) - # Configuration-time: See Unit/lit.site.cfg.in - if (CMAKE_CFG_INTDIR STREQUAL ".") - set(LLVM_BUILD_MODE ".") - else () - set(LLVM_BUILD_MODE "%(build_mode)s") - endif () -endmacro() - -# Takes a list of path names in pathlist and a base directory, and returns -# a list of paths relative to the base directory in out_pathlist. -# Paths that are on a different drive than the basedir (on Windows) or that -# contain symlinks are returned absolute. -# Use with LLVM_LIT_PATH_FUNCTION below. -function(make_paths_relative out_pathlist basedir pathlist) - # Passing ARG_PATH_VALUES as-is to execute_process() makes cmake strip - # empty list entries. So escape the ;s in the list and do the splitting - # ourselves. cmake has no relpath function, so use Python for that. - string(REPLACE ";" "\\;" pathlist_escaped "${pathlist}") - execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "\n -import os, sys\n -base = sys.argv[1] -def haslink(p):\n - if not p or p == os.path.dirname(p): return False\n - return os.path.islink(p) or haslink(os.path.dirname(p))\n -def relpath(p):\n - if not p: return ''\n - if os.path.splitdrive(p)[0] != os.path.splitdrive(base)[0]: return p\n - if haslink(p) or haslink(base): return p\n - return os.path.relpath(p, base)\n -if len(sys.argv) < 3: sys.exit(0)\n -sys.stdout.write(';'.join(relpath(p) for p in sys.argv[2].split(';')))" - ${basedir} - ${pathlist_escaped} - OUTPUT_VARIABLE pathlist_relative - ERROR_VARIABLE error - RESULT_VARIABLE result) - if (NOT result EQUAL 0) - message(FATAL_ERROR "make_paths_relative() failed due to error '${result}', with stderr\n${error}") - endif() - set(${out_pathlist} "${pathlist_relative}" PARENT_SCOPE) -endfunction() - -# Converts a file that's relative to the current python file to an absolute -# path. Since this uses __file__, it has to be emitted into python files that -# use it and can't be in a lit module. Use with make_paths_relative(). -string(CONCAT LLVM_LIT_PATH_FUNCTION - "# Allow generated file to be relocatable.\n" - "import os\n" - "import platform\n" - "def path(p):\n" - " if not p: return ''\n" - " # Follows lit.util.abs_path_preserve_drive, which cannot be imported here.\n" - " if platform.system() == 'Windows':\n" - " return os.path.abspath(os.path.join(os.path.dirname(__file__), p))\n" - " else:\n" - " return os.path.realpath(os.path.join(os.path.dirname(__file__), p))\n" - ) - -# This function provides an automatic way to 'configure'-like generate a file -# based on a set of common and custom variables, specifically targeting the -# variables needed for the 'lit.site.cfg' files. This function bundles the -# common variables that any Lit instance is likely to need, and custom -# variables can be passed in. -# The keyword PATHS is followed by a list of cmake variable names that are -# mentioned as `path("@varname@")` in the lit.cfg.py.in file. Variables in that -# list are treated as paths that are relative to the directory the generated -# lit.cfg.py file is in, and the `path()` function converts the relative -# path back to absolute form. This makes it possible to move a build directory -# containing lit.cfg.py files from one machine to another. -function(configure_lit_site_cfg site_in site_out) - cmake_parse_arguments(ARG "" "" "MAIN_CONFIG;PATHS" ${ARGN}) - - if ("${ARG_MAIN_CONFIG}" STREQUAL "") - get_filename_component(INPUT_DIR ${site_in} DIRECTORY) - set(ARG_MAIN_CONFIG "${INPUT_DIR}/lit.cfg") - endif() - - foreach(c ${LLVM_TARGETS_TO_BUILD}) - set(TARGETS_BUILT "${TARGETS_BUILT} ${c}") - endforeach(c) - set(TARGETS_TO_BUILD ${TARGETS_BUILT}) - - set(SHLIBEXT "${LTDL_SHLIB_EXT}") - - set_llvm_build_mode() - - # For standalone builds of subprojects, these might not be the build tree but - # a provided binary tree. - set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR}) - set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR}) - string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}") - string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" LLVM_LIBS_DIR "${LLVM_LIBRARY_DIR}") - # Like LLVM_{TOOLS,LIBS}_DIR, but pointing at the build tree. - string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_TOOLS_DIR "${LLVM_RUNTIME_OUTPUT_INTDIR}") - string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_LIBS_DIR "${LLVM_LIBRARY_OUTPUT_INTDIR}") - string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}") - - # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for - # plugins. We may rename it. - if(LLVM_ENABLE_PLUGINS) - set(ENABLE_SHARED "1") - else() - set(ENABLE_SHARED "0") - endif() - - if(LLVM_ENABLE_ASSERTIONS) - set(ENABLE_ASSERTIONS "1") - else() - set(ENABLE_ASSERTIONS "0") - endif() - - set(HOST_OS ${CMAKE_SYSTEM_NAME}) - set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR}) - - set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}") - set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") - set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}") - - string(CONCAT LIT_SITE_CFG_IN_HEADER - "# Autogenerated from ${site_in}\n# Do not edit!\n\n" - "${LLVM_LIT_PATH_FUNCTION}" - ) - - # Override config_target_triple (and the env) - if(LLVM_TARGET_TRIPLE_ENV) - # This is expanded into the heading. - string(CONCAT LIT_SITE_CFG_IN_HEADER "${LIT_SITE_CFG_IN_HEADER}" - "import os\n" - "target_env = \"${LLVM_TARGET_TRIPLE_ENV}\"\n" - "config.target_triple = config.environment[target_env] = os.environ.get(target_env, \"${LLVM_TARGET_TRIPLE}\")\n" - ) - - # This is expanded to; config.target_triple = ""+config.target_triple+"" - set(LLVM_TARGET_TRIPLE "\"+config.target_triple+\"") - endif() - - if (ARG_PATHS) - # Walk ARG_PATHS and collect the current value of the variables in there. - # list(APPEND) ignores empty elements exactly if the list is empty, - # so start the list with a dummy element and drop it, to make sure that - # even empty values make it into the values list. - set(ARG_PATH_VALUES "dummy") - foreach(path ${ARG_PATHS}) - list(APPEND ARG_PATH_VALUES "${${path}}") - endforeach() - list(REMOVE_AT ARG_PATH_VALUES 0) - - get_filename_component(OUTPUT_DIR ${site_out} DIRECTORY) - make_paths_relative( - ARG_PATH_VALUES_RELATIVE "${OUTPUT_DIR}" "${ARG_PATH_VALUES}") - - list(LENGTH ARG_PATHS len_paths) - list(LENGTH ARG_PATH_VALUES len_path_values) - list(LENGTH ARG_PATH_VALUES_RELATIVE len_path_value_rels) - if ((NOT ${len_paths} EQUAL ${len_path_values}) OR - (NOT ${len_paths} EQUAL ${len_path_value_rels})) - message(SEND_ERROR "PATHS lengths got confused") - endif() - - # Transform variables mentioned in ARG_PATHS to relative paths for - # the configure_file() call. Variables are copied to subscopeds by cmake, - # so this only modifies the local copy of the variables. - math(EXPR arg_path_limit "${len_paths} - 1") - foreach(i RANGE ${arg_path_limit}) - list(GET ARG_PATHS ${i} val1) - list(GET ARG_PATH_VALUES_RELATIVE ${i} val2) - set(${val1} ${val2}) - endforeach() - endif() - - configure_file(${site_in} ${site_out} @ONLY) - - if (EXISTS "${ARG_MAIN_CONFIG}") - # Remember main config / generated site config for llvm-lit.in. - get_property(LLVM_LIT_CONFIG_FILES GLOBAL PROPERTY LLVM_LIT_CONFIG_FILES) - list(APPEND LLVM_LIT_CONFIG_FILES "${ARG_MAIN_CONFIG}" "${site_out}") - set_property(GLOBAL PROPERTY LLVM_LIT_CONFIG_FILES ${LLVM_LIT_CONFIG_FILES}) - endif() -endfunction() - -function(dump_all_cmake_variables) - get_cmake_property(_variableNames VARIABLES) - foreach (_variableName ${_variableNames}) - message(STATUS "${_variableName}=${${_variableName}}") - endforeach() -endfunction() - -function(get_llvm_lit_path base_dir file_name) - cmake_parse_arguments(ARG "ALLOW_EXTERNAL" "" "" ${ARGN}) - - if (ARG_ALLOW_EXTERNAL) - set (LLVM_EXTERNAL_LIT "" CACHE STRING "Command used to spawn lit") - if ("${LLVM_EXTERNAL_LIT}" STREQUAL "") - set(LLVM_EXTERNAL_LIT "${LLVM_DEFAULT_EXTERNAL_LIT}") - endif() - - if (NOT "${LLVM_EXTERNAL_LIT}" STREQUAL "") - if (EXISTS ${LLVM_EXTERNAL_LIT}) - get_filename_component(LIT_FILE_NAME ${LLVM_EXTERNAL_LIT} NAME) - get_filename_component(LIT_BASE_DIR ${LLVM_EXTERNAL_LIT} DIRECTORY) - set(${file_name} ${LIT_FILE_NAME} PARENT_SCOPE) - set(${base_dir} ${LIT_BASE_DIR} PARENT_SCOPE) - return() - elseif (NOT DEFINED CACHE{LLVM_EXTERNAL_LIT_MISSING_WARNED_ONCE}) - message(WARNING "LLVM_EXTERNAL_LIT set to ${LLVM_EXTERNAL_LIT}, but the path does not exist.") - set(LLVM_EXTERNAL_LIT_MISSING_WARNED_ONCE YES CACHE INTERNAL "") - endif() - endif() - endif() - - set(lit_file_name "llvm-lit") - if (CMAKE_HOST_WIN32 AND NOT CYGWIN) - # llvm-lit needs suffix.py for multiprocess to find a main module. - set(lit_file_name "${lit_file_name}.py") - endif () - set(${file_name} ${lit_file_name} PARENT_SCOPE) - - get_property(LLVM_LIT_BASE_DIR GLOBAL PROPERTY LLVM_LIT_BASE_DIR) - if (NOT "${LLVM_LIT_BASE_DIR}" STREQUAL "") - set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE) - endif() - - # Allow individual projects to provide an override - if (NOT "${LLVM_LIT_OUTPUT_DIR}" STREQUAL "") - set(LLVM_LIT_BASE_DIR ${LLVM_LIT_OUTPUT_DIR}) - elseif(NOT "${LLVM_RUNTIME_OUTPUT_INTDIR}" STREQUAL "") - set(LLVM_LIT_BASE_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) - else() - set(LLVM_LIT_BASE_DIR "") - endif() - - # Cache this so we don't have to do it again and have subsequent calls - # potentially disagree on the value. - set_property(GLOBAL PROPERTY LLVM_LIT_BASE_DIR ${LLVM_LIT_BASE_DIR}) - set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE) -endfunction() - -# 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} ${LLVM_LIT_ARGS}") - separate_arguments(LIT_ARGS) - if (NOT CMAKE_CFG_INTDIR STREQUAL ".") - list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR}) - endif () - - # Get the path to the lit to *run* tests with. This can be overriden by - # the user by specifying -DLLVM_EXTERNAL_LIT= - get_llvm_lit_path( - lit_base_dir - lit_file_name - ALLOW_EXTERNAL - ) - - set(LIT_COMMAND "${Python3_EXECUTABLE};${lit_base_dir}/${lit_file_name}") - 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() - - 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() - -# Convert a target name like check-clang to a variable name like CLANG. -function(umbrella_lit_testsuite_var target outvar) - if (NOT target MATCHES "^check-") - message(FATAL_ERROR "umbrella lit suites must be check-*, not '${target}'") - endif() - string(SUBSTRING "${target}" 6 -1 var) - string(REPLACE "-" "_" var ${var}) - string(TOUPPER "${var}" var) - set(${outvar} "${var}" PARENT_SCOPE) -endfunction() - -# Start recording all lit test suites for a combined 'check-foo' target. -# The recording continues until umbrella_lit_testsuite_end() creates the target. -function(umbrella_lit_testsuite_begin target) - umbrella_lit_testsuite_var(${target} name) - set_property(GLOBAL APPEND PROPERTY LLVM_LIT_UMBRELLAS ${name}) -endfunction() - -# Create a combined 'check-foo' target for a set of related test suites. -# It runs all suites added since the matching umbrella_lit_testsuite_end() call. -# Tests marked EXCLUDE_FROM_CHECK_ALL are not gathered. -function(umbrella_lit_testsuite_end target) - umbrella_lit_testsuite_var(${target} name) - - get_property(testsuites GLOBAL PROPERTY LLVM_${name}_LIT_TESTSUITES) - get_property(params GLOBAL PROPERTY LLVM_${name}_LIT_PARAMS) - get_property(depends GLOBAL PROPERTY LLVM_${name}_LIT_DEPENDS) - get_property(extra_args GLOBAL PROPERTY LLVM_${name}_LIT_EXTRA_ARGS) - # Additional test targets are not gathered, but may be set externally. - get_property(additional_test_targets - GLOBAL PROPERTY LLVM_${name}_ADDITIONAL_TEST_TARGETS) - - string(TOLOWER ${name} name) - add_lit_target(${target} - "Running ${name} regression tests" - ${testsuites} - PARAMS ${params} - DEPENDS ${depends} ${additional_test_targets} - ARGS ${extra_args} - ) -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 "EXCLUDE_FROM_CHECK_ALL" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) - - # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all. - if(NOT ARG_EXCLUDE_FROM_CHECK_ALL) - get_property(gather_names GLOBAL PROPERTY LLVM_LIT_UMBRELLAS) - foreach(name ${gather_names}) - # Register the testsuites, params and depends for the umbrella check rule. - set_property(GLOBAL APPEND PROPERTY LLVM_${name}_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS}) - set_property(GLOBAL APPEND PROPERTY LLVM_${name}_LIT_PARAMS ${ARG_PARAMS}) - set_property(GLOBAL APPEND PROPERTY LLVM_${name}_LIT_DEPENDS ${ARG_DEPENDS}) - set_property(GLOBAL APPEND PROPERTY LLVM_${name}_LIT_EXTRA_ARGS ${ARG_ARGS}) - endforeach() - endif() - - # 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_lit_testsuites project directory) - if (NOT LLVM_ENABLE_IDE) - cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" "PARAMS;DEPENDS;ARGS" ${ARGN}) - - if (NOT ARG_FOLDER) - set(ARG_FOLDER "Test Subdirectories") - endif() - - # Search recursively for test directories by assuming anything not - # in a directory called Inputs contains tests. - file(GLOB_RECURSE to_process LIST_DIRECTORIES true ${directory}/*) - foreach(lit_suite ${to_process}) - if(NOT IS_DIRECTORY ${lit_suite}) - continue() - endif() - string(FIND ${lit_suite} Inputs is_inputs) - string(FIND ${lit_suite} Output is_output) - if (NOT (is_inputs EQUAL -1 AND is_output EQUAL -1)) - continue() - endif() - - # Create a check- target for the directory. - string(REPLACE ${directory} "" name_slash ${lit_suite}) - if (name_slash) - string(REPLACE "/" "-" name_slash ${name_slash}) - string(REPLACE "\\" "-" name_dashes ${name_slash}) - string(TOLOWER "${project}${name_dashes}" name_var) - add_lit_target("check-${name_var}" "Running lit suite ${lit_suite}" - ${lit_suite} - ${EXCLUDE_FROM_CHECK_ALL} - PARAMS ${ARG_PARAMS} - DEPENDS ${ARG_DEPENDS} - ARGS ${ARG_ARGS} - ) - set_target_properties(check-${name_var} PROPERTIES FOLDER ${ARG_FOLDER}) - endif() - endforeach() - endif() -endfunction() - -function(llvm_install_library_symlink name dest type) - cmake_parse_arguments(ARG "" "COMPONENT" "" ${ARGN}) - foreach(path ${CMAKE_MODULE_PATH}) - if(EXISTS ${path}/LLVMInstallSymlink.cmake) - set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake) - break() - endif() - endforeach() - - set(component ${ARG_COMPONENT}) - if(NOT component) - set(component ${name}) - endif() - - set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) - set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) - - if(LLVM_USE_SYMLINKS) - set(LLVM_LINK_OR_COPY create_symlink) - else() - set(LLVM_LINK_OR_COPY copy) - endif() - - set(output_dir lib${LLVM_LIBDIR_SUFFIX}) - if(WIN32 AND "${type}" STREQUAL "SHARED") - set(output_dir "${CMAKE_INSTALL_BINDIR}") - endif() - - install(SCRIPT ${INSTALL_SYMLINK} - CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\" \"${LLVM_LINK_OR_COPY}\")" - COMPONENT ${component}) - -endfunction() - -function(llvm_install_symlink project name dest) - get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS) - if(LLVM_TOOL_LLVM_DRIVER_BUILD - AND ${dest} IN_LIST LLVM_DRIVER_TOOLS - AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${dest} IN_LIST LLVM_DISTRIBUTION_COMPONENTS) - ) - return() - endif() - cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) - foreach(path ${CMAKE_MODULE_PATH}) - if(EXISTS ${path}/LLVMInstallSymlink.cmake) - set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake) - break() - endif() - endforeach() - - if(ARG_COMPONENT) - set(component ${ARG_COMPONENT}) - else() - if(ARG_ALWAYS_GENERATE) - set(component ${dest}) - else() - set(component ${name}) - endif() - endif() - - set(full_name ${name}${CMAKE_EXECUTABLE_SUFFIX}) - set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) - if (${dest} STREQUAL "llvm-driver") - set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX}) - endif() - - if(LLVM_USE_SYMLINKS) - set(LLVM_LINK_OR_COPY create_symlink) - else() - set(LLVM_LINK_OR_COPY copy) - endif() - - set(output_dir "${${project}_TOOLS_INSTALL_DIR}") - - install(SCRIPT ${INSTALL_SYMLINK} - CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\" \"${LLVM_LINK_OR_COPY}\")" - COMPONENT ${component}) - - if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) - add_llvm_install_targets(install-${name} - DEPENDS ${name} ${dest} - COMPONENT ${component} - SYMLINK ${dest}) - endif() -endfunction() - -function(llvm_add_tool_symlink project link_name target) - cmake_parse_arguments(ARG "ALWAYS_GENERATE" "OUTPUT_DIR" "" ${ARGN}) - - get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS) - - if (${target} IN_LIST LLVM_DRIVER_TOOLS) - set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${target} ${link_name}) - endif() - set(dest_binary "$") - - # This got a bit gross... For multi-configuration generators the target - # properties return the resolved value of the string, not the build system - # expression. To reconstruct the platform-agnostic path we have to do some - # magic. First we grab one of the types, and a type-specific path. Then from - # the type-specific path we find the last occurrence of the type in the path, - # and replace it with CMAKE_CFG_INTDIR. This allows the build step to be type - # agnostic again. - if(NOT ARG_OUTPUT_DIR) - # If you're not overriding the OUTPUT_DIR, we can make the link relative in - # the same directory. - if(LLVM_USE_SYMLINKS) - set(dest_binary "$") - endif() - if(CMAKE_CONFIGURATION_TYPES) - list(GET CMAKE_CONFIGURATION_TYPES 0 first_type) - string(TOUPPER ${first_type} first_type_upper) - set(first_type_suffix _${first_type_upper}) - endif() - get_target_property(target_type ${target} TYPE) - if(${target_type} STREQUAL "STATIC_LIBRARY") - get_target_property(ARG_OUTPUT_DIR ${target} ARCHIVE_OUTPUT_DIRECTORY${first_type_suffix}) - elseif(UNIX AND ${target_type} STREQUAL "SHARED_LIBRARY") - get_target_property(ARG_OUTPUT_DIR ${target} LIBRARY_OUTPUT_DIRECTORY${first_type_suffix}) - else() - get_target_property(ARG_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY${first_type_suffix}) - endif() - if(CMAKE_CONFIGURATION_TYPES) - string(FIND "${ARG_OUTPUT_DIR}" "/${first_type}/" type_start REVERSE) - string(SUBSTRING "${ARG_OUTPUT_DIR}" 0 ${type_start} path_prefix) - string(SUBSTRING "${ARG_OUTPUT_DIR}" ${type_start} -1 path_suffix) - string(REPLACE "/${first_type}/" "/${CMAKE_CFG_INTDIR}/" - path_suffix ${path_suffix}) - set(ARG_OUTPUT_DIR ${path_prefix}${path_suffix}) - endif() - endif() - - if(LLVM_USE_SYMLINKS) - set(LLVM_LINK_OR_COPY create_symlink) - else() - set(LLVM_LINK_OR_COPY copy) - endif() - - set(output_path "${ARG_OUTPUT_DIR}/${link_name}${CMAKE_EXECUTABLE_SUFFIX}") - - set(target_name ${link_name}) - if(TARGET ${link_name}) - set(target_name ${link_name}-link) - endif() - - - if(ARG_ALWAYS_GENERATE) - set_property(DIRECTORY APPEND PROPERTY - ADDITIONAL_MAKE_CLEAN_FILES ${dest_binary}) - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}") - else() - add_custom_command(OUTPUT ${output_path} - COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}" - DEPENDS ${target}) - - # TODO: Make use of generator expressions below once CMake 3.19 or higher is the minimum supported version. - set(should_build_all) - get_target_property(target_excluded_from_all ${target} EXCLUDE_FROM_ALL) - if (NOT target_excluded_from_all) - set(should_build_all ALL) - endif() - add_custom_target(${target_name} ${should_build_all} DEPENDS ${target} ${output_path}) - set_target_properties(${target_name} PROPERTIES FOLDER Tools) - - # Make sure both the link and target are toolchain tools - if (${link_name} IN_LIST LLVM_TOOLCHAIN_TOOLS AND ${target} IN_LIST LLVM_TOOLCHAIN_TOOLS) - set(TOOL_IS_TOOLCHAIN ON) - endif() - - if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) - llvm_install_symlink("${project}" ${link_name} ${target}) - endif() - endif() -endfunction() - -function(add_llvm_tool_symlink link_name target) - llvm_add_tool_symlink(LLVM ${ARGV}) -endfunction() - -function(llvm_externalize_debuginfo name) - if(NOT LLVM_EXTERNALIZE_DEBUGINFO) - return() - endif() - - if(NOT LLVM_EXTERNALIZE_DEBUGINFO_SKIP_STRIP) - if(APPLE) - if(NOT CMAKE_STRIP) - set(CMAKE_STRIP xcrun strip) - endif() - set(strip_command COMMAND ${CMAKE_STRIP} -S -x $) - else() - set(strip_command COMMAND ${CMAKE_STRIP} -g -x $) - endif() - endif() - - if(APPLE) - if(LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION) - set(file_ext ${LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION}) - else() - set(file_ext dSYM) - endif() - - set(output_name "$.${file_ext}") - - if(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR) - set(output_path "-o=${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}") - else() - set(output_path "-o=${output_name}") - endif() - - if(CMAKE_CXX_FLAGS MATCHES "-flto" - OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto") - - set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o) - set_property(TARGET ${name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-object_path_lto,${lto_object}") - endif() - if(NOT CMAKE_DSYMUTIL) - set(CMAKE_DSYMUTIL xcrun dsymutil) - endif() - add_custom_command(TARGET ${name} POST_BUILD - COMMAND ${CMAKE_DSYMUTIL} ${output_path} $ - ${strip_command} - ) - else() - add_custom_command(TARGET ${name} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ $.debug - ${strip_command} -R .gnu_debuglink - COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$.debug $ - ) - endif() -endfunction() - -# Usage: llvm_codesign(name [FORCE] [ENTITLEMENTS file] [BUNDLE_PATH path]) -function(llvm_codesign name) - cmake_parse_arguments(ARG "FORCE" "ENTITLEMENTS;BUNDLE_PATH" "" ${ARGN}) - - if(NOT LLVM_CODESIGNING_IDENTITY) - return() - endif() - - if(CMAKE_GENERATOR STREQUAL "Xcode") - set_target_properties(${name} PROPERTIES - XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${LLVM_CODESIGNING_IDENTITY} - ) - if(DEFINED ARG_ENTITLEMENTS) - set_target_properties(${name} PROPERTIES - XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${ARG_ENTITLEMENTS} - ) - endif() - elseif(APPLE AND CMAKE_HOST_SYSTEM_NAME MATCHES Darwin) - if(NOT CMAKE_CODESIGN) - set(CMAKE_CODESIGN xcrun codesign) - endif() - if(NOT CMAKE_CODESIGN_ALLOCATE) - execute_process( - COMMAND xcrun -f codesign_allocate - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE - ) - endif() - if(DEFINED ARG_ENTITLEMENTS) - set(pass_entitlements --entitlements ${ARG_ENTITLEMENTS}) - endif() - - if (NOT ARG_BUNDLE_PATH) - set(ARG_BUNDLE_PATH $) - endif() - - # ld64 now always codesigns the binaries it creates. Apply the force arg - # unconditionally so that we can - for example - add entitlements to the - # targets that need it. - set(force_flag "-f") - - add_custom_command( - TARGET ${name} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E - env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE} - ${CMAKE_CODESIGN} -s ${LLVM_CODESIGNING_IDENTITY} - ${pass_entitlements} ${force_flag} ${ARG_BUNDLE_PATH} - ) - endif() -endfunction() - -function(llvm_setup_rpath name) - if(CMAKE_INSTALL_RPATH) - return() - endif() - - if(LLVM_INSTALL_PREFIX AND NOT (LLVM_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX)) - set(extra_libdir ${LLVM_LIBRARY_DIR}) - elseif(LLVM_BUILD_LIBRARY_DIR) - set(extra_libdir ${LLVM_LIBRARY_DIR}) - endif() - - if (APPLE) - set(_install_name_dir INSTALL_NAME_DIR "@rpath") - set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) - # $ORIGIN is not interpreted at link time by aix ld. - # Since BUILD_SHARED_LIBS is only recommended for use by developers, - # hardcode the rpath to build/install lib dir first in this mode. - # FIXME: update this when there is better solution. - set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - elseif(UNIX) - set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) - set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}") - if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") - set_property(TARGET ${name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-z,origin ") - endif() - if(LLVM_LINKER_IS_GNULD) - # $ORIGIN is not interpreted at link time by ld.bfd - set_property(TARGET ${name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ") - endif() - else() - return() - endif() - - # Enable BUILD_WITH_INSTALL_RPATH unless CMAKE_BUILD_RPATH is set and not - # building for macOS or AIX, as those platforms seemingly require it. - # On AIX, the tool chain doesn't support modifying rpaths/libpaths for XCOFF - # on install at the moment, so BUILD_WITH_INSTALL_RPATH is required. - if("${CMAKE_BUILD_RPATH}" STREQUAL "") - if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin|AIX") - set_property(TARGET ${name} PROPERTY BUILD_WITH_INSTALL_RPATH ON) - else() - set_property(TARGET ${name} APPEND PROPERTY BUILD_RPATH "${_build_rpath}") - endif() - endif() - - set_target_properties(${name} PROPERTIES - INSTALL_RPATH "${_install_rpath}" - ${_install_name_dir}) -endfunction() - -function(setup_dependency_debugging name) - if(NOT LLVM_DEPENDENCY_DEBUGGING) - return() - endif() - - if("intrinsics_gen" IN_LIST ARGN) - return() - endif() - - set(deny_attributes_inc "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Attributes.inc\"))") - set(deny_intrinsics_inc "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Intrinsics.inc\"))") - - set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_inc} ${deny_intrinsics_inc}'") - set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command}) -endfunction() - -# If the sources at the given `path` are under version control, set `out_var` -# to the the path of a file which will be modified when the VCS revision -# changes, attempting to create that file if it does not exist; if no such -# file exists and one cannot be created, instead set `out_var` to the -# empty string. -# -# If the sources are not under version control, do not define `out_var`. -function(find_first_existing_vc_file path out_var) - if(NOT EXISTS "${path}") - return() - endif() - find_package(Git) - if(GIT_FOUND) - execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir - WORKING_DIRECTORY ${path} - RESULT_VARIABLE git_result - OUTPUT_VARIABLE git_output - ERROR_QUIET) - if(git_result EQUAL 0) - string(STRIP "${git_output}" git_output) - get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path}) - # Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD - if (NOT EXISTS "${git_dir}/logs/HEAD") - execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD - WORKING_DIRECTORY "${git_dir}/logs" - RESULT_VARIABLE touch_head_result - ERROR_QUIET) - if (NOT touch_head_result EQUAL 0) - set(${out_var} "" PARENT_SCOPE) - return() - endif() - endif() - set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE) - endif() - endif() -endfunction() - -function(get_host_tool_path tool_name setting_name exe_var_name target_var_name) - set(${setting_name}_DEFAULT "") - - if(LLVM_NATIVE_TOOL_DIR) - if(EXISTS "${LLVM_NATIVE_TOOL_DIR}/${tool_name}${LLVM_HOST_EXECUTABLE_SUFFIX}") - set(${setting_name}_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/${tool_name}${LLVM_HOST_EXECUTABLE_SUFFIX}") - endif() - endif() - - set(${setting_name} "${${setting_name}_DEFAULT}" CACHE - STRING "Host ${tool_name} executable. Saves building if cross-compiling.") - - if(${setting_name}) - set(exe_name ${${setting_name}}) - set(target_name "") - elseif(LLVM_USE_HOST_TOOLS) - get_native_tool_path(${tool_name} exe_name) - set(target_name ${exe_name}) - else() - set(exe_name $) - set(target_name ${tool_name}) - endif() - set(${exe_var_name} "${exe_name}" CACHE STRING "") - set(${target_var_name} "${target_name}" CACHE STRING "") -endfunction() - -function(setup_host_tool tool_name setting_name exe_var_name target_var_name) - get_host_tool_path(${tool_name} ${setting_name} ${exe_var_name} ${target_var_name}) - # Set up a native tool build if necessary - if(LLVM_USE_HOST_TOOLS AND NOT ${setting_name}) - build_native_tool(${tool_name} exe_name DEPENDS ${tool_name}) - add_custom_target(${target_var_name} DEPENDS ${exe_name}) - endif() -endfunction() - -# Adds the unittests folder if gtest is available. -function(llvm_add_unittests tests_added) - if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h) - add_subdirectory(unittests) - set(${tests_added} ON PARENT_SCOPE) - else() - message(WARNING "gtest not found, unittests will not be available") - endif() -endfunction() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CheckCompilerVersion.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CheckCompilerVersion.cmake deleted file mode 100644 index 4b3a0eb..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CheckCompilerVersion.cmake +++ /dev/null @@ -1,110 +0,0 @@ -# Check if the host compiler is new enough. -# These versions are updated based on the following policy: -# llvm.org/docs/DeveloperPolicy.html#toolchain - -include(CheckCXXSourceCompiles) - -set(GCC_MIN 7.4) -set(GCC_SOFT_ERROR 7.4) -set(CLANG_MIN 5.0) -set(CLANG_SOFT_ERROR 5.0) -set(APPLECLANG_MIN 10.0) -set(APPLECLANG_SOFT_ERROR 10.0) - -# https://en.wikipedia.org/wiki/Microsoft_Visual_C#Internal_version_numbering -# _MSC_VER == 1927 MSVC++ 14.27 Visual Studio 2019 Version 16.7 -set(MSVC_MIN 19.27) -set(MSVC_SOFT_ERROR 19.27) - -set(LIBSTDCXX_MIN 7) -set(LIBSTDCXX_SOFT_ERROR 7) - - -if(DEFINED LLVM_COMPILER_CHECKED) - return() -endif() -set(LLVM_COMPILER_CHECKED ON) - -if(LLVM_FORCE_USE_OLD_TOOLCHAIN) - return() -endif() - -function(check_compiler_version NAME NICE_NAME MINIMUM_VERSION SOFT_ERROR_VERSION) - if(NOT CMAKE_CXX_COMPILER_ID STREQUAL NAME) - return() - endif() - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MINIMUM_VERSION) - message(FATAL_ERROR "Host ${NICE_NAME} version must be at least ${MINIMUM_VERSION}, your version is ${CMAKE_CXX_COMPILER_VERSION}.") - elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS SOFT_ERROR_VERSION) - if(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN) - message(WARNING "Host ${NICE_NAME} version should be at least ${SOFT_ERROR_VERSION} because LLVM will soon use new C++ features which your toolchain version doesn't support. Your version is ${CMAKE_CXX_COMPILER_VERSION}. Ignoring because you've set LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN, but very soon your toolchain won't be supported.") - else() - message(FATAL_ERROR "Host ${NICE_NAME} version should be at least ${SOFT_ERROR_VERSION} because LLVM will soon use new C++ features which your toolchain version doesn't support. Your version is ${CMAKE_CXX_COMPILER_VERSION}. You can temporarily opt out using LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN, but very soon your toolchain won't be supported.") - endif() - endif() -endfunction(check_compiler_version) - -check_compiler_version("GNU" "GCC" ${GCC_MIN} ${GCC_SOFT_ERROR}) -check_compiler_version("Clang" "Clang" ${CLANG_MIN} ${CLANG_SOFT_ERROR}) -check_compiler_version("AppleClang" "Apple Clang" ${APPLECLANG_MIN} ${APPLECLANG_SOFT_ERROR}) -check_compiler_version("MSVC" "Visual Studio" ${MSVC_MIN} ${MSVC_SOFT_ERROR}) - -# See https://developercommunity.visualstudio.com/content/problem/845933/miscompile-boolean-condition-deduced-to-be-always.html -# and thread "[llvm-dev] Longstanding failing tests - clang-tidy, MachO, Polly" -# on llvm-dev Jan 21-23 2020. -if ((${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) AND - (19.24 VERSION_LESS_EQUAL ${CMAKE_CXX_COMPILER_VERSION}) AND - (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 19.25)) - if(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN) - message(WARNING "Host Visual Studio version 16.4 is known to miscompile part of LLVM") - else() - message(FATAL_ERROR "Host Visual Studio version 16.4 is known to miscompile part of LLVM, please use clang-cl or upgrade to 16.5 or above (use -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON to ignore)") - endif() -endif() - - -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") - if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS MSVC_MIN) - message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=${MSVC_MIN}, your version is ${CMAKE_CXX_SIMULATE_VERSION}.") - endif() - set(CLANG_CL 1) - elseif(NOT LLVM_ENABLE_LIBCXX) - # Test that we aren't using too old of a version of libstdc++. - 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 -#if defined(__GLIBCXX__) -#if !defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE < ${LIBSTDCXX_MIN} -#error Unsupported libstdc++ version -#endif -#endif -int main() { return 0; } -" - LLVM_LIBSTDCXX_MIN) - if(NOT LLVM_LIBSTDCXX_MIN) - message(FATAL_ERROR "libstdc++ version must be at least ${GCC_MIN}.") - endif() - check_cxx_source_compiles(" -#include -#if defined(__GLIBCXX__) -#if !defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE < ${LIBSTDCXX_SOFT_ERROR} -#error Unsupported libstdc++ version -#endif -#endif -int main() { return 0; } -" - LLVM_LIBSTDCXX_SOFT_ERROR) - if(NOT LLVM_LIBSTDCXX_SOFT_ERROR) - if(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN) - message(WARNING "libstdc++ version should be at least ${LIBSTDCXX_SOFT_ERROR} because LLVM will soon use new C++ features which your toolchain version doesn't support. Ignoring because you've set LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN, but very soon your toolchain won't be supported.") - else() - message(FATAL_ERROR "libstdc++ version should be at least ${LIBSTDCXX_SOFT_ERROR} because LLVM will soon use new C++ features which your toolchain version doesn't support. You can temporarily opt out using LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN, but very soon your toolchain won't be supported.") - endif() - endif() - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES}) - endif() -endif() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CheckProblematicConfigurations.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CheckProblematicConfigurations.cmake deleted file mode 100644 index e133873..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CheckProblematicConfigurations.cmake +++ /dev/null @@ -1,19 +0,0 @@ - -option(LLVM_ALLOW_PROBLEMATIC_CONFIGURATIONS OFF "Set this option to ON to allow problematic toolchain configurations. Use on your own risk.") - -macro(log_problematic MESSAGE) - if(LLVM_ALLOW_PROBLEMATIC_CONFIGURATIONS) - message(WARNING "${MESSAGE}") - else() - message(FATAL_ERROR "${MESSAGE}\nYou can force usage of this configuration by passing -DLLVM_ALLOW_PROBLEMATIC_CONFIGURATIONS=ON") - endif() -endmacro() - -# MSVC and /arch:AVX is untested and have created problems before. See: -# https://github.com/llvm/llvm-project/issues/54645 -if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) - string(TOLOWER "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}" _FLAGS) - if(_FLAGS MATCHES "/arch:avx[0-9]*") - log_problematic("Compiling LLVM with MSVC and the /arch:AVX flag is known to cause issues with parts of LLVM.\nSee https://github.com/llvm/llvm-project/issues/54645 for details.\nUse clang-cl if you want to enable AVX instructions.") - endif() -endif() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CrossCompile.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CrossCompile.cmake deleted file mode 100644 index 6af47b5..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/CrossCompile.cmake +++ /dev/null @@ -1,134 +0,0 @@ -include(AddLLVM) -include(LLVMExternalProjectUtils) - - -function(llvm_create_cross_target project_name target_name toolchain buildtype) - - if(NOT DEFINED ${project_name}_${target_name}_BUILD) - set(${project_name}_${target_name}_BUILD - "${CMAKE_CURRENT_BINARY_DIR}/${target_name}") - set(${project_name}_${target_name}_BUILD - ${${project_name}_${target_name}_BUILD} PARENT_SCOPE) - message(STATUS "Setting native build dir to " ${${project_name}_${target_name}_BUILD}) - endif(NOT DEFINED ${project_name}_${target_name}_BUILD) - - if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake) - set(CROSS_TOOLCHAIN_FLAGS_INIT - -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\") - elseif (NOT CMAKE_CROSSCOMPILING) - set(CROSS_TOOLCHAIN_FLAGS_INIT - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - ) - endif() - set(CROSS_TOOLCHAIN_FLAGS_${target_name} ${CROSS_TOOLCHAIN_FLAGS_INIT} - CACHE STRING "Toolchain configuration for ${target_name}") - - # project specific version of the flags up above - set(CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name} "" - CACHE STRING "Toolchain configuration for ${project_name}_${target_name}") - - if (buildtype) - set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}") - endif() - if (LLVM_USE_LINKER AND NOT CMAKE_CROSSCOMPILING) - set(linker_flag "-DLLVM_USE_LINKER=${LLVM_USE_LINKER}") - endif() - if (LLVM_EXTERNAL_CLANG_SOURCE_DIR) - # Propagate LLVM_EXTERNAL_CLANG_SOURCE_DIR so that clang-tblgen can be built - set(external_clang_dir "-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${LLVM_EXTERNAL_CLANG_SOURCE_DIR}") - endif() - - add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD} - COMMAND ${CMAKE_COMMAND} -E make_directory ${${project_name}_${target_name}_BUILD} - COMMENT "Creating ${${project_name}_${target_name}_BUILD}...") - - add_custom_target(CREATE_${project_name}_${target_name} - DEPENDS ${${project_name}_${target_name}_BUILD}) - - # Escape semicolons in the targets list so that cmake doesn't expand - # them to spaces. - string(REPLACE ";" "$" targets_to_build_arg - "${LLVM_TARGETS_TO_BUILD}") - string(REPLACE ";" "$" experimental_targets_to_build_arg - "${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}") - - string(REPLACE ";" "$" llvm_enable_projects_arg - "${LLVM_ENABLE_PROJECTS}") - string(REPLACE ";" "$" llvm_external_projects_arg - "${LLVM_EXTERNAL_PROJECTS}") - string(REPLACE ";" "$" llvm_enable_runtimes_arg - "${LLVM_ENABLE_RUNTIMES}") - - set(external_project_source_dirs) - foreach(project ${LLVM_EXTERNAL_PROJECTS}) - canonicalize_tool_name(${project} name) - list(APPEND external_project_source_dirs - "-DLLVM_EXTERNAL_${name}_SOURCE_DIR=${LLVM_EXTERNAL_${name}_SOURCE_DIR}") - endforeach() - - add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt - COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" - -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}" - -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" - -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}" - ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR} - ${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}} - -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE - -DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}" - -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${experimental_targets_to_build_arg}" - -DLLVM_DEFAULT_TARGET_TRIPLE="${LLVM_TARGET_TRIPLE}" - -DLLVM_TARGET_ARCH="${LLVM_TARGET_ARCH}" - -DLLVM_ENABLE_PROJECTS="${llvm_enable_projects_arg}" - -DLLVM_EXTERNAL_PROJECTS="${llvm_external_projects_arg}" - -DLLVM_ENABLE_RUNTIMES="${llvm_enable_runtimes_arg}" - ${external_project_source_dirs} - -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN="${LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN}" - -DLLVM_INCLUDE_BENCHMARKS=OFF - -DLLVM_INCLUDE_TESTS=OFF - ${build_type_flags} ${linker_flag} ${external_clang_dir} - ${ARGN} - WORKING_DIRECTORY ${${project_name}_${target_name}_BUILD} - DEPENDS CREATE_${project_name}_${target_name} - COMMENT "Configuring ${target_name} ${project_name}...") - - add_custom_target(CONFIGURE_${project_name}_${target_name} - DEPENDS ${${project_name}_${target_name}_BUILD}/CMakeCache.txt) - -endfunction() - -function(get_native_tool_path target output_path_var) - if(CMAKE_CONFIGURATION_TYPES) - set(output_path "${${PROJECT_NAME}_NATIVE_BUILD}/Release/bin/${target}") - else() - set(output_path "${${PROJECT_NAME}_NATIVE_BUILD}/bin/${target}") - endif() - set(${output_path_var} ${output_path}${LLVM_HOST_EXECUTABLE_SUFFIX} PARENT_SCOPE) -endfunction() - -# Sets up a native build for a tool, used e.g. for cross-compilation and -# LLVM_OPTIMIZED_TABLEGEN. Always builds in Release. -# - target: The target to build natively -# - output_path_var: A variable name which receives the path to the built target -# - DEPENDS: Any additional dependencies for the target -function(build_native_tool target output_path_var) - cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) - - get_native_tool_path(${target} output_path) - - # Make chain of preceding actions - if(CMAKE_GENERATOR MATCHES "Visual Studio") - get_property(host_targets GLOBAL PROPERTY ${PROJECT_NAME}_HOST_TARGETS) - set_property(GLOBAL APPEND PROPERTY ${PROJECT_NAME}_HOST_TARGETS ${output_path}) - endif() - - llvm_ExternalProject_BuildCmd(build_cmd ${target} ${${PROJECT_NAME}_NATIVE_BUILD} - CONFIGURATION Release) - add_custom_command(OUTPUT "${output_path}" - COMMAND ${build_cmd} - DEPENDS CONFIGURE_${PROJECT_NAME}_NATIVE ${ARG_DEPENDS} ${host_targets} - WORKING_DIRECTORY "${${PROJECT_NAME}_NATIVE_BUILD}" - COMMENT "Building native ${target}..." - USES_TERMINAL) - set(${output_path_var} "${output_path}" PARENT_SCOPE) -endfunction() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/DetermineGCCCompatible.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/DetermineGCCCompatible.cmake deleted file mode 100644 index 1369ebe..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/DetermineGCCCompatible.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# 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/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/HandleLLVMOptions.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/HandleLLVMOptions.cmake deleted file mode 100644 index 4d3e642..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/HandleLLVMOptions.cmake +++ /dev/null @@ -1,1419 +0,0 @@ -# This CMake module is responsible for interpreting the user defined LLVM_ -# options and executing the appropriate CMake commands to realize the users' -# selections. - -# This is commonly needed so make sure it's defined before we include anything -# else. -string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) - -include(CheckCompilerVersion) -include(CheckProblematicConfigurations) -include(HandleLLVMStdlib) -include(CheckCCompilerFlag) -include(CheckCSourceCompiles) -include(CheckCXXCompilerFlag) -include(CheckCXXSourceCompiles) -include(CheckSymbolExists) -include(CMakeDependentOption) -include(LLVMProcessSources) - -if(CMAKE_LINKER MATCHES ".*lld" OR (LLVM_USE_LINKER STREQUAL "lld" OR LLVM_ENABLE_LLD)) - set(LINKER_IS_LLD TRUE) -else() - set(LINKER_IS_LLD FALSE) -endif() - -if(CMAKE_LINKER MATCHES "lld-link" OR (MSVC AND (LLVM_USE_LINKER STREQUAL "lld" OR LLVM_ENABLE_LLD))) - set(LINKER_IS_LLD_LINK TRUE) -else() - set(LINKER_IS_LLD_LINK FALSE) -endif() - -set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO") -string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO) - -# Ninja Job Pool support -# The following only works with the Ninja generator in CMake >= 3.0. -set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING - "Define the maximum number of concurrent compilation jobs (Ninja only).") -if(LLVM_PARALLEL_COMPILE_JOBS) - if(NOT CMAKE_GENERATOR MATCHES "Ninja") - message(WARNING "Job pooling is only available with Ninja generators.") - else() - set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS}) - set(CMAKE_JOB_POOL_COMPILE compile_job_pool) - endif() -endif() - -set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING - "Define the maximum number of concurrent link jobs (Ninja only).") -if(CMAKE_GENERATOR MATCHES "Ninja") - if(NOT LLVM_PARALLEL_LINK_JOBS AND uppercase_LLVM_ENABLE_LTO STREQUAL "THIN") - message(STATUS "ThinLTO provides its own parallel linking - limiting parallel link jobs to 2.") - set(LLVM_PARALLEL_LINK_JOBS "2") - endif() - if(LLVM_PARALLEL_LINK_JOBS) - set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS}) - set(CMAKE_JOB_POOL_LINK link_job_pool) - endif() -elseif(LLVM_PARALLEL_LINK_JOBS) - message(WARNING "Job pooling is only available with Ninja generators.") -endif() - -if( LLVM_ENABLE_ASSERTIONS ) - # MSVC doesn't like _DEBUG on release builds. See PR 4379. - if( NOT MSVC ) - add_compile_definitions(_DEBUG) - endif() - # On non-Debug builds cmake automatically defines NDEBUG, so we - # explicitly undefine it: - if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) - add_compile_options($<$,$>:-UNDEBUG>) - if (MSVC) - # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. - foreach (flags_var_to_scrub - CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS_MINSIZEREL) - string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " - "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") - endforeach() - endif() - endif() - # Enable assertions in libstdc++. - add_compile_definitions(_GLIBCXX_ASSERTIONS) - # Enable the hardened mode in libc++. - add_compile_definitions(_LIBCPP_ENABLE_HARDENED_MODE) -endif() - -if(LLVM_ENABLE_EXPENSIVE_CHECKS) - add_compile_definitions(EXPENSIVE_CHECKS) - - # In some libstdc++ versions, std::min_element is not constexpr when - # _GLIBCXX_DEBUG is enabled. - CHECK_CXX_SOURCE_COMPILES(" - #define _GLIBCXX_DEBUG - #include - int main(int argc, char** argv) { - static constexpr int data[] = {0, 1}; - constexpr const int* min_elt = std::min_element(&data[0], &data[2]); - return 0; - }" CXX_SUPPORTS_GLIBCXX_DEBUG) - if(CXX_SUPPORTS_GLIBCXX_DEBUG) - add_compile_definitions(_GLIBCXX_DEBUG) - else() - add_compile_definitions(_GLIBCXX_ASSERTIONS) - endif() -endif() - -if (LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS) - add_compile_definitions(STRICT_FIXED_SIZE_VECTORS) -endif() - -string(TOUPPER "${LLVM_ABI_BREAKING_CHECKS}" uppercase_LLVM_ABI_BREAKING_CHECKS) - -if( uppercase_LLVM_ABI_BREAKING_CHECKS STREQUAL "WITH_ASSERTS" ) - if( LLVM_ENABLE_ASSERTIONS ) - set( LLVM_ENABLE_ABI_BREAKING_CHECKS 1 ) - endif() -elseif( uppercase_LLVM_ABI_BREAKING_CHECKS STREQUAL "FORCE_ON" ) - set( LLVM_ENABLE_ABI_BREAKING_CHECKS 1 ) -elseif( uppercase_LLVM_ABI_BREAKING_CHECKS STREQUAL "FORCE_OFF" ) - # We don't need to do anything special to turn off ABI breaking checks. -elseif( NOT DEFINED LLVM_ABI_BREAKING_CHECKS ) - # Treat LLVM_ABI_BREAKING_CHECKS like "FORCE_OFF" when it has not been - # defined. -else() - message(FATAL_ERROR "Unknown value for LLVM_ABI_BREAKING_CHECKS: \"${LLVM_ABI_BREAKING_CHECKS}\"!") -endif() - -if( LLVM_REVERSE_ITERATION ) - set( LLVM_ENABLE_REVERSE_ITERATION 1 ) -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) -elseif(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() -elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic") - set(LLVM_ON_WIN32 0) - set(LLVM_ON_UNIX 0) - set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) -else() - MESSAGE(SEND_ERROR "Unable to determine platform") -endif() - -if (CMAKE_SYSTEM_NAME MATCHES "OS390") - set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) -endif() - -set(EXEEXT ${CMAKE_EXECUTABLE_SUFFIX}) -set(LTDL_SHLIB_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) - -# We use *.dylib rather than *.so on darwin, but we stick with *.so on AIX. -if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") - set(LLVM_PLUGIN_EXT ${CMAKE_SHARED_MODULE_SUFFIX}) -else() - set(LLVM_PLUGIN_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) -endif() - -if(APPLE) - # Darwin-specific linker flags for loadable modules. - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress") -endif() - -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - # RHEL7 has ar and ranlib being non-deterministic by default. The D flag forces determinism, - # however only GNU version of ar and ranlib (2.27) have this option. - # RHEL DTS7 is also affected by this, which uses GNU binutils 2.28 - execute_process(COMMAND ${CMAKE_AR} rD t.a - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE AR_RESULT - OUTPUT_QUIET - ERROR_QUIET - ) - if(${AR_RESULT} EQUAL 0) - execute_process(COMMAND ${CMAKE_RANLIB} -D t.a - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE RANLIB_RESULT - OUTPUT_QUIET - ERROR_QUIET - ) - if(${RANLIB_RESULT} EQUAL 0) - set(CMAKE_C_ARCHIVE_CREATE " Dqc " - CACHE STRING "archive create command") - set(CMAKE_C_ARCHIVE_APPEND " Dq ") - set(CMAKE_C_ARCHIVE_FINISH " -D " CACHE STRING "ranlib command") - - set(CMAKE_CXX_ARCHIVE_CREATE " Dqc " - CACHE STRING "archive create command") - set(CMAKE_CXX_ARCHIVE_APPEND " Dq ") - set(CMAKE_CXX_ARCHIVE_FINISH " -D " CACHE STRING "ranlib command") - endif() - file(REMOVE ${CMAKE_BINARY_DIR}/t.a) - endif() -endif() - -if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") - # -fPIC does not enable the large code model for GCC on AIX but does for XL. - if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - append("-mcmodel=large" CMAKE_CXX_FLAGS CMAKE_C_FLAGS) - append("-Wl,-bglink=large" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - elseif(CMAKE_CXX_COMPILER_ID MATCHES "XL") - # XL generates a small number of relocations not of the large model, -bbigtoc is needed. - append("-Wl,-bbigtoc" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - # The default behaviour on AIX processes dynamic initialization of non-local variables with - # static storage duration even for archive members that are otherwise unreferenced. - # Since `--whole-archive` is not used by the LLVM build to keep such initializations for Linux, - # we can limit the processing for archive members to only those that are otherwise referenced. - append("-bcdtors:mbr" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() - if(BUILD_SHARED_LIBS) - # See rpath handling in AddLLVM.cmake - # FIXME: Remove this warning if this rpath is no longer hardcoded. - message(WARNING "Build and install environment path info may be exposed; binaries will also be unrelocatable.") - endif() -endif() - -# Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO -# build might work on ELF but fail on MachO/COFF. -if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|OS390" OR - WIN32 OR CYGWIN) AND - NOT LLVM_USE_SANITIZER) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") -endif() - -# Pass -Wl,-z,nodelete. This makes sure our shared libraries are not unloaded -# by dlclose(). We need that since the CLI API relies on cross-references -# between global objects which became horribly broken when one of the libraries -# is unloaded. -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,nodelete") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,nodelete") -endif() - - -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() - -function(has_msvc_incremental_no_flag flags incr_no_flag_on) - set(${incr_no_flag_on} OFF PARENT_SCOPE) - string(FIND "${flags}" "/INCREMENTAL" idx REVERSE) - if (${idx} GREATER -1) - string(SUBSTRING "${flags}" ${idx} 15 no_flag) - if (${no_flag} MATCHES "/INCREMENTAL:NO") - set(${incr_no_flag_on} ON PARENT_SCOPE) - endif() - endif() -endfunction() - -if( LLVM_ENABLE_LLD ) - if ( LLVM_USE_LINKER ) - message(FATAL_ERROR "LLVM_ENABLE_LLD and LLVM_USE_LINKER can't be set at the same time") - endif() - - # In case of MSVC cmake always invokes the linker directly, so the linker - # should be specified by CMAKE_LINKER cmake variable instead of by -fuse-ld - # compiler option. - if ( MSVC ) - if(NOT CMAKE_LINKER MATCHES "lld-link") - get_filename_component(CXX_COMPILER_DIR ${CMAKE_CXX_COMPILER} DIRECTORY) - get_filename_component(C_COMPILER_DIR ${CMAKE_C_COMPILER} DIRECTORY) - find_program(LLD_LINK NAMES "lld-link" "lld-link.exe" HINTS ${CXX_COMPILER_DIR} ${C_COMPILER_DIR} DOC "lld linker") - if(NOT LLD_LINK) - message(FATAL_ERROR - "LLVM_ENABLE_LLD set, but cannot find lld-link. " - "Consider setting CMAKE_LINKER to lld-link path.") - endif() - set(CMAKE_LINKER ${LLD_LINK}) - endif() - else() - set(LLVM_USE_LINKER "lld") - endif() -endif() - -if( LLVM_USE_LINKER ) - append("-fuse-ld=${LLVM_USE_LINKER}" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER) - if ( NOT CXX_SUPPORTS_CUSTOM_LINKER ) - message(FATAL_ERROR "Host compiler does not support '-fuse-ld=${LLVM_USE_LINKER}'") - endif() -endif() - -if( LLVM_ENABLE_PIC ) - if( XCODE ) - # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't - # know how to disable this, so just force ENABLE_PIC off for now. - message(WARNING "-fPIC not supported with Xcode.") - elseif( WIN32 OR CYGWIN) - # On Windows all code is PIC. MinGW warns if -fPIC is used. - else() - add_flag_or_print_warning("-fPIC" FPIC) - # Enable interprocedural optimizations for non-inline functions which would - # otherwise be disabled due to GCC -fPIC's default. - # Note: GCC<10.3 has a bug on SystemZ. - # - # Note: Clang allows IPO for -fPIC so this optimization is less effective. - # Clang 13 has a bug related to -fsanitize-coverage - # -fno-semantic-interposition (https://reviews.llvm.org/D117183). - if ((CMAKE_COMPILER_IS_GNUCXX AND - NOT (LLVM_NATIVE_ARCH STREQUAL "SystemZ" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.3)) - OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 14)) - add_flag_if_supported("-fno-semantic-interposition" FNO_SEMANTIC_INTERPOSITION) - endif() - endif() - # GCC for MIPS can miscompile LLVM due to PR37701. - if(CMAKE_COMPILER_IS_GNUCXX AND LLVM_NATIVE_ARCH STREQUAL "Mips" AND - NOT Uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - add_flag_or_print_warning("-fno-shrink-wrap" FNO_SHRINK_WRAP) - endif() - # gcc with -O3 -fPIC generates TLS sequences that violate the spec on - # Solaris/sparcv9, causing executables created with the system linker - # to SEGV (GCC PR target/96607). - # clang with -O3 -fPIC generates code that SEGVs. - # Both can be worked around by compiling with -O instead. - if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" AND LLVM_NATIVE_ARCH STREQUAL "Sparc") - llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O[23]" "-O") - llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O[23]" "-O") - endif() -endif() - -if((NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX")) AND - (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang"))) - # GCC for MinGW does nothing about -fvisibility-inlines-hidden, but warns - # about use of the attributes. As long as we don't use the attributes (to - # override the default) we shouldn't set the command line options either. - # GCC on AIX warns if -fvisibility-inlines-hidden is used and Clang on AIX doesn't currently support visibility. - check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG) - append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS) -endif() - -if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MINGW) - add_compile_definitions(_FILE_OFFSET_BITS=64) -endif() - -if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) - # TODO: support other platforms and toolchains. - if( LLVM_BUILD_32_BITS ) - message(STATUS "Building 32 bits executables and libraries.") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32") - - # FIXME: CMAKE_SIZEOF_VOID_P is still 8 - add_compile_definitions(_LARGEFILE_SOURCE) - add_compile_definitions(_FILE_OFFSET_BITS=64) - endif( LLVM_BUILD_32_BITS ) -endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) - -# If building on a GNU specific 32-bit system, make sure off_t is 64 bits -# so that off_t can stored offset > 2GB. -# Android until version N (API 24) doesn't support it. -if (ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 24)) - set(LLVM_FORCE_SMALLFILE_FOR_ANDROID TRUE) -endif() -if( CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT LLVM_FORCE_SMALLFILE_FOR_ANDROID) - # FIXME: It isn't handled in LLVM_BUILD_32_BITS. - add_compile_definitions(_LARGEFILE_SOURCE) - add_compile_definitions(_FILE_OFFSET_BITS=64) -endif() - -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() - -# On Win32 using MS tools, provide an option to set the number of parallel jobs -# to use. -if( MSVC_IDE ) - set(LLVM_COMPILER_JOBS "0" CACHE STRING - "Number of parallel compiler jobs. 0 means use all processors. Default is 0.") - if( NOT LLVM_COMPILER_JOBS STREQUAL "1" ) - if( LLVM_COMPILER_JOBS STREQUAL "0" ) - add_compile_options(/MP) - else() - message(STATUS "Number of parallel compiler jobs set to " ${LLVM_COMPILER_JOBS}) - add_compile_options(/MP${LLVM_COMPILER_JOBS}) - endif() - else() - message(STATUS "Parallel compilation disabled") - endif() -endif() - -# 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 us in tasks such as parsing recursive - # C++ templates in Clang. - 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") - - # Pass -mbig-obj to mingw gas to avoid COFF 2**16 section limit. - if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - append("-Wa,-mbig-obj" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() -endif() - -option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON) - -if( MSVC ) - include(ChooseMSVCCRT) - - # Add definitions that make MSVC much less annoying. - add_compile_definitions( - # For some reason MS wants to deprecate a bunch of standard functions... - _CRT_SECURE_NO_DEPRECATE - _CRT_SECURE_NO_WARNINGS - _CRT_NONSTDC_NO_DEPRECATE - _CRT_NONSTDC_NO_WARNINGS - _SCL_SECURE_NO_DEPRECATE - _SCL_SECURE_NO_WARNINGS - ) - - # Tell MSVC to use the Unicode version of the Win32 APIs instead of ANSI. - add_compile_definitions( - UNICODE - _UNICODE - ) - - if (LLVM_WINSYSROOT) - if (NOT CLANG_CL) - message(ERROR "LLVM_WINSYSROOT requires clang-cl") - endif() - append("/winsysroot${LLVM_WINSYSROOT}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - if (LINKER_IS_LLD_LINK) - append("/winsysroot:${LLVM_WINSYSROOT}" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) - endif() - endif() - - if (LLVM_ENABLE_WERROR) - append("/WX" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif (LLVM_ENABLE_WERROR) - - append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - - if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Enable standards-conforming preprocessor. - # https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor - append("/Zc:preprocessor" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif () - - # Some projects use the __cplusplus preprocessor macro to check support for - # a particular version of the C++ standard. When this option is not specified - # explicitly, macro's value is "199711L" that implies C++98 Standard. - # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ - append("/Zc:__cplusplus" CMAKE_CXX_FLAGS) - - # Allow users to request PDBs in release mode. CMake offeres the - # RelWithDebInfo configuration, but it uses different optimization settings - # (/Ob1 vs /Ob2 or -O2 vs -O3). LLVM provides this flag so that users can get - # PDBs without changing codegen. - option(LLVM_ENABLE_PDB OFF) - if (LLVM_ENABLE_PDB AND uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") - append("/Zi" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - # /DEBUG disables linker GC and ICF, but we want those in Release mode. - append("/DEBUG /OPT:REF /OPT:ICF" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) - endif() - - # Get all linker flags in upper case form so we can search them. - string(CONCAT all_linker_flags_uppercase - ${CMAKE_EXE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} " " - ${CMAKE_EXE_LINKER_FLAGS} " " - ${CMAKE_MODULE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} " " - ${CMAKE_MODULE_LINKER_FLAGS} " " - ${CMAKE_SHARED_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} " " - ${CMAKE_SHARED_LINKER_FLAGS}) - string(TOUPPER "${all_linker_flags_uppercase}" all_linker_flags_uppercase) - - if (CLANG_CL AND LINKER_IS_LLD) - # If we are using clang-cl with lld-link and /debug is present in any of the - # linker flag variables, pass -gcodeview-ghash to the compiler to speed up - # linking. This flag is orthogonal from /Zi, /Z7, and other flags that - # enable debug info emission, and only has an effect if those are also in - # use. - string(FIND "${all_linker_flags_uppercase}" "/DEBUG" linker_flag_idx) - if (${linker_flag_idx} GREATER -1) - add_flag_if_supported("-gcodeview-ghash" GCODEVIEW_GHASH) - endif() - endif() - - # "Generate Intrinsic Functions". - append("/Oi" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT LLVM_ENABLE_LTO) - # clang-cl and cl by default produce non-deterministic binaries because - # link.exe /incremental requires a timestamp in the .obj file. clang-cl - # has the flag /Brepro to force deterministic binaries. We want to pass that - # whenever you're building with clang unless you're passing /incremental - # or using LTO (/Brepro with LTO would result in a warning about the flag - # being unused, because we're not generating object files). - # This checks CMAKE_CXX_COMPILER_ID in addition to check_cxx_compiler_flag() - # because cl.exe does not emit an error on flags it doesn't understand, - # letting check_cxx_compiler_flag() claim it understands all flags. - check_cxx_compiler_flag("/Brepro" SUPPORTS_BREPRO) - if (SUPPORTS_BREPRO) - # Check if /INCREMENTAL is passed to the linker and complain that it - # won't work with /Brepro. - has_msvc_incremental_no_flag("${CMAKE_EXE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_EXE_LINKER_FLAGS}" NO_INCR_EXE) - has_msvc_incremental_no_flag("${CMAKE_MODULE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_MODULE_LINKER_FLAGS}" NO_INCR_MODULE) - has_msvc_incremental_no_flag("${CMAKE_SHARED_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_SHARED_LINKER_FLAGS}" NO_INCR_SHARED) - if (NO_INCR_EXE AND NO_INCR_MODULE AND NO_INCR_SHARED) - append("/Brepro" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - else() - message(WARNING "/Brepro not compatible with /INCREMENTAL linking - builds will be non-deterministic") - endif() - endif() - endif() - # By default MSVC has a 2^16 limit on the number of sections in an object file, - # but in many objects files need more than that. This flag is to increase the - # number of sections. - append("/bigobj" CMAKE_CXX_FLAGS) - - # Enable standards conformance mode. - # This ensures handling of various C/C++ constructs is more similar to other compilers. - append("/permissive-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) -endif( MSVC ) - -# Warnings-as-errors handling for GCC-compatible compilers: -if ( LLVM_COMPILER_IS_GCC_COMPATIBLE ) - append_if(LLVM_ENABLE_WERROR "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append_if(LLVM_ENABLE_WERROR "-Wno-error" CMAKE_REQUIRED_FLAGS) -endif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) - -# Specific default warnings-as-errors for compilers accepting GCC-compatible warning flags: -if ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" ) - add_flag_if_supported("-Werror=date-time" WERROR_DATE_TIME) - add_flag_if_supported("-Werror=unguarded-availability-new" WERROR_UNGUARDED_AVAILABILITY_NEW) -endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" ) - -if ( LLVM_COMPILER_IS_GCC_COMPATIBLE ) - # LLVM data structures like llvm::User and llvm::MDNode rely on - # the value of object storage persisting beyond the lifetime of the - # object (#24952). This is not standard compliant and causes a runtime - # crash if LLVM is built with GCC and LTO enabled (#57740). Until - # these bugs are fixed, we need to disable dead store eliminations - # based on object lifetime. - add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS) -endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE ) - -# Modules enablement for GCC-compatible compilers: -if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES ) - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(module_flags "-fmodules -fmodules-cache-path=${PROJECT_BINARY_DIR}/module.cache") - if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # On Darwin -fmodules does not imply -fcxx-modules. - set(module_flags "${module_flags} -fcxx-modules") - endif() - if (LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY) - set(module_flags "${module_flags} -Xclang -fmodules-local-submodule-visibility") - endif() - if (LLVM_ENABLE_MODULE_DEBUGGING AND - ((uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") OR - (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO"))) - set(module_flags "${module_flags} -gmodules") - endif() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${module_flags}") - - # Check that we can build code with modules enabled, and that repeatedly - # including still manages to respect NDEBUG properly. - CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG - #include - #define NDEBUG - #include - int main() { assert(this code is not compiled); }" - CXX_SUPPORTS_MODULES) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) - if (CXX_SUPPORTS_MODULES) - append("${module_flags}" CMAKE_CXX_FLAGS) - else() - message(FATAL_ERROR "LLVM_ENABLE_MODULES is not supported by this compiler") - endif() -endif( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES ) - -if (MSVC) - 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' - -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data' - -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' - -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized' - -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 - -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 ''conversion' : conversion from 'type1' to 'type2', 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' - # C4709 is disabled because of a bug with Visual Studio 2017 as of - # v15.8.8. Re-evaluate the usefulness of this diagnostic when the bug - # is fixed. - -wd4709 # Suppress comma operator within array index expression - - # We'd like this warning to be enabled, but it triggers from code in - # WinBase.h that we don't have control over. - -wd5105 # Suppress macro expansion producing 'defined' has undefined behavior - - # Ideally, we'd like this warning to be enabled, but even MSVC 2019 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. - -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) - - # Enable warnings - if (LLVM_ENABLE_WARNINGS) - # Put /W4 in front of all the -we flags. cl.exe doesn't care, but for - # clang-cl having /W4 after the -we flags will re-enable the warnings - # disabled by -we. - set(msvc_warning_flags "/W4 ${msvc_warning_flags}") - # CMake appends /W3 by default, and having /W3 followed by /W4 will result in - # cl : Command line warning D9025 : overriding '/W3' with '/W4'. Since this is - # a command line warning and not a compiler warning, it cannot be suppressed except - # by fixing the command line. - string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - - if (LLVM_ENABLE_PEDANTIC) - # No MSVC equivalent available - endif (LLVM_ENABLE_PEDANTIC) - endif (LLVM_ENABLE_WARNINGS) - - foreach(flag ${msvc_warning_flags}) - append("${flag}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endforeach(flag) -endif (MSVC) - -if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)) - - # 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_C_FLAGS 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() - - if (LLVM_ENABLE_PEDANTIC AND LLVM_COMPILER_IS_GCC_COMPATIBLE) - append("-pedantic" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append("-Wno-long-long" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - - # GCC warns about redundant toplevel semicolons (enabled by -pedantic - # above), while Clang doesn't. Enable the corresponding Clang option to - # pick up on these even in builds with Clang. - add_flag_if_supported("-Wc++98-compat-extra-semi" CXX98_COMPAT_EXTRA_SEMI_FLAG) - endif() - - add_flag_if_supported("-Wimplicit-fallthrough" IMPLICIT_FALLTHROUGH_FLAG) - add_flag_if_supported("-Wcovered-switch-default" COVERED_SWITCH_DEFAULT_FLAG) - append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS) - append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS) - - # Disable -Wnonnull for GCC warning as it is emitting a lot of false positives. - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - append("-Wno-nonnull" CMAKE_CXX_FLAGS) - 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) - - # Disable -Wredundant-move and -Wpessimizing-move on GCC>=9. GCC wants to - # remove std::move in code like "A foo(ConvertibleToA a) { - # return std::move(a); }", but this code does not compile (or uses the copy - # constructor instead) on clang<=3.8. Clang also has a -Wredundant-move and - # -Wpessimizing-move, but they only fire when the types match exactly, so we - # can keep them here. - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - check_cxx_compiler_flag("-Wredundant-move" CXX_SUPPORTS_REDUNDANT_MOVE_FLAG) - append_if(CXX_SUPPORTS_REDUNDANT_MOVE_FLAG "-Wno-redundant-move" CMAKE_CXX_FLAGS) - check_cxx_compiler_flag("-Wpessimizing-move" CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG) - append_if(CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG "-Wno-pessimizing-move" CMAKE_CXX_FLAGS) - endif() - - # 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 for a class marked final, when it has a - # friend declaration. If it does, don't add -Wnon-virtual-dtor. The case is - # considered unhelpful (https://gcc.gnu.org/PR102168). - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=non-virtual-dtor") - CHECK_CXX_SOURCE_COMPILES("class f {}; - class base {friend f; public: virtual void anchor();protected: ~base();}; - 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) - - append("-Wdelete-non-virtual-dtor" CMAKE_CXX_FLAGS) - - # Enable -Wsuggest-override if it's available, and only if it doesn't - # suggest adding 'override' to functions that are already marked 'final' - # (which means it is disabled for GCC < 9.2). - check_cxx_compiler_flag("-Wsuggest-override" CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG) - if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG) - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=suggest-override") - CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();}; - class derived : base {public: void anchor() final;}; - int main() { return 0; }" - CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) - append_if(CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL "-Wsuggest-override" CMAKE_CXX_FLAGS) - endif() - - # Check if -Wcomment is OK with an // comment ending with '\' if the next - # line is also a // comment. - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror -Wcomment") - CHECK_C_SOURCE_COMPILES("// \\\\\\n//\\nint main(void) {return 0;}" - C_WCOMMENT_ALLOWS_LINE_WRAP) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) - if (NOT C_WCOMMENT_ALLOWS_LINE_WRAP) - append("-Wno-comment" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - - # Enable -Wstring-conversion to catch misuse of string literals. - add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG) - - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # Disable the misleading indentation warning with GCC; GCC can - # produce noisy notes about this getting disabled in large files. - # See e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89549 - check_cxx_compiler_flag("-Wmisleading-indentation" CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG) - append_if(CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG "-Wno-misleading-indentation" CMAKE_CXX_FLAGS) - else() - # Prevent bugs that can happen with llvm's brace style. - add_flag_if_supported("-Wmisleading-indentation" MISLEADING_INDENTATION_FLAG) - endif() - - # Enable -Wctad-maybe-unsupported to catch unintended use of CTAD. - add_flag_if_supported("-Wctad-maybe-unsupported" CTAD_MAYBE_UNSPPORTED_FLAG) -endif (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)) - -if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT LLVM_ENABLE_WARNINGS) - append("-w" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) -endif() - -# Enable '-index-store-path' on a Debug build, if the compiler supports it and for non-IDE generators. -option(LLVM_DISABLE_INDEX_STORE "Disable '-index-store-path' flag" Off) -if (NOT LLVM_DISABLE_INDEX_STORE AND NOT XCODE AND NOT MSVC_IDE AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - set(INDEX_DATA_STORE_PATH "${PROJECT_BINARY_DIR}/IndexStore" CACHE STRING "Index store path") - - check_c_compiler_flag("-Werror -index-store-path \"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/IndexStore\"" "C_SUPPORTS_INDEX_STORE") - append_if("C_SUPPORTS_INDEX_STORE" "-index-store-path \"${INDEX_DATA_STORE_PATH}\"" CMAKE_C_FLAGS) - check_cxx_compiler_flag("-Werror -index-store-path \"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/IndexStore\"" "CXX_SUPPORTS_INDEX_STORE") - append_if("CXX_SUPPORTS_INDEX_STORE" "-index-store-path \"${INDEX_DATA_STORE_PATH}\"" CMAKE_CXX_FLAGS) -endif() - -macro(append_common_sanitizer_flags) - if (NOT MSVC OR CLANG_CL) - # Append -fno-omit-frame-pointer and turn on debug info to get better - # stack traces. - add_flag_if_supported("-fno-omit-frame-pointer" FNO_OMIT_FRAME_POINTER) - if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND - NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") - add_flag_if_supported("-gline-tables-only" GLINE_TABLES_ONLY) - endif() - # Use -O1 even in debug mode, otherwise sanitizers slowdown is too large. - if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND LLVM_OPTIMIZE_SANITIZED_BUILDS) - add_flag_if_supported("-O1" O1) - endif() - else() - # Always ask the linker to produce symbols with asan. - append("/Z7" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append("/debug" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - # Not compatible with /INCREMENTAL link. - foreach (flags_opt_to_scrub - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - string (REGEX REPLACE "(^| )/INCREMENTAL($| )" " /INCREMENTAL:NO " - "${flags_opt_to_scrub}" "${${flags_opt_to_scrub}}") - endforeach() - if (LLVM_HOST_TRIPLE MATCHES "i[2-6]86-.*") - # Keep frame pointers around. - append("/Oy-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - endif() -endmacro() - -# Turn on sanitizers if necessary. -if(LLVM_USE_SANITIZER) - if (LLVM_ON_UNIX) - if (LLVM_USE_SANITIZER STREQUAL "Address") - append_common_sanitizer_flags() - append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - elseif (LLVM_USE_SANITIZER STREQUAL "HWAddress") - append_common_sanitizer_flags() - append("-fsanitize=hwaddress" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") - append_common_sanitizer_flags() - append("-fsanitize=memory" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") - append("-fsanitize-memory-track-origins" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") - append_common_sanitizer_flags() - append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - elseif (LLVM_USE_SANITIZER STREQUAL "Thread") - append_common_sanitizer_flags() - append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - elseif (LLVM_USE_SANITIZER STREQUAL "DataFlow") - append("-fsanitize=dataflow" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR - LLVM_USE_SANITIZER STREQUAL "Undefined;Address") - append_common_sanitizer_flags() - append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - elseif (LLVM_USE_SANITIZER STREQUAL "Leaks") - append_common_sanitizer_flags() - append("-fsanitize=leak" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - else() - message(FATAL_ERROR "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") - endif() - elseif(MINGW) - if (LLVM_USE_SANITIZER STREQUAL "Address") - append_common_sanitizer_flags() - append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") - append_common_sanitizer_flags() - append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR - LLVM_USE_SANITIZER STREQUAL "Undefined;Address") - append_common_sanitizer_flags() - append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append("${LLVM_UBSAN_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - else() - message(FATAL_ERROR "This sanitizer not yet supported in a MinGW environment: ${LLVM_USE_SANITIZER}") - endif() - elseif(MSVC) - if (NOT LLVM_USE_SANITIZER MATCHES "^(Address|Undefined|Address;Undefined|Undefined;Address)$") - message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${LLVM_USE_SANITIZER}") - endif() - append_common_sanitizer_flags() - if (LINKER_IS_LLD_LINK) - if (LLVM_HOST_TRIPLE MATCHES "i[2-6]86-.*") - set(arch "i386") - else() - set(arch "x86_64") - endif() - # Prepare ASAN runtime if needed - if (LLVM_USE_SANITIZER MATCHES ".*Address.*") - if (${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$") - append("/wholearchive:clang_rt.asan-${arch}.lib /wholearchive:clang_rt.asan_cxx-${arch}.lib" - CMAKE_EXE_LINKER_FLAGS) - append("/wholearchive:clang_rt.asan_dll_thunk-${arch}.lib" - CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - else() - append("clang_rt.asan_dynamic-${arch}.lib /wholearchive:clang_rt.asan_dynamic_runtime_thunk-${arch}.lib" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() - endif() - endif() - if (LLVM_USE_SANITIZER MATCHES ".*Address.*") - if (NOT CLANG_CL) - append("/fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - # Not compatible with /RTC flags. - foreach (flags_opt_to_scrub - CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}) - string (REGEX REPLACE "(^| )/RTC[1csu]*($| )" " " - "${flags_opt_to_scrub}" "${${flags_opt_to_scrub}}") - endforeach() - else() - append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - endif() - if (LLVM_USE_SANITIZER MATCHES ".*Undefined.*") - if (NOT CLANG_CL) - message(FATAL_ERROR "This sanitizer is only supported by clang-cl: Undefined") - endif() - append(${LLVM_UBSAN_FLAGS} CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - else() - message(FATAL_ERROR "LLVM_USE_SANITIZER is not supported on this platform.") - endif() - if (LLVM_USE_SANITIZE_COVERAGE) - append("-fsanitize=fuzzer-no-link" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - if (LLVM_USE_SANITIZER MATCHES ".*Undefined.*") - set(IGNORELIST_FILE "${PROJECT_SOURCE_DIR}/utils/sanitizers/ubsan_ignorelist.txt") - if (EXISTS "${IGNORELIST_FILE}") - # Use this option name version since -fsanitize-ignorelist is only - # accepted with clang 13.0 or newer. - append("-fsanitize-blacklist=${IGNORELIST_FILE}" - CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - endif() -endif() - -# Turn on -gsplit-dwarf if requested in debug builds. -if (LLVM_USE_SPLIT_DWARF AND - ((uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") OR - (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO"))) - # Limit to clang and gcc so far. Add compilers supporting this option. - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR - CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_compile_options(-gsplit-dwarf) - include(LLVMCheckLinkerFlag) - llvm_check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX) - append_if(LINKER_SUPPORTS_GDB_INDEX "-Wl,--gdb-index" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() -endif() - -add_compile_definitions(__STDC_CONSTANT_MACROS) -add_compile_definitions(__STDC_FORMAT_MACROS) -add_compile_definitions(__STDC_LIMIT_MACROS) - -# clang and gcc don't default-print colored diagnostics when invoked from Ninja. -if (UNIX AND - CMAKE_GENERATOR MATCHES "Ninja" AND - (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR - (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND - NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)))) - append("-fdiagnostics-color" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) -endif() - -# lld doesn't print colored diagnostics when invoked from Ninja -if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja") - include(LLVMCheckLinkerFlag) - llvm_check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) - append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics" - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) -endif() - -# Add flags for add_dead_strip(). -# FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF? -# But MinSizeRel seems to add that automatically, so maybe disable these -# flags instead if LLVM_NO_DEAD_STRIP is set. -if(NOT CYGWIN AND NOT MSVC) - if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND - NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS) - if (C_SUPPORTS_FNO_FUNCTION_SECTIONS) - # Don't add -ffunction-sections if it can't be disabled with -fno-function-sections. - # Doing so will break sanitizers. - add_flag_if_supported("-ffunction-sections" FFUNCTION_SECTIONS) - elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL") - append("-qfuncsect" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - add_flag_if_supported("-fdata-sections" FDATA_SECTIONS) - endif() -elseif(MSVC) - if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) - append("/Gw" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() -endif() - -if(MSVC) - # Remove flags here, for exceptions and RTTI. - # Each target property or source property should be responsible to control - # them. - # CL.EXE complains to override flags like "/GR /GR-". - string(REGEX REPLACE "(^| ) */EH[-cs]+ *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REGEX REPLACE "(^| ) */GR-? *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -endif() - -# Provide public options to globally control RTTI and EH -option(LLVM_ENABLE_EH "Enable Exception handling" OFF) -option(LLVM_ENABLE_RTTI "Enable run time type information" OFF) -if(LLVM_ENABLE_EH AND NOT LLVM_ENABLE_RTTI) - message(FATAL_ERROR "Exception handling requires RTTI. You must set LLVM_ENABLE_RTTI to ON") -endif() - -option(LLVM_ENABLE_IR_PGO "Build LLVM and tools with IR PGO instrumentation (deprecated)" Off) -mark_as_advanced(LLVM_ENABLE_IR_PGO) - -set(LLVM_BUILD_INSTRUMENTED OFF CACHE STRING "Build LLVM and tools with PGO instrumentation. May be specified as IR or Frontend") -set(LLVM_VP_COUNTERS_PER_SITE "1.5" CACHE STRING "Value profile counters to use per site for IR PGO with Clang") -mark_as_advanced(LLVM_BUILD_INSTRUMENTED LLVM_VP_COUNTERS_PER_SITE) -string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" uppercase_LLVM_BUILD_INSTRUMENTED) - -if (LLVM_BUILD_INSTRUMENTED) - if (LLVM_ENABLE_IR_PGO OR uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "IR") - append("-fprofile-generate=\"${LLVM_PROFILE_DATA_DIR}\"" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS) - if(NOT LINKER_IS_LLD_LINK) - append("-fprofile-generate=\"${LLVM_PROFILE_DATA_DIR}\"" - CMAKE_EXE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) - endif() - # Set this to avoid running out of the value profile node section - # under clang in dynamic linking mode. - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND - CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11 AND - LLVM_LINK_LLVM_DYLIB) - append("-Xclang -mllvm -Xclang -vp-counters-per-site=${LLVM_VP_COUNTERS_PER_SITE}" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS) - endif() - elseif(uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "CSIR") - append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\"" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS) - if(NOT LINKER_IS_LLD_LINK) - append("-fcs-profile-generate=\"${LLVM_CSPROFILE_DATA_DIR}\"" - CMAKE_EXE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) - endif() - else() - append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\"" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS) - if(NOT LINKER_IS_LLD_LINK) - append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\"" - CMAKE_EXE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) - endif() - endif() -endif() - -# When using clang-cl with an instrumentation-based tool, add clang's library -# resource directory to the library search path. Because cmake invokes the -# linker directly, it isn't sufficient to pass -fsanitize=* to the linker. -if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER)) - execute_process( - COMMAND ${CMAKE_CXX_COMPILER} /clang:-print-libgcc-file-name /clang:--rtlib=compiler-rt - OUTPUT_VARIABLE clang_compiler_rt_file - ERROR_VARIABLE clang_cl_stderr - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE clang_cl_exit_code) - if (NOT "${clang_cl_exit_code}" STREQUAL "0") - message(FATAL_ERROR - "Unable to invoke clang-cl to find resource dir: ${clang_cl_stderr}") - endif() - file(TO_CMAKE_PATH "${clang_compiler_rt_file}" clang_compiler_rt_file) - get_filename_component(clang_runtime_dir "${clang_compiler_rt_file}" DIRECTORY) - append("/libpath:\"${clang_runtime_dir}\"" - CMAKE_EXE_LINKER_FLAGS - CMAKE_MODULE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) -endif() - -if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE}) - if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) - append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\"" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS) - if(NOT LINKER_IS_LLD_LINK) - append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\"" - CMAKE_EXE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) - endif() - else() - message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang") - endif() -endif() - -option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation" Off) -mark_as_advanced(LLVM_BUILD_INSTRUMENTED_COVERAGE) -append_if(LLVM_BUILD_INSTRUMENTED_COVERAGE "-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\" -fcoverage-mapping" - CMAKE_CXX_FLAGS - CMAKE_C_FLAGS - CMAKE_EXE_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS) - -if (LLVM_BUILD_INSTRUMENTED AND LLVM_BUILD_INSTRUMENTED_COVERAGE) - message(FATAL_ERROR "LLVM_BUILD_INSTRUMENTED and LLVM_BUILD_INSTRUMENTED_COVERAGE cannot both be specified") -endif() - -set(LLVM_THINLTO_CACHE_PATH "${PROJECT_BINARY_DIR}/lto.cache" CACHE STRING "Set ThinLTO cache path. This can be used when building LLVM from several different directiories.") - -if(LLVM_ENABLE_LTO AND LLVM_ON_WIN32 AND NOT LINKER_IS_LLD_LINK AND NOT MINGW) - message(FATAL_ERROR "When compiling for Windows, LLVM_ENABLE_LTO requires using lld as the linker (point CMAKE_LINKER at lld-link.exe)") -endif() -if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN") - append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS) - if(NOT LINKER_IS_LLD_LINK) - append("-flto=thin" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() - # If the linker supports it, enable the lto cache. This improves initial build - # time a little since we re-link a lot of the same objects, and significantly - # improves incremental build time. - # FIXME: We should move all this logic into the clang driver. - if(APPLE) - append("-Wl,-cache_path_lto,${LLVM_THINLTO_CACHE_PATH}" - CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - elseif((UNIX OR MINGW) AND LLVM_USE_LINKER STREQUAL "lld") - append("-Wl,--thinlto-cache-dir=${LLVM_THINLTO_CACHE_PATH}" - CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - elseif(LLVM_USE_LINKER STREQUAL "gold") - append("-Wl,--plugin-opt,cache-dir=${LLVM_THINLTO_CACHE_PATH}" - CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - elseif(LINKER_IS_LLD_LINK) - append("/lldltocache:${LLVM_THINLTO_CACHE_PATH}" - CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() -elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL") - append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS) - if(NOT LINKER_IS_LLD_LINK) - append("-flto=full" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() -elseif(LLVM_ENABLE_LTO) - append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS) - if(NOT LINKER_IS_LLD_LINK) - append("-flto" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() -endif() - -# Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we are -# doing dynamic linking (see below). -set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF) -if (NOT (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB)) - set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default ON) -endif() - -# This option makes utils/extract_symbols.py be used to determine the list of -# symbols to export from LLVM tools. This is necessary when on AIX or when using -# MSVC if you want to allow plugins. On AIX we don't show this option, and we -# enable it by default except when the LLVM libraries are set up for dynamic -# linking (due to incompatibility). With MSVC, note that the plugin has to -# explicitly link against (exactly one) tool so we can't unilaterally turn on -# LLVM_ENABLE_PLUGINS when it's enabled. -CMAKE_DEPENDENT_OPTION(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS - "Export symbols from LLVM tools so that plugins can import them" OFF - "NOT ${CMAKE_SYSTEM_NAME} MATCHES AIX" ${LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default}) -if(BUILD_SHARED_LIBS AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS) - message(FATAL_ERROR "BUILD_SHARED_LIBS not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS") -endif() -if(LLVM_LINK_LLVM_DYLIB AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS) - message(FATAL_ERROR "LLVM_LINK_LLVM_DYLIB not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS") -endif() - -# By default we should enable LLVM_ENABLE_IDE only for multi-configuration -# generators. This option disables optional build system features that make IDEs -# less usable. -set(LLVM_ENABLE_IDE_default OFF) -if (CMAKE_CONFIGURATION_TYPES) - set(LLVM_ENABLE_IDE_default ON) -endif() -option(LLVM_ENABLE_IDE - "Disable optional build system features that cause problems for IDE generators" - ${LLVM_ENABLE_IDE_default}) -if (CMAKE_CONFIGURATION_TYPES AND NOT LLVM_ENABLE_IDE) - message(WARNING "Disabling LLVM_ENABLE_IDE on multi-configuration generators is not recommended.") -endif() - -function(get_compile_definitions) - get_directory_property(top_dir_definitions DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS) - foreach(definition ${top_dir_definitions}) - if(DEFINED result) - string(APPEND result " -D${definition}") - else() - set(result "-D${definition}") - endif() - endforeach() - set(LLVM_DEFINITIONS "${result}" PARENT_SCOPE) -endfunction() -get_compile_definitions() - -option(LLVM_FORCE_ENABLE_STATS "Enable statistics collection for builds that wouldn't normally enable it" OFF) - -check_symbol_exists(os_signpost_interval_begin "os/signpost.h" macos_signposts_available) -if(macos_signposts_available) - check_cxx_source_compiles( - "#include - int main() { os_signpost_interval_begin(nullptr, 0, \"\", \"\"); return 0; }" - macos_signposts_usable) - if(macos_signposts_usable) - set(LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS "WITH_ASSERTS" CACHE STRING - "Enable support for Xcode signposts. Can be WITH_ASSERTS, FORCE_ON, FORCE_OFF") - string(TOUPPER "${LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS}" - uppercase_LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS) - if( uppercase_LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS STREQUAL "WITH_ASSERTS" ) - if( LLVM_ENABLE_ASSERTIONS ) - set( LLVM_SUPPORT_XCODE_SIGNPOSTS 1 ) - endif() - elseif( uppercase_LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS STREQUAL "FORCE_ON" ) - set( LLVM_SUPPORT_XCODE_SIGNPOSTS 1 ) - elseif( uppercase_LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS STREQUAL "FORCE_OFF" ) - # We don't need to do anything special to turn off signposts. - elseif( NOT DEFINED LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS ) - # Treat LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS like "FORCE_OFF" when it has not been - # defined. - else() - message(FATAL_ERROR "Unknown value for LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS:" - " \"${LLVM_ENABLE_SUPPORT_XCODE_SIGNPOSTS}\"!") - endif() - endif() -endif() - -set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources") - -option(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO "Use relative paths in debug info" OFF) - -if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO) - check_c_compiler_flag("-fdebug-prefix-map=foo=bar" SUPPORTS_FDEBUG_PREFIX_MAP) - if(LLVM_ENABLE_PROJECTS_USED) - get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE) - else() - set(source_root "${LLVM_MAIN_SRC_DIR}") - endif() - file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}") - append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES) -endif() - -set(LLVM_ENABLE_EXPERIMENTAL_DEPSCAN OFF CACHE BOOL - "Use the experimental -fdepscan and related flags") -set(LLVM_DEPSCAN_MODE "" CACHE STRING "Mode for -fdepscan if used") -set(LLVM_DEPSCAN_DAEMON "" CACHE STRING "Path to existing DepScan daemon to use") -set(LLVM_CAS_BUILTIN_PATH "" CACHE STRING "Path to pass for -fcas-builtin-path") -set(LLVM_CAS_BUILTIN_PATH_Default "/^llvm::cas::builtin::default/llvm.cas.builtin.default") -if (LLVM_CAS_BUILTIN_PATH) - set(LLVM_CAS_BUILTIN_PATH_Default "${LLVM_CAS_BUILTIN_PATH}") -endif() -if(LLVM_ENABLE_EXPERIMENTAL_DEPSCAN) - # Don't daemonize when running the check. - check_c_compiler_flag("-fdepscan=off" SUPPORTS_DEPSCAN) - - # Check LLVM_DEPSCAN_MODE before entering if() in order to claim it. - if(LLVM_DEPSCAN_MODE) - append_if(SUPPORTS_DEPSCAN "-fdepscan=${LLVM_DEPSCAN_MODE}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - else() - append_if(SUPPORTS_DEPSCAN "-fdepscan" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - - if(SUPPORTS_DEPSCAN) - if(LLVM_DEPSCAN_DAEMON) - append("-fdepscan-daemon=${LLVM_DEPSCAN_DAEMON}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - else() - check_c_compiler_flag("-fdepscan=off -fdepscan-share-stop=cmake" SUPPORTS_DEPSCAN_SHARE) - if(SUPPORTS_DEPSCAN_SHARE) - get_filename_component(CMAKE_MAKE_PROGRAM_NAME "${CMAKE_MAKE_PROGRAM}" NAME) - if(CMAKE_GENERATOR STREQUAL "Ninja") - # Ninja should always be direct parent of clang invocations (except - # during configuration). Avoid unnecessary ancestor searches. - set(fdepscan_share "-fdepscan-share-parent") - else() - # Other build systems may use subshells. - set(fdepscan_share "-fdepscan-share") - endif() - - append("${fdepscan_share}=${CMAKE_MAKE_PROGRAM_NAME}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append("-fdepscan-share-stop=cmake" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - endif() - - if(LLVM_ENABLE_PROJECTS_USED) - get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE) - else() - set(source_root "${LLVM_MAIN_SRC_DIR}") - endif() - - append("-fdepscan-prefix-map-sdk=/^sdk" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append("-fdepscan-prefix-map-toolchain=/^toolchain" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append("-fdepscan-prefix-map=${source_root}=/^source" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append("-fdepscan-prefix-map=${CMAKE_BINARY_DIR}=/^build" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - if(LLVM_CAS_BUILTIN_PATH) - append("-Xclang -fcas-path -Xclang ${LLVM_CAS_BUILTIN_PATH}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - endif() - - # Create a LLDB init file to remap prefix map back to original path. - # TODO: Remap SDK and toolchain path. - set(lldb_prefix_remap_init_file "${CMAKE_BINARY_DIR}/.lldbinit") - file(WRITE ${lldb_prefix_remap_init_file} "settings set target.source-map /^source ${source_root} /^build ${CMAKE_BINARY_DIR}") - - check_c_compiler_flag("-greproducible" SUPPORTS_GREPRODUCIBLE) - if(SUPPORTS_GREPRODUCIBLE) - append("-greproducible" - CMAKE_C_FLAGS CMAKE_CXX_FLAGS - CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() - endif() -endif() - - -option(LLVM_USE_RELATIVE_PATHS_IN_FILES "Use relative paths in sources and debug info" OFF) - -if(LLVM_USE_RELATIVE_PATHS_IN_FILES) - check_c_compiler_flag("-ffile-prefix-map=foo=bar" SUPPORTS_FFILE_PREFIX_MAP) - if(LLVM_ENABLE_PROJECTS_USED) - get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE) - else() - set(source_root "${LLVM_MAIN_SRC_DIR}") - endif() - file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}") - append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES) -endif() - -set(LLVM_THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third-party CACHE STRING - "Directory containing third party software used by LLVM (e.g. googletest)") - -set(LLVM_UNITTEST_LINK_FLAGS "" CACHE STRING - "Additional linker flags for unit tests") - -if(LLVM_ENABLE_LLVM_LIBC) - check_library_exists(llvmlibc printf "" HAVE_LLVM_LIBC) - if(NOT HAVE_LLVM_LIBC) - message(WARNING "Unable to link against LLVM libc. LLVM will be built without linking against the LLVM libc overlay.") - endif() -endif() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/HandleLLVMStdlib.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/HandleLLVMStdlib.cmake deleted file mode 100644 index 7afc10c..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/HandleLLVMStdlib.cmake +++ /dev/null @@ -1,54 +0,0 @@ -# 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(LLVMCheckLinkerFlag) - set(LLVM_LIBCXX_USED 0) - if(LLVM_ENABLE_LIBCXX) - if(LLVM_COMPILER_IS_GCC_COMPATIBLE) - check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB) - llvm_check_linker_flag(CXX "-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) - set(LLVM_LIBCXX_USED 1) - else() - message(WARNING "Can't specify libc++ with '-stdlib='") - endif() - else() - message(WARNING "Not sure how to specify libc++ for this compiler") - endif() - endif() - - if(LLVM_STATIC_LINK_CXX_STDLIB) - if(LLVM_COMPILER_IS_GCC_COMPATIBLE) - check_cxx_compiler_flag("-static-libstdc++" - CXX_COMPILER_SUPPORTS_STATIC_STDLIB) - llvm_check_linker_flag(CXX "-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB) - if(CXX_COMPILER_SUPPORTS_STATIC_STDLIB AND - CXX_LINKER_SUPPORTS_STATIC_STDLIB) - append("-static-libstdc++" - CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS - CMAKE_MODULE_LINKER_FLAGS) - else() - message(WARNING - "Can't specify static linking for the C++ standard library") - endif() - else() - message(WARNING "Not sure how to specify static linking of C++ standard " - "library for this compiler") - endif() - endif() -endif() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVM-Config.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVM-Config.cmake deleted file mode 100644 index 96ccf20..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVM-Config.cmake +++ /dev/null @@ -1,350 +0,0 @@ -cmake_policy(PUSH) -cmake_policy(SET CMP0057 NEW) - -function(get_system_libs return_var) - message(AUTHOR_WARNING "get_system_libs no longer needed") - set(${return_var} "" PARENT_SCOPE) -endfunction() - - -function(link_system_libs target) - message(AUTHOR_WARNING "link_system_libs no longer needed") -endfunction() - -# is_llvm_target_library( -# library -# Name of the LLVM library to check -# return_var -# Output variable name -# ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS -# ALL_TARGETS - default looks at the full list of known targets -# INCLUDED_TARGETS - looks only at targets being configured -# OMITTED_TARGETS - looks only at targets that are not being configured -# ) -function(is_llvm_target_library library return_var) - cmake_parse_arguments(ARG "ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS" "" "" ${ARGN}) - # Sets variable `return_var' to ON if `library' corresponds to a - # LLVM supported target. To OFF if it doesn't. - set(${return_var} OFF PARENT_SCOPE) - string(TOUPPER "${library}" capitalized_lib) - if(ARG_INCLUDED_TARGETS) - string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" targets) - elseif(ARG_OMITTED_TARGETS) - set(omitted_targets ${LLVM_ALL_TARGETS}) - if (LLVM_TARGETS_TO_BUILD) - list(REMOVE_ITEM omitted_targets ${LLVM_TARGETS_TO_BUILD}) - endif() - string(TOUPPER "${omitted_targets}" targets) - else() - string(TOUPPER "${LLVM_ALL_TARGETS}" targets) - endif() - foreach(t ${targets}) - if( capitalized_lib STREQUAL t OR - capitalized_lib STREQUAL "${t}" OR - capitalized_lib STREQUAL "${t}DESC" OR - capitalized_lib STREQUAL "${t}CODEGEN" OR - capitalized_lib STREQUAL "${t}ASMPARSER" OR - capitalized_lib STREQUAL "${t}ASMPRINTER" OR - capitalized_lib STREQUAL "${t}DISASSEMBLER" OR - capitalized_lib STREQUAL "${t}INFO" OR - capitalized_lib STREQUAL "${t}UTILS" ) - set(${return_var} ON PARENT_SCOPE) - break() - endif() - endforeach() -endfunction(is_llvm_target_library) - -function(is_llvm_target_specifier library return_var) - is_llvm_target_library(${library} ${return_var} ${ARGN}) - string(TOUPPER "${library}" capitalized_lib) - if(NOT ${return_var}) - if( capitalized_lib STREQUAL "ALLTARGETSASMPARSERS" OR - capitalized_lib STREQUAL "ALLTARGETSDESCS" OR - capitalized_lib STREQUAL "ALLTARGETSDISASSEMBLERS" OR - capitalized_lib STREQUAL "ALLTARGETSINFOS" OR - capitalized_lib STREQUAL "NATIVE" OR - capitalized_lib STREQUAL "NATIVECODEGEN" ) - set(${return_var} ON PARENT_SCOPE) - endif() - endif() -endfunction() - -macro(llvm_config executable) - cmake_parse_arguments(ARG "USE_SHARED" "" "" ${ARGN}) - set(link_components ${ARG_UNPARSED_ARGUMENTS}) - - if(ARG_USE_SHARED) - # If USE_SHARED is specified, then we link against libLLVM, - # but also against the component libraries below. This is - # done in case libLLVM does not contain all of the components - # the target requires. - # - # Strip LLVM_DYLIB_COMPONENTS out of link_components. - # To do this, we need special handling for "all", since that - # may imply linking to libraries that are not included in - # libLLVM. - - if (DEFINED link_components AND DEFINED LLVM_DYLIB_COMPONENTS) - if("${LLVM_DYLIB_COMPONENTS}" STREQUAL "all") - set(link_components "") - else() - list(REMOVE_ITEM link_components ${LLVM_DYLIB_COMPONENTS}) - endif() - endif() - - target_link_libraries(${executable} PRIVATE LLVM) - endif() - - explicit_llvm_config(${executable} ${link_components}) -endmacro(llvm_config) - - -function(explicit_llvm_config executable) - set( link_components ${ARGN} ) - - llvm_map_components_to_libnames(LIBRARIES ${link_components}) - get_target_property(t ${executable} TYPE) - if(t STREQUAL "STATIC_LIBRARY") - target_link_libraries(${executable} INTERFACE ${LIBRARIES}) - elseif(t STREQUAL "EXECUTABLE" OR t STREQUAL "SHARED_LIBRARY" OR t STREQUAL "MODULE_LIBRARY") - target_link_libraries(${executable} PRIVATE ${LIBRARIES}) - else() - # Use plain form for legacy user. - target_link_libraries(${executable} ${LIBRARIES}) - endif() -endfunction(explicit_llvm_config) - - -# This is Deprecated -function(llvm_map_components_to_libraries OUT_VAR) - message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead") - explicit_map_components_to_libraries(result ${ARGN}) - set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE ) -endfunction(llvm_map_components_to_libraries) - -# Expand pseudo-components into real components. -# Does not cover 'native', 'backend', or 'engine' as these require special -# handling. Also does not cover 'all' as we only have a list of the libnames -# available and not a list of the components. -function(llvm_expand_pseudo_components out_components) - set( link_components ${ARGN} ) - if(NOT LLVM_AVAILABLE_LIBS) - # Inside LLVM itself available libs are in a global property. - get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS) - endif() - foreach(c ${link_components}) - # add codegen, asmprinter, asmparser, disassembler - if("${c}" IN_LIST LLVM_TARGETS_TO_BUILD) - if(LLVM${c}CodeGen IN_LIST LLVM_AVAILABLE_LIBS) - list(APPEND expanded_components "${c}CodeGen") - else() - if(LLVM${c} IN_LIST LLVM_AVAILABLE_LIBS) - list(APPEND expanded_components "${c}") - else() - message(FATAL_ERROR "Target ${c} is not in the set of libraries.") - endif() - endif() - foreach(subcomponent IN ITEMS AsmPrinter AsmParser Desc Disassembler Info Utils) - if(LLVM${c}${subcomponent} IN_LIST LLVM_AVAILABLE_LIBS) - list(APPEND expanded_components "${c}${subcomponent}") - endif() - endforeach() - elseif("${c}" STREQUAL "nativecodegen" ) - foreach(subcomponent IN ITEMS CodeGen Desc Info) - if(LLVM${LLVM_NATIVE_ARCH}${subcomponent} IN_LIST LLVM_AVAILABLE_LIBS) - list(APPEND expanded_components "${LLVM_NATIVE_ARCH}${subcomponent}") - endif() - endforeach() - elseif("${c}" STREQUAL "AllTargetsCodeGens" ) - # Link all the codegens from all the targets - foreach(t ${LLVM_TARGETS_TO_BUILD}) - if( TARGET LLVM${t}CodeGen) - list(APPEND expanded_components "${t}CodeGen") - endif() - endforeach(t) - elseif("${c}" STREQUAL "AllTargetsAsmParsers" ) - # Link all the asm parsers from all the targets - foreach(t ${LLVM_TARGETS_TO_BUILD}) - if(LLVM${t}AsmParser IN_LIST LLVM_AVAILABLE_LIBS) - list(APPEND expanded_components "${t}AsmParser") - endif() - endforeach(t) - elseif( "${c}" STREQUAL "AllTargetsDescs" ) - # Link all the descs from all the targets - foreach(t ${LLVM_TARGETS_TO_BUILD}) - if(LLVM${t}Desc IN_LIST LLVM_AVAILABLE_LIBS) - list(APPEND expanded_components "${t}Desc") - endif() - endforeach(t) - elseif("${c}" STREQUAL "AllTargetsDisassemblers" ) - # Link all the disassemblers from all the targets - foreach(t ${LLVM_TARGETS_TO_BUILD}) - if(LLVM${t}Disassembler IN_LIST LLVM_AVAILABLE_LIBS) - list(APPEND expanded_components "${t}Disassembler") - endif() - endforeach(t) - elseif("${c}" STREQUAL "AllTargetsInfos" ) - # Link all the infos from all the targets - foreach(t ${LLVM_TARGETS_TO_BUILD}) - if(LLVM${t}Info IN_LIST LLVM_AVAILABLE_LIBS) - list(APPEND expanded_components "${t}Info") - endif() - endforeach(t) - elseif("${c}" STREQUAL "AllTargetsMCAs" ) - # Link all the TargetMCAs from all the targets - foreach(t ${LLVM_TARGETS_TO_BUILD}) - if( TARGET LLVM${t}TargetMCA ) - list(APPEND expanded_components "${t}TargetMCA") - endif() - endforeach(t) - else() - list(APPEND expanded_components "${c}") - endif() - endforeach() - set(${out_components} ${expanded_components} PARENT_SCOPE) -endfunction(llvm_expand_pseudo_components out_components) - -# This is a variant intended for the final user: -# Map LINK_COMPONENTS to actual libnames. -function(llvm_map_components_to_libnames out_libs) - set( link_components ${ARGN} ) - if(NOT LLVM_AVAILABLE_LIBS) - # Inside LLVM itself available libs are in a global property. - get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS) - endif() - string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs) - - get_property(LLVM_TARGETS_CONFIGURED GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED) - - # Generally in our build system we avoid order-dependence. Unfortunately since - # not all targets create the same set of libraries we actually need to ensure - # that all build targets associated with a target are added before we can - # process target dependencies. - if(NOT LLVM_TARGETS_CONFIGURED) - foreach(c ${link_components}) - is_llvm_target_specifier("${c}" iltl_result ALL_TARGETS) - if(iltl_result) - message(FATAL_ERROR "Specified target library before target registration is complete.") - endif() - endforeach() - endif() - - # Expand some keywords: - if(engine IN_LIST link_components) - if(${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_TO_BUILD AND - ${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_WITH_JIT) - list(APPEND link_components "jit") - list(APPEND link_components "native") - else() - list(APPEND link_components "interpreter") - endif() - endif() - if(native IN_LIST link_components AND "${LLVM_NATIVE_ARCH}" IN_LIST LLVM_TARGETS_TO_BUILD) - list(APPEND link_components ${LLVM_NATIVE_ARCH}) - endif() - - # Translate symbolic component names to real libraries: - llvm_expand_pseudo_components(link_components ${link_components}) - foreach(c ${link_components}) - get_property(c_rename GLOBAL PROPERTY LLVM_COMPONENT_NAME_${c}) - if(c_rename) - set(c ${c_rename}) - endif() - if("${c}" STREQUAL "native" ) - # already processed - elseif("${c}" STREQUAL "backend" ) - # same case as in `native'. - elseif("${c}" STREQUAL "engine" ) - # already processed - elseif("${c}" STREQUAL "all" ) - get_property(all_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS) - list(APPEND expanded_components ${all_components}) - else() - # Canonize the component name: - string(TOUPPER "${c}" capitalized) - list(FIND capitalized_libs LLVM${capitalized} lib_idx) - if( lib_idx LESS 0 ) - # The component is unknown. Maybe is an omitted target? - is_llvm_target_library("${c}" iltl_result OMITTED_TARGETS) - if(iltl_result) - # A missing library to a directly referenced omitted target would be bad. - message(FATAL_ERROR "Library '${c}' is a direct reference to a target library for an omitted target.") - else() - # If it is not an omitted target we should assume it is a component - # that hasn't yet been processed by CMake. Missing components will - # cause errors later in the configuration, so we can safely assume - # that this is valid here. - list(APPEND expanded_components LLVM${c}) - endif() - else( lib_idx LESS 0 ) - list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib) - list(APPEND expanded_components ${canonical_lib}) - endif( lib_idx LESS 0 ) - endif("${c}" STREQUAL "native" ) - endforeach(c) - - set(${out_libs} ${expanded_components} PARENT_SCOPE) -endfunction() - -# Perform a post-order traversal of the dependency graph. -# This duplicates the algorithm used by llvm-config, originally -# in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents. -function(expand_topologically name required_libs visited_libs) - if(NOT ${name} IN_LIST visited_libs) - list(APPEND visited_libs ${name}) - set(visited_libs ${visited_libs} PARENT_SCOPE) - - # - get_property(libname GLOBAL PROPERTY LLVM_COMPONENT_NAME_${name}) - if(libname) - set(cname LLVM${libname}) - elseif(TARGET ${name}) - set(cname ${name}) - elseif(TARGET LLVM${name}) - set(cname LLVM${name}) - else() - message(FATAL_ERROR "unknown component ${name}") - endif() - - get_property(lib_deps TARGET ${cname} PROPERTY LLVM_LINK_COMPONENTS) - foreach( lib_dep ${lib_deps} ) - expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}") - set(required_libs ${required_libs} PARENT_SCOPE) - set(visited_libs ${visited_libs} PARENT_SCOPE) - endforeach() - - list(APPEND required_libs ${cname}) - set(required_libs ${required_libs} PARENT_SCOPE) - endif() -endfunction() - -# Expand dependencies while topologically sorting the list of libraries: -function(llvm_expand_dependencies out_libs) - set(expanded_components ${ARGN}) - - set(required_libs) - set(visited_libs) - foreach( lib ${expanded_components} ) - expand_topologically(${lib} "${required_libs}" "${visited_libs}") - endforeach() - - if(required_libs) - list(REVERSE required_libs) - endif() - set(${out_libs} ${required_libs} PARENT_SCOPE) -endfunction() - -function(explicit_map_components_to_libraries out_libs) - llvm_map_components_to_libnames(link_libs ${ARGN}) - llvm_expand_dependencies(expanded_components ${link_libs}) - # Return just the libraries included in this build: - set(result) - foreach(c ${expanded_components}) - if( TARGET ${c} ) - set(result ${result} ${c}) - endif() - endforeach(c) - set(${out_libs} ${result} PARENT_SCOPE) -endfunction(explicit_map_components_to_libraries) - -cmake_policy(POP) diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMCheckLinkerFlag.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMCheckLinkerFlag.cmake deleted file mode 100644 index e09bbc6..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMCheckLinkerFlag.cmake +++ /dev/null @@ -1,28 +0,0 @@ -include(CheckLinkerFlag OPTIONAL) - -if (COMMAND check_linker_flag) - macro(llvm_check_linker_flag) - check_linker_flag(${ARGN}) - endmacro() -else() - # Until the minimum CMAKE version is 3.18 - - include(CheckCXXCompilerFlag) - - # cmake builtin compatible, except we assume lang is C or CXX - function(llvm_check_linker_flag lang flag out_var) - cmake_policy(PUSH) - cmake_policy(SET CMP0056 NEW) - set(_CMAKE_EXE_LINKER_FLAGS_SAVE ${CMAKE_EXE_LINKER_FLAGS}) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}") - if("${lang}" STREQUAL "C") - check_c_compiler_flag("" ${out_var}) - elseif("${lang}" STREQUAL "CXX") - check_cxx_compiler_flag("" ${out_var}) - else() - message(FATAL_ERROR "\"${lang}\" is not C or CXX") - endif() - set(CMAKE_EXE_LINKER_FLAGS ${_CMAKE_EXE_LINKER_FLAGS_SAVE}) - cmake_policy(POP) - endfunction() -endif() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfig.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfig.cmake deleted file mode 100644 index dec1fce..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfig.cmake +++ /dev/null @@ -1,144 +0,0 @@ -# This file provides information and services to the final user. - -# Compute the installation prefix from this LLVMConfig.cmake file location. -get_filename_component(LLVM_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(LLVM_INSTALL_PREFIX "${LLVM_INSTALL_PREFIX}" PATH) -get_filename_component(LLVM_INSTALL_PREFIX "${LLVM_INSTALL_PREFIX}" PATH) -get_filename_component(LLVM_INSTALL_PREFIX "${LLVM_INSTALL_PREFIX}" PATH) - -set(LLVM_VERSION_MAJOR 17) -set(LLVM_VERSION_MINOR 0) -set(LLVM_VERSION_PATCH 0) -set(LLVM_VERSION_SUFFIX git) -set(LLVM_PACKAGE_VERSION 17.0.0git) -set(LLVM_PACKAGE_BUGREPORT https://bugs.llvm.org/) - -set(LLVM_BUILD_TYPE Release) - -set(LLVM_USE_CRT_DEBUG ) -set(LLVM_USE_CRT_MINSIZEREL ) -set(LLVM_USE_CRT_RELEASE ) -set(LLVM_USE_CRT_RELWITHDEBINFO ) - -set(LLVM_USE_SPLIT_DWARF OFF) - -set(LLVM_COMMON_DEPENDS ) - -set(LLVM_AVAILABLE_LIBS ) - -set(LLVM_DYLIB_COMPONENTS all) - -set(LLVM_ALL_TARGETS AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86;XCore) - -set(LLVM_TARGETS_TO_BUILD AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86;XCore) - -set(LLVM_TARGETS_WITH_JIT X86;PowerPC;AArch64;ARM;Mips;SystemZ) - -set_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_LTO ) - -set(TARGET_TRIPLE "x86_64-unknown-linux-gnu") - -set(LLVM_HOST_TRIPLE "x86_64-unknown-linux-gnu") - -set(LLVM_ABI_BREAKING_CHECKS WITH_ASSERTS) - -set(LLVM_ENABLE_WARNINGS ON) - -set(LLVM_ENABLE_EXPENSIVE_CHECKS OFF) - -set(LLVM_ENABLE_ASSERTIONS OFF) - -set(LLVM_ENABLE_EH OFF) - -set(LLVM_ENABLE_RTTI OFF) - -set(LLVM_ENABLE_TERMINFO 1) - -set(LLVM_ENABLE_THREADS ON) - -set(LLVM_ENABLE_UNWIND_TABLES ON) - -set(LLVM_ENABLE_ZLIB 1) -if(LLVM_ENABLE_ZLIB) - find_package(ZLIB) -endif() - -set(LLVM_ENABLE_LIBXML2 1) -if(LLVM_ENABLE_LIBXML2) - find_package(LibXml2) -endif() - -set(LLVM_WITH_Z3 ) - -set(LLVM_ENABLE_DIA_SDK 0) - -set(LLVM_NATIVE_ARCH X86) - -set(LLVM_ENABLE_PIC ON) - -set(LLVM_BUILD_32_BITS OFF) - -set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE) - -if (NOT "" STREQUAL "") - set(LLVM_PTHREAD_LIB "") -endif() - -set(LLVM_ENABLE_PLUGINS ON) -set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS OFF) -set(LLVM_PLUGIN_EXT .so) - -set(LLVM_ON_UNIX 1) - -set(LLVM_LIBDIR_SUFFIX ) - -set(LLVM_INCLUDE_DIRS "${LLVM_INSTALL_PREFIX}/include") -set(LLVM_LIBRARY_DIRS "${LLVM_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") - -set(LLVM_APPEND_VC_REV "ON") - -# These variables are duplicated for install tree but they have different -# values for build tree. LLVM_INCLUDE_DIRS contains both source -# and generated include directories while the following variables have -# them split. -set(LLVM_INCLUDE_DIR "${LLVM_INSTALL_PREFIX}/include") -set(LLVM_MAIN_INCLUDE_DIR "${LLVM_INSTALL_PREFIX}/include") -set(LLVM_LIBRARY_DIR "${LLVM_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") - -set(LLVM_DEFINITIONS "-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS") -set(LLVM_CMAKE_DIR "${LLVM_INSTALL_PREFIX}/lib/cmake/llvm") -set(LLVM_BINARY_DIR "${LLVM_INSTALL_PREFIX}") -set(LLVM_TOOLS_BINARY_DIR "${LLVM_INSTALL_PREFIX}/bin") -set(LLVM_TOOLS_INSTALL_DIR "bin") -set(LLVM_HAVE_OPT_VIEWER_MODULES 0) -set(LLVM_CONFIGURATION_TYPES ) -set(LLVM_ENABLE_SHARED_LIBS OFF) - -set(LLVM_DEFAULT_EXTERNAL_LIT "") -set(LLVM_LIT_ARGS "") - -set(LLVM_HAVE_LIBXAR "") - -if(NOT TARGET LLVMSupport) - include("${LLVM_CMAKE_DIR}/LLVMExports.cmake") - -endif() - -# By creating the following targets here, subprojects that depend on -# LLVM's tablegen-generated headers can always depend on this target -# whether building in-tree with LLVM or not. -if(NOT TARGET intrinsics_gen) - add_custom_target(intrinsics_gen) -endif() -if(NOT TARGET omp_gen) - add_custom_target(omp_gen) -endif() -if(NOT TARGET acc_gen) - add_custom_target(acc_gen) -endif() -if(NOT TARGET RISCVTargetParserTableGen) - add_custom_target(RISCVTargetParserTableGen) -endif() - -set_property(GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED On) -include(${LLVM_CMAKE_DIR}/LLVM-Config.cmake) diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfig.cmake.in b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfig.cmake.in deleted file mode 100644 index 42dfd60..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfig.cmake.in +++ /dev/null @@ -1,170 +0,0 @@ -# This file provides information and services to the final user. - -@LLVM_CONFIG_CODE@ - -# For finding self-installed Find*.cmake packages. -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") - -set(LLVM_VERSION_MAJOR @LLVM_VERSION_MAJOR@) -set(LLVM_VERSION_MINOR @LLVM_VERSION_MINOR@) -set(LLVM_VERSION_PATCH @LLVM_VERSION_PATCH@) -set(LLVM_VERSION_SUFFIX @LLVM_VERSION_SUFFIX@) -set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@) -set(LLVM_PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@) - -set(LLVM_BUILD_TYPE @CMAKE_BUILD_TYPE@) - -set(LLVM_USE_CRT_DEBUG @LLVM_USE_CRT_DEBUG@) -set(LLVM_USE_CRT_MINSIZEREL @LLVM_USE_CRT_MINSIZEREL@) -set(LLVM_USE_CRT_RELEASE @LLVM_USE_CRT_RELEASE@) -set(LLVM_USE_CRT_RELWITHDEBINFO @LLVM_USE_CRT_RELWITHDEBINFO@) - -set(LLVM_USE_SPLIT_DWARF @LLVM_USE_SPLIT_DWARF@) - -set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@) - -set(LLVM_AVAILABLE_LIBS @LLVM_AVAILABLE_LIBS@) - -@LLVM_CONFIG_LINK_LLVM_DYLIB@ - -set(LLVM_DYLIB_COMPONENTS @LLVM_DYLIB_COMPONENTS@) - -set(LLVM_ALL_TARGETS @LLVM_ALL_TARGETS@) - -set(LLVM_TARGETS_TO_BUILD @LLVM_TARGETS_TO_BUILD@) - -set(LLVM_TARGETS_WITH_JIT @LLVM_TARGETS_WITH_JIT@) - -@all_llvm_lib_deps@ - -set(LLVM_TARGET_TRIPLE "@LLVM_TARGET_TRIPLE@") - -set(LLVM_HOST_TRIPLE "@LLVM_HOST_TRIPLE@") - -set(LLVM_ABI_BREAKING_CHECKS @LLVM_ABI_BREAKING_CHECKS@) - -set(LLVM_ENABLE_WARNINGS @LLVM_ENABLE_WARNINGS@) - -set(LLVM_ENABLE_EXPENSIVE_CHECKS @LLVM_ENABLE_EXPENSIVE_CHECKS@) - -set(LLVM_ENABLE_ASSERTIONS @LLVM_ENABLE_ASSERTIONS@) - -set(LLVM_ENABLE_EH @LLVM_ENABLE_EH@) - -set(LLVM_ENABLE_FFI @LLVM_ENABLE_FFI@) -if(LLVM_ENABLE_FFI) - find_package(FFI) -endif() - -set(LLVM_ENABLE_RTTI @LLVM_ENABLE_RTTI@) - -set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@) -if(LLVM_ENABLE_LIBEDIT) - find_package(LibEdit) -endif() - -set(LLVM_ENABLE_TERMINFO @LLVM_ENABLE_TERMINFO@) -if(LLVM_ENABLE_TERMINFO) - find_package(Terminfo) -endif() - -set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@) - -set(LLVM_ENABLE_UNWIND_TABLES @LLVM_ENABLE_UNWIND_TABLES@) - -set(LLVM_ENABLE_ZLIB @LLVM_ENABLE_ZLIB@) -if(LLVM_ENABLE_ZLIB) - set(ZLIB_ROOT @ZLIB_ROOT@) - find_package(ZLIB) -endif() - -set(LLVM_ENABLE_ZSTD @LLVM_ENABLE_ZSTD@) -if(LLVM_ENABLE_ZSTD) - find_package(zstd) -endif() - -set(LLVM_ENABLE_LIBXML2 @LLVM_ENABLE_LIBXML2@) -if(LLVM_ENABLE_LIBXML2) - find_package(LibXml2) -endif() - -set(LLVM_ENABLE_CURL @LLVM_ENABLE_CURL@) -if(LLVM_ENABLE_CURL) - find_package(CURL) -endif() - -set(LLVM_WITH_Z3 @LLVM_WITH_Z3@) - -set(LLVM_ENABLE_DIA_SDK @LLVM_ENABLE_DIA_SDK@) - -set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@) - -set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@) - -set(LLVM_BUILD_32_BITS @LLVM_BUILD_32_BITS@) - -if (NOT "@LLVM_PTHREAD_LIB@" STREQUAL "") - set(LLVM_PTHREAD_LIB "@LLVM_PTHREAD_LIB@") -endif() - -set(LLVM_ENABLE_PLUGINS @LLVM_ENABLE_PLUGINS@) -set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS @LLVM_EXPORT_SYMBOLS_FOR_PLUGINS@) -set(LLVM_PLUGIN_EXT @LLVM_PLUGIN_EXT@) - -set(LLVM_ON_UNIX @LLVM_ON_UNIX@) - -set(LLVM_LIBDIR_SUFFIX @LLVM_LIBDIR_SUFFIX@) - -set(LLVM_INCLUDE_DIRS "@LLVM_CONFIG_INCLUDE_DIRS@") -set(LLVM_LIBRARY_DIRS "@LLVM_CONFIG_LIBRARY_DIRS@") - -set(LLVM_APPEND_VC_REV "@LLVM_APPEND_VC_REV@") - -# These variables are duplicated for install tree but they have different -# values for build tree. LLVM_INCLUDE_DIRS contains both source -# and generated include directories while the following variables have -# them split. - -# These are the "main" dirs -set(LLVM_MAIN_INCLUDE_DIR "@LLVM_CONFIG_MAIN_INCLUDE_DIR@") -set(LLVM_LIBRARY_DIR "@LLVM_CONFIG_LIBRARY_DIR@") - -# This is a secondary one for generated files -set(LLVM_INCLUDE_DIR "@LLVM_CONFIG_INCLUDE_DIR@") - -set(LLVM_DEFINITIONS "@LLVM_DEFINITIONS@") -set(LLVM_BINARY_DIR "@LLVM_CONFIG_BINARY_DIR@") -set(LLVM_CMAKE_DIR "@LLVM_CONFIG_CMAKE_DIR@") -set(LLVM_TOOLS_BINARY_DIR "@LLVM_CONFIG_TOOLS_BINARY_DIR@") -set(LLVM_HAVE_OPT_VIEWER_MODULES @LLVM_HAVE_OPT_VIEWER_MODULES@) -set(LLVM_CONFIGURATION_TYPES @CMAKE_CONFIGURATION_TYPES@) -set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@) - -set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@") -set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@") - -set(LLVM_HAVE_LIBXAR "@LLVM_HAVE_LIBXAR@") - -if(NOT TARGET LLVMSupport) - @LLVM_CONFIG_INCLUDE_EXPORTS@ - @llvm_config_include_buildtree_only_exports@ -endif() - -# By creating the following targets here, subprojects that depend on -# LLVM's tablegen-generated headers can always depend on this target -# whether building in-tree with LLVM or not. -if(NOT TARGET intrinsics_gen) - add_custom_target(intrinsics_gen) -endif() -if(NOT TARGET omp_gen) - add_custom_target(omp_gen) -endif() -if(NOT TARGET acc_gen) - add_custom_target(acc_gen) -endif() -if(NOT TARGET RISCVTargetParserTableGen) - add_custom_target(RISCVTargetParserTableGen) -endif() - -set_property(GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED On) -include(${LLVM_CMAKE_DIR}/LLVM-Config.cmake) diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfigExtensions.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfigExtensions.cmake deleted file mode 100644 index e3a40e0..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMConfigExtensions.cmake +++ /dev/null @@ -1 +0,0 @@ -set(LLVM_STATIC_EXTENSIONS ) \ No newline at end of file diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMDistributionSupport.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMDistributionSupport.cmake deleted file mode 100644 index 0b78f8f..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMDistributionSupport.cmake +++ /dev/null @@ -1,291 +0,0 @@ -# Utility functions for packaging an LLVM distribution. See the -# BuildingADistribution documentation for more details. - -# These functions assume a number of conventions that are common across all LLVM -# subprojects: -# - The generated CMake exports file for ${project} is called ${project}Targets -# (except for LLVM where it's called ${project}Exports for legacy reasons). -# - The build target for the CMake exports is called ${project}-cmake-exports -# (except LLVM where it's just cmake-exports). -# - The ${PROJECT}${distribution}_HAS_EXPORTS global property holds whether a -# project has any exports for a particular ${distribution} (where ${PROJECT} -# is the project name in uppercase). -# - The ${PROJECT}_CMAKE_DIR variable is computed by ${project}Config.cmake to -# hold the path of the installed CMake modules directory. -# - The ${PROJECT}_INSTALL_PACKAGE_DIR variable contains the install destination -# for the project's CMake modules. - -include_guard(GLOBAL) - -if(LLVM_DISTRIBUTION_COMPONENTS AND LLVM_DISTRIBUTIONS) - message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS and LLVM_DISTRIBUTIONS cannot be specified together") -endif() - -if(LLVM_DISTRIBUTION_COMPONENTS OR LLVM_DISTRIBUTIONS) - if(LLVM_ENABLE_IDE) - message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)") - endif() -endif() - -# Build the map of targets to distributions that's used to look up the -# distribution for a target later. The distribution for ${target} is stored in -# the global property LLVM_DISTRIBUTION_FOR_${target}. -function(llvm_distribution_build_target_map) - foreach(target ${LLVM_DISTRIBUTION_COMPONENTS}) - # CMake doesn't easily distinguish between properties that are unset and - # properties that are empty (you have to do a second get_property call with - # the SET option, which is unergonomic), so just use a special marker to - # denote the default (unnamed) distribution. - set_property(GLOBAL PROPERTY LLVM_DISTRIBUTION_FOR_${target} "") - endforeach() - - foreach(distribution ${LLVM_DISTRIBUTIONS}) - foreach(target ${LLVM_${distribution}_DISTRIBUTION_COMPONENTS}) - # By default, we allow a target to be in multiple distributions, and use - # the last one to determine its export set. We disallow this in strict - # mode, emitting a single error at the end for readability. - if(LLVM_STRICT_DISTRIBUTIONS) - get_property(current_distribution GLOBAL PROPERTY LLVM_DISTRIBUTION_FOR_${target}) - if(current_distribution AND NOT current_distribution STREQUAL distribution) - set_property(GLOBAL APPEND_STRING PROPERTY LLVM_DISTRIBUTION_ERRORS - "Target ${target} cannot be in multiple distributions \ - ${distribution} and ${current_distribution}\n" - ) - endif() - endif() - set_property(GLOBAL PROPERTY LLVM_DISTRIBUTION_FOR_${target} ${distribution}) - endforeach() - endforeach() -endfunction() - -# The include guard ensures this will only be called once. The rest of this file -# only defines other functions (i.e. it doesn't execute any more code directly). -llvm_distribution_build_target_map() - -# Look up the distribution a particular target belongs to. -# - target: The target to look up. -# - in_distribution_var: The variable with this name is set in the caller's -# scope to indicate if the target is in any distribution. If no distributions -# have been configured, this will always be set to true. -# - distribution_var: The variable with this name is set in the caller's scope -# to indicate the distribution name for the target. If the target belongs to -# the default (unnamed) distribution, or if no distributions have been -# configured, it's set to the empty string. -# - UMBRELLA: The (optional) umbrella target that the target is a part of. For -# example, all LLVM libraries have the umbrella target llvm-libraries. -function(get_llvm_distribution target in_distribution_var distribution_var) - if(NOT LLVM_DISTRIBUTION_COMPONENTS AND NOT LLVM_DISTRIBUTIONS) - set(${in_distribution_var} YES PARENT_SCOPE) - set(${distribution_var} "" PARENT_SCOPE) - return() - endif() - - cmake_parse_arguments(ARG "" UMBRELLA "" ${ARGN}) - get_property(distribution GLOBAL PROPERTY LLVM_DISTRIBUTION_FOR_${target}) - if(ARG_UMBRELLA) - get_property(umbrella_distribution GLOBAL PROPERTY LLVM_DISTRIBUTION_FOR_${ARG_UMBRELLA}) - if(LLVM_STRICT_DISTRIBUTIONS AND distribution AND umbrella_distribution AND - NOT distribution STREQUAL umbrella_distribution) - set_property(GLOBAL APPEND_STRING PROPERTY LLVM_DISTRIBUTION_ERRORS - "Target ${target} has different distribution ${distribution} from its \ - umbrella target's (${ARG_UMBRELLA}) distribution ${umbrella_distribution}\n" - ) - endif() - if(NOT distribution) - set(distribution ${umbrella_distribution}) - endif() - endif() - - if(distribution) - set(${in_distribution_var} YES PARENT_SCOPE) - if(distribution STREQUAL "") - set(distribution "") - endif() - set(${distribution_var} "${distribution}" PARENT_SCOPE) - else() - set(${in_distribution_var} NO PARENT_SCOPE) - endif() -endfunction() - -# Get the EXPORT argument to use for an install command for a target in a -# project. As explained at the top of the file, the project export set for a -# distribution is named ${project}{distribution}Targets (except for LLVM where -# it's named ${project}{distribution}Exports for legacy reasons). Also set the -# ${PROJECT}_${DISTRIBUTION}_HAS_EXPORTS global property to mark the project as -# having exports for the distribution. -# - target: The target to get the EXPORT argument for. -# - project: The project to produce the argument for. IMPORTANT: The casing of -# this argument should match the casing used by the project's Config.cmake -# file. The correct casing for the LLVM projects is Clang, Flang, LLD, LLVM, -# and MLIR. -# - export_arg_var The variable with this name is set in the caller's scope to -# the EXPORT argument for the target for the project. -# - UMBRELLA: The (optional) umbrella target that the target is a part of. For -# example, all LLVM libraries have the umbrella target llvm-libraries. -function(get_target_export_arg target project export_arg_var) - string(TOUPPER "${project}" project_upper) - if(project STREQUAL "LLVM") - set(suffix "Exports") # legacy - else() - set(suffix "Targets") - endif() - - get_llvm_distribution(${target} in_distribution distribution ${ARGN}) - - if(in_distribution) - set(${export_arg_var} EXPORT ${project}${distribution}${suffix} PARENT_SCOPE) - if(distribution) - string(TOUPPER "${distribution}" distribution_upper) - set_property(GLOBAL PROPERTY ${project_upper}_${distribution_upper}_HAS_EXPORTS True) - else() - set_property(GLOBAL PROPERTY ${project_upper}_HAS_EXPORTS True) - endif() - else() - set(${export_arg_var} "" PARENT_SCOPE) - endif() -endfunction() - -# Produce a string of CMake include() commands to include the exported targets -# files for all distributions. See the comment at the top of this file for -# various assumptions made. -# - project: The project to produce the commands for. IMPORTANT: See the comment -# for get_target_export_arg above for the correct casing of this argument. -# - includes_var: The variable with this name is set in the caller's scope to -# the string of include commands. -function(get_config_exports_includes project includes_var) - string(TOUPPER "${project}" project_upper) - set(prefix "\${${project_upper}_CMAKE_DIR}/${project}") - if(project STREQUAL "LLVM") - set(suffix "Exports.cmake") # legacy - else() - set(suffix "Targets.cmake") - endif() - - if(NOT LLVM_DISTRIBUTIONS) - set(${includes_var} "include(\"${prefix}${suffix}\")" PARENT_SCOPE) - else() - set(includes) - foreach(distribution ${LLVM_DISTRIBUTIONS}) - list(APPEND includes "include(\"${prefix}${distribution}${suffix}\" OPTIONAL)") - endforeach() - string(REPLACE ";" "\n" includes "${includes}") - set(${includes_var} "${includes}" PARENT_SCOPE) - endif() -endfunction() - -# Create the install commands and targets for the distributions' CMake exports. -# The target to install ${distribution} for a project is called -# ${project}-${distribution}-cmake-exports, where ${project} is the project name -# in lowercase and ${distribution} is the distribution name in lowercase, except -# for LLVM, where the target is just called ${distribution}-cmake-exports. See -# the comment at the top of this file for various assumptions made. -# - project: The project. IMPORTANT: See the comment for get_target_export_arg -# above for the correct casing of this argument. -function(install_distribution_exports project) - string(TOUPPER "${project}" project_upper) - string(TOLOWER "${project}" project_lower) - if(project STREQUAL "LLVM") - set(prefix "") - set(suffix "Exports") # legacy - else() - set(prefix "${project_lower}-") - set(suffix "Targets") - endif() - set(destination "${${project_upper}_INSTALL_PACKAGE_DIR}") - - if(NOT LLVM_DISTRIBUTIONS) - get_property(has_exports GLOBAL PROPERTY ${project_upper}_HAS_EXPORTS) - if(has_exports) - install(EXPORT ${project}${suffix} DESTINATION "${destination}" - COMPONENT ${prefix}cmake-exports) - endif() - else() - foreach(distribution ${LLVM_DISTRIBUTIONS}) - string(TOUPPER "${distribution}" distribution_upper) - get_property(has_exports GLOBAL PROPERTY ${project_upper}_${distribution_upper}_HAS_EXPORTS) - if(has_exports) - string(TOLOWER "${distribution}" distribution_lower) - set(target ${prefix}${distribution_lower}-cmake-exports) - install(EXPORT ${project}${distribution}${suffix} DESTINATION "${destination}" - COMPONENT ${target}) - if(NOT LLVM_ENABLE_IDE) - add_custom_target(${target}) - add_llvm_install_targets(install-${target} COMPONENT ${target}) - endif() - endif() - endforeach() - endif() -endfunction() - -# Create the targets for installing the configured distributions. The -# ${distribution} target builds the distribution, install-${distribution} -# installs it, and install-${distribution}-stripped installs a stripped version, -# where ${distribution} is the distribution name in lowercase, or "distribution" -# for the default distribution. -function(llvm_distribution_add_targets) - # This function is called towards the end of LLVM's CMakeLists.txt, so all - # errors will have been seen by now. - if(LLVM_STRICT_DISTRIBUTIONS) - get_property(errors GLOBAL PROPERTY LLVM_DISTRIBUTION_ERRORS) - if(errors) - string(PREPEND errors - "Strict distribution errors (turn off LLVM_STRICT_DISTRIBUTIONS to bypass):\n" - ) - message(FATAL_ERROR "${errors}") - endif() - endif() - - set(distributions "${LLVM_DISTRIBUTIONS}") - if(NOT distributions) - # CMake seemingly doesn't distinguish between an empty list and a list - # containing one element which is the empty string, so just use a special - # marker to denote the default (unnamed) distribution and fix it in the - # loop. - set(distributions "") - endif() - - get_property(LLVM_DRIVER_TOOL_SYMLINKS GLOBAL PROPERTY LLVM_DRIVER_TOOL_SYMLINKS) - - foreach(distribution ${distributions}) - if(distribution STREQUAL "") - set(distribution_target distribution) - # Preserve legacy behavior for LLVM_DISTRIBUTION_COMPONENTS. - set(distribution_components ${LLVM_DISTRIBUTION_COMPONENTS} ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS}) - else() - string(TOLOWER "${distribution}" distribution_lower) - set(distribution_target ${distribution_lower}-distribution) - set(distribution_components ${LLVM_${distribution}_DISTRIBUTION_COMPONENTS}) - endif() - - add_custom_target(${distribution_target}) - add_custom_target(install-${distribution_target}) - add_custom_target(install-${distribution_target}-stripped) - - foreach(target ${distribution_components}) - # Note that some distribution components may not have an actual target, but only an install-FOO target. - # This happens for example if a target is an INTERFACE target. - if(TARGET ${target}) - add_dependencies(${distribution_target} ${target}) - endif() - - if(TARGET install-${target}) - add_dependencies(install-${distribution_target} install-${target}) - elseif(TARGET install-llvm-driver AND ${target} IN_LIST LLVM_DRIVER_TOOL_SYMLINKS) - add_dependencies(install-${distribution_target} install-llvm-driver) - else() - message(SEND_ERROR "Specified distribution component '${target}' doesn't have an install target") - endif() - - if(TARGET install-${target}-stripped) - add_dependencies(install-${distribution_target}-stripped install-${target}-stripped) - elseif(TARGET install-llvm-driver-stripped AND ${target} IN_LIST LLVM_DRIVER_TOOL_SYMLINKS) - add_dependencies(install-${distribution_target}-stripped install-llvm-driver-stripped) - else() - message(SEND_ERROR - "Specified distribution component '${target}' doesn't have an install-stripped target." - " Its installation target creation should be changed to use add_llvm_install_targets," - " or you should manually create the 'install-${target}-stripped' target.") - endif() - endforeach() - endforeach() -endfunction() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExports-release.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExports-release.cmake deleted file mode 100644 index 96671f8..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExports-release.cmake +++ /dev/null @@ -1,9 +0,0 @@ -#---------------------------------------------------------------- -# Generated CMake target import file for configuration "Release". -#---------------------------------------------------------------- - -# Commands may need to know the format version. -set(CMAKE_IMPORT_FILE_VERSION 1) - -# Commands beyond this point should not need to know the version. -set(CMAKE_IMPORT_FILE_VERSION) diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExports.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExports.cmake deleted file mode 100644 index fdf753a..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExports.cmake +++ /dev/null @@ -1,90 +0,0 @@ -# Generated by CMake - -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6) - message(FATAL_ERROR "CMake >= 2.6.0 required") -endif() -cmake_policy(PUSH) -cmake_policy(VERSION 2.6...3.20) -#---------------------------------------------------------------- -# Generated CMake target import file. -#---------------------------------------------------------------- - -# Commands may need to know the format version. -set(CMAKE_IMPORT_FILE_VERSION 1) - -# Protect against multiple inclusion, which would fail when already imported targets are added once more. -set(_targetsDefined) -set(_targetsNotDefined) -set(_expectedTargets) -foreach(_expectedTarget) - list(APPEND _expectedTargets ${_expectedTarget}) - if(NOT TARGET ${_expectedTarget}) - list(APPEND _targetsNotDefined ${_expectedTarget}) - endif() - if(TARGET ${_expectedTarget}) - list(APPEND _targetsDefined ${_expectedTarget}) - endif() -endforeach() -if("${_targetsDefined}" STREQUAL "${_expectedTargets}") - unset(_targetsDefined) - unset(_targetsNotDefined) - unset(_expectedTargets) - set(CMAKE_IMPORT_FILE_VERSION) - cmake_policy(POP) - return() -endif() -if(NOT "${_targetsDefined}" STREQUAL "") - message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") -endif() -unset(_targetsDefined) -unset(_targetsNotDefined) -unset(_expectedTargets) - -# Compute the installation prefix relative to this file. -get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -if(_IMPORT_PREFIX STREQUAL "/") - set(_IMPORT_PREFIX "") -endif() - -if(CMAKE_VERSION VERSION_LESS 2.8.12) - message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.") -endif() - -# Load information for each installed configuration. -get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -file(GLOB CONFIG_FILES "${_DIR}/LLVMExports-*.cmake") -foreach(f ${CONFIG_FILES}) - include(${f}) -endforeach() - -# Cleanup temporary variables. -set(_IMPORT_PREFIX) - -# Loop over all imported files and verify that they actually exist -foreach(target ${_IMPORT_CHECK_TARGETS} ) - foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) - if(NOT EXISTS "${file}" ) - message(FATAL_ERROR "The imported target \"${target}\" references the file - \"${file}\" -but this file does not exist. Possible reasons include: -* The file was deleted, renamed, or moved to another location. -* An install or uninstall procedure did not complete successfully. -* The installation package was faulty and contained - \"${CMAKE_CURRENT_LIST_FILE}\" -but not all the files it references. -") - endif() - endforeach() - unset(_IMPORT_CHECK_FILES_FOR_${target}) -endforeach() -unset(_IMPORT_CHECK_TARGETS) - -# This file does not depend on other imported targets which have -# been exported from the same project but in a separate export set. - -# Commands beyond this point should not need to know the version. -set(CMAKE_IMPORT_FILE_VERSION) -cmake_policy(POP) diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExternalProjectUtils.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExternalProjectUtils.cmake deleted file mode 100644 index 4b5b600..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMExternalProjectUtils.cmake +++ /dev/null @@ -1,405 +0,0 @@ -include(ExternalProject) - -# llvm_ExternalProject_BuildCmd(out_var target) -# Utility function for constructing command lines for external project targets -function(llvm_ExternalProject_BuildCmd out_var target bin_dir) - cmake_parse_arguments(ARG "" "CONFIGURATION" "" ${ARGN}) - if(NOT ARG_CONFIGURATION) - set(ARG_CONFIGURATION "$") - endif() - if (CMAKE_GENERATOR MATCHES "Make") - # Use special command for Makefiles to support parallelism. - set(${out_var} "$(MAKE)" "-C" "${bin_dir}" "${target}" PARENT_SCOPE) - else() - set(tool_args "${LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS}") - if(NOT tool_args STREQUAL "") - string(CONFIGURE "${tool_args}" tool_args @ONLY) - string(PREPEND tool_args "-- ") - separate_arguments(tool_args UNIX_COMMAND "${tool_args}") - endif() - set(${out_var} ${CMAKE_COMMAND} --build ${bin_dir} --target ${target} - --config ${ARG_CONFIGURATION} ${tool_args} PARENT_SCOPE) - endif() -endfunction() - -# is_msvc_triple(out_var triple) -# Checks whether the passed triple refers to an MSVC environment -function(is_msvc_triple out_var triple) - if (triple MATCHES ".*-windows-msvc.*") - set(${out_var} TRUE PARENT_SCOPE) - else() - set(${out_var} FALSE PARENT_SCOPE) - endif() -endfunction() - - -# llvm_ExternalProject_Add(name source_dir ... -# USE_TOOLCHAIN -# Use just-built tools (see TOOLCHAIN_TOOLS) -# EXCLUDE_FROM_ALL -# Exclude this project from the all target -# NO_INSTALL -# Don't generate install targets for this project -# ALWAYS_CLEAN -# Always clean the sub-project before building -# CMAKE_ARGS arguments... -# Optional cmake arguments to pass when configuring the project -# TOOLCHAIN_TOOLS targets... -# Targets for toolchain tools (defaults to clang;lld) -# DEPENDS targets... -# Targets that this project depends on -# EXTRA_TARGETS targets... -# Extra targets in the subproject to generate targets for -# PASSTHROUGH_PREFIXES prefix... -# Extra variable prefixes (name is always included) to pass down -# STRIP_TOOL path -# Use provided strip tool instead of the default one. -# TARGET_TRIPLE triple -# Optional target triple to pass to the compiler -# ) -function(llvm_ExternalProject_Add name source_dir) - cmake_parse_arguments(ARG - "USE_TOOLCHAIN;EXCLUDE_FROM_ALL;NO_INSTALL;ALWAYS_CLEAN" - "SOURCE_DIR" - "CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS;PASSTHROUGH_PREFIXES;STRIP_TOOL;TARGET_TRIPLE" - ${ARGN}) - canonicalize_tool_name(${name} nameCanon) - - foreach(arg ${ARG_CMAKE_ARGS}) - if(arg MATCHES "^-DCMAKE_SYSTEM_NAME=") - string(REGEX REPLACE "^-DCMAKE_SYSTEM_NAME=(.*)$" "\\1" _cmake_system_name "${arg}") - endif() - endforeach() - - # If CMAKE_SYSTEM_NAME is not set explicitly in the arguments passed to us, - # reflect CMake's own default. - if (NOT _cmake_system_name) - set(_cmake_system_name "${CMAKE_HOST_SYSTEM_NAME}") - endif() - - if(NOT ARG_TARGET_TRIPLE) - set(target_triple ${LLVM_DEFAULT_TARGET_TRIPLE}) - else() - set(target_triple ${ARG_TARGET_TRIPLE}) - endif() - - is_msvc_triple(is_msvc_target ${target_triple}) - - if(NOT ARG_TOOLCHAIN_TOOLS) - set(ARG_TOOLCHAIN_TOOLS clang) - # AIX 64-bit XCOFF and big AR format is not yet supported in some of these tools. - if(NOT _cmake_system_name STREQUAL AIX) - list(APPEND ARG_TOOLCHAIN_TOOLS lld llvm-ar llvm-ranlib llvm-nm llvm-objdump) - if(_cmake_system_name STREQUAL Darwin) - list(APPEND ARG_TOOLCHAIN_TOOLS llvm-libtool-darwin llvm-lipo) - elseif(is_msvc_target) - list(APPEND ARG_TOOLCHAIN_TOOLS llvm-lib llvm-rc) - if (LLVM_ENABLE_LIBXML2) - list(APPEND ARG_TOOLCHAIN_TOOLS llvm-mt) - endif() - else() - # TODO: These tools don't fully support Mach-O format yet. - list(APPEND ARG_TOOLCHAIN_TOOLS llvm-objcopy llvm-strip llvm-readelf) - endif() - endif() - endif() - foreach(tool ${ARG_TOOLCHAIN_TOOLS}) - if(TARGET ${tool}) - list(APPEND TOOLCHAIN_TOOLS ${tool}) - - # $ only works on add_executable or add_library targets - # The below logic mirrors cmake's own implementation - get_target_property(target_type "${tool}" TYPE) - if(NOT target_type STREQUAL "OBJECT_LIBRARY" AND - NOT target_type STREQUAL "UTILITY" AND - NOT target_type STREQUAL "GLOBAL_TARGET" AND - NOT target_type STREQUAL "INTERFACE_LIBRARY") - list(APPEND TOOLCHAIN_BINS $) - endif() - - endif() - endforeach() - - if(NOT ARG_RUNTIME_LIBRARIES) - set(ARG_RUNTIME_LIBRARIES compiler-rt libcxx) - endif() - foreach(lib ${ARG_RUNTIME_LIBRARIES}) - if(TARGET ${lib}) - list(APPEND RUNTIME_LIBRARIES ${lib}) - endif() - endforeach() - - if(ARG_ALWAYS_CLEAN) - set(always_clean clean) - endif() - - if(clang IN_LIST TOOLCHAIN_TOOLS) - set(CLANG_IN_TOOLCHAIN On) - endif() - - if(RUNTIME_LIBRARIES AND CLANG_IN_TOOLCHAIN) - list(APPEND TOOLCHAIN_BINS ${RUNTIME_LIBRARIES}) - endif() - - set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${name}-stamps/) - set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${name}-bins/) - - add_custom_target(${name}-clear - COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR} - COMMENT "Clobbering ${name} build and stamp directories" - USES_TERMINAL - ) - - # Find all variables that start with a prefix and propagate them through - get_cmake_property(variableNames VARIABLES) - - list(APPEND ARG_PASSTHROUGH_PREFIXES ${nameCanon}) - foreach(prefix ${ARG_PASSTHROUGH_PREFIXES}) - foreach(variableName ${variableNames}) - if(variableName MATCHES "^${prefix}") - string(REPLACE ";" "|" value "${${variableName}}") - list(APPEND PASSTHROUGH_VARIABLES - -D${variableName}=${value}) - endif() - endforeach() - endforeach() - - # Populate the non-project-specific passthrough variables - foreach(variableName ${LLVM_EXTERNAL_PROJECT_PASSTHROUGH}) - if(DEFINED ${variableName}) - if("${${variableName}}" STREQUAL "") - set(value "") - else() - string(REPLACE ";" "|" value "${${variableName}}") - endif() - list(APPEND PASSTHROUGH_VARIABLES - -D${variableName}=${value}) - endif() - endforeach() - - if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING) - if(CLANG_IN_TOOLCHAIN) - if(is_msvc_target) - set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX} - -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX} - -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}) - else() - set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX} - -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX} - -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}) - endif() - endif() - if(lld IN_LIST TOOLCHAIN_TOOLS) - if(is_msvc_target) - list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link${CMAKE_EXECUTABLE_SUFFIX}) - elseif(NOT _cmake_system_name STREQUAL Darwin) - list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/ld.lld${CMAKE_EXECUTABLE_SUFFIX}) - endif() - endif() - if(llvm-ar IN_LIST TOOLCHAIN_TOOLS) - if(is_msvc_target) - list(APPEND compiler_args -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-lib${CMAKE_EXECUTABLE_SUFFIX}) - else() - list(APPEND compiler_args -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar${CMAKE_EXECUTABLE_SUFFIX}) - endif() - endif() - if(llvm-libtool-darwin IN_LIST TOOLCHAIN_TOOLS) - list(APPEND compiler_args -DCMAKE_LIBTOOL=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-libtool-darwin${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-lipo IN_LIST TOOLCHAIN_TOOLS) - list(APPEND compiler_args -DCMAKE_LIPO=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-lipo${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-ranlib IN_LIST TOOLCHAIN_TOOLS) - list(APPEND compiler_args -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-nm IN_LIST TOOLCHAIN_TOOLS) - list(APPEND compiler_args -DCMAKE_NM=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-nm${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-objdump IN_LIST TOOLCHAIN_TOOLS) - list(APPEND compiler_args -DCMAKE_OBJDUMP=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-objdump${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-objcopy IN_LIST TOOLCHAIN_TOOLS) - list(APPEND compiler_args -DCMAKE_OBJCOPY=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-objcopy${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-strip IN_LIST TOOLCHAIN_TOOLS AND NOT ARG_STRIP_TOOL) - list(APPEND compiler_args -DCMAKE_STRIP=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-strip${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-readelf IN_LIST TOOLCHAIN_TOOLS) - list(APPEND compiler_args -DCMAKE_READELF=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-readelf${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-mt IN_LIST TOOLCHAIN_TOOLS AND is_msvc_target) - list(APPEND compiler_args -DCMAKE_MT=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-mt${CMAKE_EXECUTABLE_SUFFIX}) - endif() - if(llvm-rc IN_LIST TOOLCHAIN_TOOLS AND is_msvc_target) - list(APPEND compiler_args -DCMAKE_RC_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-rc${CMAKE_EXECUTABLE_SUFFIX}) - endif() - list(APPEND ARG_DEPENDS ${TOOLCHAIN_TOOLS}) - endif() - - if(ARG_STRIP_TOOL) - list(APPEND compiler_args -DCMAKE_STRIP=${ARG_STRIP_TOOL}) - endif() - - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp - DEPENDS ${ARG_DEPENDS} - COMMAND ${CMAKE_COMMAND} -E touch ${BINARY_DIR}/CMakeCache.txt - COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_DIR}/${name}-mkdir - COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp - COMMENT "Clobbering bootstrap build and stamp directories" - ) - - add_custom_target(${name}-clobber - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp) - - if(ARG_EXCLUDE_FROM_ALL) - set(exclude EXCLUDE_FROM_ALL 1) - endif() - - if(CMAKE_SYSROOT) - set(sysroot_arg -DCMAKE_SYSROOT=${CMAKE_SYSROOT}) - endif() - - if(CMAKE_CROSSCOMPILING OR _cmake_system_name STREQUAL AIX) - set(compiler_args -DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER} - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_LINKER=${CMAKE_LINKER} - -DCMAKE_AR=${CMAKE_AR} - -DCMAKE_RANLIB=${CMAKE_RANLIB} - -DCMAKE_NM=${CMAKE_NM} - -DCMAKE_OBJCOPY=${CMAKE_OBJCOPY} - -DCMAKE_OBJDUMP=${CMAKE_OBJDUMP} - -DCMAKE_STRIP=${CMAKE_STRIP} - -DCMAKE_READELF=${CMAKE_READELF}) - endif() - if(CMAKE_CROSSCOMPILING) - set(llvm_config_path ${LLVM_CONFIG_PATH}) - - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - string(REGEX MATCH "^[0-9]+" CLANG_VERSION_MAJOR - ${PACKAGE_VERSION}) - if(DEFINED CLANG_RESOURCE_DIR AND NOT CLANG_RESOURCE_DIR STREQUAL "") - set(resource_dir ${LLVM_TOOLS_BINARY_DIR}/${CLANG_RESOURCE_DIR}) - else() - set(resource_dir "${LLVM_LIBRARY_DIR}/clang/${CLANG_VERSION_MAJOR}") - endif() - set(flag_types ASM C CXX MODULE_LINKER SHARED_LINKER EXE_LINKER) - foreach(type ${flag_types}) - set(${type}_flag -DCMAKE_${type}_FLAGS=-resource-dir=${resource_dir}) - endforeach() - string(REPLACE ";" "|" flag_string "${flag_types}") - foreach(arg ${ARG_CMAKE_ARGS}) - if(arg MATCHES "^-DCMAKE_(${flag_string})_FLAGS") - foreach(type ${flag_types}) - if(arg MATCHES "^-DCMAKE_${type}_FLAGS") - string(REGEX REPLACE "^-DCMAKE_${type}_FLAGS=(.*)$" "\\1" flag_value "${arg}") - set(${type}_flag "${${type}_flag} ${flag_value}") - endif() - endforeach() - else() - list(APPEND cmake_args ${arg}) - endif() - endforeach() - foreach(type ${flag_types}) - list(APPEND cmake_args ${${type}_flag}) - endforeach() - else() - set(cmake_args ${ARG_CMAKE_ARGS}) - endif() - else() - set(llvm_config_path "$") - set(cmake_args ${ARG_CMAKE_ARGS}) - endif() - - if(ARG_TARGET_TRIPLE) - list(APPEND compiler_args -DCMAKE_C_COMPILER_TARGET=${ARG_TARGET_TRIPLE}) - list(APPEND compiler_args -DCMAKE_CXX_COMPILER_TARGET=${ARG_TARGET_TRIPLE}) - list(APPEND compiler_args -DCMAKE_ASM_COMPILER_TARGET=${ARG_TARGET_TRIPLE}) - endif() - - ExternalProject_Add(${name} - DEPENDS ${ARG_DEPENDS} llvm-config - ${name}-clobber - PREFIX ${CMAKE_BINARY_DIR}/projects/${name} - SOURCE_DIR ${source_dir} - STAMP_DIR ${STAMP_DIR} - BINARY_DIR ${BINARY_DIR} - ${exclude} - CMAKE_ARGS ${${nameCanon}_CMAKE_ARGS} - --no-warn-unused-cli - ${compiler_args} - -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} - ${sysroot_arg} - -DLLVM_BINARY_DIR=${PROJECT_BINARY_DIR} - -DLLVM_CONFIG_PATH=${llvm_config_path} - -DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR} - -DLLVM_HOST_TRIPLE=${LLVM_HOST_TRIPLE} - -DLLVM_HAVE_LINK_VERSION_SCRIPT=${LLVM_HAVE_LINK_VERSION_SCRIPT} - -DLLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO=${LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO} - -DLLVM_USE_RELATIVE_PATHS_IN_FILES=${LLVM_USE_RELATIVE_PATHS_IN_FILES} - -DLLVM_LIT_ARGS=${LLVM_LIT_ARGS} - -DLLVM_SOURCE_PREFIX=${LLVM_SOURCE_PREFIX} - -DPACKAGE_VERSION=${PACKAGE_VERSION} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} - -DCMAKE_EXPORT_COMPILE_COMMANDS=1 - ${cmake_args} - ${PASSTHROUGH_VARIABLES} - INSTALL_COMMAND "" - STEP_TARGETS configure build - BUILD_ALWAYS 1 - USES_TERMINAL_CONFIGURE 1 - USES_TERMINAL_BUILD 1 - USES_TERMINAL_INSTALL 1 - LIST_SEPARATOR | - ) - - if(ARG_USE_TOOLCHAIN) - set(force_deps DEPENDS ${TOOLCHAIN_BINS}) - endif() - - llvm_ExternalProject_BuildCmd(run_clean clean ${BINARY_DIR}) - ExternalProject_Add_Step(${name} clean - COMMAND ${run_clean} - COMMENT "Cleaning ${name}..." - DEPENDEES configure - ${force_deps} - WORKING_DIRECTORY ${BINARY_DIR} - EXCLUDE_FROM_MAIN 1 - USES_TERMINAL 1 - ) - ExternalProject_Add_StepTargets(${name} clean) - - if(ARG_USE_TOOLCHAIN) - add_dependencies(${name}-clean ${name}-clobber) - set_target_properties(${name}-clean PROPERTIES - SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp) - endif() - - if(NOT ARG_NO_INSTALL) - install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -DCMAKE_INSTALL_DO_STRIP=\${CMAKE_INSTALL_DO_STRIP} -P ${BINARY_DIR}/cmake_install.cmake\)" - COMPONENT ${name}) - - add_llvm_install_targets(install-${name} - DEPENDS ${name} - COMPONENT ${name}) - endif() - - # Add top-level targets - foreach(target ${ARG_EXTRA_TARGETS}) - if(DEFINED ${target}) - set(external_target "${${target}}") - else() - set(external_target "${target}") - endif() - llvm_ExternalProject_BuildCmd(build_runtime_cmd ${external_target} ${BINARY_DIR}) - add_custom_target(${target} - COMMAND ${build_runtime_cmd} - DEPENDS ${name}-configure - WORKING_DIRECTORY ${BINARY_DIR} - VERBATIM - USES_TERMINAL) - endforeach() -endfunction() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMInstallSymlink.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMInstallSymlink.cmake deleted file mode 100644 index 0ef4b82..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMInstallSymlink.cmake +++ /dev/null @@ -1,26 +0,0 @@ -# We need to execute this script at installation time because the -# DESTDIR environment variable may be unset at configuration time. -# See PR8397. - -# Set to an arbitrary directory to silence GNUInstallDirs warnings -# regarding being unable to determine libdir. -set(CMAKE_INSTALL_LIBDIR "lib") -include(GNUInstallDirs) - -function(install_symlink name target outdir link_or_copy) - # link_or_copy is the "command" to pass to cmake -E. - # It should be either "create_symlink" or "copy". - - set(DESTDIR $ENV{DESTDIR}) - if(NOT IS_ABSOLUTE "${outdir}") - set(outdir "${CMAKE_INSTALL_PREFIX}/${outdir}") - endif() - set(outdir "${DESTDIR}${outdir}") - - message(STATUS "Creating ${name}") - - execute_process( - COMMAND "${CMAKE_COMMAND}" -E ${link_or_copy} "${target}" "${name}" - WORKING_DIRECTORY "${outdir}") - -endfunction() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMProcessSources.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMProcessSources.cmake deleted file mode 100644 index 340aa7b..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/LLVMProcessSources.cmake +++ /dev/null @@ -1,122 +0,0 @@ -include(AddFileDependencies) -include(CMakeParseArguments) - -function(llvm_replace_compiler_option var old new) - # Replaces a compiler option or switch `old' in `var' by `new'. - # If `old' is not in `var', appends `new' to `var'. - # Example: llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2") - # If the option already is on the variable, don't add it: - if( "${${var}}" MATCHES "(^| )${new}($| )" ) - set(n "") - else() - set(n "${new}") - endif() - if( "${${var}}" MATCHES "(^| )${old}($| )" ) - string( REGEX REPLACE "(^| )${old}($| )" " ${n} " ${var} "${${var}}" ) - else() - set( ${var} "${${var}} ${n}" ) - endif() - set( ${var} "${${var}}" PARENT_SCOPE ) -endfunction(llvm_replace_compiler_option) - -macro(add_td_sources srcs) - file(GLOB tds *.td) - if( tds ) - source_group("TableGen descriptions" FILES ${tds}) - set_source_files_properties(${tds} PROPERTIES HEADER_FILE_ONLY ON) - list(APPEND ${srcs} ${tds}) - endif() -endmacro(add_td_sources) - -function(add_header_files_for_glob hdrs_out glob) - file(GLOB hds ${glob}) - set(filtered) - foreach(file ${hds}) - # Explicit existence check is necessary to filter dangling symlinks - # out. See https://bugs.gentoo.org/674662. - if(EXISTS ${file}) - list(APPEND filtered ${file}) - endif() - endforeach() - set(${hdrs_out} ${filtered} PARENT_SCOPE) -endfunction(add_header_files_for_glob) - -function(find_all_header_files hdrs_out additional_headerdirs) - add_header_files_for_glob(hds *.h) - list(APPEND all_headers ${hds}) - - foreach(additional_dir ${additional_headerdirs}) - add_header_files_for_glob(hds "${additional_dir}/*.h") - list(APPEND all_headers ${hds}) - add_header_files_for_glob(hds "${additional_dir}/*.inc") - list(APPEND all_headers ${hds}) - endforeach(additional_dir) - - set( ${hdrs_out} ${all_headers} PARENT_SCOPE ) -endfunction(find_all_header_files) - - -function(llvm_process_sources OUT_VAR) - cmake_parse_arguments(ARG "PARTIAL_SOURCES_INTENDED" "" "ADDITIONAL_HEADERS;ADDITIONAL_HEADER_DIRS" ${ARGN}) - set(sources ${ARG_UNPARSED_ARGUMENTS}) - llvm_check_source_file_list(${sources}) - - # This adds .td and .h files to the Visual Studio solution: - add_td_sources(sources) - find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}") - if (hdrs) - set_source_files_properties(${hdrs} PROPERTIES HEADER_FILE_ONLY ON) - endif() - set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON) - list(APPEND sources ${ARG_ADDITIONAL_HEADERS} ${hdrs}) - - set( ${OUT_VAR} ${sources} PARENT_SCOPE ) -endfunction(llvm_process_sources) - - -function(llvm_check_source_file_list) - cmake_parse_arguments(ARG "" "SOURCE_DIR" "" ${ARGN}) - foreach(l ${ARG_UNPARSED_ARGUMENTS}) - get_filename_component(fp ${l} REALPATH) - list(APPEND listed ${fp}) - endforeach() - - if(ARG_SOURCE_DIR) - file(GLOB globbed - "${ARG_SOURCE_DIR}/*.c" "${ARG_SOURCE_DIR}/*.cpp") - else() - file(GLOB globbed *.c *.cpp) - endif() - - set_property(DIRECTORY APPEND PROPERTY LLVM_SOURCE_FILES ${listed}) - if (ARG_PARTIAL_SOURCES_INTENDED) # llvm_process_source's scope - return() - endif() - get_directory_property(listed LLVM_SOURCE_FILES) - - foreach(g ${globbed}) - get_filename_component(fn ${g} NAME) - if(ARG_SOURCE_DIR) - set(entry "${g}") - else() - set(entry "${fn}") - endif() - get_filename_component(gp ${g} REALPATH) - - # Don't reject hidden files. Some editors create backups in the - # same directory as the file. - if (NOT "${fn}" MATCHES "^\\.") - if(NOT ${entry} IN_LIST LLVM_OPTIONAL_SOURCES) - if(NOT ${gp} IN_LIST listed) - if(ARG_SOURCE_DIR) - set(fn_relative "${ARG_SOURCE_DIR}/${fn}") - else() - set(fn_relative "${fn}") - endif() - message(SEND_ERROR "Found unknown source file ${fn_relative} -Please update ${CMAKE_CURRENT_LIST_FILE}\n") - endif() - endif() - endif() - endforeach() -endfunction(llvm_check_source_file_list) diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/SetTargetTriple.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/SetTargetTriple.cmake deleted file mode 100644 index ed0a53c..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/SetTargetTriple.cmake +++ /dev/null @@ -1,13 +0,0 @@ -macro(set_llvm_target_triple) - set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE_default}" CACHE STRING - "Default target for which LLVM will generate code." ) - if (TARGET_TRIPLE) - message(WARNING "TARGET_TRIPLE is deprecated and will be removed in a future release. " - "Please use LLVM_DEFAULT_TARGET_TRIPLE instead.") - set(LLVM_TARGET_TRIPLE "${TARGET_TRIPLE}") - else() - set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}") - endif() - message(STATUS "LLVM host triple: ${LLVM_HOST_TRIPLE}") - message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}") -endmacro() diff --git a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/TableGen.cmake b/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/TableGen.cmake deleted file mode 100644 index 7fd6628..0000000 --- a/recipes-devtools/swift/swift-stdlib/llvm-cmake-modules/TableGen.cmake +++ /dev/null @@ -1,216 +0,0 @@ -# LLVM_TARGET_DEFINITIONS must contain the name of the .td file to process, -# while LLVM_TARGET_DEPENDS may contain additional file dependencies. -# Extra parameters for `tblgen' may come after `ofn' parameter. -# Adds the name of the generated file to TABLEGEN_OUTPUT. -include(LLVMDistributionSupport) - -function(tablegen project ofn) - cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN}) - - # Override ${project} with ${project}_TABLEGEN_PROJECT - if(NOT "${${project}_TABLEGEN_PROJECT}" STREQUAL "") - set(project ${${project}_TABLEGEN_PROJECT}) - endif() - - # Validate calling context. - if(NOT ${project}_TABLEGEN_EXE) - message(FATAL_ERROR "${project}_TABLEGEN_EXE not set") - endif() - - # Use depfile instead of globbing arbitrary *.td(s) for Ninja. - if(CMAKE_GENERATOR MATCHES "Ninja") - # Make output path relative to build.ninja, assuming located on - # ${CMAKE_BINARY_DIR}. - # CMake emits build targets as relative paths but Ninja doesn't identify - # absolute path (in *.d) as relative path (in build.ninja) - # Note that tblgen is executed on ${CMAKE_BINARY_DIR} as working directory. - file(RELATIVE_PATH ofn_rel - ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}) - set(additional_cmdline - -o ${ofn_rel} - -d ${ofn_rel}.d - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.d - ) - set(local_tds) - set(global_tds) - else() - file(GLOB local_tds "*.td") - file(GLOB_RECURSE global_tds "${LLVM_MAIN_INCLUDE_DIR}/llvm/*.td") - set(additional_cmdline - -o ${CMAKE_CURRENT_BINARY_DIR}/${ofn} - ) - endif() - - if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS}) - set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS}) - else() - set(LLVM_TARGET_DEFINITIONS_ABSOLUTE - ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS}) - endif() - if (LLVM_ENABLE_DAGISEL_COV AND "-gen-dag-isel" IN_LIST ARGN) - list(APPEND LLVM_TABLEGEN_FLAGS "-instrument-coverage") - endif() - if (LLVM_ENABLE_GISEL_COV AND "-gen-global-isel" IN_LIST ARGN) - list(APPEND LLVM_TABLEGEN_FLAGS "-instrument-gisel-coverage") - list(APPEND LLVM_TABLEGEN_FLAGS "-gisel-coverage-file=${LLVM_GISEL_COV_PREFIX}all") - endif() - if (LLVM_OMIT_DAGISEL_COMMENTS AND "-gen-dag-isel" IN_LIST ARGN) - list(APPEND LLVM_TABLEGEN_FLAGS "-omit-comments") - endif() - - # MSVC can't support long string literals ("long" > 65534 bytes)[1], so if there's - # a possibility of generated tables being consumed by MSVC, generate arrays of - # char literals, instead. If we're cross-compiling, then conservatively assume - # that the source might be consumed by MSVC. - # [1] https://docs.microsoft.com/en-us/cpp/cpp/compiler-limits?view=vs-2017 - if (MSVC AND project STREQUAL LLVM) - list(APPEND LLVM_TABLEGEN_FLAGS "--long-string-literals=0") - endif() - if (CMAKE_GENERATOR MATCHES "Visual Studio") - # Visual Studio has problems with llvm-tblgen's native --write-if-changed - # behavior. Since it doesn't do restat optimizations anyway, just don't - # pass --write-if-changed there. - set(tblgen_change_flag) - else() - set(tblgen_change_flag "--write-if-changed") - endif() - - if (NOT LLVM_ENABLE_WARNINGS) - list(APPEND LLVM_TABLEGEN_FLAGS "-no-warn-on-unused-template-args") - endif() - - # We need both _TABLEGEN_TARGET and _TABLEGEN_EXE in the DEPENDS list - # (both the target and the file) to have .inc files rebuilt on - # a tablegen change, as cmake does not propagate file-level dependencies - # of custom targets. See the following ticket for more information: - # https://cmake.org/Bug/view.php?id=15858 - # The dependency on both, the target and the file, produces the same - # dependency twice in the result file when - # ("${${project}_TABLEGEN_TARGET}" STREQUAL "${${project}_TABLEGEN_EXE}") - # but lets us having smaller and cleaner code here. - get_directory_property(tblgen_includes INCLUDE_DIRECTORIES) - list(APPEND tblgen_includes ${ARG_EXTRA_INCLUDES}) - # Filter out empty items before prepending each entry with -I - list(REMOVE_ITEM tblgen_includes "") - list(TRANSFORM tblgen_includes PREPEND -I) - - set(tablegen_exe ${${project}_TABLEGEN_EXE}) - set(tablegen_depends ${${project}_TABLEGEN_TARGET} ${tablegen_exe}) - - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn} - COMMAND ${tablegen_exe} ${ARG_UNPARSED_ARGUMENTS} -I ${CMAKE_CURRENT_SOURCE_DIR} - ${tblgen_includes} - ${LLVM_TABLEGEN_FLAGS} - ${LLVM_TARGET_DEFINITIONS_ABSOLUTE} - ${tblgen_change_flag} - ${additional_cmdline} - # The file in LLVM_TARGET_DEFINITIONS may be not in the current - # directory and local_tds may not contain it, so we must - # explicitly list it here: - DEPENDS ${ARG_DEPENDS} ${tablegen_depends} - ${local_tds} ${global_tds} - ${LLVM_TARGET_DEFINITIONS_ABSOLUTE} - ${LLVM_TARGET_DEPENDS} - COMMENT "Building ${ofn}..." - ) - - # `make clean' must remove all those generated files: - set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${ofn}) - - set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn} PARENT_SCOPE) - set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${ofn} PROPERTIES - GENERATED 1) -endfunction() - -# Creates a target for publicly exporting tablegen dependencies. -function(add_public_tablegen_target target) - if(NOT TABLEGEN_OUTPUT) - message(FATAL_ERROR "Requires tablegen() definitions as TABLEGEN_OUTPUT.") - endif() - add_custom_target(${target} - DEPENDS ${TABLEGEN_OUTPUT}) - if(LLVM_COMMON_DEPENDS) - add_dependencies(${target} ${LLVM_COMMON_DEPENDS}) - endif() - set_target_properties(${target} PROPERTIES FOLDER "Tablegenning") - set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${target} PARENT_SCOPE) -endfunction() - -macro(add_tablegen target project) - cmake_parse_arguments(ADD_TABLEGEN "" "DESTINATION;EXPORT" "" ${ARGN}) - - set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) - set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen) - - add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB - ${ADD_TABLEGEN_UNPARSED_ARGUMENTS}) - set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS}) - - set(${project}_TABLEGEN_DEFAULT "${target}") - if (LLVM_NATIVE_TOOL_DIR) - if (EXISTS "${LLVM_NATIVE_TOOL_DIR}/${target}${LLVM_HOST_EXECUTABLE_SUFFIX}") - set(${project}_TABLEGEN_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/${target}${LLVM_HOST_EXECUTABLE_SUFFIX}") - endif() - endif() - - # FIXME: Quick fix to reflect LLVM_TABLEGEN to llvm-min-tblgen - if("${target}" STREQUAL "llvm-min-tblgen" - AND NOT "${LLVM_TABLEGEN}" STREQUAL "" - AND NOT "${LLVM_TABLEGEN}" STREQUAL "llvm-tblgen") - set(${project}_TABLEGEN_DEFAULT "${LLVM_TABLEGEN}") - endif() - - if(ADD_TABLEGEN_EXPORT) - set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}" CACHE - STRING "Native TableGen executable. Saves building one when cross-compiling.") - else() - # Internal tablegen - set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}") - set_target_properties(${target} PROPERTIES EXCLUDE_FROM_ALL ON) - endif() - - # Effective tblgen executable to be used: - set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN} PARENT_SCOPE) - set(${project}_TABLEGEN_TARGET ${${project}_TABLEGEN} PARENT_SCOPE) - - if(LLVM_USE_HOST_TOOLS) - if( ${${project}_TABLEGEN} STREQUAL "${target}" ) - # The NATIVE tablegen executable *must* depend on the current target one - # otherwise the native one won't get rebuilt when the tablgen sources - # change, and we end up with incorrect builds. - build_native_tool(${target} ${project}_TABLEGEN_EXE DEPENDS ${target}) - set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE) - - add_custom_target(${target}-host DEPENDS ${${project}_TABLEGEN_EXE}) - set(${project}_TABLEGEN_TARGET ${target}-host PARENT_SCOPE) - - # If we're using the host tablegen, and utils were not requested, we have no - # need to build this tablegen. - if ( NOT LLVM_BUILD_UTILS ) - set_target_properties(${target} PROPERTIES EXCLUDE_FROM_ALL ON) - endif() - endif() - endif() - - if (ADD_TABLEGEN_DESTINATION AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND - (LLVM_BUILD_UTILS OR ${target} IN_LIST LLVM_DISTRIBUTION_COMPONENTS)) - set(export_arg) - if(ADD_TABLEGEN_EXPORT) - get_target_export_arg(${target} ${ADD_TABLEGEN_EXPORT} export_arg) - endif() - install(TARGETS ${target} - ${export_arg} - COMPONENT ${target} - RUNTIME DESTINATION "${ADD_TABLEGEN_DESTINATION}") - if(NOT LLVM_ENABLE_IDE) - add_llvm_install_targets("install-${target}" - DEPENDS ${target} - COMPONENT ${target}) - endif() - endif() - if(ADD_TABLEGEN_EXPORT) - string(TOUPPER ${ADD_TABLEGEN_EXPORT} export_upper) - set_property(GLOBAL APPEND PROPERTY ${export_upper}_EXPORTS ${target}) - endif() -endmacro() From fa6b776f6619608791a3180a05ea5b5947398ed8 Mon Sep 17 00:00:00 2001 From: "Jesse L. Zamora" Date: Sun, 22 Jun 2025 15:19:15 -0400 Subject: [PATCH 3/3] Fix do_fix_gcc_install_dir typos - SWIFT_TARGET_ARCH cannot be used since the arch in the sysroot may likely be different. - Looks like pointing to `-oe-linux` was another typo as well in swift.bbclass. --- classes/swift.bbclass | 2 +- recipes-devtools/swift/swift-stdlib.bb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/swift.bbclass b/classes/swift.bbclass index 21e0441..4ffb31b 100644 --- a/classes/swift.bbclass +++ b/classes/swift.bbclass @@ -26,7 +26,7 @@ SWIFT_TARGET_ARCH = "${@oe.utils.conditional('TARGET_ARCH', 'arm', 'armv7', 'aar do_fix_gcc_install_dir() { # symbolic links do not work, will not be found by Swift clang driver # this is necessary to make the libstdc++ location heuristic work, necessary for C++ interop - (cd ${STAGING_DIR_TARGET}/usr/lib && rm -rf gcc && mkdir -p gcc && cp -rp ${SWIFT_TARGET_ARCH}-oe-linux gcc) + (cd ${STAGING_DIR_TARGET}/usr/lib && rm -rf gcc && mkdir -p gcc && cp -rp ${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS} gcc) } addtask fix_gcc_install_dir before do_configure after do_prepare_recipe_sysroot diff --git a/recipes-devtools/swift/swift-stdlib.bb b/recipes-devtools/swift/swift-stdlib.bb index be8ca75..8e6d1a3 100644 --- a/recipes-devtools/swift/swift-stdlib.bb +++ b/recipes-devtools/swift/swift-stdlib.bb @@ -39,7 +39,7 @@ SWIFT_CXX_LINK_FLAGS = "-target ${SWIFT_TARGET_NAME} --sysroot ${STAGING_DIR_TAR do_fix_gcc_install_dir() { # symbolic links do not work, will not be found by Swift clang driver # this is necessary to make the libstdc++ location heuristic work, necessary for C++ interop - (cd ${STAGING_DIR_TARGET}/usr/lib && rm -rf gcc && mkdir -p gcc && cp -rp ${SWIFT_TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS} gcc) + (cd ${STAGING_DIR_TARGET}/usr/lib && rm -rf gcc && mkdir -p gcc && cp -rp ${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS} gcc) } addtask fix_gcc_install_dir before do_configure after do_prepare_recipe_sysroot