Skip to content

Commit c514200

Browse files
authored
Merge pull request #145 from aminroosta/dev
dev branch: cmake + catch + travis fix
2 parents e2248fa + c549436 commit c514200

38 files changed

+1625
-5667
lines changed

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
config.log
55

66
config.status
7+
compile_commands.json
8+
build/
79

8-
Makefile
9-
10-
tests/*
11-
!tests/*.cc

.travis.yml

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@ language: cpp
22
sudo: required
33
dist: trusty
44

5+
cache:
6+
apt: true
7+
directories:
8+
- /home/travis/.hunter/
9+
510
addons:
611
apt:
712
sources:
813
- ubuntu-toolchain-r-test
14+
- george-edison55-precise-backports
915
packages:
10-
- gcc-5
1116
- g++-5
12-
- libsqlite3-dev
1317
- libsqlcipher-dev
14-
- libboost-all-dev
18+
- cmake
1519

1620
before_install:
1721
- export CXX="g++-5" CC="gcc-5"
1822

19-
script: ./configure && make test && make clean && make LDFLAGS="-lsqlcipher -DENABLE_SQLCIPHER_TESTS" test
23+
script: mkdir build && cd ./build && cmake .. && cmake --build . && ctest .
24+
25+
# TODO: fix sqlcipher test
26+
# script: mkdir build && cd ./build && cmake -DENABLE_SQLCIPHER_TESTS=ON .. && make && ./tests

.ycm_extra_conf.py

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import os
2+
import ycm_core
3+
4+
from clang_helpers import PrepareClangFlags
5+
6+
def DirectoryOfThisScript():
7+
return os.path.dirname(os.path.abspath(__file__))
8+
9+
# This is the single most important line in this script. Everything else is just nice to have but
10+
# not strictly necessary.
11+
compilation_database_folder = DirectoryOfThisScript()
12+
13+
# This provides a safe fall-back if no compilation commands are available. You could also add a
14+
# includes relative to your project directory, for example.
15+
flags = [
16+
'-Wall',
17+
'-std=c++14',
18+
'-x',
19+
'c++',
20+
'-isystem', '/usr/local/include',
21+
'-isystem', '/usr/include',
22+
'-I.',
23+
]
24+
25+
database = ycm_core.CompilationDatabase(compilation_database_folder)
26+
27+
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
28+
29+
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
30+
if not working_directory:
31+
return list( flags )
32+
new_flags = []
33+
make_next_absolute = False
34+
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
35+
for flag in flags:
36+
new_flag = flag
37+
38+
if make_next_absolute:
39+
make_next_absolute = False
40+
if not flag.startswith( '/' ):
41+
new_flag = os.path.join( working_directory, flag )
42+
43+
for path_flag in path_flags:
44+
if flag == path_flag:
45+
make_next_absolute = True
46+
break
47+
48+
if flag.startswith( path_flag ):
49+
path = flag[ len( path_flag ): ]
50+
new_flag = path_flag + os.path.join( working_directory, path )
51+
break
52+
53+
if new_flag:
54+
new_flags.append( new_flag )
55+
return new_flags
56+
57+
58+
def IsHeaderFile( filename ):
59+
extension = os.path.splitext( filename )[ 1 ]
60+
return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
61+
62+
63+
def GetCompilationInfoForFile( filename ):
64+
# The compilation_commands.json file generated by CMake does not have entries
65+
# for header files. So we do our best by asking the db for flags for a
66+
# corresponding source file, if any. If one exists, the flags for that file
67+
# should be good enough.
68+
if IsHeaderFile( filename ):
69+
basename = os.path.splitext( filename )[ 0 ]
70+
for extension in SOURCE_EXTENSIONS:
71+
replacement_file = basename + extension
72+
if os.path.exists( replacement_file ):
73+
compilation_info = database.GetCompilationInfoForFile(
74+
replacement_file )
75+
if compilation_info.compiler_flags_:
76+
return compilation_info
77+
return None
78+
return database.GetCompilationInfoForFile( filename )
79+
80+
81+
def FlagsForFile( filename, **kwargs ):
82+
if database:
83+
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
84+
# python list, but a "list-like" StringVec object
85+
compilation_info = GetCompilationInfoForFile( filename )
86+
if not compilation_info:
87+
return None
88+
89+
final_flags = MakeRelativePathsInFlagsAbsolute(
90+
compilation_info.compiler_flags_,
91+
compilation_info.compiler_working_dir_ )
92+
93+
else:
94+
relative_to = DirectoryOfThisScript()
95+
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
96+
97+
return {
98+
'flags': final_flags,
99+
'do_cache': True
100+
}

CMakeLists.txt

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
OPTION(ENABLE_SQLCIPHER_TESTS "enable sqlchipher test")
3+
4+
# Creates the file compile_commands.json in the build directory.
5+
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
set (CMAKE_CXX_STANDARD 14)
7+
8+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
9+
include("cmake/HunterGate.cmake")
10+
include("cmake/Catch.cmake")
11+
12+
HunterGate(
13+
URL "https://github.com/ruslo/hunter/archive/v0.19.227.tar.gz"
14+
SHA1 "808b778a443fcdf19c2d18fea8fa4bb59d16596a"
15+
)
16+
17+
project(SqliteModernCpp)
18+
19+
hunter_add_package(Catch)
20+
hunter_add_package(sqlite3)
21+
22+
find_package(Catch CONFIG REQUIRED)
23+
find_package(sqlite3 CONFIG REQUIRED)
24+
25+
set(TEST_SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests)
26+
file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc)
27+
28+
IF(NOT ENABLE_SQLCIPHER_TESTS)
29+
list(REMOVE_ITEM TEST_SOURCES ${TEST_SOURCE_DIR}/sqlcipher.cc)
30+
ENDIF(NOT ENABLE_SQLCIPHER_TESTS)
31+
32+
enable_testing()
33+
34+
add_library (sqlite_modern_cpp INTERFACE)
35+
target_include_directories(sqlite_modern_cpp INTERFACE hdr/)
36+
37+
add_executable(tests ${TEST_SOURCES})
38+
target_include_directories(tests INTERFACE ${SQLITE3_INCLUDE_DIRS})
39+
if(ENABLE_SQLCIPHER_TESTS)
40+
target_link_libraries(tests Catch::Catch sqlite_modern_cpp sqlite3::sqlite3 -lsqlcipher)
41+
else()
42+
target_link_libraries(tests Catch::Catch sqlite_modern_cpp sqlite3::sqlite3)
43+
endif()
44+
45+
catch_discover_tests(tests)
46+
47+
# Place the file in the source directory, permitting us to place a single configuration file for YCM there.
48+
# YCM is the code-completion engine for (neo)vim https://github.com/Valloric/YouCompleteMe
49+
IF(EXISTS "${CMAKE_BINARY_DIR}/compile_commands.json")
50+
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E copy_if_different
51+
${CMAKE_BINARY_DIR}/compile_commands.json
52+
${CMAKE_SOURCE_DIR}/compile_commands.json
53+
)
54+
ENDIF()

Makefile.in

-110
This file was deleted.

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,8 @@ int main() {
322322
};
323323
}
324324
```
325-
326-
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.
327-
328325
If the optional library is not available, the experimental/optional one will be used instead.
329326
330-
**Note: boost support is deprecated and will be removed in future versions.**
331-
332327
Variant type support (C++17)
333328
----
334329
If your columns may have flexible types, you can use C++17's `std::variant` to extract the value.
@@ -438,18 +433,23 @@ NDK support
438433
Just Make sure you are using the full path of your database file :
439434
`sqlite::database db("/data/data/com.your.package/dbfile.db")`.
440435
441-
Building and Installing
436+
Installation
442437
----
438+
The project is header only.
439+
Simply point your compiler at the hdr/ directory.
443440
444-
The usual way works for installing:
441+
Contributing
442+
----
443+
Install cmake and build the project.
444+
Dependencies will be installed automatically (using hunter).
445445
446446
```bash
447-
./configure && make && sudo make install
448-
447+
mkdir build
448+
cd ./build
449+
cmake ..
450+
make
449451
```
450452

451-
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.
452-
453453
Breaking Changes
454454
----
455455
See breaking changes documented in each [Release](https://github.com/aminroosta/sqlite_modern_cpp/releases).

cmake/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)