-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev branch: cmake + catch + travis fix #145
Changes from 8 commits
ab60859
b340ce1
45260a2
16d314f
4b92d31
d6d9270
de22bd3
ed82cb3
c549436
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ | |
config.log | ||
|
||
config.status | ||
compile_commands.json | ||
build/ | ||
|
||
Makefile | ||
|
||
tests/* | ||
!tests/*.cc |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,28 @@ language: cpp | |
sudo: required | ||
dist: trusty | ||
|
||
cache: | ||
apt: true | ||
directories: | ||
- /home/travis/.hunter/ | ||
|
||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
- george-edison55-precise-backports | ||
packages: | ||
- gcc-5 | ||
- g++-5 | ||
- libsqlite3-dev | ||
- libsqlcipher-dev | ||
- libboost-all-dev | ||
- cmake-data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cmake depends on cmake-data anyway, so this is redundant. I think we should remove it to keep the list of packages short. |
||
- cmake | ||
|
||
before_install: | ||
- export CXX="g++-5" CC="gcc-5" | ||
|
||
script: ./configure && make test && make clean && make LDFLAGS="-lsqlcipher -DENABLE_SQLCIPHER_TESTS" test | ||
script: mkdir build && cd ./build && cmake .. && make && ./tests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
|
||
# TODO: fix sqlcipher test | ||
# script: mkdir build && cd ./build && cmake -DENABLE_SQLCIPHER_TESTS=ON .. && make && ./tests |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import os | ||
import ycm_core | ||
|
||
from clang_helpers import PrepareClangFlags | ||
|
||
def DirectoryOfThisScript(): | ||
return os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# This is the single most important line in this script. Everything else is just nice to have but | ||
# not strictly necessary. | ||
compilation_database_folder = DirectoryOfThisScript() | ||
|
||
# This provides a safe fall-back if no compilation commands are available. You could also add a | ||
# includes relative to your project directory, for example. | ||
flags = [ | ||
'-Wall', | ||
'-std=c++14', | ||
'-stdlib=libc++', | ||
'-x', | ||
'c++', | ||
'-I', | ||
'.', | ||
'-isystem', '/usr/local/include', | ||
'-isystem', '/usr/include', | ||
'-I.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current directory is already added on line 21 and 22. |
||
] | ||
|
||
if compilation_database_folder: | ||
database = ycm_core.CompilationDatabase(compilation_database_folder) | ||
else: | ||
database = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The else block is unreachable |
||
|
||
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] | ||
|
||
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' ] | ||
|
||
|
||
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 ): | ||
basename = os.path.splitext( filename )[ 0 ] | ||
for extension in SOURCE_EXTENSIONS: | ||
replacement_file = basename + extension | ||
if os.path.exists( replacement_file ): | ||
compilation_info = database.GetCompilationInfoForFile( | ||
replacement_file ) | ||
if compilation_info.compiler_flags_: | ||
return compilation_info | ||
return None | ||
return database.GetCompilationInfoForFile( filename ) | ||
|
||
|
||
def FlagsForFile( filename, **kwargs ): | ||
if database: | ||
# 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_ ) | ||
|
||
else: | ||
relative_to = DirectoryOfThisScript() | ||
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) | ||
|
||
return { | ||
'flags': final_flags, | ||
'do_cache': True | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
OPTION(ENABLE_SQLCIPHER_TESTS "enable sqlchipher test") | ||
|
||
# Creates the file compile_commands.json in the build directory. | ||
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set (CMAKE_CXX_STANDARD 14) | ||
|
||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") | ||
include("cmake/HunterGate.cmake") | ||
include("cmake/ParseAndAddCatchTests.cmake") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ParseAndAddCatchTests tries to parse the source to extract the tests. |
||
include("cmake/DownloadProject.CMake") | ||
|
||
HunterGate( | ||
URL "https://github.com/ruslo/hunter/archive/v0.19.227.tar.gz" | ||
SHA1 "808b778a443fcdf19c2d18fea8fa4bb59d16596a" | ||
) | ||
|
||
project(SqliteModernCpp) | ||
|
||
hunter_add_package(Catch) | ||
hunter_add_package(sqlite3) | ||
|
||
find_package(Catch CONFIG REQUIRED) | ||
find_package(sqlite3 CONFIG REQUIRED) | ||
|
||
set(TEST_SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests) | ||
file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc) | ||
|
||
IF(NOT ENABLE_SQLCIPHER_TESTS) | ||
list(REMOVE_ITEM TEST_SOURCES ${TEST_SOURCE_DIR}/sqlcipher.cc) | ||
ENDIF(NOT ENABLE_SQLCIPHER_TESTS) | ||
|
||
enable_testing() | ||
|
||
add_library (sqlite_modern_cpp INTERFACE) | ||
target_include_directories(sqlite_modern_cpp INTERFACE hdr/) | ||
|
||
add_executable(tests ${TEST_SOURCES}) | ||
target_include_directories(tests INTERFACE ${SQLITE3_INCLUDE_DIRS}) | ||
if(ENABLE_SQLCIPHER_TESTS) | ||
target_link_libraries(tests Catch::Catch sqlite_modern_cpp sqlite3::sqlite3 -lsqlcipher) | ||
else() | ||
target_link_libraries(tests Catch::Catch sqlite_modern_cpp sqlite3::sqlite3) | ||
endif() | ||
|
||
ParseAndAddCatchTests(tests) | ||
|
||
# Place the file in the source directory, permitting us to place a single configuration file for YCM there. | ||
# YCM is the code-completion engine for (neo)vim https://github.com/Valloric/YouCompleteMe | ||
IF(EXISTS "${CMAKE_BINARY_DIR}/compile_commands.json") | ||
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${CMAKE_BINARY_DIR}/compile_commands.json | ||
${CMAKE_SOURCE_DIR}/compile_commands.json | ||
) | ||
ENDIF() |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMake ignores the preinstalled SQLite and downloads and installs it's own version, so there is no point in requiring this.