Skip to content

Commit

Permalink
Add system header directories to user flags
Browse files Browse the repository at this point in the history
  • Loading branch information
micbou committed Aug 28, 2018
1 parent 3869152 commit 25839f8
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 242 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*.la
*.a

# Executables
ycm_fake_clang*

# Clang archives
clang_archives

Expand Down
2 changes: 1 addition & 1 deletion CORE_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
39
40
20 changes: 5 additions & 15 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,22 +530,12 @@ def BuildYcmdLib( cmake, cmake_common_args, script_args ):
quiet = script_args.quiet,
status_message = 'Generating ycmd build configuration' )

build_targets = [ 'ycm_core' ]
if script_args.core_tests:
build_targets.append( 'ycm_core_tests' )
if 'YCM_BENCHMARK' in os.environ:
build_targets.append( 'ycm_core_benchmarks' )

build_config = GetCMakeBuildConfiguration( script_args )

for target in build_targets:
build_command = ( [ cmake, '--build', '.', '--target', target ] +
build_config )
CheckCall( build_command,
exit_message = BUILD_ERROR_MESSAGE,
quiet = script_args.quiet,
status_message = 'Compiling ycmd target: {0}'.format(
target ) )
build_command = [ cmake, '--build', '.' ] + build_config
CheckCall( build_command,
exit_message = BUILD_ERROR_MESSAGE,
quiet = script_args.quiet,
status_message = 'Compiling ycmd' )

if script_args.core_tests:
RunYcmdTests( script_args, build_dir )
Expand Down
12 changes: 7 additions & 5 deletions cpp/ycm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,10 @@ set( PYBIND11_INCLUDES_DIR "${CMAKE_SOURCE_DIR}/pybind11" )

file( GLOB_RECURSE SERVER_SOURCES *.h *.cpp )

# The test and benchmark sources are a part of a different target, so we remove
# them. The CMakeFiles cpp file is picked up when the user creates an in-source
# build, and we don't want that. We also remove client-specific code.
file( GLOB_RECURSE to_remove tests/*.h tests/*.cpp benchmarks/*.h
benchmarks/*.cpp CMakeFiles/*.cpp *client* )
# The tests, benchmarks, and fake_clang sources are a part of a different
# target, so we remove them. The CMakeFiles cpp file is picked up when the user
# creates an in-source build, and we don't want that.
file( GLOB_RECURSE to_remove tests/* benchmarks/* fake_clang/* CMakeFiles/* )

if( to_remove )
list( REMOVE_ITEM SERVER_SOURCES ${to_remove} )
Expand Down Expand Up @@ -460,6 +459,9 @@ if( SYSTEM_IS_OPENBSD OR SYSTEM_IS_FREEBSD )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread" )
endif()

if ( USE_CLANG_COMPLETER )
add_subdirectory( fake_clang )
endif()
if ( DEFINED ENV{YCM_TESTRUN} )
add_subdirectory( tests )
endif()
Expand Down
38 changes: 38 additions & 0 deletions cpp/ycm/fake_clang/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (C) 2018 ycmd contributors
#
# This file is part of ycmd.
#
# ycmd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ycmd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ycmd. If not, see <http://www.gnu.org/licenses/>.

project( ycm_fake_clang )
cmake_minimum_required( VERSION 2.8 )

include_directories( ${ycm_core_SOURCE_DIR} )

add_executable( ${PROJECT_NAME} main.cpp )

target_link_libraries( ${PROJECT_NAME}
${LIBCLANG_TARGET} )

# Build ycm_fake_clang in ycmd root folder.
if ( MSVC )
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set_target_properties( ${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/../../.. )
endforeach()
else()
set_target_properties( ${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../.. )
endif()
42 changes: 42 additions & 0 deletions cpp/ycm/fake_clang/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2018 ycmd contributors
//
// This file is part of ycmd.
//
// ycmd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ycmd is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ycmd. If not, see <http://www.gnu.org/licenses/>.

#include <clang-c/Index.h>
#include <iostream>

// This small program simulates the output of the clang executable when ran with
// the -E and -v flags. It takes a list of flags as arguments and creates the
// corresponding translation unit. When retrieving user flags, ycmd executes
// this program as follows
//
// ycm_fake_clang -resource-dir=... [flag ...] -E -v filename
//
// and extract the list of system header paths from the output. These
// directories are then added to the list of flags to provide completion of
// system headers in include statements and allow jumping to these headers.
int main( int argc, char **argv ) {
CXIndex index = clang_createIndex( 0, 0 );
CXTranslationUnit tu;
CXErrorCode result = clang_parseTranslationUnit2FullArgv(
index, nullptr, argv, argc, nullptr, 0, CXTranslationUnit_None, &tu );
if ( result != CXError_Success ) {
return EXIT_FAILURE;
}

clang_disposeTranslationUnit( tu );
return EXIT_SUCCESS;
}
Loading

0 comments on commit 25839f8

Please sign in to comment.