Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/DFHack/dfhack into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
PeridexisErrant committed Feb 1, 2016
2 parents d17b3db + 91f8583 commit 9a81fb1
Show file tree
Hide file tree
Showing 108 changed files with 4,508 additions and 1,339 deletions.
42 changes: 10 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
# linux backup files
*~

#Kdevelop project file
#Kdevelop project files
*.kdev4

# compiled binaries
output/*

# this one is important, track it
!output/Memory.xml

# a file generated by cmake
dfhack/include/config.h
library/private/config.h
.kdev4

# any build folders
build*/
nix
buntu
build/VC2010

#except for the real one
!build/

# Sphinx generated documentation
docs/_*
docs/html/

#except for the real one
!build/

# in-place build
build/Makefile
build/CMakeCache.txt
Expand All @@ -35,27 +26,17 @@ build/CMakeFiles
build/doc
build/lua
build/bin
build/depends
build/library
build/tools
build/plugins
build/depends
build/scripts
build/install_manifest.txt
build/README.html
build/LUA_API.html
build/COMPILE.html

#ignore Kdevelop stuff
.kdev4

#fake curses header
examples/fake-curses.h
build/_CPack_Packages
build/dfhack-*.zip
build/dfhack-*.bz2

# Python binding binaries
*.pyc
dfhack/python/pydfhack/_pydfhack.so
dfhack/python/PyDFHack.egg-info
dfhack/python/build
dfhack/python/dist

# CPack stuff
build/CPack*Config.cmake
Expand All @@ -71,6 +52,3 @@ tags

# Mac OS X .DS_Store files
.DS_Store

# autogenerated include-all.rst files
**include-all.rst
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ script:
- sh travis/git-info.sh
- python travis/pr-check-base.py
- python travis/lint.py
- python travis/authors-rst.py
- python travis/script-in-readme.py
- python travis/script-syntax.py --ext=lua --cmd="luac5.2 -p"
- python travis/script-syntax.py --ext=rb --cmd="ruby -c" --path scripts/
- mkdir build-travis
- cd build-travis
- cmake .. && make -j3
- cmake .. -DBUILD_DOCS:BOOL=ON
- make -j3
notifications:
email: false
130 changes: 130 additions & 0 deletions .ycm_extra_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
'''This file provides editor completions while working on DFHack using ycmd:
https://github.com/Valloric/ycmd
'''

# pylint: disable=import-error,invalid-name,missing-docstring,unused-argument

import os
import ycm_core

def DirectoryOfThisScript():
return os.path.dirname(os.path.abspath(__file__))

# We need to tell YouCompleteMe how to compile this project. We do this using
# clang's "Compilation Database" system, which essentially just dumps a big
# json file into the build folder.
# More details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# We don't use clang, but luckily CMake supports generating a database on its
# own, using:
# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )

for potential_build_folder in ['build', 'build-osx']:
if os.path.exists(DirectoryOfThisScript() + os.path.sep + potential_build_folder
+ os.path.sep + 'compile_commands.json'):
database = ycm_core.CompilationDatabase(potential_build_folder)
break
else:
raise RuntimeError("Can't find dfhack build folder: not one of build, build-osx")


def MakeRelativePathsInFlagsAbsolute(flags, working_directory):
if not working_directory:
return list(flags)
new_flags = []
make_next_absolute = False
path_flags = ['-isystem', '-I', '-iquote', '--sysroot=']
for flag in flags:
new_flag = flag

if make_next_absolute:
make_next_absolute = False
if not flag.startswith('/'):
new_flag = os.path.join(working_directory, flag)

for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break

if flag.startswith(path_flag):
path = flag[len(path_flag):]
new_flag = path_flag + os.path.join(working_directory, path)
break

if new_flag:
new_flags.append(new_flag)
return new_flags


def IsHeaderFile(filename):
extension = os.path.splitext(filename)[1]
return extension in ['.h', '.hxx', '.hpp', '.hh']


SOURCE_EXTENSIONS = ['.cpp', '.cxx', '.cc', '.c', '.m', '.mm']

def PotentialAlternatives(header):
dirname, filename = os.path.split(header)
basename, _ = os.path.splitext(filename)

source_dirs = [dirname]

if dirname.endswith(os.path.sep + 'include'):
# if we're in a folder 'include', also look in its parent
parent = os.path.abspath(os.path.join(dirname, os.path.pardir))
source_dirs.append(parent)
# and ../src (used by lua dependency)
source_dirs.append(os.path.join(parent, 'src'))

include_idx = dirname.rfind(os.path.sep + 'include' + os.path.sep)
if include_idx != -1:
# we're in a subfolder of a parent '/include/'
# .../include/subdir/path
# look in .../subdir/path
source_dirs.append(
dirname[:include_idx] +
os.path.sep +
dirname[include_idx + len('include') + 2*len(os.path.sep):]
)

for source_dir in source_dirs:
for ext in SOURCE_EXTENSIONS:
yield source_dir + os.path.sep + basename + ext


def GetCompilationInfoForFile(filename):
# The compilation_commands.json file generated by CMake does not have entries
# for header files. So we do our best by asking the db for flags for a
# corresponding source file, if any. If one exists, the flags for that file
# should be good enough.
if IsHeaderFile(filename):
for alternative in PotentialAlternatives(filename):
if os.path.exists(alternative):
compilation_info = database.GetCompilationInfoForFile(
alternative
)

if compilation_info.compiler_flags_:
return compilation_info
return None
else:
return database.GetCompilationInfoForFile(filename)


def FlagsForFile(filename, **kwargs):
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object
compilation_info = GetCompilationInfoForFile(filename)
if not compilation_info:
return None

final_flags = MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_
)

return {
'flags': final_flags,
'do_cache': True
}
34 changes: 25 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else(CMAKE_CONFIGURATION_TYPES)
endif (NOT CMAKE_BUILD_TYPE)
endif(CMAKE_CONFIGURATION_TYPES)

OPTION(BUILD_DOCS "Choose whether to build the documentation (requires python and Sphinx)." ON)
OPTION(BUILD_DOCS "Choose whether to build the documentation (requires python and Sphinx)." OFF)

## some generic CMake magic
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
Expand All @@ -24,8 +24,13 @@ project(dfhack)
macro(CHECK_GCC COMPILER_PATH)
execute_process(COMMAND ${COMPILER_PATH} -dumpversion OUTPUT_VARIABLE GCC_VERSION_OUT)
string(STRIP "${GCC_VERSION_OUT}" GCC_VERSION_OUT)
if (${GCC_VERSION_OUT} VERSION_LESS "4.5" OR ${GCC_VERSION_OUT} VERSION_GREATER "4.9.9")
message(SEND_ERROR "${COMPILER_PATH} version ${GCC_VERSION_OUT} cannot be used - use GCC 4.5 through 4.9")
if (${GCC_VERSION_OUT} VERSION_LESS "4.5")
message(SEND_ERROR "${COMPILER_PATH} version ${GCC_VERSION_OUT} cannot be used - use GCC 4.5 or later")
elseif (${GCC_VERSION_OUT} VERSION_GREATER "4.9.9")
# GCC 5 changes ABI name mangling to enable C++11 changes.
# This must be disabled to enable linking against DF.
# http://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-abi/
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()
endmacro()

Expand Down Expand Up @@ -53,6 +58,11 @@ if(MSVC)
add_definitions( "/wd4819" )
endif()

IF(CMAKE_CROSSCOMPILING)
SET(DFHACK_NATIVE_BUILD_DIR "DFHACK_NATIVE_BUILD_DIR-NOTFOUND" CACHE FILEPATH "Path to a native build directory")
INCLUDE("${DFHACK_NATIVE_BUILD_DIR}/ImportExecutables.cmake")
ENDIF()

# set up folder structures for IDE solutions
# MSVC Express won't load solutions that use this. It also doesn't include MFC supported
# Check for MFC!
Expand Down Expand Up @@ -81,19 +91,23 @@ ${dfhack_SOURCE_DIR}/CMake/Modules
${CMAKE_MODULE_PATH}
)

# generates compile_commands.json, used for autocompletion by some editors
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# mixing the build system with the source code is ugly and stupid. enforce the opposite :)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed.")
endif()

# make sure all the necessary submodules have been set up
if (NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl OR NOT EXISTS ${dfhack_SOURCE_DIR}/depends/clsocket/CMakeLists.txt)
message(SEND_ERROR "One or more required submodules could not be found! Run 'git submodule update --init' from the root DFHack directory. (See the section 'Getting the Code' in Compile.rst or Compile.html)")
message(SEND_ERROR "One or more required submodules could not be found! Run 'git submodule update --init' from the root DFHack directory. (See the section 'Getting the Code' in docs/Compile.rst)")
endif()

# set up versioning.
set(DF_VERSION "0.40.24")
SET(DFHACK_RELEASE "r4")
set(DF_VERSION "0.42.05")
SET(DFHACK_RELEASE "alpha0")
SET(DFHACK_PRERELEASE TRUE)

set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")

Expand Down Expand Up @@ -164,6 +178,8 @@ endif()
# find and make available libz
if(NOT UNIX)
SET(ZLIB_ROOT depends/zlib/)
else()
set(ZLIB_ROOT /usr/lib/i386-linux-gnu)
endif()
find_package(ZLIB REQUIRED)
include_directories(depends/protobuf)
Expand All @@ -176,9 +192,9 @@ include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(depends/clsocket/src)
add_subdirectory(depends)

find_package(Git)
find_package(Git REQUIRED)
if(NOT GIT_FOUND)
message(FATAL_ERROR "could not find git")
message(SEND_ERROR "could not find git")
endif()

# build the lib itself
Expand All @@ -196,7 +212,7 @@ endif()

add_subdirectory(scripts)

find_package(Sphinx)
find_package(Sphinx QUIET)
if (BUILD_DOCS)
if (NOT SPHINX_FOUND)
message(SEND_ERROR "Sphinx not found but BUILD_DOCS enabled")
Expand Down
Loading

0 comments on commit 9a81fb1

Please sign in to comment.