[Lldb-commits] [lldb] r176306 - Finish up CMake support for LLDB (tested on Linux)

Daniel Malea daniel.malea at intel.com
Thu Feb 28 15:11:46 PST 2013


Author: dmalea
Date: Thu Feb 28 17:11:46 2013
New Revision: 176306

URL: http://llvm.org/viewvc/llvm-project?rev=176306&view=rev
Log:
Finish up CMake support for LLDB (tested on Linux)
- add missing scripts (driver, tests, etc...)
- enable running of tests from cmake with "make check-lldb" target
- fix up problem with clang dependencies (this enables parallel builds)
- implement platform-specific FIXMEs in source/CMakeLists.txt



Added:
    lldb/trunk/CMakeLists.txt
    lldb/trunk/scripts/CMakeLists.txt
    lldb/trunk/test/CMakeLists.txt
    lldb/trunk/tools/CMakeLists.txt
    lldb/trunk/tools/driver/CMakeLists.txt
Modified:
    lldb/trunk/source/CMakeLists.txt
    lldb/trunk/source/Core/CMakeLists.txt

Added: lldb/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/CMakeLists.txt?rev=176306&view=auto
==============================================================================
--- lldb/trunk/CMakeLists.txt (added)
+++ lldb/trunk/CMakeLists.txt Thu Feb 28 17:11:46 2013
@@ -0,0 +1,187 @@
+# 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)
+
+  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.")    
+
+  set(LLDB_DISABLE_PYTHON 1 BOOL "Disables the Python scripting integration.")
+
+  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)
+      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)
+  endif()  
+
+  list(APPEND CMAKE_MODULE_PATH "${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake")
+
+  get_filename_component(PATH_TO_LLVM_BUILD ${LLDB_PATH_TO_LLVM_BUILD}
+                         ABSOLUTE)
+                         
+  get_filename_component(PATH_TO_CLANG_BUILD ${LLDB_PATH_TO_CLANG_BUILD}
+                         ABSOLUTE)                         
+                         
+  include(AddLLVM)
+  include("${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake")
+  include(HandleLLVMOptions)
+
+  set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
+
+  set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
+  set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR})
+  
+  set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
+
+  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"
+                   "${PATH_TO_CLANG_BUILD}/lib")
+
+  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+
+  set(LLDB_BUILT_STANDALONE 1)
+  
+  if (LLDB_DISABLE_PYTHON)
+    add_definitions( -DLLDB_DISABLE_PYTHON )
+  endif() 
+endif()
+
+macro(add_lldb_definitions)
+  # We don't want no semicolons on LLDB_DEFINITIONS:
+  foreach(arg ${ARGN})
+    set(LLDB_DEFINITIONS "${LLVM_DEFINITIONS} ${arg}")
+  endforeach(arg)
+  add_definitions( ${ARGN} )
+endmacro(add_lldb_definitions)
+
+include_directories(/usr/include/python2.7)
+include_directories(../clang/include)
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
+set(CMAKE_CXX_FLAGS "-std=c++11")
+
+# Disable MSVC warnings
+if( MSVC )
+  add_lldb_definitions(
+    -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'
+    -wd4068 # Suppress 'warning C4068: unknown pragma'
+    -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'
+    -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'
+  )
+endif() 
+
+set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+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()
+
+macro(add_lldb_library name)
+  llvm_process_sources(srcs ${ARGN})
+  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 (MODULE)
+    set(libkind MODULE)
+  elseif (SHARED_LIBRARY)
+    set(libkind SHARED)
+  else()
+    set(libkind STATIC)
+  endif()
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+  add_library(${name} ${libkind} ${srcs})
+  #if (LLVM_COMMON_DEPENDS)
+  ##add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
+  #endif()
+
+  if(LLDB_USED_LIBS)
+    target_link_libraries(${name} -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group)
+  endif()
+  target_link_libraries(${name} ${CLANG_USED_LIBS})
+  target_link_libraries(${name} ${LLVM_USED_LIBS})
+  llvm_config(${name} ${LLVM_LINK_COMPONENTS})
+  target_link_libraries(${name} ${LLVM_COMMON_LIBS})
+  link_system_libs(${name})
+  if (LLVM_COMMON_DEPENDS)
+    add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
+  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.
+  set (LLDB_DEPENDENCIES
+    ClangDiagnosticCommon
+    #ClangDiagnosticFrontend
+    #libclang.so
+    )
+  add_dependencies(${name} ${LLDB_DEPENDENCIES})
+
+  install(TARGETS ${name}
+    LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+    ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+  set_target_properties(${name} PROPERTIES FOLDER "lldb libraries")
+endmacro(add_lldb_library)
+
+macro(add_lldb_executable name)
+  #add_llvm_executable(${name} ${ARGN})
+  llvm_process_sources( ALL_FILES ${ARGN} )
+  add_executable(${name} ${ALL_FILES})
+  #target_link_libraries(${name} ${CLANG_USED_LIBS})
+  #llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
+  #link_system_libs( ${name} )
+  #if (LLVM_COMMON_DEPENDS)
+  #add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
+  #endif()
+  set_target_properties(${name} PROPERTIES FOLDER "lldb executables")
+endmacro(add_lldb_executable)
+
+include_directories(BEFORE
+  ${CMAKE_CURRENT_BINARY_DIR}/include
+  ${CMAKE_CURRENT_SOURCE_DIR}/include
+  )
+
+install(DIRECTORY include/
+  DESTINATION include
+  FILES_MATCHING
+  PATTERN "*.h"
+  PATTERN ".svn" EXCLUDE
+  )
+
+#add_subdirectory(include)
+add_subdirectory(scripts)
+add_subdirectory(source)
+add_subdirectory(test)
+add_subdirectory(tools)

Added: lldb/trunk/scripts/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/CMakeLists.txt?rev=176306&view=auto
==============================================================================
--- lldb/trunk/scripts/CMakeLists.txt (added)
+++ lldb/trunk/scripts/CMakeLists.txt Thu Feb 28 17:11:46 2013
@@ -0,0 +1,15 @@
+set(LLVM_NO_RTTI 1)
+
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
+  DEPENDS ${LLDB_SOURCE_DIR}/scripts/lldb.swig
+  # swig was directly invoked on Windows (where the Python API is not being generated) but on other platforms, we need to run the *swig-wrapper-classes.sh shell-scripts.
+  #COMMAND swig -c++ -shadow -python -I${LLDB_SOURCE_DIR}/include -I./. -outdir ${LLDB_SOURCE_DIR}/scripts/Python  -o ${LLDB_SOURCE_DIR}/source/LLDBWrapPython.cpp ${LLDB_SOURCE_DIR}/scripts/lldb.swig
+  COMMAND SRCROOT=${LLDB_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/build-swig-wrapper-classes.sh ${LLDB_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR} -debug -m
+  COMMAND SRCROOT=${LLDB_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/finish-swig-wrapper-classes.sh ${LLDB_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR} -debug -m
+  COMMENT "Building lldb python wrapper")
+set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp PROPERTIES GENERATED 1)
+
+ADD_CUSTOM_TARGET(swig_wrapper ALL echo
+    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
+    )

Modified: lldb/trunk/source/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/CMakeLists.txt?rev=176306&r1=176305&r2=176306&view=diff
==============================================================================
--- lldb/trunk/source/CMakeLists.txt (original)
+++ lldb/trunk/source/CMakeLists.txt Thu Feb 28 17:11:46 2013
@@ -1,10 +1,11 @@
 include_directories(.)
 
-# FIXME: these includes should be enabled only for Linux builds
+if ( CMAKE_SYSTEM_NAME MATCHES "Linux" )
 include_directories(
   Plugins/Process/Linux
   Plugins/Process/POSIX
   )
+endif ()
 
 add_subdirectory(API)
 add_subdirectory(Breakpoint)
@@ -27,7 +28,6 @@ set( LLDB_USED_LIBS
   lldbHostCommon
   lldbCore
   lldbExpression
-  #lldbInitAndLog
   lldbInterpreter
   lldbSymbol
   lldbTarget  
@@ -63,21 +63,28 @@ set( LLDB_USED_LIBS
   lldbPluginABIMacOSX_i386
   lldbPluginABISysV_x86_64
   lldbPluginInstructionARM
-  lldbPluginOSPython
-
-  
-  # Windows (FIXME: detect host OS and enable below if Windows)
-  #lldbHostWindows
-  #lldbPluginPlatformWindows
   lldbPluginObjectFilePECOFF
-  #Ws2_32
-  
-  # Linux (FIXME: detect host OS and enable below if Linux)
-  lldbHostLinux
-  lldbPluginProcessLinux
-  lldbPluginProcessPOSIX
+  lldbPluginOSPython
   )
-  
+
+# Windows-only libraries
+if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
+  list(APPEND LLDB_USED_LIBS
+    #lldbHostWindows
+    #lldbPluginPlatformWindows
+    #Ws2_32
+    )
+endif ()
+
+# Linux-only libraries
+if ( CMAKE_SYSTEM_NAME MATCHES "Linux" )
+  list(APPEND LLDB_USED_LIBS
+    lldbHostLinux
+    lldbPluginProcessLinux
+    lldbPluginProcessPOSIX
+    )
+endif ()
+
 set( CLANG_USED_LIBS
   clangAnalysis
   clangAST
@@ -127,6 +134,26 @@ add_lldb_library(liblldb
   ${CMAKE_CURRENT_BINARY_DIR}/../scripts/LLDBWrapPython.cpp
   )
 set_target_properties(liblldb PROPERTIES OUTPUT_NAME lldb)
+
+# Determine LLDB revision and repository. GetSourceVersion and GetRepositoryPath are shell-scripts, and as
+# such will not work on Windows.
+if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
+  execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLDB_SOURCE_DIR}
+                  OUTPUT_VARIABLE LLDB_REVISION)
+  string(REGEX REPLACE "(\r?\n)+$" "" LLDB_REVISION ${LLDB_REVISION})
+
+  execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLDB_SOURCE_DIR}
+                  OUTPUT_VARIABLE LLDB_REPOSITORY)
+  string(REGEX REPLACE "(\r?\n)+$" "" LLDB_REPOSITORY ${LLDB_REPOSITORY})
+  string(REPLACE " " "" LLDB_REPOSITORY ${LLDB_REPOSITORY})
+
+  set_property(
+    SOURCE lldb.cpp
+    PROPERTY COMPILE_DEFINITIONS "LLDB_REVISION=\"${LLDB_REVISION}\"" "LLDB_REPOSITORY=\"${LLDB_REPOSITORY}\"")
+endif ()
+# FIXME: implement svn/git revision and repository parsing solution on Windows. There is an SVN-only
+#        revision parsing solution in tools/clang/lib/Basic/CMakelists.txt.
+
 target_link_libraries(liblldb ${LLDB_SYSTEM_LIBS})
 add_dependencies(liblldb swig_wrapper)
 

Modified: lldb/trunk/source/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/CMakeLists.txt?rev=176306&r1=176305&r2=176306&view=diff
==============================================================================
--- lldb/trunk/source/Core/CMakeLists.txt (original)
+++ lldb/trunk/source/Core/CMakeLists.txt Thu Feb 28 17:11:46 2013
@@ -74,3 +74,12 @@ add_lldb_library(lldbCore
   VMRange.cpp
   #Windows.cpp
   )
+
+#FIXME: Below we append -frtti to cxa_demangle.cpp (and let the compiler choose to ignore the
+#       -fno-rtti that is added due to LLVM_NO_RTTI at the top of this file.) It would be
+#       better to replace -fno-rtti with -frtti rather than just appending the latter option.
+set_property(
+  SOURCE cxa_demangle.cpp
+  PROPERTY COMPILE_FLAGS -frtti
+  )
+

Added: lldb/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/CMakeLists.txt?rev=176306&view=auto
==============================================================================
--- lldb/trunk/test/CMakeLists.txt (added)
+++ lldb/trunk/test/CMakeLists.txt Thu Feb 28 17:11:46 2013
@@ -0,0 +1,51 @@
+function(add_python_test_target name test_script args comment)
+  set(PYTHON_TEST_COMMAND
+    ${PYTHON_EXECUTABLE}
+    ${test_script}
+    ${args}
+    )
+
+  add_custom_target(${name}
+    COMMAND ${PYTHON_TEST_COMMAND} ${ARG_DEFAULT_ARGS}
+    COMMENT "${comment}"
+    )
+endfunction()
+
+# Users can override LLDB_TEST_ARGS to modify the way LLDB tests are run. See help below.
+set(LLDB_TEST_ARGS
+  -C
+  ${CMAKE_C_COMPILER}
+  CACHE STRING "Specify compiler(s) and architecture(s) with which run LLDB tests. For example: '-C gcc -C clang -A i386 -A x86_64'"
+  )
+string(REPLACE " " ";" LLDB_TEST_ARGS ${LLDB_TEST_ARGS})
+
+set(LLDB_TRACE_DIR "${CMAKE_BINARY_DIR}/lldb-test-traces"
+  CACHE STRING "Set directory to output LLDB test traces (for tests that do not pass.)"
+  )
+
+set(LLDB_COMMON_TEST_ARGS
+  #--headers
+  #${LLDB_SOURCE_DIR}/include
+  --executable
+  ${CMAKE_BINARY_DIR}/bin/lldb
+  -s
+  ${LLDB_TRACE_DIR}
+  )
+
+add_python_test_target(check-lldb-single
+  ${LLDB_SOURCE_DIR}/test/dotest.py
+  "${LLDB_COMMON_TEST_ARGS};${LLDB_TEST_ARGS}"
+  "Testing LLDB with args: ${LLDB_COMMON_TEST_ARGS};${LLDB_TEST_ARGS}"
+  )
+
+set(LLDB_DOSEP_ARGS
+  -o;\"-q;${LLDB_COMMON_TEST_ARGS};${LLDB_TEST_ARGS}\"
+  )
+
+# If tests crash cause LLDB to crash, or things are otherwise unstable, or if machine-parsable
+# output is desired (i.e. in continuous integration contexts) check-lldb-sep is a better target.
+add_python_test_target(check-lldb
+  ${LLDB_SOURCE_DIR}/test/dosep.ty
+  "${LLDB_DOSEP_ARGS}"
+  "Testing LLDB (with a separate subprocess per test) with args: ${LLDB_COMMON_TEST_ARGS};${LLDB_TEST_ARGS}"
+  )

Added: lldb/trunk/tools/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/CMakeLists.txt?rev=176306&view=auto
==============================================================================
--- lldb/trunk/tools/CMakeLists.txt (added)
+++ lldb/trunk/tools/CMakeLists.txt Thu Feb 28 17:11:46 2013
@@ -0,0 +1,2 @@
+#add_subdirectory(debugserver)
+add_subdirectory(driver)

Added: lldb/trunk/tools/driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/CMakeLists.txt?rev=176306&view=auto
==============================================================================
--- lldb/trunk/tools/driver/CMakeLists.txt (added)
+++ lldb/trunk/tools/driver/CMakeLists.txt Thu Feb 28 17:11:46 2013
@@ -0,0 +1,16 @@
+set(LLVM_NO_RTTI 1)
+add_lldb_executable(lldb
+  Driver.cpp
+  #DriverEvents.cpp
+  #DriverOptions.cpp
+  #DriverPosix.cpp
+  IOChannel.cpp
+  )
+
+target_link_libraries(lldb liblldb)
+# TODO: why isn't this done by add_lldb_executable?
+#target_link_libraries(lldb ${LLDB_USED_LIBS})
+#llvm_config(lldb ${LLVM_LINK_COMPONENTS})
+
+install(TARGETS lldb
+  RUNTIME DESTINATION bin)





More information about the lldb-commits mailing list