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 ${cmake_2_8_12_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} ${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} ${cmake_2_8_12_PUBLIC} 66 -Wl,--start-group ${CLANG_USED_LIBS} -Wl,--end-group) 67 else() 68 target_link_libraries(${name} ${cmake_2_8_12_PUBLIC} ${CLANG_USED_LIBS}) 69 endif() 70 endif() 71 llvm_config(${name} ${LLVM_LINK_COMPONENTS}) 72 73 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb") 74 if (PARAM_SHARED) 75 install(TARGETS ${name} 76 RUNTIME DESTINATION bin 77 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 78 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 79 else() 80 install(TARGETS ${name} 81 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 82 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 83 endif() 84 endif() 85 endif() 86 87 # Hack: only some LLDB libraries depend on the clang autogenerated headers, 88 # but it is simple enough to make all of LLDB depend on some of those 89 # headers without negatively impacting much of anything. 90 add_dependencies(${name} libclang) 91 92 set_target_properties(${name} PROPERTIES FOLDER "lldb libraries") 93endmacro(add_lldb_library) 94 95macro(add_lldb_executable name) 96 add_llvm_executable(${name} ${ARGN}) 97 set_target_properties(${name} PROPERTIES FOLDER "lldb executables") 98endmacro(add_lldb_executable) 99 100# Support appending linker flags to an existing target. 101# This will preserve the existing linker flags on the 102# target, if there are any. 103function(lldb_append_link_flags target_name new_link_flags) 104 # Retrieve existing linker flags. 105 get_target_property(current_link_flags ${target_name} LINK_FLAGS) 106 107 # If we had any linker flags, include them first in the new linker flags. 108 if(current_link_flags) 109 set(new_link_flags "${current_link_flags} ${new_link_flags}") 110 endif() 111 112 # Now set them onto the target. 113 set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags}) 114endfunction() 115