Skip to content
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

Merged
merged 9 commits into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
config.log

config.status
compile_commands.json
build/

Makefile

tests/*
!tests/*.cc
14 changes: 12 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

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.

- libsqlcipher-dev
- libboost-all-dev
- cmake-data
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
Maybe gcc-5 can be removed too, it's just a dependency of g++-5

- 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using make test instead of ./tests would be less surprising for newcomers familiar with cmake


# TODO: fix sqlcipher test
# script: mkdir build && cd ./build && cmake -DENABLE_SQLCIPHER_TESTS=ON .. && make && ./tests
106 changes: 106 additions & 0 deletions .ycm_extra_conf.py
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.',
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
}
55 changes: 55 additions & 0 deletions CMakeLists.txt
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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParseAndAddCatchTests tries to parse the source to extract the tests.
This leads to problems with our disabled tests (especially the variant test).
These problems could probably be fixed by using this script from the Catch repo instead.

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()
110 changes: 0 additions & 110 deletions Makefile.in

This file was deleted.

22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,8 @@ int main() {
};
}
```

If you do not have C++17 support, you can use boost optional instead by defining `_MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT` before importing the `sqlite_modern_cpp` header.

If the optional library is not available, the experimental/optional one will be used instead.

**Note: boost support is deprecated and will be removed in future versions.**

Variant type support (C++17)
----
If your columns may have flexible types, you can use C++17's `std::variant` to extract the value.
Expand Down Expand Up @@ -438,18 +433,23 @@ NDK support
Just Make sure you are using the full path of your database file :
`sqlite::database db("/data/data/com.your.package/dbfile.db")`.

Building and Installing
Installation
----
The project is header only.
Simply point your compiler at the hdr/ directory.

The usual way works for installing:
Contributing
----
Install cmake and build the project.
Dependencies will be installed automatically (using hunter).

```bash
./configure && make && sudo make install

mkdir build
cd ./build
cmake ..
make
```

Note, there's nothing to make, so you there's no need to run configure and you can simply point your compiler at the hdr/ directory.

Breaking Changes
----
See breaking changes documented in each [Release](https://github.com/aminroosta/sqlite_modern_cpp/releases).
Expand Down
Binary file added cmake/.DS_Store
Binary file not shown.
Loading