Created
October 20, 2017 11:00
-
-
Save Squareys/fde8c47f4244c00a10443e0b255033d0 to your computer and use it in GitHub Desktop.
YCM Configuration for UE4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# YCM configuration for Unreal Engine 4 projects | |
# | |
# Parses a generated Visual Studio project file and extracts its | |
# include dirs and symbols to be passed on to ycm/libclang. | |
# | |
# Note: For me this worked only on some files, but crashed ycm on others | |
# (using YCM with libclang-3.9.?, if I remember correctly...). May work | |
# better with newer versions? | |
# | |
import os | |
import xml.etree.ElementTree | |
def FlagsForFile(filename, **kwargs): | |
project_name = "" # TODO: Your project name here! | |
flags = ['-x', 'c++', '-Wall', '-Wextra', '-Werror', '-std=c++11'] | |
debug = False | |
cur_dir = os.path.dirname(os.path.abspath(__file__)) | |
# Read {project_name}.vcxproj xml file and get definitions and includes | |
last_dir = os.curdir | |
os.chdir(os.path.join(cur_dir, "Intermediate/ProjectFiles/")) | |
proj = xml.etree.ElementTree.parse("{project_name}.vcxproj".format(project_name=project_name)).getroot() | |
prefix = "{http://schemas.microsoft.com/developer/msbuild/2003}" | |
for g in proj.findall(prefix + "PropertyGroup"): | |
definitions = g.find(prefix + "NMakePreprocessorDefinitions") | |
if definitions is not None: | |
definitions = ["".join(["-D", d]) for d in definitions.text.split(';')] | |
if debug: | |
for d in definitions[1:]: | |
print(d) | |
flags.extend(definitions[1:]) | |
includes = g.find(prefix + "NMakeIncludeSearchPath") | |
if includes is not None: | |
incs = [] | |
for d in includes.text.split(';'): | |
if d.endswith("Public") or d.endswith("Classes") or project_name in d: | |
if os.path.isdir(d): | |
incs.append(d) | |
elif debug: | |
print("No such path:" + d) | |
include_dirs = ["".join(["-I", os.path.abspath(d).replace("\\", "/")]) for d in incs] | |
include_dirs = ["Source/{project_name}/"] | |
for dir in include_dirs: | |
flags.extend(['-I', os.path.join(cur_dir, dir.format(project_name=project_name))]) | |
os.chdir(last_dir) | |
return {"flags": flags, "do_cache": True} | |
FlagsForFile("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment