1function(add_lldb_library name) 2 # only supported parameters to this macro are the optional 3 # MODULE;SHARED;STATIC library type and source files 4 cmake_parse_arguments(PARAM 5 "MODULE;SHARED;STATIC;OBJECT;PLUGIN" 6 "ENTITLEMENTS" 7 "EXTRA_CXXFLAGS;DEPENDS;LINK_LIBS;LINK_COMPONENTS" 8 ${ARGN}) 9 llvm_process_sources(srcs ${PARAM_UNPARSED_ARGUMENTS}) 10 list(APPEND LLVM_LINK_COMPONENTS ${PARAM_LINK_COMPONENTS}) 11 12 if(PARAM_PLUGIN) 13 set_property(GLOBAL APPEND PROPERTY LLDB_PLUGINS ${name}) 14 endif() 15 16 if (MSVC_IDE OR XCODE) 17 string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR}) 18 list(GET split_path -1 dir) 19 file(GLOB_RECURSE headers 20 ../../include/lldb${dir}/*.h) 21 set(srcs ${srcs} ${headers}) 22 endif() 23 if (PARAM_MODULE) 24 set(libkind MODULE) 25 elseif (PARAM_SHARED) 26 set(libkind SHARED) 27 elseif (PARAM_OBJECT) 28 set(libkind OBJECT) 29 else () 30 # PARAM_STATIC or library type unspecified. BUILD_SHARED_LIBS 31 # does not control the kind of libraries created for LLDB, 32 # only whether or not they link to shared/static LLVM/Clang 33 # libraries. 34 set(libkind STATIC) 35 endif() 36 37 #PIC not needed on Win 38 # FIXME: Setting CMAKE_CXX_FLAGS here is a no-op, use target_compile_options 39 # or omit this logic instead. 40 if (NOT WIN32) 41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") 42 endif() 43 44 if (PARAM_OBJECT) 45 add_library(${name} ${libkind} ${srcs}) 46 else() 47 if(PARAM_ENTITLEMENTS) 48 set(pass_ENTITLEMENTS ENTITLEMENTS ${PARAM_ENTITLEMENTS}) 49 endif() 50 51 if(LLDB_NO_INSTALL_DEFAULT_RPATH) 52 set(pass_NO_INSTALL_RPATH NO_INSTALL_RPATH) 53 endif() 54 55 llvm_add_library(${name} ${libkind} ${srcs} 56 LINK_LIBS ${PARAM_LINK_LIBS} 57 DEPENDS ${PARAM_DEPENDS} 58 ${pass_ENTITLEMENTS} 59 ${pass_NO_INSTALL_RPATH} 60 ) 61 62 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb") 63 if (PARAM_SHARED) 64 if(${name} STREQUAL "liblldb" AND LLDB_BUILD_FRAMEWORK) 65 if(LLDB_FRAMEWORK_INSTALL_DIR) 66 set(install_dir ${LLDB_FRAMEWORK_INSTALL_DIR}) 67 else() 68 set(install_dir ".") 69 endif() 70 else() 71 set(install_dir lib${LLVM_LIBDIR_SUFFIX}) 72 endif() 73 install(TARGETS ${name} 74 COMPONENT ${name} 75 RUNTIME DESTINATION bin 76 LIBRARY DESTINATION ${install_dir} 77 ARCHIVE DESTINATION ${install_dir}) 78 else() 79 install(TARGETS ${name} 80 COMPONENT ${name} 81 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 82 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 83 endif() 84 if (NOT CMAKE_CONFIGURATION_TYPES) 85 add_llvm_install_targets(install-${name} 86 DEPENDS ${name} 87 COMPONENT ${name}) 88 endif() 89 endif() 90 endif() 91 92 93 # Hack: only some LLDB libraries depend on the clang autogenerated headers, 94 # but it is simple enough to make all of LLDB depend on some of those 95 # headers without negatively impacting much of anything. 96 if(NOT LLDB_BUILT_STANDALONE) 97 add_dependencies(${name} clang-tablegen-targets) 98 endif() 99 100 # Add in any extra C++ compilation flags for this library. 101 target_compile_options(${name} PRIVATE ${PARAM_EXTRA_CXXFLAGS}) 102 103 if(PARAM_PLUGIN) 104 set_target_properties(${name} PROPERTIES FOLDER "lldb plugins") 105 else() 106 set_target_properties(${name} PROPERTIES FOLDER "lldb libraries") 107 endif() 108endfunction(add_lldb_library) 109 110function(add_lldb_executable name) 111 cmake_parse_arguments(ARG 112 "GENERATE_INSTALL" 113 "ENTITLEMENTS" 114 "LINK_LIBS;LINK_COMPONENTS" 115 ${ARGN} 116 ) 117 118 if(ARG_ENTITLEMENTS) 119 set(pass_ENTITLEMENTS ENTITLEMENTS ${ARG_ENTITLEMENTS}) 120 endif() 121 122 if(LLDB_NO_INSTALL_DEFAULT_RPATH) 123 set(pass_NO_INSTALL_RPATH NO_INSTALL_RPATH) 124 endif() 125 126 list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS}) 127 add_llvm_executable(${name} 128 ${pass_ENTITLEMENTS} 129 ${pass_NO_INSTALL_RPATH} 130 ${ARG_UNPARSED_ARGUMENTS} 131 ) 132 133 target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS}) 134 set_target_properties(${name} PROPERTIES FOLDER "lldb executables") 135 136 if(ARG_GENERATE_INSTALL) 137 install(TARGETS ${name} 138 COMPONENT ${name} 139 RUNTIME DESTINATION bin) 140 if (NOT CMAKE_CONFIGURATION_TYPES) 141 add_llvm_install_targets(install-${name} 142 DEPENDS ${name} 143 COMPONENT ${name}) 144 endif() 145 endif() 146endfunction(add_lldb_executable) 147 148 149macro(add_lldb_tool_subdirectory name) 150 add_llvm_subdirectory(LLDB TOOL ${name}) 151endmacro() 152 153function(add_lldb_tool name) 154 add_lldb_executable(${name} GENERATE_INSTALL ${ARGN}) 155endfunction() 156 157# Support appending linker flags to an existing target. 158# This will preserve the existing linker flags on the 159# target, if there are any. 160function(lldb_append_link_flags target_name new_link_flags) 161 # Retrieve existing linker flags. 162 get_target_property(current_link_flags ${target_name} LINK_FLAGS) 163 164 # If we had any linker flags, include them first in the new linker flags. 165 if(current_link_flags) 166 set(new_link_flags "${current_link_flags} ${new_link_flags}") 167 endif() 168 169 # Now set them onto the target. 170 set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags}) 171endfunction() 172 173# For tools that depend on liblldb, account for varying directory structures in 174# which LLDB.framework can be used and distributed: In the build-tree we find it 175# by its absolute target path. This is only relevant for running the test suite. 176# In the install step CMake will remove this entry and insert the final RPATHs. 177# These are relative to the file path from where the tool will be loaded on the 178# enduser system. 179# 180# Note that the LLVM install-tree doesn't match the enduser system structure 181# for LLDB.framework, so by default dependent tools will not be functional in 182# their install location. The LLDB_FRAMEWORK_INSTALL_DIR variable allows to fix 183# this. If specified, it causes the install-tree location of the framework to be 184# added as an extra RPATH below. 185# 186function(lldb_setup_framework_rpaths_in_tool name) 187 # The installed framework is relocatable and can be in different locations. 188 set(rpaths_install_tree) 189 190 if(LLDB_FRAMEWORK_INSTALL_DIR) 191 list(APPEND rpaths_install_tree "@loader_path/../${LLDB_FRAMEWORK_INSTALL_DIR}") 192 endif() 193 194 list(APPEND rpaths_install_tree "@loader_path/../../../SharedFrameworks") 195 list(APPEND rpaths_install_tree "@loader_path/../../System/Library/PrivateFrameworks") 196 list(APPEND rpaths_install_tree "@loader_path/../../Library/PrivateFrameworks") 197 198 # In the build-tree, we know the exact path to the framework directory. 199 get_target_property(framework_target_dir liblldb LIBRARY_OUTPUT_DIRECTORY) 200 201 # If LLDB_NO_INSTALL_DEFAULT_RPATH was NOT enabled (default), this overwrites 202 # the default settings from llvm_setup_rpath(). 203 set_target_properties(${name} PROPERTIES 204 BUILD_WITH_INSTALL_RPATH OFF 205 BUILD_RPATH "${framework_target_dir}" 206 INSTALL_RPATH "${rpaths_install_tree}" 207 ) 208 209 add_dependencies(${name} lldb-framework) 210endfunction() 211 212# Unified handling for executable LLDB.framework resources. Given the name of an 213# executable target, this function adds a post-build step to copy it to the 214# framework bundle in the build-tree. 215function(lldb_add_to_framework name) 216 set(subdir "LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources") 217 218 # Destination for the copy in the build-tree. While the framework target may 219 # not exist yet, it will exist when the generator expression gets expanded. 220 set(copy_dest "$<TARGET_FILE_DIR:liblldb>/../../../${subdir}") 221 222 # Copy into the framework's Resources directory for testing. 223 add_custom_command(TARGET ${name} POST_BUILD 224 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${name}> ${copy_dest} 225 COMMENT "Copy ${name} to ${copy_dest}" 226 ) 227endfunction() 228 229# CMake's set_target_properties() doesn't allow to pass lists for RPATH 230# properties directly (error: "called with incorrect number of arguments"). 231# Instead of defining two list variables each time, use this helper function. 232function(lldb_setup_rpaths name) 233 cmake_parse_arguments(LIST "" "" "BUILD_RPATH;INSTALL_RPATH" ${ARGN}) 234 set_target_properties(${name} PROPERTIES 235 BUILD_WITH_INSTALL_RPATH OFF 236 BUILD_RPATH "${LIST_BUILD_RPATH}" 237 INSTALL_RPATH "${LIST_INSTALL_RPATH}" 238 ) 239endfunction()