1function(lldb_link_common_libs name targetkind) 2 if (NOT LLDB_USED_LIBS) 3 return() 4 endif() 5 6 set(COMPILER_SUPPORTS_GROUPS OFF) 7 if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") 8 # The Darwin linker doesn't understand --start-group/--end-group. 9 set(COMPILER_SUPPORTS_GROUPS ON) 10 endif() 11 12 if(${targetkind} MATCHES "SHARED") 13 set(LINK_KEYWORD ${cmake_2_8_12_PUBLIC}) 14 endif() 15 16 if(${targetkind} MATCHES "SHARED" OR ${targetkind} MATCHES "EXE") 17 if (COMPILER_SUPPORTS_GROUPS) 18 target_link_libraries(${name} ${LINK_KEYWORD} 19 -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group) 20 else() 21 target_link_libraries(${name} ${LINK_KEYWORD} ${LLDB_USED_LIBS}) 22 endif() 23 endif() 24endfunction(lldb_link_common_libs) 25 26macro(add_lldb_library name) 27 # only supported parameters to this macro are the optional 28 # MODULE;SHARED;STATIC library type and source files 29 cmake_parse_arguments(PARAM 30 "MODULE;SHARED;STATIC;OBJECT" 31 "" 32 "" 33 ${ARGN}) 34 llvm_process_sources(srcs ${PARAM_UNPARSED_ARGUMENTS}) 35 36 if (MSVC_IDE OR XCODE) 37 string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR}) 38 list(GET split_path -1 dir) 39 file(GLOB_RECURSE headers 40 ../../include/lldb${dir}/*.h) 41 set(srcs ${srcs} ${headers}) 42 endif() 43 if (PARAM_MODULE) 44 set(libkind MODULE) 45 elseif (PARAM_SHARED) 46 set(libkind SHARED) 47 elseif (PARAM_OBJECT) 48 set(libkind OBJECT) 49 else () 50 # PARAM_STATIC or library type unspecified. BUILD_SHARED_LIBS 51 # does not control the kind of libraries created for LLDB, 52 # only whether or not they link to shared/static LLVM/Clang 53 # libraries. 54 set(libkind STATIC) 55 endif() 56 57 #PIC not needed on Win 58 if (NOT MSVC) 59 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") 60 endif() 61 62 if (PARAM_OBJECT) 63 add_library(${name} ${libkind} ${srcs}) 64 else() 65 llvm_add_library(${name} ${libkind} ${srcs}) 66 67 lldb_link_common_libs(${name} "${libkind}") 68 69 70 target_link_libraries(${name} ${cmake_2_8_12_PUBLIC} ${CLANG_USED_LIBS}) 71 llvm_config(${name} ${LLVM_LINK_COMPONENTS}) 72 73 if (PARAM_SHARED) 74 install(TARGETS ${name} 75 RUNTIME DESTINATION bin 76 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 77 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 78 else() 79 install(TARGETS ${name} 80 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 81 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 82 endif() 83 endif() 84 85 # Hack: only some LLDB libraries depend on the clang autogenerated headers, 86 # but it is simple enough to make all of LLDB depend on some of those 87 # headers without negatively impacting much of anything. 88 add_dependencies(${name} libclang) 89 90 set_target_properties(${name} PROPERTIES FOLDER "lldb libraries") 91endmacro(add_lldb_library) 92 93macro(add_lldb_executable name) 94 add_llvm_executable(${name} ${ARGN}) 95 set_target_properties(${name} PROPERTIES FOLDER "lldb executables") 96endmacro(add_lldb_executable) 97