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 PRIVATE) 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 "DEPENDS" 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 if (PARAM_SHARED) 60 if (LLDB_LINKER_SUPPORTS_GROUPS) 61 llvm_add_library(${name} ${libkind} ${srcs} LINK_LIBS 62 -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group 63 -Wl,--start-group ${CLANG_USED_LIBS} -Wl,--end-group 64 DEPENDS ${PARAM_DEPENDS} 65 ) 66 else() 67 llvm_add_library(${name} ${libkind} ${srcs} LINK_LIBS 68 ${LLDB_USED_LIBS} ${CLANG_USED_LIBS} 69 DEPENDS ${PARAM_DEPENDS} 70 ) 71 endif() 72 else() 73 llvm_add_library(${name} ${libkind} ${srcs} DEPENDS ${PARAM_DEPENDS}) 74 endif() 75 76 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb") 77 if (PARAM_SHARED) 78 set(out_dir lib${LLVM_LIBDIR_SUFFIX}) 79 if(${name} STREQUAL "liblldb" AND LLDB_BUILD_FRAMEWORK) 80 set(out_dir ${LLDB_FRAMEWORK_INSTALL_DIR}) 81 endif() 82 install(TARGETS ${name} 83 RUNTIME DESTINATION bin 84 LIBRARY DESTINATION ${out_dir} 85 ARCHIVE DESTINATION ${out_dir}) 86 else() 87 install(TARGETS ${name} 88 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 89 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 90 endif() 91 endif() 92 endif() 93 94 # Hack: only some LLDB libraries depend on the clang autogenerated headers, 95 # but it is simple enough to make all of LLDB depend on some of those 96 # headers without negatively impacting much of anything. 97 get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS) 98 if(CLANG_TABLEGEN_TARGETS) 99 add_dependencies(${name} ${CLANG_TABLEGEN_TARGETS}) 100 endif() 101 102 set_target_properties(${name} PROPERTIES FOLDER "lldb libraries") 103endmacro(add_lldb_library) 104 105macro(add_lldb_executable name) 106 cmake_parse_arguments(ARG "INCLUDE_IN_FRAMEWORK" "" "" ${ARGN}) 107 add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) 108 set_target_properties(${name} PROPERTIES 109 FOLDER "lldb executables") 110 111 if(LLDB_BUILD_FRAMEWORK) 112 if(ARG_INCLUDE_IN_FRAMEWORK) 113 string(REGEX REPLACE "[^/]+" ".." _dots ${LLDB_FRAMEWORK_INSTALL_DIR}) 114 set_target_properties(${name} PROPERTIES 115 RUNTIME_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:liblldb>/Resources 116 BUILD_WITH_INSTALL_RPATH On 117 INSTALL_RPATH "@loader_path/../../../../${_dots}/${LLDB_FRAMEWORK_INSTALL_DIR}") 118 119 add_llvm_tool_symlink(${name} ${name} ARG_ALWAYS_GENERATE 120 OUTPUT_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) 121 else() 122 set_target_properties(${name} PROPERTIES 123 BUILD_WITH_INSTALL_RPATH On 124 INSTALL_RPATH "@loader_path/../${LLDB_FRAMEWORK_INSTALL_DIR}") 125 endif() 126 endif() 127endmacro(add_lldb_executable) 128 129# Support appending linker flags to an existing target. 130# This will preserve the existing linker flags on the 131# target, if there are any. 132function(lldb_append_link_flags target_name new_link_flags) 133 # Retrieve existing linker flags. 134 get_target_property(current_link_flags ${target_name} LINK_FLAGS) 135 136 # If we had any linker flags, include them first in the new linker flags. 137 if(current_link_flags) 138 set(new_link_flags "${current_link_flags} ${new_link_flags}") 139 endif() 140 141 # Now set them onto the target. 142 set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags}) 143endfunction() 144