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 "" ) 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;STATIC;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 85 if(ARG_SHARED AND ARG_STATIC) 86 set(LIBTYPE SHARED STATIC) 87 elseif(ARG_SHARED) 88 set(LIBTYPE SHARED) 89 else() 90 # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set, 91 # so we need to handle it here. 92 if(BUILD_SHARED_LIBS) 93 set(LIBTYPE SHARED) 94 else() 95 set(LIBTYPE STATIC) 96 endif() 97 if(NOT XCODE) 98 # The Xcode generator doesn't handle object libraries correctly. 99 list(APPEND LIBTYPE OBJECT) 100 endif() 101 set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name}) 102 endif() 103 llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs}) 104 105 set(libs ${name}) 106 if(ARG_SHARED AND ARG_STATIC) 107 list(APPEND libs ${name}_static) 108 endif() 109 110 foreach(lib ${libs}) 111 if(TARGET ${lib}) 112 target_link_libraries(${lib} INTERFACE ${LLVM_COMMON_LIBS}) 113 114 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN) 115 set(export_to_clangtargets) 116 if(${lib} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR 117 "clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR 118 NOT LLVM_DISTRIBUTION_COMPONENTS) 119 set(export_to_clangtargets EXPORT ClangTargets) 120 set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True) 121 endif() 122 123 install(TARGETS ${lib} 124 COMPONENT ${lib} 125 ${export_to_clangtargets} 126 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 127 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} 128 RUNTIME DESTINATION bin) 129 130 if (NOT LLVM_ENABLE_IDE) 131 add_llvm_install_targets(install-${lib} 132 DEPENDS ${lib} 133 COMPONENT ${lib}) 134 endif() 135 136 set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${lib}) 137 endif() 138 set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${lib}) 139 else() 140 # Add empty "phony" target 141 add_custom_target(${lib}) 142 endif() 143 endforeach() 144 145 set_target_properties(${name} PROPERTIES FOLDER "Clang libraries") 146 set_clang_windows_version_resource_properties(${name}) 147endmacro(add_clang_library) 148 149macro(add_clang_executable name) 150 add_llvm_executable( ${name} ${ARGN} ) 151 set_target_properties(${name} PROPERTIES FOLDER "Clang executables") 152 set_clang_windows_version_resource_properties(${name}) 153endmacro(add_clang_executable) 154 155macro(add_clang_tool name) 156 if (NOT CLANG_BUILD_TOOLS) 157 set(EXCLUDE_FROM_ALL ON) 158 endif() 159 160 add_clang_executable(${name} ${ARGN}) 161 add_dependencies(${name} clang-resource-headers) 162 163 if (CLANG_BUILD_TOOLS) 164 set(export_to_clangtargets) 165 if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR 166 NOT LLVM_DISTRIBUTION_COMPONENTS) 167 set(export_to_clangtargets EXPORT ClangTargets) 168 set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True) 169 endif() 170 171 install(TARGETS ${name} 172 ${export_to_clangtargets} 173 RUNTIME DESTINATION bin 174 COMPONENT ${name}) 175 176 if(NOT LLVM_ENABLE_IDE) 177 add_llvm_install_targets(install-${name} 178 DEPENDS ${name} 179 COMPONENT ${name}) 180 endif() 181 set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name}) 182 endif() 183endmacro() 184 185macro(add_clang_symlink name dest) 186 add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) 187 # Always generate install targets 188 llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) 189endmacro() 190 191function(clang_target_link_libraries target type) 192 if (CLANG_LINK_CLANG_DYLIB) 193 target_link_libraries(${target} ${type} clang-cpp) 194 else() 195 target_link_libraries(${target} ${type} ${ARGN}) 196 endif() 197 198endfunction() 199