# Syntax:
# clang_tablegen output-file [tablegen-arg ...] SOURCE source-file
# [[TARGET cmake-target-name] [DEPENDS extra-dependency ...]]
#
# Generates a custom command for invoking tblgen as
#
# tblgen source-file -o=output-file tablegen-arg ...
#
# and, if cmake-target-name is provided, creates a custom target for
# executing the custom command depending on output-file. It is
# possible to list more files to depend after DEPENDS.
cmake_parse_arguments(CTG "" "SOURCE;TARGET" "" ${ARGN})
message(FATAL_ERROR "SOURCE source-file required by clang_tablegen")
set( CLANG_TABLEGEN_ARGUMENTS
"" )
set( LLVM_TARGET_DEFINITIONS
${CTG_SOURCE} )
tablegen(CLANG ${CTG_UNPARSED_ARGUMENTS} ${CLANG_TABLEGEN_ARGUMENTS})
add_public_tablegen_target(${CTG_TARGET})
set_property(GLOBAL APPEND PROPERTY CLANG_TABLEGEN_TARGETS
${CTG_TARGET})
macro(set_clang_windows_version_resource_properties name
)
if(DEFINED windows_resource_file
)
set_windows_version_resource_properties(${name} ${windows_resource_file}
VERSION_MAJOR ${CLANG_VERSION_MAJOR}
VERSION_MINOR ${CLANG_VERSION_MINOR}
VERSION_PATCHLEVEL ${CLANG_VERSION_PATCHLEVEL}
VERSION_STRING "${CLANG_VERSION}"
PRODUCT_NAME "clang")
macro(add_clang_subdirectory name
)
add_llvm_subdirectory(CLANG TOOL ${name})
macro(add_clang_library name
)
cmake_parse_arguments(ARG
"SHARED;STATIC;INSTALL_WITH_TOOLCHAIN"
""
"ADDITIONAL_HEADERS"
${ARGN})
# Add public headers
file(RELATIVE_PATH lib_path
${CLANG_SOURCE_DIR}/lib/
${CMAKE_CURRENT_SOURCE_DIR}
)
if(NOT lib_path
MATCHES "^[.][.]")
file( GLOB_RECURSE headers
${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.h
${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.def
)
${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.td
)
set(srcs
${headers} ${tds})
if(srcs
OR ARG_ADDITIONAL_HEADERS
)
ADDITIONAL_HEADERS
${srcs}
${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
)
if(ARG_SHARED
AND ARG_STATIC
)
set(LIBTYPE
SHARED STATIC)
# llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
# so we need to handle it here.
# The Xcode generator doesn't handle object libraries correctly.
list(APPEND LIBTYPE OBJECT
)
set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS
${name})
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
if(ARG_SHARED
AND ARG_STATIC
)
list(APPEND libs
${name}_static
)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY
OR ARG_INSTALL_WITH_TOOLCHAIN
)
get_target_export_arg(${name} Clang export_to_clangtargets UMBRELLA clang-libraries)
COMPONENT ${lib}
${export_to_clangtargets}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
add_llvm_install_targets(install-${lib}
DEPENDS ${lib}
COMPONENT ${lib})
# Add empty "phony" target
set_clang_windows_version_resource_properties(${name})
macro(add_clang_executable name
)
add_llvm_executable( ${name} ${ARGN} )
set_clang_windows_version_resource_properties(${name})
macro(add_clang_tool name
)
cmake_parse_arguments(ARG "DEPENDS;GENERATE_DRIVER" "" "" ${ARGN})
if (NOT CLANG_BUILD_TOOLS
)
AND LLVM_TOOL_LLVM_DRIVER_BUILD
AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS)
)
set(get_obj_args
${ARGN})
list(FILTER get_obj_args EXCLUDE
REGEX "^SUPPORT_PLUGINS$")
generate_llvm_objects(${name} ${get_obj_args})
add_clang_executable(${name} ${ARGN})
get_target_export_arg(${name} Clang export_to_clangtargets)
${export_to_clangtargets}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT ${name})
add_llvm_install_targets(install-${name}
DEPENDS ${name}
COMPONENT ${name})
macro(add_clang_symlink 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)
)
set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_
${dest} ${name})
llvm_add_tool_symlink(CLANG ${name} ${dest} ALWAYS_GENERATE)
# Always generate install targets
llvm_install_symlink(CLANG ${name} ${dest} ALWAYS_GENERATE)
function(clang_target_link_libraries target type
)
if (TARGET obj.
${target})
get_property(LLVM_DRIVER_TOOLS
GLOBAL PROPERTY LLVM_DRIVER_TOOLS
)
if(LLVM_TOOL_LLVM_DRIVER_BUILD
AND ${target} IN_LIST LLVM_DRIVER_TOOLS
)
if (CLANG_LINK_CLANG_DYLIB
)