2021-12-21 00:21:15 +08:00
set ( LLVM_VERSION "13.0.0" )
2019-10-08 01:35:13 +08:00
2020-05-04 11:30:17 +08:00
vcpkg_check_linkage ( ONLY_STATIC_LIBRARY )
2019-10-08 01:35:13 +08:00
2020-05-04 11:30:17 +08:00
vcpkg_from_github (
2019-10-08 01:35:13 +08:00
O U T _ S O U R C E _ P A T H S O U R C E _ P A T H
2020-05-04 11:30:17 +08:00
R E P O l l v m / l l v m - p r o j e c t
2020-12-01 01:56:22 +08:00
R E F l l v m o r g - $ { L L V M _ V E R S I O N }
2021-12-21 00:21:15 +08:00
S H A 5 1 2 8 0 0 4 c 0 5 d 3 2 b 9 7 2 0 f b 3 3 9 1 7 8 3 6 2 1 6 9 0 c 1 d f 9 b d 1 e 9 7 e 7 2 c b f f 9 1 9 2 e d 8 8 a 8 4 b 0 a c d 3 0 3 b 6 1 4 3 2 1 4 5 f a 9 1 7 b 5 b 5 e 5 4 8 c 8 c e e 2 9 b 2 4 e f 8 5 4 7 d c c 8 6 7 7 a d f 4 8 1 6 e 7 a 8 a 0 e b 2
2020-05-04 11:30:17 +08:00
H E A D _ R E F m a s t e r
2019-10-08 01:35:13 +08:00
P A T C H E S
2020-12-01 01:56:22 +08:00
0 0 0 2 - f i x - i n s t a l l - p a t h s . p a t c h # This patch fixes paths in ClangConfig.cmake, LLVMConfig.cmake, LLDConfig.cmake etc.
0 0 0 3 - f i x - o p e n m p - d e b u g . p a t c h
2020-08-28 03:27:39 +08:00
0 0 0 4 - f i x - d r - 1 7 3 4 . p a t c h
2020-11-13 09:31:34 +08:00
0 0 0 5 - f i x - t o o l s - p a t h . p a t c h
2021-04-14 06:17:17 +08:00
0 0 0 7 - f i x - c o m p i l e r - r t - i n s t a l l - p a t h . p a t c h
0 0 0 9 - f i x - t o o l s - i n s t a l l - p a t h . p a t c h
2021-06-30 07:08:28 +08:00
0 0 1 0 - f i x - l i b f f i . p a t c h
0 0 1 1 - f i x - l i b x m l 2 . p a t c h
2019-10-08 01:35:13 +08:00
)
2021-04-14 06:17:17 +08:00
vcpkg_check_features (
O U T _ F E A T U R E _ O P T I O N S F E A T U R E _ O P T I O N S
2021-03-30 00:39:04 +08:00
F E A T U R E S
2021-04-14 06:17:17 +08:00
t o o l s L L V M _ B U I L D _ T O O L S
t o o l s L L V M _ I N C L U D E _ T O O L S
u t i l s L L V M _ B U I L D _ U T I L S
u t i l s L L V M _ I N C L U D E _ U T I L S
e n a b l e - r t t i L L V M _ E N A B L E _ R T T I
e n a b l e - f f i L L V M _ E N A B L E _ F F I
e n a b l e - t e r m i n f o L L V M _ E N A B L E _ T E R M I N F O
e n a b l e - t h r e a d s L L V M _ E N A B L E _ T H R E A D S
e n a b l e - e h L L V M _ E N A B L E _ E H
e n a b l e - b i n d i n g s L L V M _ E N A B L E _ B I N D I N G S
2019-10-30 14:06:59 +08:00
)
2020-12-01 01:56:22 +08:00
# LLVM generates CMake error due to Visual Studio version 16.4 is known to miscompile part of LLVM.
# LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON disables this 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.
list ( APPEND FEATURE_OPTIONS
- D L L V M _ T E M P O R A R I L Y _ A L L O W _ O L D _ T O O L C H A I N = O N
)
2021-06-30 07:08:28 +08:00
# Force enable or disable external libraries
set ( llvm_external_libraries
z l i b
l i b x m l 2
)
foreach ( external_library IN LISTS llvm_external_libraries )
string ( TOLOWER "enable-${external_library}" feature_name )
string ( TOUPPER "LLVM_ENABLE_${external_library}" define_name )
if ( feature_name IN_LIST FEATURES )
list ( APPEND FEATURE_OPTIONS
- D $ { d e f i n e _ n a m e } = F O R C E _ O N
)
else ( )
list ( APPEND FEATURE_OPTIONS
- D $ { d e f i n e _ n a m e } = O F F
)
endif ( )
endforeach ( )
2020-05-04 11:30:17 +08:00
# By default assertions are enabled for Debug configuration only.
if ( "enable-assertions" IN_LIST FEATURES )
# Force enable assertions for all configurations.
list ( APPEND FEATURE_OPTIONS
- D L L V M _ E N A B L E _ A S S E R T I O N S = O N
)
elseif ( "disable-assertions" IN_LIST FEATURES )
# Force disable assertions for all configurations.
list ( APPEND FEATURE_OPTIONS
- D L L V M _ E N A B L E _ A S S E R T I O N S = O F F
)
2019-10-08 01:35:13 +08:00
endif ( )
2020-05-04 11:30:17 +08:00
# LLVM_ABI_BREAKING_CHECKS can be WITH_ASSERTS (default), FORCE_ON or FORCE_OFF.
# By default abi-breaking checks are enabled if assertions are enabled.
if ( "enable-abi-breaking-checks" IN_LIST FEATURES )
# Force enable abi-breaking checks.
list ( APPEND FEATURE_OPTIONS
- D L L V M _ A B I _ B R E A K I N G _ C H E C K S = F O R C E _ O N
)
elseif ( "disable-abi-breaking-checks" IN_LIST FEATURES )
# Force disable abi-breaking checks.
list ( APPEND FEATURE_OPTIONS
- D L L V M _ A B I _ B R E A K I N G _ C H E C K S = F O R C E _ O F F
)
2019-10-08 01:35:13 +08:00
endif ( )
2020-05-04 11:30:17 +08:00
set ( LLVM_ENABLE_PROJECTS )
if ( "clang" IN_LIST FEATURES OR "clang-tools-extra" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "clang" )
if ( "disable-clang-static-analyzer" IN_LIST FEATURES )
list ( APPEND FEATURE_OPTIONS
# Disable ARCMT
- D C L A N G _ E N A B L E _ A R C M T = O F F
# Disable static analyzer
- D C L A N G _ E N A B L E _ S T A T I C _ A N A L Y Z E R = O F F
)
endif ( )
2021-04-14 06:17:17 +08:00
# 1) LLVM/Clang tools are relocated from ./bin/ to ./tools/llvm/ (LLVM_TOOLS_INSTALL_DIR=tools/llvm)
# 2) Clang resource files are relocated from ./lib/clang/<version> to ./tools/llvm/lib/clang/<version> (see patch 0007-fix-compiler-rt-install-path.patch)
# So, the relative path should be changed from ../lib/clang/<version> to ./lib/clang/<version>
list ( APPEND FEATURE_OPTIONS -DCLANG_RESOURCE_DIR=lib/clang/ ${ LLVM_VERSION } )
2020-05-04 11:30:17 +08:00
endif ( )
if ( "clang-tools-extra" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "clang-tools-extra" )
endif ( )
if ( "compiler-rt" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "compiler-rt" )
endif ( )
2020-12-01 01:56:22 +08:00
if ( "flang" IN_LIST FEATURES )
2021-12-21 00:21:15 +08:00
if ( VCPKG_TARGET_IS_WINDOWS AND VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" )
message ( FATAL_ERROR "Building Flang with MSVC is not supported on x86. Disable it until issues are fixed." )
2020-12-01 01:56:22 +08:00
endif ( )
list ( APPEND LLVM_ENABLE_PROJECTS "flang" )
list ( APPEND FEATURE_OPTIONS
# Flang requires C++17
- D C M A K E _ C X X _ S T A N D A R D = 1 7
)
endif ( )
2021-04-14 06:17:17 +08:00
if ( "libclc" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "libclc" )
endif ( )
if ( "libcxx" IN_LIST FEATURES )
if ( VCPKG_TARGET_IS_WINDOWS )
message ( FATAL_ERROR "Building libcxx with MSVC is not supported. Disable it until issues are fixed." )
endif ( )
list ( APPEND LLVM_ENABLE_PROJECTS "libcxx" )
endif ( )
if ( "libcxxabi" IN_LIST FEATURES )
if ( VCPKG_TARGET_IS_WINDOWS )
message ( FATAL_ERROR "Building libcxxabi with MSVC is not supported. Disable it until issues are fixed." )
endif ( )
list ( APPEND LLVM_ENABLE_PROJECTS "libcxxabi" )
endif ( )
if ( "libunwind" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "libunwind" )
endif ( )
2020-05-04 11:30:17 +08:00
if ( "lld" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "lld" )
endif ( )
2020-12-01 01:56:22 +08:00
if ( "lldb" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "lldb" )
endif ( )
if ( "mlir" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "mlir" )
endif ( )
2020-05-04 11:30:17 +08:00
if ( "openmp" IN_LIST FEATURES )
2020-12-01 01:56:22 +08:00
# Disable OpenMP on Windows (see https://bugs.llvm.org/show_bug.cgi?id=45074).
if ( VCPKG_TARGET_IS_WINDOWS )
2021-04-14 06:17:17 +08:00
message ( FATAL_ERROR "Building OpenMP with MSVC is not supported. Disable it until issues are fixed." )
2020-12-01 01:56:22 +08:00
endif ( )
2020-05-04 11:30:17 +08:00
list ( APPEND LLVM_ENABLE_PROJECTS "openmp" )
# Perl is required for the OpenMP run-time
vcpkg_find_acquire_program ( PERL )
2021-12-21 00:21:15 +08:00
get_filename_component ( PERL_PATH ${ PERL } DIRECTORY )
vcpkg_add_to_path ( ${ PERL_PATH } )
2020-12-01 01:56:22 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
list ( APPEND FEATURE_OPTIONS
- D L I B O M P _ D E F A U L T _ L I B _ N A M E = l i b o m p d
)
endif ( )
2020-05-04 11:30:17 +08:00
endif ( )
2021-04-14 06:17:17 +08:00
if ( "parallel-libs" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "parallel-libs" )
endif ( )
2020-05-04 11:30:17 +08:00
if ( "polly" IN_LIST FEATURES )
list ( APPEND LLVM_ENABLE_PROJECTS "polly" )
endif ( )
2021-04-14 06:17:17 +08:00
if ( "pstl" IN_LIST FEATURES )
if ( VCPKG_TARGET_IS_WINDOWS )
message ( FATAL_ERROR "Building pstl with MSVC is not supported. Disable it until issues are fixed." )
endif ( )
list ( APPEND LLVM_ENABLE_PROJECTS "pstl" )
2021-02-23 02:49:55 +08:00
endif ( )
2020-10-14 08:54:46 +08:00
set ( known_llvm_targets
2020-12-01 01:56:22 +08:00
A A r c h 6 4
A M D G P U
A R M
A V R
B P F
H e x a g o n
L a n a i
2021-07-23 06:50:52 +08:00
M i p s
2020-12-01 01:56:22 +08:00
M S P 4 3 0
N V P T X
P o w e r P C
R I S C V
S p a r c
2021-07-23 06:50:52 +08:00
S y s t e m Z
2020-12-01 01:56:22 +08:00
W e b A s s e m b l y
X 8 6
X C o r e
)
2020-03-26 11:43:02 +08:00
2020-10-14 08:54:46 +08:00
set ( LLVM_TARGETS_TO_BUILD "" )
foreach ( llvm_target IN LISTS known_llvm_targets )
string ( TOLOWER "target-${llvm_target}" feature_name )
if ( feature_name IN_LIST FEATURES )
list ( APPEND LLVM_TARGETS_TO_BUILD "${llvm_target}" )
2020-05-04 11:30:17 +08:00
endif ( )
2020-10-14 08:54:46 +08:00
endforeach ( )
2019-10-08 01:35:13 +08:00
2020-05-04 11:30:17 +08:00
vcpkg_find_acquire_program ( PYTHON3 )
2020-12-01 01:56:22 +08:00
get_filename_component ( PYTHON3_DIR ${ PYTHON3 } DIRECTORY )
vcpkg_add_to_path ( ${ PYTHON3_DIR } )
2019-10-08 01:35:13 +08:00
2021-07-23 06:50:52 +08:00
if ( NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "${VCPKG_DETECTED_CMAKE_SYSTEM_PROCESSOR}" )
# TODO: support more targets and OS
if ( VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64" )
if ( VCPKG_TARGET_IS_OSX )
list ( APPEND CROSS_OPTIONS -DLLVM_HOST_TRIPLE=arm64-apple-darwin20.3.0 )
list ( APPEND CROSS_OPTIONS -DLLVM_DEFAULT_TARGET_TRIPLE=arm64-apple-darwin20.3.0 )
elseif ( VCPKG_TARGET_IS_WINDOWS )
list ( APPEND CROSS_OPTIONS -DLLVM_HOST_TRIPLE=arm64-pc-win32 )
list ( APPEND CROSS_OPTIONS -DLLVM_DEFAULT_TARGET_TRIPLE=arm64-pc-win32 )
# Remove if PR #16111 is merged
list ( APPEND CROSS_OPTIONS -DCMAKE_CROSSCOMPILING=ON )
list ( APPEND CROSS_OPTIONS -DCMAKE_SYSTEM_PROCESSOR:STRING=ARM64 )
list ( APPEND CROSS_OPTIONS -DCMAKE_SYSTEM_NAME:STRING=Windows )
endif ( )
list ( APPEND CROSS_OPTIONS -DLLVM_TARGET_ARCH=AArch64 )
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" )
if ( VCPKG_TARGET_IS_OSX )
list ( APPEND CROSS_OPTIONS -DLLVM_HOST_TRIPLE=x86_64-apple-darwin20.3.0 )
list ( APPEND CROSS_OPTIONS -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-apple-darwin20.3.0 )
endif ( )
list ( APPEND CROSS_OPTIONS -DLLVM_TARGET_ARCH=X86 )
endif ( )
endif ( )
2021-12-21 00:21:15 +08:00
vcpkg_cmake_configure (
2020-05-04 11:30:17 +08:00
S O U R C E _ P A T H $ { S O U R C E _ P A T H } / l l v m
O P T I O N S
$ { F E A T U R E _ O P T I O N S }
2021-07-23 06:50:52 +08:00
$ { C R O S S _ O P T I O N S }
2020-05-04 11:30:17 +08:00
- D L L V M _ I N C L U D E _ E X A M P L E S = O F F
- D L L V M _ B U I L D _ E X A M P L E S = O F F
- D L L V M _ I N C L U D E _ T E S T S = O F F
- D L L V M _ B U I L D _ T E S T S = O F F
# Force TableGen to be built with optimization. This will significantly improve build time.
- D L L V M _ O P T I M I Z E D _ T A B L E G E N = O N
2020-12-01 01:56:22 +08:00
" - D L L V M _ E N A B L E _ P R O J E C T S = $ { L L V M _ E N A B L E _ P R O J E C T S } "
" - D L L V M _ T A R G E T S _ T O _ B U I L D = $ { L L V M _ T A R G E T S _ T O _ B U I L D } "
- D P A C K A G E _ V E R S I O N = $ { L L V M _ V E R S I O N }
2020-05-04 11:30:17 +08:00
# Limit the maximum number of concurrent link jobs to 1. This should fix low amount of memory issue for link.
- D L L V M _ P A R A L L E L _ L I N K _ J O B S = 1
# Disable build LLVM-C.dll (Windows only) due to doesn't compile with CMAKE_DEBUG_POSTFIX
- D L L V M _ B U I L D _ L L V M _ C _ D Y L I B = O F F
2020-12-01 01:56:22 +08:00
# Path for binary subdirectory (defaults to 'bin')
- D L L V M _ T O O L S _ I N S T A L L _ D I R = t o o l s / l l v m
O P T I O N S _ D E B U G
2020-05-04 11:30:17 +08:00
- D C M A K E _ D E B U G _ P O S T F I X = d
2019-10-08 01:35:13 +08:00
)
2021-12-21 00:21:15 +08:00
vcpkg_cmake_install ( ADD_BIN_TO_PATH )
2020-05-04 11:30:17 +08:00
2021-12-21 00:21:15 +08:00
function ( llvm_cmake_package_config_fixup package_name )
cmake_parse_arguments ( "arg" "DO_NOT_DELETE_PARENT_CONFIG_PATH" "FEATURE_NAME" "" ${ ARGN } )
if ( NOT DEFINED arg_FEATURE_NAME )
set ( arg_FEATURE_NAME ${ package_name } )
2020-05-16 04:28:48 +08:00
endif ( )
2021-12-21 00:21:15 +08:00
if ( "${arg_FEATURE_NAME}" STREQUAL "${PORT}" OR "${arg_FEATURE_NAME}" IN_LIST FEATURES )
set ( args )
list ( APPEND args PACKAGE_NAME "${package_name}" )
if ( arg_DO_NOT_DELETE_PARENT_CONFIG_PATH )
list ( APPEND args "DO_NOT_DELETE_PARENT_CONFIG_PATH" )
endif ( )
vcpkg_cmake_config_fixup ( ${ args } )
file ( INSTALL "${SOURCE_PATH}/${package_name}/LICENSE.TXT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${package_name}" RENAME copyright )
if ( EXISTS "${CMAKE_CURRENT_LIST_DIR}/${package_name}_usage" )
file ( INSTALL "${CMAKE_CURRENT_LIST_DIR}/${package_name}_usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${package_name}" RENAME usage )
endif ( )
2020-12-01 01:56:22 +08:00
endif ( )
2021-12-21 00:21:15 +08:00
endfunction ( )
2020-12-01 01:56:22 +08:00
2021-12-21 00:21:15 +08:00
llvm_cmake_package_config_fixup ( "clang" DO_NOT_DELETE_PARENT_CONFIG_PATH )
llvm_cmake_package_config_fixup ( "flang" DO_NOT_DELETE_PARENT_CONFIG_PATH )
llvm_cmake_package_config_fixup ( "lld" DO_NOT_DELETE_PARENT_CONFIG_PATH )
llvm_cmake_package_config_fixup ( "mlir" DO_NOT_DELETE_PARENT_CONFIG_PATH )
llvm_cmake_package_config_fixup ( "polly" DO_NOT_DELETE_PARENT_CONFIG_PATH )
llvm_cmake_package_config_fixup ( "ParallelSTL" FEATURE_NAME "pstl" DO_NOT_DELETE_PARENT_CONFIG_PATH )
llvm_cmake_package_config_fixup ( "llvm" )
2020-05-04 11:30:17 +08:00
2021-12-21 00:21:15 +08:00
set ( empty_dirs )
if ( "clang-tools-extra" IN_LIST FEATURES )
list ( APPEND empty_dirs "${CURRENT_PACKAGES_DIR}/include/clang-tidy/plugin" )
2020-11-13 09:31:34 +08:00
endif ( )
2020-05-04 11:30:17 +08:00
2021-12-21 00:21:15 +08:00
if ( "flang" IN_LIST FEATURES )
list ( APPEND empty_dirs "${CURRENT_PACKAGES_DIR}/include/flang/Config" )
list ( APPEND empty_dirs "${CURRENT_PACKAGES_DIR}/include/flang/CMakeFiles" )
list ( APPEND empty_dirs "${CURRENT_PACKAGES_DIR}/include/flang/Optimizer/CMakeFiles" )
list ( APPEND empty_dirs "${CURRENT_PACKAGES_DIR}/include/flang/Optimizer/CodeGen/CMakeFiles" )
list ( APPEND empty_dirs "${CURRENT_PACKAGES_DIR}/include/flang/Optimizer/Dialect/CMakeFiles" )
list ( APPEND empty_dirs "${CURRENT_PACKAGES_DIR}/include/flang/Optimizer/Transforms/CMakeFiles" )
2020-12-01 01:56:22 +08:00
endif ( )
2021-12-21 00:21:15 +08:00
if ( empty_dirs )
foreach ( empty_dir IN LISTS empty_dirs )
if ( NOT EXISTS "${empty_dir}" )
message ( SEND_ERROR "Directory '${empty_dir}' is not exist. Please remove it from the checking." )
else ( )
file ( GLOB_RECURSE files_in_dir "${empty_dir}/*" )
if ( files_in_dir )
message ( SEND_ERROR "Directory '${empty_dir}' is not empty. Please remove it from the checking." )
else ( )
file ( REMOVE_RECURSE "${empty_dir}" )
endif ( )
endif ( )
endforeach ( )
2020-12-01 01:56:22 +08:00
endif ( )
2021-04-14 06:17:17 +08:00
vcpkg_copy_tool_dependencies ( ${ CURRENT_PACKAGES_DIR } /tools/ ${ PORT } )
2020-12-01 01:56:22 +08:00
2020-11-13 09:31:34 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
file ( REMOVE_RECURSE ${ CURRENT_PACKAGES_DIR } /debug/include )
file ( REMOVE_RECURSE ${ CURRENT_PACKAGES_DIR } /debug/share )
2020-12-01 01:56:22 +08:00
file ( REMOVE_RECURSE ${ CURRENT_PACKAGES_DIR } /debug/tools )
2020-05-04 11:30:17 +08:00
endif ( )
2020-11-13 09:31:34 +08:00
# LLVM still generates a few DLLs in the static build:
# * libclang.dll
# * LTO.dll
# * Remarks.dll
set ( VCPKG_POLICY_DLLS_IN_STATIC_LIBRARY enabled )