2017-09-12 21:17:19 -07:00
|
|
|
# Copyright (c) 2014 Andrew Kelley
|
|
|
|
# This file is MIT licensed.
|
|
|
|
# See http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
# LLVM_FOUND
|
|
|
|
# LLVM_INCLUDE_DIRS
|
|
|
|
# LLVM_LIBRARIES
|
2019-07-09 10:31:13 -07:00
|
|
|
# LLVM_LIBDIRS
|
2017-09-12 21:17:19 -07:00
|
|
|
|
2017-09-28 07:48:13 -07:00
|
|
|
find_program(LLVM_CONFIG_EXE
|
2019-07-09 10:31:13 -07:00
|
|
|
NAMES llvm-config-8 llvm-config-8.0 llvm-config80 llvm-config
|
|
|
|
PATHS
|
|
|
|
"/mingw64/bin"
|
|
|
|
"/c/msys64/mingw64/bin"
|
|
|
|
"c:/msys64/mingw64/bin"
|
|
|
|
"C:/Libraries/llvm-8.0.0/bin")
|
2017-09-28 07:48:13 -07:00
|
|
|
|
2019-02-07 09:18:01 -08:00
|
|
|
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
|
|
|
message(FATAL_ERROR "unable to find llvm-config")
|
|
|
|
endif()
|
|
|
|
|
2019-02-07 09:18:01 -08:00
|
|
|
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
|
|
|
message(FATAL_ERROR "unable to find llvm-config")
|
|
|
|
endif()
|
|
|
|
|
2019-01-19 07:47:33 -08:00
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --version
|
|
|
|
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2019-01-19 07:47:33 -08:00
|
|
|
|
2019-02-07 09:24:55 -08:00
|
|
|
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 8)
|
|
|
|
message(FATAL_ERROR "expected LLVM 8.x but found ${LLVM_CONFIG_VERSION}")
|
2019-02-07 09:18:01 -08:00
|
|
|
endif()
|
2019-02-07 09:24:55 -08:00
|
|
|
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 9)
|
|
|
|
message(FATAL_ERROR "expected LLVM 8.x but found ${LLVM_CONFIG_VERSION}")
|
2019-02-07 09:18:01 -08:00
|
|
|
endif()
|
2019-02-07 09:24:55 -08:00
|
|
|
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 9)
|
|
|
|
message(FATAL_ERROR "expected LLVM 8.x but found ${LLVM_CONFIG_VERSION}")
|
2019-01-19 07:47:33 -08:00
|
|
|
endif()
|
|
|
|
|
2019-02-07 09:18:01 -08:00
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --targets-built
|
|
|
|
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
|
2019-02-07 09:18:01 -08:00
|
|
|
function(NEED_TARGET TARGET_NAME)
|
2019-07-09 10:31:13 -07:00
|
|
|
list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index)
|
|
|
|
if (${_index} EQUAL -1)
|
|
|
|
message(FATAL_ERROR "LLVM is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
|
|
|
|
endif()
|
2019-02-07 09:18:01 -08:00
|
|
|
endfunction(NEED_TARGET)
|
|
|
|
NEED_TARGET("AArch64")
|
|
|
|
NEED_TARGET("AMDGPU")
|
|
|
|
NEED_TARGET("ARM")
|
|
|
|
NEED_TARGET("BPF")
|
|
|
|
NEED_TARGET("Hexagon")
|
|
|
|
NEED_TARGET("Lanai")
|
|
|
|
NEED_TARGET("Mips")
|
|
|
|
NEED_TARGET("MSP430")
|
|
|
|
NEED_TARGET("NVPTX")
|
|
|
|
NEED_TARGET("PowerPC")
|
|
|
|
NEED_TARGET("Sparc")
|
|
|
|
NEED_TARGET("SystemZ")
|
2019-02-07 09:24:55 -08:00
|
|
|
NEED_TARGET("WebAssembly")
|
2019-02-07 09:18:01 -08:00
|
|
|
NEED_TARGET("X86")
|
|
|
|
NEED_TARGET("XCore")
|
|
|
|
|
2019-07-09 02:03:57 -07:00
|
|
|
if(ZIG_STATIC_LLVM)
|
2017-09-28 07:48:13 -07:00
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static
|
|
|
|
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
|
2017-09-23 15:46:03 -07:00
|
|
|
|
2017-09-28 07:48:13 -07:00
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
|
|
|
|
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
|
2017-09-23 15:46:03 -07:00
|
|
|
|
2017-09-28 07:48:13 -07:00
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --libdir --link-static
|
|
|
|
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
|
2017-09-28 07:48:13 -07:00
|
|
|
endif()
|
|
|
|
if(NOT LLVM_LIBRARIES)
|
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --libs
|
|
|
|
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
|
2017-09-23 15:46:03 -07:00
|
|
|
|
2017-09-28 07:48:13 -07:00
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --system-libs
|
|
|
|
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
|
2017-09-12 21:17:19 -07:00
|
|
|
|
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --libdir
|
|
|
|
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
|
2017-09-28 07:48:13 -07:00
|
|
|
endif()
|
2017-09-12 21:17:19 -07:00
|
|
|
|
2017-09-28 07:48:13 -07:00
|
|
|
execute_process(
|
2019-07-09 10:31:13 -07:00
|
|
|
COMMAND ${LLVM_CONFIG_EXE} --includedir
|
|
|
|
OUTPUT_VARIABLE LLVM_INCLUDE_DIRS
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2017-09-12 21:17:19 -07:00
|
|
|
|
2017-09-28 07:48:13 -07:00
|
|
|
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
|
2017-09-13 11:30:57 -07:00
|
|
|
|
2017-09-28 07:48:13 -07:00
|
|
|
if(NOT LLVM_LIBRARIES)
|
2018-09-19 14:34:52 -07:00
|
|
|
find_library(LLVM_LIBRARIES NAMES LLVM LLVM-8 LLVM-8.0)
|
2017-09-12 21:17:19 -07:00
|
|
|
endif()
|
|
|
|
|
2017-09-28 07:48:13 -07:00
|
|
|
link_directories("${CMAKE_PREFIX_PATH}/lib")
|
2019-07-09 10:31:13 -07:00
|
|
|
link_directories("${LLVM_LIBDIRS}")
|
2017-09-12 21:17:19 -07:00
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package_handle_standard_args(LLVM DEFAULT_MSG LLVM_LIBRARIES LLVM_INCLUDE_DIRS)
|
|
|
|
|
2019-07-09 10:31:13 -07:00
|
|
|
mark_as_advanced(LLVM_INCLUDE_DIRS LLVM_LIBRARIES LLVM_LIBDIRS)
|