diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2016-01-06 20:12:03 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2016-01-06 20:12:03 +0000 |
commit | 9e6d35490a6542f9c97607f93c2ef8ca8e03cbcc (patch) | |
tree | dd2a1ddf0476664c2b823409c36cbccd52662ca7 /cmake | |
parent | 3bd2e91faeb9eeec1aae82c64a3253afff551cfd (diff) | |
download | src-9e6d35490a6542f9c97607f93c2ef8ca8e03cbcc.tar.gz src-9e6d35490a6542f9c97607f93c2ef8ca8e03cbcc.zip |
Notes
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/LLDBDependencies.cmake | 207 | ||||
-rw-r--r-- | cmake/modules/AddLLDB.cmake | 114 | ||||
-rw-r--r-- | cmake/modules/LLDBConfig.cmake | 412 | ||||
-rw-r--r-- | cmake/modules/LLDBStandalone.cmake | 99 | ||||
-rw-r--r-- | cmake/platforms/Android.cmake | 188 |
5 files changed, 1020 insertions, 0 deletions
diff --git a/cmake/LLDBDependencies.cmake b/cmake/LLDBDependencies.cmake new file mode 100644 index 000000000000..073fa28b2528 --- /dev/null +++ b/cmake/LLDBDependencies.cmake @@ -0,0 +1,207 @@ +set( LLDB_USED_LIBS + lldbBase + lldbBreakpoint + lldbCommands + lldbDataFormatters + lldbHost + lldbCore + lldbExpression + lldbInitialization + lldbInterpreter + lldbSymbol + lldbTarget + lldbUtility + + # Plugins + lldbPluginDisassemblerLLVM + lldbPluginSymbolFileDWARF + lldbPluginSymbolFileSymtab + lldbPluginDynamicLoaderStatic + lldbPluginDynamicLoaderPosixDYLD + lldbPluginDynamicLoaderHexagonDYLD + lldbPluginDynamicLoaderWindowsDYLD + + lldbPluginCPlusPlusLanguage + lldbPluginGoLanguage + lldbPluginObjCLanguage + lldbPluginObjCPlusPlusLanguage + + lldbPluginObjectFileELF + lldbPluginObjectFileJIT + lldbPluginSymbolVendorELF + lldbPluginObjectContainerBSDArchive + lldbPluginObjectContainerMachOArchive + lldbPluginProcessGDBRemote + lldbPluginProcessUtility + lldbPluginPlatformAndroid + lldbPluginPlatformGDB + lldbPluginPlatformFreeBSD + lldbPluginPlatformKalimba + lldbPluginPlatformLinux + lldbPluginPlatformNetBSD + lldbPluginPlatformPOSIX + lldbPluginPlatformWindows + lldbPluginObjectContainerMachOArchive + lldbPluginObjectContainerBSDArchive + lldbPluginPlatformMacOSX + lldbPluginDynamicLoaderMacOSXDYLD + lldbPluginUnwindAssemblyInstEmulation + lldbPluginUnwindAssemblyX86 + lldbPluginAppleObjCRuntime + lldbPluginRenderScriptRuntime + lldbPluginLanguageRuntimeGo + lldbPluginCXXItaniumABI + lldbPluginABIMacOSX_arm + lldbPluginABIMacOSX_arm64 + lldbPluginABIMacOSX_i386 + lldbPluginABISysV_arm + lldbPluginABISysV_arm64 + lldbPluginABISysV_i386 + lldbPluginABISysV_x86_64 + lldbPluginABISysV_hexagon + lldbPluginABISysV_ppc + lldbPluginABISysV_ppc64 + lldbPluginABISysV_mips + lldbPluginABISysV_mips64 + lldbPluginInstructionARM + lldbPluginInstructionARM64 + lldbPluginInstructionMIPS + lldbPluginInstructionMIPS64 + lldbPluginObjectFilePECOFF + lldbPluginOSGo + lldbPluginOSPython + lldbPluginMemoryHistoryASan + lldbPluginInstrumentationRuntimeAddressSanitizer + lldbPluginSystemRuntimeMacOSX + lldbPluginProcessElfCore + lldbPluginJITLoaderGDB + lldbPluginExpressionParserClang + lldbPluginExpressionParserGo + ) + +# Windows-only libraries +if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) + list(APPEND LLDB_USED_LIBS + lldbPluginProcessWindows + lldbPluginProcessWinMiniDump + lldbPluginProcessWindowsCommon + Ws2_32 + Rpcrt4 + ) +endif () + +# Linux-only libraries +if ( CMAKE_SYSTEM_NAME MATCHES "Linux" ) + list(APPEND LLDB_USED_LIBS + lldbPluginProcessLinux + lldbPluginProcessPOSIX + ) +endif () + +# FreeBSD-only libraries +if ( CMAKE_SYSTEM_NAME MATCHES "FreeBSD" ) + list(APPEND LLDB_USED_LIBS + lldbPluginProcessFreeBSD + lldbPluginProcessPOSIX + ) +endif () + +# NetBSD-only libraries +if ( CMAKE_SYSTEM_NAME MATCHES "NetBSD" ) + list(APPEND LLDB_USED_LIBS + lldbPluginProcessPOSIX + ) +endif () + +# Darwin-only libraries +if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) + list(APPEND LLDB_USED_LIBS + lldbPluginDynamicLoaderDarwinKernel + lldbPluginObjectFileMachO + lldbPluginProcessMachCore + lldbPluginProcessMacOSXKernel + lldbPluginSymbolVendorMacOSX + ) +endif() + +set( CLANG_USED_LIBS + clangAnalysis + clangAST + clangBasic + clangCodeGen + clangDriver + clangEdit + clangFrontend + clangLex + clangParse + clangRewrite + clangRewriteFrontend + clangSema + clangSerialization + ) + +set(LLDB_SYSTEM_LIBS) +if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT __ANDROID_NDK__) + if (NOT LLDB_DISABLE_LIBEDIT) + list(APPEND LLDB_SYSTEM_LIBS edit) + endif() + if (NOT LLDB_DISABLE_CURSES) + list(APPEND LLDB_SYSTEM_LIBS ${CURSES_LIBRARIES}) + if(LLVM_ENABLE_TERMINFO AND HAVE_TERMINFO) + list(APPEND LLDB_SYSTEM_LIBS ${TERMINFO_LIBS}) + endif() + endif() +endif() +# On FreeBSD/NetBSD backtrace() is provided by libexecinfo, not libc. +if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD") + list(APPEND LLDB_SYSTEM_LIBS execinfo) +endif() + +if (NOT LLDB_DISABLE_PYTHON AND NOT LLVM_BUILD_STATIC) + list(APPEND LLDB_SYSTEM_LIBS ${PYTHON_LIBRARIES}) +endif() + +list(APPEND LLDB_SYSTEM_LIBS ${system_libs}) + +if (LLVM_BUILD_STATIC) + if (NOT LLDB_DISABLE_PYTHON) + list(APPEND LLDB_SYSTEM_LIBS python2.7 util) + endif() + if (NOT LLDB_DISABLE_CURSES) + list(APPEND LLDB_SYSTEM_LIBS gpm) + endif() +endif() + +set( LLVM_LINK_COMPONENTS + ${LLVM_TARGETS_TO_BUILD} + interpreter + asmparser + bitreader + bitwriter + codegen + ipo + selectiondag + bitreader + mc + mcjit + core + mcdisassembler + executionengine + runtimedyld + option + support + ) + +if ( NOT LLDB_DISABLE_PYTHON ) + set(LLDB_WRAP_PYTHON ${LLDB_BINARY_DIR}/scripts/LLDBWrapPython.cpp) + + set_source_files_properties(${LLDB_WRAP_PYTHON} PROPERTIES GENERATED 1) + if (CLANG_CL) + set_source_files_properties(${LLDB_WRAP_PYTHON} PROPERTIES COMPILE_FLAGS -Wno-unused-function) + endif() + if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND + NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + set_property(SOURCE ${LLDB_WRAP_PYTHON} + APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-sequence-point -Wno-cast-qual") + endif () +endif() diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake new file mode 100644 index 000000000000..672b0a53feaf --- /dev/null +++ b/cmake/modules/AddLLDB.cmake @@ -0,0 +1,114 @@ +function(lldb_link_common_libs name targetkind) + if (NOT LLDB_USED_LIBS) + return() + endif() + + if(${targetkind} MATCHES "SHARED") + set(LINK_KEYWORD ${cmake_2_8_12_PUBLIC}) + endif() + + if(${targetkind} MATCHES "SHARED" OR ${targetkind} MATCHES "EXE") + if (LLDB_LINKER_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_OBJECT) + set(libkind OBJECT) + else () + # 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) + 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}") + + if (PARAM_SHARED) + if (LLDB_LINKER_SUPPORTS_GROUPS) + target_link_libraries(${name} ${cmake_2_8_12_PUBLIC} + -Wl,--start-group ${CLANG_USED_LIBS} -Wl,--end-group) + else() + target_link_libraries(${name} ${cmake_2_8_12_PUBLIC} ${CLANG_USED_LIBS}) + endif() + endif() + llvm_config(${name} ${LLVM_LINK_COMPONENTS}) + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb") + 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() + 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) + +# 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() diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake new file mode 100644 index 000000000000..f5247a269822 --- /dev/null +++ b/cmake/modules/LLDBConfig.cmake @@ -0,0 +1,412 @@ +set(LLDB_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) +set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source") +set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include") + +set(LLDB_LINKER_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(LLDB_LINKER_SUPPORTS_GROUPS ON) +endif() + +if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) + set(LLDB_DEFAULT_DISABLE_PYTHON 0) + set(LLDB_DEFAULT_DISABLE_CURSES 1) +else() + if ( __ANDROID_NDK__ ) + set(LLDB_DEFAULT_DISABLE_PYTHON 1) + set(LLDB_DEFAULT_DISABLE_CURSES 1) + else() + set(LLDB_DEFAULT_DISABLE_PYTHON 0) + set(LLDB_DEFAULT_DISABLE_CURSES 0) + endif() +endif() + +set(LLDB_DISABLE_PYTHON ${LLDB_DEFAULT_DISABLE_PYTHON} CACHE BOOL + "Disables the Python scripting integration.") +set(LLDB_DISABLE_CURSES ${LLDB_DEFAULT_DISABLE_CURSES} CACHE BOOL + "Disables the Curses integration.") + +set(LLDB_RELOCATABLE_PYTHON 0 CACHE BOOL + "Causes LLDB to use the PYTHONHOME environment variable to locate Python.") + +if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") + set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL + "Causes lldb to export all symbols when building liblldb.") +else() + # Windows doesn't support toggling this, so don't bother making it a + # cache variable. + set(LLDB_EXPORT_ALL_SYMBOLS 0) +endif() + +if ((NOT MSVC) OR MSVC12) + add_definitions( -DHAVE_ROUND ) +endif() + +if (LLDB_DISABLE_CURSES) + add_definitions( -DLLDB_DISABLE_CURSES ) +endif() + +# On Windows, we can't use the normal FindPythonLibs module that comes with CMake, +# for a number of reasons. +# 1) Prior to MSVC 2015, it is only possible to embed Python if python itself was +# compiled with an identical version (and build configuration) of MSVC as LLDB. +# The standard algorithm does not take into account the differences between +# a binary release distribution of python and a custom built distribution. +# 2) From MSVC 2015 and onwards, it is only possible to use Python 3.5 or later. +# 3) FindPythonLibs queries the registry to locate Python, and when looking for a +# 64-bit version of Python, since cmake.exe is a 32-bit executable, it will see +# a 32-bit view of the registry. As such, it is impossible for FindPythonLibs to +# locate 64-bit Python libraries. +# This function is designed to address those limitations. Currently it only partially +# addresses them, but it can be improved and extended on an as-needed basis. +function(find_python_libs_windows) + if ("${PYTHON_HOME}" STREQUAL "") + message("LLDB embedded Python on Windows requires specifying a value for PYTHON_HOME. Python support disabled.") + set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE) + return() + endif() + + file(TO_CMAKE_PATH "${PYTHON_HOME}/Include" PYTHON_INCLUDE_DIRS) + + if(EXISTS "${PYTHON_INCLUDE_DIRS}/patchlevel.h") + file(STRINGS "${PYTHON_INCLUDE_DIRS}/patchlevel.h" python_version_str + REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"") + string(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"+]+)[+]?\".*" "\\1" + PYTHONLIBS_VERSION_STRING "${python_version_str}") + message("-- Found Python version ${PYTHONLIBS_VERSION_STRING}") + string(REGEX REPLACE "([0-9]+)[.]([0-9]+)[.][0-9]+" "python\\1\\2" PYTHONLIBS_BASE_NAME "${PYTHONLIBS_VERSION_STRING}") + unset(python_version_str) + else() + message("Unable to find ${PYTHON_INCLUDE_DIRS}/patchlevel.h, Python installation is corrupt.") + message("Python support will be disabled for this build.") + set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE) + return() + endif() + + file(TO_CMAKE_PATH "${PYTHON_HOME}" PYTHON_HOME) + file(TO_CMAKE_PATH "${PYTHON_HOME}/python_d.exe" PYTHON_DEBUG_EXE) + file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}_d.lib" PYTHON_DEBUG_LIB) + file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}_d.dll" PYTHON_DEBUG_DLL) + + file(TO_CMAKE_PATH "${PYTHON_HOME}/python.exe" PYTHON_RELEASE_EXE) + file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}.lib" PYTHON_RELEASE_LIB) + file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}.dll" PYTHON_RELEASE_DLL) + + if (NOT EXISTS ${PYTHON_DEBUG_EXE}) + message("Unable to find ${PYTHON_DEBUG_EXE}") + unset(PYTHON_DEBUG_EXE) + endif() + + if (NOT EXISTS ${PYTHON_RELEASE_EXE}) + message("Unable to find ${PYTHON_RELEASE_EXE}") + unset(PYTHON_RELEASE_EXE) + endif() + + if (NOT EXISTS ${PYTHON_DEBUG_LIB}) + message("Unable to find ${PYTHON_DEBUG_LIB}") + unset(PYTHON_DEBUG_LIB) + endif() + + if (NOT EXISTS ${PYTHON_RELEASE_LIB}) + message("Unable to find ${PYTHON_RELEASE_LIB}") + unset(PYTHON_RELEASE_LIB) + endif() + + if (NOT EXISTS ${PYTHON_DEBUG_DLL}) + message("Unable to find ${PYTHON_DEBUG_DLL}") + unset(PYTHON_DEBUG_DLL) + endif() + + if (NOT EXISTS ${PYTHON_RELEASE_DLL}) + message("Unable to find ${PYTHON_RELEASE_DLL}") + unset(PYTHON_RELEASE_DLL) + endif() + + if (NOT (PYTHON_DEBUG_EXE AND PYTHON_RELEASE_EXE AND PYTHON_DEBUG_LIB AND PYTHON_RELEASE_LIB AND PYTHON_DEBUG_DLL AND PYTHON_RELEASE_DLL)) + message("Python installation is corrupt. Python support will be disabled for this build.") + set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE) + return() + endif() + + # Generator expressions are evaluated in the context of each build configuration generated + # by CMake. Here we use the $<CONFIG:Debug>:VALUE logical generator expression to ensure + # that the debug Python library, DLL, and executable are used in the Debug build configuration. + # + # Generator expressions can be difficult to grok at first so here's a breakdown of the one + # used for PYTHON_LIBRARY: + # + # 1. $<CONFIG:Debug> evaluates to 1 when the Debug configuration is being generated, + # or 0 in all other cases. + # 2. $<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}> expands to ${PYTHON_DEBUG_LIB} when the Debug + # configuration is being generated, or nothing (literally) in all other cases. + # 3. $<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}> expands to ${PYTHON_RELEASE_LIB} when + # any configuration other than Debug is being generated, or nothing in all other cases. + # 4. The conditionals in 2 & 3 are mutually exclusive. + # 5. A logical expression with a conditional that evaluates to 0 yields no value at all. + # + # Due to 4 & 5 it's possible to concatenate 2 & 3 to obtain a single value specific to each + # build configuration. In this example the value will be ${PYTHON_DEBUG_LIB} when generating the + # Debug configuration, or ${PYTHON_RELEASE_LIB} when generating any other configuration. + # Note that it's imperative that there is no whitespace between the two expressions, otherwise + # CMake will insert a semicolon between the two. + set (PYTHON_EXECUTABLE $<$<CONFIG:Debug>:${PYTHON_DEBUG_EXE}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_EXE}>) + set (PYTHON_LIBRARY $<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}>) + set (PYTHON_DLL $<$<CONFIG:Debug>:${PYTHON_DEBUG_DLL}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_DLL}>) + + set (PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} PARENT_SCOPE) + set (PYTHON_LIBRARY ${PYTHON_LIBRARY} PARENT_SCOPE) + set (PYTHON_DLL ${PYTHON_DLL} PARENT_SCOPE) + set (PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} PARENT_SCOPE) + + message("-- LLDB Found PythonExecutable: ${PYTHON_RELEASE_EXE} and ${PYTHON_DEBUG_EXE}") + message("-- LLDB Found PythonLibs: ${PYTHON_RELEASE_LIB} and ${PYTHON_DEBUG_LIB}") + message("-- LLDB Found PythonDLL: ${PYTHON_RELEASE_DLL} and ${PYTHON_DEBUG_DLL}") + message("-- LLDB Found PythonIncludeDirs: ${PYTHON_INCLUDE_DIRS}") +endfunction(find_python_libs_windows) + +if (NOT LLDB_DISABLE_PYTHON) + if(UNIX) + # This is necessary for crosscompile on Ubuntu 14.04 64bit. Need a proper fix. + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") + endif() + endif() + + if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") + find_python_libs_windows() + + if (NOT LLDB_RELOCATABLE_PYTHON) + file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME) + add_definitions( -DLLDB_PYTHON_HOME="${LLDB_PYTHON_HOME}" ) + endif() + else() + find_package(PythonLibs REQUIRED) + endif() + + if (PYTHON_INCLUDE_DIRS) + include_directories(${PYTHON_INCLUDE_DIRS}) + endif() +endif() + +if (LLDB_DISABLE_PYTHON) + unset(PYTHON_INCLUDE_DIRS) + unset(PYTHON_LIBRARY) + add_definitions( -DLLDB_DISABLE_PYTHON ) +endif() + +if (LLVM_EXTERNAL_CLANG_SOURCE_DIR) + include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include) +else () + include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include) +endif () +include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include") + +# Disable GCC warnings +check_cxx_compiler_flag("-Wno-deprecated-declarations" + CXX_SUPPORTS_NO_DEPRECATED_DECLARATIONS) +if (CXX_SUPPORTS_NO_DEPRECATED_DECLARATIONS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") +endif () + +check_cxx_compiler_flag("-Wno-unknown-pragmas" + CXX_SUPPORTS_NO_UNKNOWN_PRAGMAS) +if (CXX_SUPPORTS_NO_UNKNOWN_PRAGMAS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") +endif () + +check_cxx_compiler_flag("-Wno-strict-aliasing" + CXX_SUPPORTS_NO_STRICT_ALIASING) +if (CXX_SUPPORTS_NO_STRICT_ALIASING) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing") +endif () + +# Disable Clang warnings +check_cxx_compiler_flag("-Wno-deprecated-register" + CXX_SUPPORTS_NO_DEPRECATED_REGISTER) +if (CXX_SUPPORTS_NO_DEPRECATED_REGISTER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register") +endif () + +check_cxx_compiler_flag("-Wno-vla-extension" + CXX_SUPPORTS_NO_VLA_EXTENSION) +if (CXX_SUPPORTS_NO_VLA_EXTENSION) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-vla-extension") +endif () + +# Disable MSVC warnings +if( MSVC ) + add_definitions( + -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch' + -wd4068 # Suppress 'warning C4068: unknown pragma' + -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type' + -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.' + -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified' + -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.' + ) +endif() + +set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +# If building on a 32-bit system, make sure off_t can store offsets > 2GB +if( CMAKE_SIZEOF_VOID_P EQUAL 4 ) + add_definitions( -D_LARGEFILE_SOURCE ) + add_definitions( -D_FILE_OFFSET_BITS=64 ) +endif() + +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " +"the makefiles distributed with LLDB. Please create a directory and run cmake " +"from there, passing the path to this source directory as the last argument. " +"This process created the file `CMakeCache.txt' and the directory " +"`CMakeFiles'. Please delete them.") +endif() + +# Compute the LLDB version from the LLVM version. +string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLDB_VERSION + ${PACKAGE_VERSION}) +message(STATUS "LLDB version: ${LLDB_VERSION}") + +if (CMAKE_VERSION VERSION_LESS 2.8.12) + set(cmake_2_8_12_INTERFACE) + set(cmake_2_8_12_PRIVATE) + set(cmake_2_8_12_PUBLIC) +else () + set(cmake_2_8_12_INTERFACE INTERFACE) + set(cmake_2_8_12_PRIVATE PRIVATE) + set(cmake_2_8_12_PUBLIC PUBLIC) +endif () + +include_directories(BEFORE + ${CMAKE_CURRENT_BINARY_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/include + ) + +if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + DESTINATION include + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) +endif() + +if (NOT LIBXML2_FOUND AND NOT (CMAKE_SYSTEM_NAME MATCHES "Windows")) + # Skip Libxml2 on Windows. In CMake 3.4 and higher, the algorithm for + # finding libxml2 got "smarter", and it can now locate the version which is + # in gnuwin32, even though that version does not contain the headers that + # LLDB uses. + find_package(LibXml2) +endif() + +# Find libraries or frameworks that may be needed +if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + find_library(CARBON_LIBRARY Carbon) + find_library(FOUNDATION_LIBRARY Foundation) + find_library(CORE_FOUNDATION_LIBRARY CoreFoundation) + find_library(CORE_SERVICES_LIBRARY CoreServices) + find_library(SECURITY_LIBRARY Security) + find_library(DEBUG_SYMBOLS_LIBRARY DebugSymbols PATHS "/System/Library/PrivateFrameworks") + + add_definitions( -DLIBXML2_DEFINED ) + list(APPEND system_libs xml2 ${CURSES_LIBRARIES}) + list(APPEND system_libs ${CARBON_LIBRARY} ${FOUNDATION_LIBRARY} + ${CORE_FOUNDATION_LIBRARY} ${CORE_SERVICES_LIBRARY} ${SECURITY_LIBRARY} + ${DEBUG_SYMBOLS_LIBRARY}) + +else() + if (LIBXML2_FOUND) + add_definitions( -DLIBXML2_DEFINED ) + list(APPEND system_libs ${LIBXML2_LIBRARIES}) + include_directories(${LIBXML2_INCLUDE_DIR}) + endif() + +endif() + +if (HAVE_LIBPTHREAD) + list(APPEND system_libs pthread) +endif(HAVE_LIBPTHREAD) + +if (HAVE_LIBDL) + list(APPEND system_libs ${CMAKE_DL_LIBS}) +endif() + +if(LLDB_REQUIRES_EH) + set(LLDB_REQUIRES_RTTI ON) +else() + if(LLVM_COMPILER_IS_GCC_COMPATIBLE) + set(LLDB_COMPILE_FLAGS "${LLDB_COMPILE_FLAGS} -fno-exceptions") + elseif(MSVC) + add_definitions( -D_HAS_EXCEPTIONS=0 ) + set(LLDB_COMPILE_FLAGS "${LLDB_COMPILE_FLAGS} /EHs-c-") + endif() +endif() + +# Disable RTTI by default +if(NOT LLDB_REQUIRES_RTTI) + if (LLVM_COMPILER_IS_GCC_COMPATIBLE) + set(LLDB_COMPILE_FLAGS "${LLDB_COMPILE_FLAGS} -fno-rtti") + elseif(MSVC) + set(LLDB_COMPILE_FLAGS "${LLDB_COMPILE_FLAGS} /GR-") + endif() +endif() + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLDB_COMPILE_FLAGS}") + +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + # Check for syscall used by lldb-server on linux. + # If these are not found, it will fall back to ptrace (slow) for memory reads. + check_cxx_source_compiles(" + #include <sys/uio.h> + int main() { process_vm_readv(0, nullptr, 0, nullptr, 0, 0); return 0; }" + HAVE_PROCESS_VM_READV) + + if (HAVE_PROCESS_VM_READV) + add_definitions(-DHAVE_PROCESS_VM_READV) + else() + # If we don't have the syscall wrapper function, but we know the syscall number, we can + # still issue the syscall manually + check_cxx_source_compiles(" + #include <sys/syscall.h> + int main() { return __NR_process_vm_readv; }" + HAVE_NR_PROCESS_VM_READV) + + if (HAVE_NR_PROCESS_VM_READV) + add_definitions(-DHAVE_NR_PROCESS_VM_READV) + endif() + endif() +endif() + +# Figure out if lldb could use lldb-server. If so, then we'll +# ensure we build lldb-server when an lldb target is being built. +if ((CMAKE_SYSTEM_NAME MATCHES "Darwin") OR + (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") OR + (CMAKE_SYSTEM_NAME MATCHES "Linux") OR + (CMAKE_SYSTEM_NAME MATCHES "NetBSD")) + set(LLDB_CAN_USE_LLDB_SERVER 1) +else() + set(LLDB_CAN_USE_LLDB_SERVER 0) +endif() + +# Figure out if lldb could use debugserver. If so, then we'll +# ensure we build debugserver when we build lldb. +if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) + set(LLDB_CAN_USE_DEBUGSERVER 1) +else() + set(LLDB_CAN_USE_DEBUGSERVER 0) +endif() + +if (NOT LLDB_DISABLE_CURSES) + find_package(Curses REQUIRED) + + find_library(CURSES_PANEL_LIBRARY NAMES panel DOC "The curses panel library") + if (NOT CURSES_PANEL_LIBRARY) + message(FATAL_ERROR "A required curses' panel library not found.") + endif () + + # Add panels to the library path + set (CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_PANEL_LIBRARY}) + + list(APPEND system_libs ${CURSES_LIBRARIES}) + include_directories(${CURSES_INCLUDE_DIR}) +endif () diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake new file mode 100644 index 000000000000..d3955f1cdf6b --- /dev/null +++ b/cmake/modules/LLDBStandalone.cmake @@ -0,0 +1,99 @@ +# If we are not building as a part of LLVM, build LLDB as an +# standalone project, using LLVM as an external library: +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(lldb) + cmake_minimum_required(VERSION 2.8) + + option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF) + + set(LLDB_PATH_TO_LLVM_SOURCE "" CACHE PATH + "Path to LLVM source code. Not necessary if using an installed LLVM.") + set(LLDB_PATH_TO_LLVM_BUILD "" CACHE PATH + "Path to the directory where LLVM was built or installed.") + + set(LLDB_PATH_TO_CLANG_SOURCE "" CACHE PATH + "Path to Clang source code. Not necessary if using an installed Clang.") + set(LLDB_PATH_TO_CLANG_BUILD "" CACHE PATH + "Path to the directory where Clang was built or installed.") + + if (LLDB_PATH_TO_LLVM_SOURCE) + if (NOT EXISTS "${LLDB_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake") + message(FATAL_ERROR "Please set LLDB_PATH_TO_LLVM_SOURCE to the root " + "directory of LLVM source code.") + else() + get_filename_component(LLVM_MAIN_SRC_DIR ${LLDB_PATH_TO_LLVM_SOURCE} + ABSOLUTE) + set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include") + list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules") + endif() + endif() + + if (LLDB_PATH_TO_CLANG_SOURCE) + get_filename_component(CLANG_MAIN_SRC_DIR ${LLDB_PATH_TO_CLANG_SOURCE} + ABSOLUTE) + set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include") + endif() + + list(APPEND CMAKE_MODULE_PATH "${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake") + + if (LLDB_PATH_TO_LLVM_BUILD) + get_filename_component(PATH_TO_LLVM_BUILD ${LLDB_PATH_TO_LLVM_BUILD} + ABSOLUTE) + else() + message(FATAL_ERROR "Please set LLDB_PATH_TO_LLVM_BUILD to the root " + "directory of LLVM build or install site.") + endif() + + if (LLDB_PATH_TO_CLANG_BUILD) + get_filename_component(PATH_TO_CLANG_BUILD ${LLDB_PATH_TO_CLANG_BUILD} + ABSOLUTE) + else() + message(FATAL_ERROR "Please set LLDB_PATH_TO_CLANG_BUILD to the root " + "directory of Clang build or install site.") + endif() + + + # These variables are used by add_llvm_library. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) + set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) + + include(AddLLVM) + include(HandleLLVMOptions) + + if (PYTHON_EXECUTABLE STREQUAL "") + set(Python_ADDITIONAL_VERSIONS 3.5 3.4 3.3 3.2 3.1 3.0 2.7 2.6 2.5) + include(FindPythonInterp) + if( NOT PYTHONINTERP_FOUND ) + message(FATAL_ERROR + "Unable to find Python interpreter, required for builds and testing. + Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") + endif() + else() + message("-- Found PythonInterp: ${PYTHON_EXECUTABLE}") + endif() + # Import CMake library targets from LLVM and Clang. + include("${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake") + if (EXISTS "${LLDB_PATH_TO_CLANG_BUILD}/share/clang/cmake/ClangConfig.cmake") + include("${LLDB_PATH_TO_CLANG_BUILD}/share/clang/cmake/ClangConfig.cmake") + endif() + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") + + set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR}) + + set(CMAKE_INCLUDE_CURRENT_DIR ON) + include_directories("${PATH_TO_LLVM_BUILD}/include" + "${LLVM_MAIN_INCLUDE_DIR}" + "${PATH_TO_CLANG_BUILD}/include" + "${CLANG_MAIN_INCLUDE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/source") + link_directories("${PATH_TO_LLVM_BUILD}/lib${LLVM_LIBDIR_SUFFIX}" + "${PATH_TO_CLANG_BUILD}/lib${LLVM_LIBDIR_SUFFIX}") + + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) + + set(LLDB_BUILT_STANDALONE 1) +endif() diff --git a/cmake/platforms/Android.cmake b/cmake/platforms/Android.cmake new file mode 100644 index 000000000000..98b695be6ef6 --- /dev/null +++ b/cmake/platforms/Android.cmake @@ -0,0 +1,188 @@ +# Toolchain config for Android standalone NDK. +# +# Usage: +# build host llvm and clang first +# cmake -DCMAKE_TOOLCHAIN_FILE=../lldb/cmake/platforms/Android.cmake \ +# -DANDROID_TOOLCHAIN_DIR=<toolchain_dir> \ +# -DANDROID_ABI=<target_abi> \ +# -DCMAKE_CXX_COMPILER_VERSION=<gcc_version> \ +# -DLLVM_TARGET_ARCH=<llvm_target_arch> \ +# -DLLVM_TARGETS_TO_BUILD=<llvm_targets_to_build> \ +# -DLLVM_TABLEGEN=<path_to_llvm-tblgen> \ +# -DCLANG_TABLEGEN=<path_to_clang-tblgen> +# +# Current Support: +# ANDROID_ABI = x86, x86_64 +# CMAKE_CXX_COMPILER_VERSION = 4.9 +# LLVM_TARGET_ARCH = X86 +# LLVM_TARGETS_TO_BUILD = X86 +# LLVM_TABLEGEN = path to host llvm-tblgen +# CLANG_TABLEGEN = path to host clang-tblgen + +if( DEFINED CMAKE_CROSSCOMPILING ) + return() +endif() + +get_property( IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE ) +if( IS_IN_TRY_COMPILE ) + # this seems necessary and works fine but I'm unsure if it breaks anything + return() +endif() + +set( CMAKE_SYSTEM_NAME Linux ) +include( CMakeForceCompiler ) + +# flags and definitions +remove_definitions( -DANDROID -D__ANDROID__ ) +add_definitions( -DANDROID -D__ANDROID_NDK__ -DLLDB_DISABLE_LIBEDIT ) +set( ANDROID True ) +set( __ANDROID_NDK__ True ) +set( LLDB_DEFAULT_DISABLE_LIBEDIT True ) + +# linking lldb-server statically for Android avoids the need to ship two +# binaries (pie for API 21+ and non-pie for API 16-). It's possible to use +# a non-pie shim on API 16-, but that requires lldb-server to dynamically export +# its symbols, which significantly increases the binary size. Static linking, on +# the other hand, has little to no effect on the binary size. +if( NOT DEFINED LLVM_BUILD_STATIC ) + set( LLVM_BUILD_STATIC True CACHE INTERNAL "" FORCE ) + set( LLVM_ENABLE_PIC FALSE CACHE INTERNAL "" FORCE ) + set( BUILD_SHARED_LIBS FALSE CACHE INTERNAL "" FORCE ) +endif() + +set( ANDROID_ABI "${ANDROID_ABI}" CACHE INTERNAL "Android Abi" FORCE ) +if( ANDROID_ABI STREQUAL "x86" ) + set( CMAKE_SYSTEM_PROCESSOR "i686" ) + set( ANDROID_TOOLCHAIN_NAME "i686-linux-android" ) +elseif( ANDROID_ABI STREQUAL "x86_64" ) + set( CMAKE_SYSTEM_PROCESSOR "x86_64" ) + set( ANDROID_TOOLCHAIN_NAME "x86_64-linux-android" ) +elseif( ANDROID_ABI STREQUAL "armeabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) + set( ANDROID_TOOLCHAIN_NAME "arm-linux-androideabi" ) +elseif( ANDROID_ABI STREQUAL "aarch64" ) + set( CMAKE_SYSTEM_PROCESSOR "aarch64" ) + set( ANDROID_TOOLCHAIN_NAME "aarch64-linux-android" ) +elseif( ANDROID_ABI STREQUAL "mips" ) + set( CMAKE_SYSTEM_PROCESSOR "mips" ) + set( ANDROID_TOOLCHAIN_NAME "mipsel-linux-android" ) +elseif( ANDROID_ABI STREQUAL "mips64" ) + set( CMAKE_SYSTEM_PROCESSOR "mips64" ) + set( ANDROID_TOOLCHAIN_NAME "mips64el-linux-android" ) +else() + message( SEND_ERROR "Unknown ANDROID_ABI = \"${ANDROID_ABI}\"." ) +endif() + +set( ANDROID_TOOLCHAIN_DIR "${ANDROID_TOOLCHAIN_DIR}" CACHE PATH "Android standalone toolchain directory" ) +set( ANDROID_SYSROOT "${ANDROID_TOOLCHAIN_DIR}/sysroot" CACHE PATH "Android Sysroot" ) + +# CMAKE_EXECUTABLE_SUFFIX is undefined in CMAKE_TOOLCHAIN_FILE +if( WIN32 ) + set( EXECUTABLE_SUFFIX ".exe" ) +endif() + +set( PYTHON_EXECUTABLE "${ANDROID_TOOLCHAIN_DIR}/bin/python${EXECUTABLE_SUFFIX}" CACHE PATH "Python exec path" ) + +if( NOT CMAKE_C_COMPILER ) + set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-gcc${EXECUTABLE_SUFFIX}" CACHE PATH "C compiler" ) + set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-g++${EXECUTABLE_SUFFIX}" CACHE PATH "C++ compiler" ) + set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-gcc${EXECUTABLE_SUFFIX}" CACHE PATH "assembler" ) + set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-strip${EXECUTABLE_SUFFIX}" CACHE PATH "strip" ) + set( CMAKE_AR "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-ar${EXECUTABLE_SUFFIX}" CACHE PATH "archive" ) + set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-ld${EXECUTABLE_SUFFIX}" CACHE PATH "linker" ) + set( CMAKE_NM "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-nm${EXECUTABLE_SUFFIX}" CACHE PATH "nm" ) + set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-objcopy${EXECUTABLE_SUFFIX}" CACHE PATH "objcopy" ) + set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-objdump${EXECUTABLE_SUFFIX}" CACHE PATH "objdump" ) + set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-ranlib${EXECUTABLE_SUFFIX}" CACHE PATH "ranlib" ) +endif() + +set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT} -funwind-tables -fsigned-char -no-canonical-prefixes" ) +# TODO: different ARM abi have different flags such as neon, vfpv etc +if( X86 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) +elseif( ANDROID_ABI STREQUAL "armeabi" ) + # 64 bit atomic operations used in c++ libraries require armv7-a instructions + # armv5te and armv6 were tried but do not work. + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mthumb" ) + if( LLVM_BUILD_STATIC ) + # Temporary workaround for static linking with the latest API. + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -DANDROID_ARM_BUILD_STATIC" ) + endif() +elseif( ANDROID_ABI STREQUAL "mips" ) + # http://b.android.com/182094 + list( FIND LLDB_SYSTEM_LIBS atomic index ) + if( index EQUAL -1 ) + list( APPEND LLDB_SYSTEM_LIBS atomic ) + set( LLDB_SYSTEM_LIBS ${LLDB_SYSTEM_LIBS} CACHE INTERNAL "" FORCE ) + endif() + if( LLVM_BUILD_STATIC ) + # Temporary workaround for static linking with the latest API. + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -DANDROID_MIPS_BUILD_STATIC" ) + endif() +endif() + +# Use gold linker and enable safe ICF in case of x86, x86_64 and arm +if ( ANDROID_ABI STREQUAL "x86" OR + ANDROID_ABI STREQUAL "x86_64" OR + ANDROID_ABI STREQUAL "armeabi") + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold -Wl,--icf=safe" ) +endif() + +if( NOT LLVM_BUILD_STATIC ) + # PIE is required for API 21+ so we enable it if we're not statically linking + # unfortunately, it is not supported before API 16 so we need to do something + # else there see http://llvm.org/pr23457 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -pie -fPIE" ) +endif() + +# linker flags +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) +set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" ) + +# cache flags +set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" ) +set( CMAKE_C_FLAGS "" CACHE STRING "c flags" ) +set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" ) +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Android c/c++ flags" ) +set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Android c/c++ linker flags" ) + +# final flags +set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) +set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) +set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) + +# global includes and link directories +set( ANDROID_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_DIR}/include/c++/${ANDROID_COMPILER_VERSION}" ) +list( APPEND ANDROID_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_DIR}/include/python2.7" ) +include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_INCLUDE_DIRS} ) + +# target environment +set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_DIR}/bin" "${ANDROID_TOOLCHAIN_DIR}/${ANDROID_TOOLCHAIN_NAME}" "${ANDROID_SYSROOT}" ) + +# only search for libraries and includes in the ndk toolchain +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + +################# BEGIN EVIL HACK ################## +# lldb-server links against libdl even though it's not being used and +# libdl.a is currently missing from the toolchain (b.android.com/178517). +# Therefore, in order to statically link lldb-server, we need a temporary +# workaround. This creates a dummy libdl.a stub until the actual +# libdl.a can be implemented in the toolchain. +if( LLVM_BUILD_STATIC ) + set( libdl "${CMAKE_BINARY_DIR}/libdl_stub" ) + file( MAKE_DIRECTORY ${libdl} ) + file( WRITE "${libdl}/libdl.c" " +#include <dlfcn.h> +void * dlopen (const char *filename, int flag) { return 0; } +const char * dlerror (void) { return 0; } +void * dlsym (void *handle, const char *symbol) { return 0; } +int dlclose (void *handle) { return 0; }") + set( flags "${CMAKE_C_FLAGS}" ) + separate_arguments( flags ) + execute_process( COMMAND ${CMAKE_C_COMPILER} ${flags} -c ${libdl}/libdl.c -o ${libdl}/libdl.o ) + execute_process( COMMAND ${CMAKE_AR} rcs ${libdl}/libdl.a ${libdl}/libdl.o ) + set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${libdl}" ) +endif() +################# END EVIL HACK ################## |