2016-12-16 06:01:17 +08:00
|
|
|
function(add_lldb_library name)
|
2015-07-17 23:26:27 +08:00
|
|
|
# only supported parameters to this macro are the optional
|
2015-03-19 00:56:24 +08:00
|
|
|
# MODULE;SHARED;STATIC library type and source files
|
|
|
|
cmake_parse_arguments(PARAM
|
2017-02-01 06:12:59 +08:00
|
|
|
"MODULE;SHARED;STATIC;OBJECT;PLUGIN"
|
2015-03-19 00:56:24 +08:00
|
|
|
""
|
2017-12-08 02:57:09 +08:00
|
|
|
"EXTRA_CXXFLAGS;DEPENDS;LINK_LIBS;LINK_COMPONENTS"
|
2015-03-19 00:56:24 +08:00
|
|
|
${ARGN})
|
|
|
|
llvm_process_sources(srcs ${PARAM_UNPARSED_ARGUMENTS})
|
2017-02-01 00:59:46 +08:00
|
|
|
list(APPEND LLVM_LINK_COMPONENTS ${PARAM_LINK_COMPONENTS})
|
2015-03-19 00:56:24 +08:00
|
|
|
|
2017-02-01 06:12:59 +08:00
|
|
|
if(PARAM_PLUGIN)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY LLDB_PLUGINS ${name})
|
|
|
|
endif()
|
|
|
|
|
2015-03-19 00:56:24 +08:00
|
|
|
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_OBJECT)
|
|
|
|
set(libkind OBJECT)
|
|
|
|
else ()
|
2015-06-04 11:12:37 +08:00
|
|
|
# PARAM_STATIC or library type unspecified. BUILD_SHARED_LIBS
|
|
|
|
# does not control the kind of libraries created for LLDB,
|
|
|
|
# only whether or not they link to shared/static LLVM/Clang
|
|
|
|
# libraries.
|
|
|
|
set(libkind STATIC)
|
2015-03-19 00:56:24 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
#PIC not needed on Win
|
2017-12-08 02:57:09 +08:00
|
|
|
# FIXME: Setting CMAKE_CXX_FLAGS here is a no-op, use target_compile_options
|
|
|
|
# or omit this logic instead.
|
2016-12-15 23:00:41 +08:00
|
|
|
if (NOT WIN32)
|
2015-03-19 00:56:24 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (PARAM_OBJECT)
|
|
|
|
add_library(${name} ${libkind} ${srcs})
|
|
|
|
else()
|
2017-02-01 00:59:46 +08:00
|
|
|
llvm_add_library(${name} ${libkind} ${srcs} LINK_LIBS
|
|
|
|
${PARAM_LINK_LIBS}
|
|
|
|
DEPENDS ${PARAM_DEPENDS})
|
2015-03-19 00:56:24 +08:00
|
|
|
|
2015-06-29 19:03:21 +08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb")
|
|
|
|
if (PARAM_SHARED)
|
2016-09-22 05:02:16 +08:00
|
|
|
set(out_dir lib${LLVM_LIBDIR_SUFFIX})
|
|
|
|
if(${name} STREQUAL "liblldb" AND LLDB_BUILD_FRAMEWORK)
|
|
|
|
set(out_dir ${LLDB_FRAMEWORK_INSTALL_DIR})
|
|
|
|
endif()
|
2015-06-29 19:03:21 +08:00
|
|
|
install(TARGETS ${name}
|
2016-12-16 06:01:17 +08:00
|
|
|
COMPONENT ${name}
|
2015-06-29 19:03:21 +08:00
|
|
|
RUNTIME DESTINATION bin
|
2016-09-22 05:02:16 +08:00
|
|
|
LIBRARY DESTINATION ${out_dir}
|
|
|
|
ARCHIVE DESTINATION ${out_dir})
|
2015-06-29 19:03:21 +08:00
|
|
|
else()
|
|
|
|
install(TARGETS ${name}
|
2016-12-16 06:01:17 +08:00
|
|
|
COMPONENT ${name}
|
2015-06-29 19:03:21 +08:00
|
|
|
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
|
|
|
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
|
|
|
|
endif()
|
2016-12-16 06:01:17 +08:00
|
|
|
if (NOT CMAKE_CONFIGURATION_TYPES)
|
2017-12-12 08:47:07 +08:00
|
|
|
add_llvm_install_targets(install-${name}
|
|
|
|
DEPENDS ${name})
|
2016-12-16 06:01:17 +08:00
|
|
|
endif()
|
2015-03-19 00:56:24 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-08-20 05:00:40 +08:00
|
|
|
# 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.
|
2017-07-28 23:39:49 +08:00
|
|
|
add_dependencies(${name} clang-tablegen-targets)
|
2015-03-19 00:56:24 +08:00
|
|
|
|
2017-12-08 02:57:09 +08:00
|
|
|
# Add in any extra C++ compilation flags for this library.
|
|
|
|
target_compile_options(${name} PRIVATE ${PARAM_EXTRA_CXXFLAGS})
|
|
|
|
|
2015-03-19 00:56:24 +08:00
|
|
|
set_target_properties(${name} PROPERTIES FOLDER "lldb libraries")
|
2016-12-16 06:01:17 +08:00
|
|
|
endfunction(add_lldb_library)
|
2015-03-19 00:56:24 +08:00
|
|
|
|
2016-12-16 06:01:17 +08:00
|
|
|
function(add_lldb_executable name)
|
2017-02-01 00:59:46 +08:00
|
|
|
cmake_parse_arguments(ARG
|
|
|
|
"INCLUDE_IN_FRAMEWORK;GENERATE_INSTALL"
|
|
|
|
""
|
|
|
|
"LINK_LIBS;LINK_COMPONENTS"
|
|
|
|
${ARGN}
|
|
|
|
)
|
|
|
|
|
|
|
|
list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
|
[cmake] Make dependencies of lldb libraries private, take 2
Summary:
The dependencies of our libraries (only liblldb, really) we marked as public, which caused all
their dependencies to be repeated when linking any executables to them. This is a problem because
then all the .a files could end up being linked twice, once to liblldb and once
again to to the executable linking against liblldb (lldb, lldb-mi). As it turns out,
our build actually depends on this behavior:
- on windows, lldb does not have getopt, so it pulls it from inside liblldb, even
though getopt is not a part of the exported interface of liblldb (maybe some of
the bsd variants have this problem as well)
- lldb-mi uses llvm, which again is not exported by liblldb
This change does not actually fix these problems (that is going to be a hard
one), but it does make them explicit by moving this magic from add_lldb_library
to the places the executable targets are defined. That way, I can link the
additional .a files only on targets that really need it, and the other targets
can build cleanly and make sure we don't regress further. It also fixes the
LLVM_LINK_LLVM_DYLIB build on linux.
Reviewers: zturner, beanz
Subscribers: ki.stfu, lldb-commits, mgorny
Differential Revision: https://reviews.llvm.org/D25680
llvm-svn: 284466
2016-10-18 18:26:57 +08:00
|
|
|
add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
|
2017-02-01 00:59:46 +08:00
|
|
|
|
[CMake] Use PRIVATE in target_link_libraries for executables
We currently use target_link_libraries without an explicit scope
specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables.
Dependencies added in this way apply to both the target and its
dependencies, i.e. they become part of the executable's link interface
and are transitive.
Transitive dependencies generally don't make sense for executables,
since you wouldn't normally be linking against an executable. This also
causes issues for generating install export files when using
LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM
library dependencies, which are currently added as interface
dependencies. If clang is in the distribution components but the LLVM
libraries it depends on aren't (which is a perfectly legitimate use case
if the LLVM libraries are being built static and there are therefore no
run-time dependencies on them), CMake will complain about the LLVM
libraries not being in export set when attempting to generate the
install export file for clang. This is reasonable behavior on CMake's
part, and the right thing is for LLVM's build system to explicitly use
PRIVATE dependencies for executables.
Unfortunately, CMake doesn't allow you to mix and match the keyword and
non-keyword target_link_libraries signatures for a single target; i.e.,
if a single call to target_link_libraries for a particular target uses
one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must
also be updated to use those keywords. This means we must do this change
in a single shot. I also fully expect to have missed some instances; I
tested by enabling all the projects in the monorepo (except dragonegg),
and configuring both with and without shared libraries, on both Darwin
and Linux, but I'm planning to rely on the buildbots for other
configurations (since it should be pretty easy to fix those).
Even after this change, we still have a lot of target_link_libraries
calls that don't specify a scope keyword, mostly for shared libraries.
I'm thinking about addressing those in a follow-up, but that's a
separate change IMO.
Differential Revision: https://reviews.llvm.org/D40823
llvm-svn: 319840
2017-12-06 05:49:56 +08:00
|
|
|
target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS})
|
2016-09-22 05:02:16 +08:00
|
|
|
set_target_properties(${name} PROPERTIES
|
|
|
|
FOLDER "lldb executables")
|
|
|
|
|
|
|
|
if(LLDB_BUILD_FRAMEWORK)
|
|
|
|
if(ARG_INCLUDE_IN_FRAMEWORK)
|
2017-07-26 04:31:15 +08:00
|
|
|
if(NOT IOS)
|
|
|
|
set(resource_dir "/Resources")
|
|
|
|
set(resource_dots "../")
|
|
|
|
endif()
|
2016-09-22 05:02:16 +08:00
|
|
|
string(REGEX REPLACE "[^/]+" ".." _dots ${LLDB_FRAMEWORK_INSTALL_DIR})
|
|
|
|
set_target_properties(${name} PROPERTIES
|
2017-07-26 04:31:15 +08:00
|
|
|
RUNTIME_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:liblldb>${resource_dir}
|
2016-09-22 05:02:16 +08:00
|
|
|
BUILD_WITH_INSTALL_RPATH On
|
2017-07-26 04:31:15 +08:00
|
|
|
INSTALL_RPATH "@loader_path/../../../${resource_dots}${_dots}/${LLDB_FRAMEWORK_INSTALL_DIR}")
|
2016-12-22 05:23:27 +08:00
|
|
|
# For things inside the framework we don't need functional install targets
|
|
|
|
# because CMake copies the resources and headers from the build directory.
|
|
|
|
# But we still need this target to exist in order to use the
|
|
|
|
# LLVM_DISTRIBUTION_COMPONENTS build option. We also need the
|
|
|
|
# install-liblldb target to depend on this tool, so that it gets put into
|
|
|
|
# the Resources directory before the framework is installed.
|
|
|
|
if(ARG_GENERATE_INSTALL)
|
|
|
|
add_custom_target(install-${name} DEPENDS ${name})
|
|
|
|
add_dependencies(install-liblldb ${name})
|
2017-12-12 08:47:07 +08:00
|
|
|
add_custom_target(install-${name}-stripped DEPENDS ${name})
|
|
|
|
add_dependencies(install-liblldb-stripped ${name})
|
2016-12-22 05:23:27 +08:00
|
|
|
endif()
|
2016-09-22 05:02:16 +08:00
|
|
|
else()
|
|
|
|
set_target_properties(${name} PROPERTIES
|
|
|
|
BUILD_WITH_INSTALL_RPATH On
|
|
|
|
INSTALL_RPATH "@loader_path/../${LLDB_FRAMEWORK_INSTALL_DIR}")
|
2016-12-21 00:28:18 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-01-04 11:36:35 +08:00
|
|
|
if(ARG_GENERATE_INSTALL AND NOT (ARG_INCLUDE_IN_FRAMEWORK AND LLDB_BUILD_FRAMEWORK ))
|
2016-12-21 00:28:18 +08:00
|
|
|
install(TARGETS ${name}
|
|
|
|
COMPONENT ${name}
|
|
|
|
RUNTIME DESTINATION bin)
|
|
|
|
if (NOT CMAKE_CONFIGURATION_TYPES)
|
2017-12-12 08:47:07 +08:00
|
|
|
add_llvm_install_targets(install-${name}
|
|
|
|
DEPENDS ${name})
|
2016-09-22 05:02:16 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
2016-12-16 06:01:17 +08:00
|
|
|
|
|
|
|
if(ARG_INCLUDE_IN_FRAMEWORK AND LLDB_BUILD_FRAMEWORK)
|
|
|
|
add_llvm_tool_symlink(${name} ${name} ALWAYS_GENERATE SKIP_INSTALL
|
|
|
|
OUTPUT_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
|
|
|
|
endif()
|
|
|
|
endfunction(add_lldb_executable)
|
|
|
|
|
|
|
|
function(add_lldb_tool name)
|
|
|
|
add_lldb_executable(${name} GENERATE_INSTALL ${ARGN})
|
|
|
|
endfunction()
|
2015-10-14 22:52:15 +08:00
|
|
|
|
|
|
|
# Support appending linker flags to an existing target.
|
|
|
|
# This will preserve the existing linker flags on the
|
|
|
|
# target, if there are any.
|
|
|
|
function(lldb_append_link_flags target_name new_link_flags)
|
|
|
|
# Retrieve existing linker flags.
|
|
|
|
get_target_property(current_link_flags ${target_name} LINK_FLAGS)
|
|
|
|
|
|
|
|
# If we had any linker flags, include them first in the new linker flags.
|
|
|
|
if(current_link_flags)
|
|
|
|
set(new_link_flags "${current_link_flags} ${new_link_flags}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Now set them onto the target.
|
|
|
|
set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags})
|
|
|
|
endfunction()
|