diff options
Diffstat (limited to 'lldb/cmake/modules/AddLLDB.cmake')
-rw-r--r-- | lldb/cmake/modules/AddLLDB.cmake | 173 |
1 files changed, 95 insertions, 78 deletions
diff --git a/lldb/cmake/modules/AddLLDB.cmake b/lldb/cmake/modules/AddLLDB.cmake index 5c1a181caf8..3bf26884fc7 100644 --- a/lldb/cmake/modules/AddLLDB.cmake +++ b/lldb/cmake/modules/AddLLDB.cmake @@ -1,78 +1,95 @@ -macro(add_lldb_library name)
- # only supported parameters to this macro are the optional
- # MODULE;SHARED;STATIC library type and source files
- cmake_parse_arguments(PARAM
- "MODULE;SHARED;STATIC;OBJECT"
- ""
- ""
- ${ARGN})
- llvm_process_sources(srcs ${PARAM_UNPARSED_ARGUMENTS})
-
- if (MSVC_IDE OR XCODE)
- string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
- list(GET split_path -1 dir)
- file(GLOB_RECURSE headers
- ../../include/lldb${dir}/*.h)
- set(srcs ${srcs} ${headers})
- endif()
- if (PARAM_MODULE)
- set(libkind MODULE)
- elseif (PARAM_SHARED)
- set(libkind SHARED)
- elseif (PARAM_STATIC)
- set(libkind STATIC)
- elseif (PARAM_OBJECT)
- set(libkind OBJECT)
- else ()
- # library type unspecified - controlled by BUILD_SHARED_LIBS
- unset(libkind)
- endif()
-
- #PIC not needed on Win
- if (NOT MSVC)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
- endif()
-
- if (PARAM_OBJECT)
- add_library(${name} ${libkind} ${srcs})
- else()
- llvm_add_library(${name} ${libkind} ${srcs})
-
- if (PARAM_STATIC)
- set(lldb_library_keyword ${cmake_2_8_12_INTERFACE})
- else ()
- set(lldb_library_keyword ${cmake_2_8_12_PUBLIC})
- endif ()
-
- if(LLDB_USED_LIBS)
- # The Darwin linker doesn't understand --start-group/--end-group.
- if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
- target_link_libraries(${name} ${lldb_library_keyword}
- -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group)
- else()
- target_link_libraries(${name} ${lldb_library_keyword} ${LLDB_USED_LIBS})
- endif()
- endif()
-
- target_link_libraries(${name} ${lldb_library_keyword} ${CLANG_USED_LIBS})
- target_link_libraries(${name} ${lldb_library_keyword} ${LLVM_USED_LIBS})
- llvm_config(${name} ${LLVM_LINK_COMPONENTS})
- target_link_libraries(${name} ${lldb_library_keyword} ${LLVM_COMMON_LIBS})
-
- install(TARGETS ${name}
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
- endif()
-
- # Hack: only some LLDB libraries depend on the clang autogenerated headers,
- # but it is simple enough to make all of LLDB depend on some of those
- # headers without negatively impacting much of anything.
- add_dependencies(${name} libclang)
-
- set_target_properties(${name} PROPERTIES FOLDER "lldb libraries")
-endmacro(add_lldb_library)
-
-macro(add_lldb_executable name)
- add_llvm_executable(${name} ${ARGN})
- set_target_properties(${name} PROPERTIES FOLDER "lldb executables")
-endmacro(add_lldb_executable)
+function(lldb_link_common_libs name targetkind) + if (NOT LLDB_USED_LIBS) + return() + endif() + + set(COMPILER_SUPPORTS_GROUPS OFF) + if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + # The Darwin linker doesn't understand --start-group/--end-group. + set(COMPILER_SUPPORTS_GROUPS ON) + endif() + + if(${targetkind} MATCHES "SHARED") + set(LINK_KEYWORD ${cmake_2_8_12_PUBLIC}) + endif() + + if(${targetkind} MATCHES "SHARED" OR ${targetkind} MATCHES "EXE") + if (COMPILER_SUPPORTS_GROUPS) + target_link_libraries(${name} ${LINK_KEYWORD} + -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group) + else() + target_link_libraries(${name} ${LINK_KEYWORD} ${LLDB_USED_LIBS}) + endif() + endif() +endfunction(lldb_link_common_libs) + +macro(add_lldb_library name) + # only supported parameters to this macro are the optional + # MODULE;SHARED;STATIC library type and source files + cmake_parse_arguments(PARAM + "MODULE;SHARED;STATIC;OBJECT" + "" + "" + ${ARGN}) + llvm_process_sources(srcs ${PARAM_UNPARSED_ARGUMENTS}) + + if (MSVC_IDE OR XCODE) + string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR}) + list(GET split_path -1 dir) + file(GLOB_RECURSE headers + ../../include/lldb${dir}/*.h) + set(srcs ${srcs} ${headers}) + endif() + if (PARAM_MODULE) + set(libkind MODULE) + elseif (PARAM_SHARED) + set(libkind SHARED) + elseif (PARAM_STATIC) + set(libkind STATIC) + elseif (PARAM_OBJECT) + set(libkind OBJECT) + else () + # library type unspecified - controlled by BUILD_SHARED_LIBS + unset(libkind) + endif() + + #PIC not needed on Win + if (NOT MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + endif() + + if (PARAM_OBJECT) + add_library(${name} ${libkind} ${srcs}) + else() + llvm_add_library(${name} ${libkind} ${srcs}) + + lldb_link_common_libs(${name} "${libkind}") + + + target_link_libraries(${name} ${cmake_2_8_12_PUBLIC} ${CLANG_USED_LIBS}) + llvm_config(${name} ${LLVM_LINK_COMPONENTS}) + + if (PARAM_SHARED) + install(TARGETS ${name} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} + ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) + else() + install(TARGETS ${name} + LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} + ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) + endif() + endif() + + # Hack: only some LLDB libraries depend on the clang autogenerated headers, + # but it is simple enough to make all of LLDB depend on some of those + # headers without negatively impacting much of anything. + add_dependencies(${name} libclang) + + set_target_properties(${name} PROPERTIES FOLDER "lldb libraries") +endmacro(add_lldb_library) + +macro(add_lldb_executable name) + add_llvm_executable(${name} ${ARGN}) + set_target_properties(${name} PROPERTIES FOLDER "lldb executables") +endmacro(add_lldb_executable) |