Description: Change build to use system libraries.
 Default build system using its own boost and llvm source to build ycm_core
 python plugin. This patch changes build system to use system libraries.
 .
 The following changes have been made to use system libraries:
 .
 cpp/CMakeLists.txt:
   * BoostParts directory removed from source, this patch also removes
     BoostParts build
 cpp/ycm/CMakeLists.txt:
   * Use find_package to find system Boost libraries and required components:
     system python regex filesystem
   * USE_SYSTEM_LIBCLANG option set to ON
   * Use file function to find llvm include directory
   * Remove BoostParts_SOURCE_DIR and CLANG_INCLUDES_DIR from
     include_directories
   * Add Boost_INCLUDE_DIR and SYS_LLVM_INCLUDE_PATHS (find function used
     to set this variable) to include_directories. Python modules not needed
     to link libpython in Debian: [python-policy, #s2.1]
   * Use clang and its versions in find_library for linker
   * Remove non standart library locations in find_library for clang
   * Remove link to librt. I don't know why upstream author thinks it's
     necessary to link librt under Linux. ycm_core works fine without librt.
   * Remove BoostParts and PYTHON_LIBRARIES from target_link_libraries for
     both CLIENT_LIB and SERVER_LIB
   * Remove copy command in post build
   * Remove non-default LIBRARY_OUTPUT_DIRECTORY
 cpp/ycm/tests/CMakeLists.txt:
   * Use Debian's gmock subdirectory (/usr/src/gmock)
   * Add Boost_LIBRARIES and PYTHON_LIBRARIES to target_link_libraries
Author: Onur Aslan <onur@onur.im>
Forwarded: not-needed

--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -166,5 +166,4 @@
     "Your C++ compiler does NOT support C++11, compiling in C++03 mode." )
 endif()
 
-add_subdirectory( BoostParts )
 add_subdirectory( ycm )
--- a/cpp/ycm/CMakeLists.txt
+++ b/cpp/ycm/CMakeLists.txt
@@ -23,6 +23,7 @@
 
 set( Python_ADDITIONAL_VERSIONS 2.7 2.6 )
 find_package( PythonLibs 2.6 REQUIRED )
+find_package( Boost 1.53 COMPONENTS system python regex filesystem REQUIRED )
 
 if ( NOT PYTHONLIBS_VERSION_STRING VERSION_LESS "3.0.0" )
   message( FATAL_ERROR
@@ -32,7 +33,7 @@
 
 option( USE_DEV_FLAGS "Use compilation flags meant for YCM developers" OFF )
 option( USE_CLANG_COMPLETER "Use Clang semantic completer for C/C++/ObjC" OFF )
-option( USE_SYSTEM_LIBCLANG "Set to ON to use the system libclang library" OFF )
+option( USE_SYSTEM_LIBCLANG "Set to ON to use the system libclang library" ON )
 set( PATH_TO_LLVM_ROOT "" CACHE PATH "Path to the root of a LLVM+Clang binary distribution" )
 set( EXTERNAL_LIBCLANG_PATH "" CACHE PATH  "Path libclang library to use" )
 
@@ -135,15 +136,19 @@
   set( CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem " )
 endif()
 
+
+# Find llvm include dir
+file (GLOB SYS_LLVM_INCLUDE_PATHS /usr/lib/llvm-3.*/include)
+
 # The SYSTEM flag makes sure that -isystem[header path] is passed to the
 # compiler instead of the standard -I[header path]. Headers included with
 # -isystem do not generate warnings (and they shouldn't; e.g. boost warnings are
 # just noise for us since we won't be changing them).
 include_directories(
   SYSTEM
-  ${BoostParts_SOURCE_DIR}
+  ${Boost_INCLUDE_DIR}
   ${PYTHON_INCLUDE_DIRS}
-  ${CLANG_INCLUDES_DIR}
+  ${SYS_LLVM_INCLUDE_PATHS}
   )
 
 file( GLOB_RECURSE SERVER_SOURCES *.h *.cpp )
@@ -193,14 +198,13 @@
     # On Debian-based systems, llvm installs into /usr/lib/llvm-x.y.
     file( GLOB SYS_LLVM_PATHS "/usr/lib/llvm*/lib" )
     # Need TEMP because find_library does not work with an option variable
-    find_library( TEMP clang
+    find_library( TEMP
+                  clang-3.3
+                  clang-3.4
+                  clang-3.5
                   PATHS
                   ${ENV_LIB_PATHS}
-                  /usr/lib
-                  /usr/lib/llvm
-                  ${SYS_LLVM_PATHS}
-                  /Library/Developer/CommandLineTools/usr/lib,
-                  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib )
+                  )
     set( EXTERNAL_LIBCLANG_PATH ${TEMP} )
   else()
     # For Macs, we do things differently; look further in this file.
@@ -223,11 +227,6 @@
   set( CMAKE_INSTALL_RPATH "${EXTRA_RPATH}:${CMAKE_INSTALL_RPATH}" )
 endif()
 
-# Needed on Linux machines, but not on Macs
-if ( UNIX AND NOT APPLE )
-  set( EXTRA_LIBS rt )
-endif()
-
 #############################################################################
 
 # We don't actually need all of the files this picks up, just the ones needed by
@@ -245,9 +244,8 @@
            )
 
 target_link_libraries( ${CLIENT_LIB}
-                       BoostParts
-                       ${PYTHON_LIBRARIES}
                        ${EXTRA_LIBS}
+                       ${Boost_LIBRARIES}
                      )
 
 #############################################################################
@@ -257,26 +255,11 @@
            )
 
 target_link_libraries( ${SERVER_LIB}
-                       BoostParts
-                       ${PYTHON_LIBRARIES}
                        ${LIBCLANG_TARGET}
                        ${EXTRA_LIBS}
+                       ${Boost_LIBRARIES}
                      )
 
-if( LIBCLANG_TARGET )
-  if( NOT WIN32 )
-    add_custom_command(
-      TARGET ${SERVER_LIB}
-      POST_BUILD
-      COMMAND ${CMAKE_COMMAND} -E copy "${LIBCLANG_TARGET}" "$<TARGET_FILE_DIR:${SERVER_LIB}>"
-    )
-  else()
-    add_custom_command(
-      TARGET ${SERVER_LIB}
-      POST_BUILD
-      COMMAND ${CMAKE_COMMAND} -E copy "${PATH_TO_LLVM_ROOT}/bin/libclang.dll" "$<TARGET_FILE_DIR:${SERVER_LIB}>")
-  endif()
-endif()
 
 #############################################################################
 
@@ -326,11 +309,6 @@
   set_target_properties( ${SERVER_LIB} PROPERTIES SUFFIX ".so")
 endif()
 
-set_target_properties( ${CLIENT_LIB} PROPERTIES
-  LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../python )
-set_target_properties( ${SERVER_LIB} PROPERTIES
-  LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../python )
-
 #############################################################################
 
 
--- a/cpp/ycm/tests/CMakeLists.txt
+++ b/cpp/ycm/tests/CMakeLists.txt
@@ -25,7 +25,7 @@
     "${CMAKE_CXX_FLAGS} -Wno-long-long -Wno-variadic-macros -Wno-missing-field-initializers -Wno-unused-private-field" )
 endif()
 
-add_subdirectory( gmock )
+add_subdirectory( /usr/src/gmock gmock )
 
 include_directories(
   ${ycm_support_libs_SOURCE_DIR}
@@ -69,6 +69,8 @@
 target_link_libraries( ${PROJECT_NAME}
                        ${SERVER_LIB}
                        ${CLIENT_LIB}
+                       ${Boost_LIBRARIES}
+                       ${PYTHON_LIBRARIES}
                        gmock )
 
 
