1function(clang_tablegen) 2 # Syntax: 3 # clang_tablegen output-file [tablegen-arg ...] SOURCE source-file 4 # [[TARGET cmake-target-name] [DEPENDS extra-dependency ...]] 5 # 6 # Generates a custom command for invoking tblgen as 7 # 8 # tblgen source-file -o=output-file tablegen-arg ... 9 # 10 # and, if cmake-target-name is provided, creates a custom target for 11 # executing the custom command depending on output-file. It is 12 # possible to list more files to depend after DEPENDS. 13 14 cmake_parse_arguments(CTG "" "SOURCE;TARGET" "" ${ARGN}) 15 16 if( NOT CTG_SOURCE ) 17 message(FATAL_ERROR "SOURCE source-file required by clang_tablegen") 18 endif() 19 20 set( CLANG_TABLEGEN_ARGUMENTS -I ${CLANG_SOURCE_DIR}/include ) 21 set( LLVM_TARGET_DEFINITIONS ${CTG_SOURCE} ) 22 tablegen(CLANG ${CTG_UNPARSED_ARGUMENTS} ${CLANG_TABLEGEN_ARGUMENTS}) 23 24 if(CTG_TARGET) 25 add_public_tablegen_target(${CTG_TARGET}) 26 set_target_properties( ${CTG_TARGET} PROPERTIES FOLDER "Clang tablegenning") 27 set_property(GLOBAL APPEND PROPERTY CLANG_TABLEGEN_TARGETS ${CTG_TARGET}) 28 endif() 29endfunction(clang_tablegen) 30 31macro(set_clang_windows_version_resource_properties name) 32 if(DEFINED windows_resource_file) 33 set_windows_version_resource_properties(${name} ${windows_resource_file} 34 VERSION_MAJOR ${CLANG_VERSION_MAJOR} 35 VERSION_MINOR ${CLANG_VERSION_MINOR} 36 VERSION_PATCHLEVEL ${CLANG_VERSION_PATCHLEVEL} 37 VERSION_STRING "${CLANG_VERSION} (${BACKEND_PACKAGE_STRING})" 38 PRODUCT_NAME "clang") 39 endif() 40endmacro() 41 42macro(add_clang_subdirectory name) 43 add_llvm_subdirectory(CLANG TOOL ${name}) 44endmacro() 45 46macro(add_clang_library name) 47 cmake_parse_arguments(ARG 48 "SHARED;INSTALL_WITH_TOOLCHAIN" 49 "" 50 "ADDITIONAL_HEADERS" 51 ${ARGN}) 52 set(srcs) 53 if(MSVC_IDE OR XCODE) 54 # Add public headers 55 file(RELATIVE_PATH lib_path 56 ${CLANG_SOURCE_DIR}/lib/ 57 ${CMAKE_CURRENT_SOURCE_DIR} 58 ) 59 if(NOT lib_path MATCHES "^[.][.]") 60 file( GLOB_RECURSE headers 61 ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.h 62 ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.def 63 ) 64 set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON) 65 66 file( GLOB_RECURSE tds 67 ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.td 68 ) 69 source_group("TableGen descriptions" FILES ${tds}) 70 set_source_files_properties(${tds}} PROPERTIES HEADER_FILE_ONLY ON) 71 72 if(headers OR tds) 73 set(srcs ${headers} ${tds}) 74 endif() 75 endif() 76 endif(MSVC_IDE OR XCODE) 77 if(srcs OR ARG_ADDITIONAL_HEADERS) 78 set(srcs 79 ADDITIONAL_HEADERS 80 ${srcs} 81 ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args. 82 ) 83 endif() 84 if(ARG_SHARED) 85 set(LIBTYPE SHARED) 86 else() 87 # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set, 88 # so we need to handle it here. 89 if(BUILD_SHARED_LIBS) 90 set(LIBTYPE SHARED) 91 else() 92 set(LIBTYPE STATIC) 93 endif() 94 if(NOT XCODE) 95 # The Xcode generator doesn't handle object libraries correctly. 96 list(APPEND LIBTYPE OBJECT) 97 endif() 98 set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name}) 99 endif() 100 llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs}) 101 102 if(TARGET ${name}) 103 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS}) 104 105 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN) 106 set(export_to_clangtargets) 107 if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR 108 "clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR 109 NOT LLVM_DISTRIBUTION_COMPONENTS) 110 set(export_to_clangtargets EXPORT ClangTargets) 111 set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True) 112 endif() 113 114 install(TARGETS ${name} 115 COMPONENT ${name} 116 ${export_to_clangtargets} 117 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 118 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} 119 RUNTIME DESTINATION bin) 120 121 if (NOT LLVM_ENABLE_IDE) 122 add_llvm_install_targets(install-${name} 123 DEPENDS ${name} 124 COMPONENT ${name}) 125 endif() 126 127 set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${name}) 128 endif() 129 set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name}) 130 else() 131 # Add empty "phony" target 132 add_custom_target(${name}) 133 endif() 134 135 set_target_properties(${name} PROPERTIES FOLDER "Clang libraries") 136 set_clang_windows_version_resource_properties(${name}) 137endmacro(add_clang_library) 138 139macro(add_clang_executable name) 140 add_llvm_executable( ${name} ${ARGN} ) 141 set_target_properties(${name} PROPERTIES FOLDER "Clang executables") 142 set_clang_windows_version_resource_properties(${name}) 143endmacro(add_clang_executable) 144 145macro(add_clang_tool name) 146 if (NOT CLANG_BUILD_TOOLS) 147 set(EXCLUDE_FROM_ALL ON) 148 endif() 149 150 add_clang_executable(${name} ${ARGN}) 151 add_dependencies(${name} clang-resource-headers) 152 153 if (CLANG_BUILD_TOOLS) 154 set(export_to_clangtargets) 155 if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR 156 NOT LLVM_DISTRIBUTION_COMPONENTS) 157 set(export_to_clangtargets EXPORT ClangTargets) 158 set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True) 159 endif() 160 161 install(TARGETS ${name} 162 ${export_to_clangtargets} 163 RUNTIME DESTINATION bin 164 COMPONENT ${name}) 165 166 if(NOT LLVM_ENABLE_IDE) 167 add_llvm_install_targets(install-${name} 168 DEPENDS ${name} 169 COMPONENT ${name}) 170 endif() 171 set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name}) 172 endif() 173endmacro() 174 175macro(add_clang_symlink name dest) 176 add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) 177 # Always generate install targets 178 llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) 179endmacro() 180 181function(clang_target_link_libraries target type) 182 if (CLANG_LINK_CLANG_DYLIB) 183 target_link_libraries(${target} ${type} clang-cpp) 184 else() 185 target_link_libraries(${target} ${type} ${ARGN}) 186 endif() 187 188endfunction() 189