1function(lldb_link_common_libs name targetkind) 2 if (NOT LLDB_USED_LIBS) 3 return() 4 endif() 5 6 if(${targetkind} MATCHES "SHARED") 7 set(LINK_KEYWORD PUBLIC) 8 endif() 9 10 if(${targetkind} MATCHES "SHARED" OR ${targetkind} MATCHES "EXE") 11 if (LLDB_LINKER_SUPPORTS_GROUPS) 12 target_link_libraries(${name} ${LINK_KEYWORD} 13 -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group) 14 else() 15 target_link_libraries(${name} ${LINK_KEYWORD} ${LLDB_USED_LIBS}) 16 endif() 17 endif() 18endfunction(lldb_link_common_libs) 19 20macro(add_lldb_library name) 21 # only supported parameters to this macro are the optional 22 # MODULE;SHARED;STATIC library type and source files 23 cmake_parse_arguments(PARAM 24 "MODULE;SHARED;STATIC;OBJECT" 25 "" 26 "" 27 ${ARGN}) 28 llvm_process_sources(srcs ${PARAM_UNPARSED_ARGUMENTS}) 29 30 if (MSVC_IDE OR XCODE) 31 string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR}) 32 list(GET split_path -1 dir) 33 file(GLOB_RECURSE headers 34 ../../include/lldb${dir}/*.h) 35 set(srcs ${srcs} ${headers}) 36 endif() 37 if (PARAM_MODULE) 38 set(libkind MODULE) 39 elseif (PARAM_SHARED) 40 set(libkind SHARED) 41 elseif (PARAM_OBJECT) 42 set(libkind OBJECT) 43 else () 44 # PARAM_STATIC or library type unspecified. BUILD_SHARED_LIBS 45 # does not control the kind of libraries created for LLDB, 46 # only whether or not they link to shared/static LLVM/Clang 47 # libraries. 48 set(libkind STATIC) 49 endif() 50 51 #PIC not needed on Win 52 if (NOT MSVC) 53 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") 54 endif() 55 56 if (PARAM_OBJECT) 57 add_library(${name} ${libkind} ${srcs}) 58 else() 59 llvm_add_library(${name} ${libkind} DISABLE_LLVM_LINK_LLVM_DYLIB ${srcs}) 60 61 lldb_link_common_libs(${name} "${libkind}") 62 63 if (PARAM_SHARED) 64 if (LLDB_LINKER_SUPPORTS_GROUPS) 65 target_link_libraries(${name} PUBLIC 66 -Wl,--start-group ${CLANG_USED_LIBS} -Wl,--end-group) 67 else() 68 target_link_libraries(${name} PUBLIC ${CLANG_USED_LIBS}) 69 endif() 70 endif() 71 llvm_config(${name} ${LLVM_LINK_COMPONENTS} ${LLVM_PRIVATE_LINK_COMPONENTS}) 72 73 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb") 74 if (PARAM_SHARED) 75 set(out_dir lib${LLVM_LIBDIR_SUFFIX}) 76 if(${name} STREQUAL "liblldb" AND LLDB_BUILD_FRAMEWORK) 77 set(out_dir ${LLDB_FRAMEWORK_INSTALL_DIR}) 78 endif() 79 install(TARGETS ${name} 80 RUNTIME DESTINATION bin 81 LIBRARY DESTINATION ${out_dir} 82 ARCHIVE DESTINATION ${out_dir}) 83 else() 84 install(TARGETS ${name} 85 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 86 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 87 endif() 88 endif() 89 endif() 90 91 # Hack: only some LLDB libraries depend on the clang autogenerated headers, 92 # but it is simple enough to make all of LLDB depend on some of those 93 # headers without negatively impacting much of anything. 94 get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS) 95 if(CLANG_TABLEGEN_TARGETS) 96 add_dependencies(${name} ${CLANG_TABLEGEN_TARGETS}) 97 endif() 98 99 set_target_properties(${name} PROPERTIES FOLDER "lldb libraries") 100endmacro(add_lldb_library) 101 102macro(add_lldb_executable name) 103 cmake_parse_arguments(ARG "INCLUDE_IN_FRAMEWORK" "" "" ${ARGN}) 104 add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARG_UNPARSED_ARGUMENTS}) 105 set_target_properties(${name} PROPERTIES 106 FOLDER "lldb executables") 107 108 if(LLDB_BUILD_FRAMEWORK) 109 if(ARG_INCLUDE_IN_FRAMEWORK) 110 string(REGEX REPLACE "[^/]+" ".." _dots ${LLDB_FRAMEWORK_INSTALL_DIR}) 111 set_target_properties(${name} PROPERTIES 112 RUNTIME_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:liblldb>/Resources 113 BUILD_WITH_INSTALL_RPATH On 114 INSTALL_RPATH "@loader_path/../../../../${_dots}/${LLDB_FRAMEWORK_INSTALL_DIR}") 115 116 add_llvm_tool_symlink(${name} $<TARGET_FILE:${name}> ARG_ALWAYS_GENERATE) 117 else() 118 set_target_properties(${name} PROPERTIES 119 BUILD_WITH_INSTALL_RPATH On 120 INSTALL_RPATH "@loader_path/../${LLDB_FRAMEWORK_INSTALL_DIR}") 121 endif() 122 endif() 123endmacro(add_lldb_executable) 124 125# Support appending linker flags to an existing target. 126# This will preserve the existing linker flags on the 127# target, if there are any. 128function(lldb_append_link_flags target_name new_link_flags) 129 # Retrieve existing linker flags. 130 get_target_property(current_link_flags ${target_name} LINK_FLAGS) 131 132 # If we had any linker flags, include them first in the new linker flags. 133 if(current_link_flags) 134 set(new_link_flags "${current_link_flags} ${new_link_flags}") 135 endif() 136 137 # Now set them onto the target. 138 set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags}) 139endfunction() 140