Ya boi came through

This commit is contained in:
TinyAtoms 2019-06-27 00:55:27 -03:00
parent 6be7af0933
commit 4294d4e68c
4 changed files with 410 additions and 396 deletions

View File

@ -1,19 +1,32 @@
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.14)
project(park) project(park)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/thirdparty/SQLiteCpp) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/thirdparty/SQLiteCpp)
include_directories( include_directories(
${CMAKE_CURRENT_LIST_DIR}/thirdparty/SQLiteCpp/include ${CMAKE_CURRENT_LIST_DIR}/thirdparty/SQLiteCpp/include
) )
add_executable(park main.cpp data.cpp headers/data.h Customer.cpp headers/Customer.h Park_spot.cpp headers/Park_spot.h Park_time.cpp headers/Park_time.h) add_executable(park main.cpp data.cpp headers/data.h Customer.cpp headers/Customer.h Park_spot.cpp headers/Park_spot.h Park_time.cpp headers/Park_time.h)
target_link_libraries(park
SQLiteCpp
sqlite3
pthread if (UNIX)
dl target_link_libraries(park
) SQLiteCpp
sqlite3
pthread
dl
)
elseif (MSYS OR MINGW)
target_link_libraries(park
SQLiteCpp
sqlite3
pthread
ssp
)
endif()

View File

@ -1,39 +1,40 @@
#include "headers/Park_spot.h" #include "headers/Park_spot.h"
#include "headers/data.h" #include "headers/data.h"
#include <iostream> #include <iostream>
#include <thread> // to make pausing work, not sure if i need chrono, or this, or both #include <thread> // to make pausing work, not sure if i need chrono, or this, or both
#include <vector> #include <vector>
/* /*
Code strucure like this: Code strucure like this:
class declarations zijn in /headers/class_naam.h, en definitions van de member class declarations zijn in /headers/class_naam.h, en definitions van de member
functs in /class_naam.cpp elke klas in zn eigen file omdat ik incomplete class functs in /class_naam.cpp elke klas in zn eigen file omdat ik incomplete class
declarations wilt tegengaan, omdat ik ze niet goed begrijp. En header/source declarations wilt tegengaan, omdat ik ze niet goed begrijp. En header/source
split om multiple definition errors tegen te gaan. split om multiple definition errors tegen te gaan.
Park_spot representeert een parkeermeter bij elke parkeer spot. Park_spot representeert een parkeermeter bij elke parkeer spot.
Een customer is een customer. Een customer is een customer.
Park time is een object die reffereert naar parkspot en customer, basically een Park time is een object die reffereert naar parkspot en customer, basically een
record die zegt dat een customer voor x tijd geparkeert heeft bij spot x, enz. record die zegt dat een customer voor x tijd geparkeert heeft bij spot x, enz.
De client clockt in en uit bij een spot. De client clockt in en uit bij een spot.
*/ */
void Wait(int sec) void Wait(int sec)
/* /*
a wait function where 1 sec represents 1 hour irl. a wait function where 1 sec represents 1 hour irl.
*/ */
{ {
std::this_thread::sleep_for(seconds{sec}); std::this_thread::sleep_for(seconds{sec});
} }
using std::cout; using std::cout;
int main() { int main() {
SQLite::Database db = data::start_db(); SQLite::Database db = data::start_db();
// see implementation of update_db, save_db and delete_db of customer to see how queries and statements work // see implementation of update_db, save_db and delete_db of customer to see how queries and statements work
Customer sagar{"Ramsaransing", Verhicle_type::medium, db}; Customer sagar{"Sagar Winston Ramsaransing", Verhicle_type::medium, db};
sagar.update_db(db); sagar.update_db(db);
sagar.delete_db(db); cout << "THIS WRKS";
} // sagar.delete_db(db);
}

BIN
test.db3

Binary file not shown.

View File

@ -1,338 +1,338 @@
# Main CMake file for compiling the library itself, examples and tests. # Main CMake file for compiling the library itself, examples and tests.
# #
# Copyright (c) 2012-2019 Sebastien Rombauts (sebastien.rombauts@gmail.com) # Copyright (c) 2012-2019 Sebastien Rombauts (sebastien.rombauts@gmail.com)
# #
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt # Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
# or copy at http://opensource.org/licenses/MIT) # or copy at http://opensource.org/licenses/MIT)
cmake_minimum_required(VERSION 2.8.12) # first version with add_compile_options() cmake_minimum_required(VERSION 2.8.12) # first version with add_compile_options()
project(SQLiteCpp) project(SQLiteCpp)
message (STATUS "CMake version: ${CMAKE_VERSION}") message (STATUS "CMake version: ${CMAKE_VERSION}")
# Define useful variables to handle OS differences: # Define useful variables to handle OS differences:
if (WIN32) if (WIN32)
set(DEV_NULL "NUL") set(DEV_NULL "NUL")
else (WIN32) # UNIX else (WIN32) # UNIX
set(DEV_NULL "/dev/null") set(DEV_NULL "/dev/null")
endif (WIN32) endif (WIN32)
# then Compiler/IDE differences: # then Compiler/IDE differences:
if (MSVC) if (MSVC)
set(CPPLINT_ARG_OUTPUT "--output=vs7") set(CPPLINT_ARG_OUTPUT "--output=vs7")
set(CPPCHECK_ARG_TEMPLATE "--template=vs") set(CPPCHECK_ARG_TEMPLATE "--template=vs")
# disable Visual Studio warnings for fopen() used in the example # disable Visual Studio warnings for fopen() used in the example
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# Flags for linking with multithread static C++ runtime, required by googletest # Flags for linking with multithread static C++ runtime, required by googletest
if (SQLITECPP_BUILD_TESTS) if (SQLITECPP_BUILD_TESTS)
message(STATUS "Linking against multithread static C++ runtime for unit tests with googletest") message(STATUS "Linking against multithread static C++ runtime for unit tests with googletest")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif (SQLITECPP_BUILD_TESTS) endif (SQLITECPP_BUILD_TESTS)
# Handle the (partly supported) MSVC versions prior to 2015 # Handle the (partly supported) MSVC versions prior to 2015
if (MSVC_VERSION LESS 1900) # OR MSVC_TOOLSET_VERSION LESS 140) if (MSVC_VERSION LESS 1900) # OR MSVC_TOOLSET_VERSION LESS 140)
message(WARNING "MSVC < 2015 detected: Visual Studio prior to 2015 is not fully supported. BLOB storage seems to be corrupted.") message(WARNING "MSVC < 2015 detected: Visual Studio prior to 2015 is not fully supported. BLOB storage seems to be corrupted.")
endif (MSVC_VERSION LESS 1900) endif (MSVC_VERSION LESS 1900)
else (MSVC) else (MSVC)
set(CPPLINT_ARG_OUTPUT "--output=eclipse") set(CPPLINT_ARG_OUTPUT "--output=eclipse")
set(CPPCHECK_ARG_TEMPLATE "--template=gcc") set(CPPCHECK_ARG_TEMPLATE "--template=gcc")
# Useful compile flags and extra warnings # Useful compile flags and extra warnings
add_compile_options(-fstack-protector -Wall -Wextra -Wpedantic -Wno-long-long -Wswitch-enum -Wshadow -Winline) add_compile_options(-fstack-protector -Wall -Wextra -Wpedantic -Wno-long-long -Wswitch-enum -Wshadow -Winline)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++0x-compat") # C++ only set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++0x-compat") # C++ only
if (CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_COMPILER_IS_GNUCXX)
# GCC flags # GCC flags
option(SQLITECPP_USE_GCOV "USE GCov instrumentation." OFF) option(SQLITECPP_USE_GCOV "USE GCov instrumentation." OFF)
if (SQLITECPP_USE_GCOV) if (SQLITECPP_USE_GCOV)
message (STATUS "Using GCov instrumentation") message (STATUS "Using GCov instrumentation")
add_compile_options (-coverage) # NOTE -fkeep-inline-functions would be usefull but not working with current google test and gcc 4.8 add_compile_options (-coverage) # NOTE -fkeep-inline-functions would be usefull but not working with current google test and gcc 4.8
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -coverage") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -coverage")
endif () endif ()
endif (CMAKE_COMPILER_IS_GNUCXX) endif (CMAKE_COMPILER_IS_GNUCXX)
endif (MSVC) endif (MSVC)
# and then common variables # and then common variables
set(CPPLINT_ARG_VERBOSE "--verbose=3") set(CPPLINT_ARG_VERBOSE "--verbose=3")
set(CPPLINT_ARG_LINELENGTH "--linelength=120") set(CPPLINT_ARG_LINELENGTH "--linelength=120")
# Print CXX compiler information # Print CXX compiler information
message (STATUS "CMAKE_CXX_COMPILER '${CMAKE_CXX_COMPILER}' '${CMAKE_CXX_COMPILER_ID}' '${CMAKE_CXX_COMPILER_VERSION}'") message (STATUS "CMAKE_CXX_COMPILER '${CMAKE_CXX_COMPILER}' '${CMAKE_CXX_COMPILER_ID}' '${CMAKE_CXX_COMPILER_VERSION}'")
# Print CXX FLAGS # Print CXX FLAGS
message (STATUS "CMAKE_CXX_FLAGS '${CMAKE_CXX_FLAGS}'") message (STATUS "CMAKE_CXX_FLAGS '${CMAKE_CXX_FLAGS}'")
if (MSVC) if (MSVC)
message (STATUS "CMAKE_CXX_FLAGS_DEBUG '${CMAKE_CXX_FLAGS_DEBUG}'") message (STATUS "CMAKE_CXX_FLAGS_DEBUG '${CMAKE_CXX_FLAGS_DEBUG}'")
message (STATUS "CMAKE_CXX_FLAGS_RELEASE '${CMAKE_CXX_FLAGS_RELEASE}'") message (STATUS "CMAKE_CXX_FLAGS_RELEASE '${CMAKE_CXX_FLAGS_RELEASE}'")
message (STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO '${CMAKE_CXX_FLAGS_RELWITHDEBINFO}'") message (STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO '${CMAKE_CXX_FLAGS_RELWITHDEBINFO}'")
message (STATUS "CMAKE_CXX_FLAGS_MINSIZEREL '${CMAKE_CXX_FLAGS_MINSIZEREL}'") message (STATUS "CMAKE_CXX_FLAGS_MINSIZEREL '${CMAKE_CXX_FLAGS_MINSIZEREL}'")
else (NOT MSVC) else (NOT MSVC)
if (CMAKE_BUILD_TYPE STREQUAL Debug) if (CMAKE_BUILD_TYPE STREQUAL Debug)
message (STATUS "CMAKE_CXX_FLAGS_DEBUG '${CMAKE_CXX_FLAGS_DEBUG}'") message (STATUS "CMAKE_CXX_FLAGS_DEBUG '${CMAKE_CXX_FLAGS_DEBUG}'")
elseif (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) elseif (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
message (STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO '${CMAKE_CXX_FLAGS_RELWITHDEBINFO}'") message (STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO '${CMAKE_CXX_FLAGS_RELWITHDEBINFO}'")
elseif (CMAKE_BUILD_TYPE STREQUAL MinSizeRel) elseif (CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
message (STATUS "CMAKE_CXX_FLAGS_MINSIZEREL '${CMAKE_CXX_FLAGS_MINSIZEREL}'") message (STATUS "CMAKE_CXX_FLAGS_MINSIZEREL '${CMAKE_CXX_FLAGS_MINSIZEREL}'")
else () else ()
message (STATUS "CMAKE_CXX_FLAGS_RELEASE '${CMAKE_CXX_FLAGS_RELEASE}'") message (STATUS "CMAKE_CXX_FLAGS_RELEASE '${CMAKE_CXX_FLAGS_RELEASE}'")
endif () endif ()
endif () endif ()
# Options relative to SQLite and SQLiteC++ functions # Options relative to SQLite and SQLiteC++ functions
option(SQLITE_ENABLE_COLUMN_METADATA "Enable Column::getColumnOriginName(). Require support from sqlite3 library." ON) option(SQLITE_ENABLE_COLUMN_METADATA "Enable Column::getColumnOriginName(). Require support from sqlite3 library." ON)
if (SQLITE_ENABLE_COLUMN_METADATA) if (SQLITE_ENABLE_COLUMN_METADATA)
# Enable the use of SQLite column metadata and Column::getColumnOriginName() method, # Enable the use of SQLite column metadata and Column::getColumnOriginName() method,
# Require that the sqlite3 library is also compiled with this flag (default under Debian/Ubuntu, but not on Mac OS X). # Require that the sqlite3 library is also compiled with this flag (default under Debian/Ubuntu, but not on Mac OS X).
add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA) add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA)
endif (SQLITE_ENABLE_COLUMN_METADATA) endif (SQLITE_ENABLE_COLUMN_METADATA)
option(SQLITE_ENABLE_ASSERT_HANDLER "Enable the user defintion of a assertion_failed() handler." OFF) option(SQLITE_ENABLE_ASSERT_HANDLER "Enable the user defintion of a assertion_failed() handler." OFF)
if (SQLITE_ENABLE_ASSERT_HANDLER) if (SQLITE_ENABLE_ASSERT_HANDLER)
# Enable the user defintion of a assertion_failed() handler (default to false, easier to handler for begginers). # Enable the user defintion of a assertion_failed() handler (default to false, easier to handler for begginers).
add_definitions(-DSQLITECPP_ENABLE_ASSERT_HANDLER) add_definitions(-DSQLITECPP_ENABLE_ASSERT_HANDLER)
endif (SQLITE_ENABLE_ASSERT_HANDLER) endif (SQLITE_ENABLE_ASSERT_HANDLER)
option(SQLITE_USE_LEGACY_STRUCT "Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)" OFF) option(SQLITE_USE_LEGACY_STRUCT "Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)" OFF)
if (SQLITE_USE_LEGACY_STRUCT) if (SQLITE_USE_LEGACY_STRUCT)
# Force forward declaration of legacy struct sqlite3_value (pre SQLite 3.19) # Force forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)
add_definitions(-DSQLITE_USE_LEGACY_STRUCT) add_definitions(-DSQLITE_USE_LEGACY_STRUCT)
endif (SQLITE_USE_LEGACY_STRUCT) endif (SQLITE_USE_LEGACY_STRUCT)
## Build the C++ Wrapper ## ## Build the C++ Wrapper ##
# adding a new file require explicittly modifing the CMakeLists.txt # adding a new file require explicittly modifing the CMakeLists.txt
# so that CMake knows that it should rebuild the project (it is best practice) # so that CMake knows that it should rebuild the project (it is best practice)
# list of sources files of the library # list of sources files of the library
set(SQLITECPP_SRC set(SQLITECPP_SRC
${PROJECT_SOURCE_DIR}/src/Backup.cpp ${PROJECT_SOURCE_DIR}/src/Backup.cpp
${PROJECT_SOURCE_DIR}/src/Column.cpp ${PROJECT_SOURCE_DIR}/src/Column.cpp
${PROJECT_SOURCE_DIR}/src/Database.cpp ${PROJECT_SOURCE_DIR}/src/Database.cpp
${PROJECT_SOURCE_DIR}/src/Exception.cpp ${PROJECT_SOURCE_DIR}/src/Exception.cpp
${PROJECT_SOURCE_DIR}/src/Statement.cpp ${PROJECT_SOURCE_DIR}/src/Statement.cpp
${PROJECT_SOURCE_DIR}/src/Transaction.cpp ${PROJECT_SOURCE_DIR}/src/Transaction.cpp
) )
source_group(src FILES ${SQLITECPP_SRC}) source_group(src FILES ${SQLITECPP_SRC})
# list of header files of the library # list of header files of the library
set(SQLITECPP_INC set(SQLITECPP_INC
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/SQLiteCpp.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/SQLiteCpp.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Assertion.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Assertion.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Backup.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Backup.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Column.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Column.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Database.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Database.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Exception.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Exception.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Statement.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Statement.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Transaction.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Transaction.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Utils.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/Utils.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/VariadicBind.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/VariadicBind.h
${PROJECT_SOURCE_DIR}/include/SQLiteCpp/ExecuteMany.h ${PROJECT_SOURCE_DIR}/include/SQLiteCpp/ExecuteMany.h
) )
source_group(include FILES ${SQLITECPP_INC}) source_group(include FILES ${SQLITECPP_INC})
# list of test files of the library # list of test files of the library
set(SQLITECPP_TESTS set(SQLITECPP_TESTS
tests/Column_test.cpp tests/Column_test.cpp
tests/Database_test.cpp tests/Database_test.cpp
tests/Statement_test.cpp tests/Statement_test.cpp
tests/Backup_test.cpp tests/Backup_test.cpp
tests/Transaction_test.cpp tests/Transaction_test.cpp
tests/VariadicBind_test.cpp tests/VariadicBind_test.cpp
tests/Exception_test.cpp tests/Exception_test.cpp
tests/ExecuteMany_test.cpp tests/ExecuteMany_test.cpp
) )
source_group(tests FILES ${SQLITECPP_TESTS}) source_group(tests FILES ${SQLITECPP_TESTS})
# list of example files of the library # list of example files of the library
set(SQLITECPP_EXAMPLES set(SQLITECPP_EXAMPLES
examples/example1/main.cpp examples/example1/main.cpp
) )
source_group(example1 FILES ${SQLITECPP_EXAMPLES}) source_group(example1 FILES ${SQLITECPP_EXAMPLES})
# list of doc files of the library # list of doc files of the library
set(SQLITECPP_DOC set(SQLITECPP_DOC
README.md README.md
LICENSE.txt LICENSE.txt
CHANGELOG.md CHANGELOG.md
TODO.txt TODO.txt
) )
source_group(doc FILES ${SQLITECPP_DOC}) source_group(doc FILES ${SQLITECPP_DOC})
# list of script files of the library # list of script files of the library
set(SQLITECPP_SCRIPT set(SQLITECPP_SCRIPT
.travis.yml .travis.yml
appveyor.yml appveyor.yml
build.bat build.bat
build.sh build.sh
cpplint.py cpplint.py
Doxyfile Doxyfile
FindSQLiteCpp.cmake FindSQLiteCpp.cmake
) )
source_group(scripts FILES ${SQLITECPP_SCRIPT}) source_group(scripts FILES ${SQLITECPP_SCRIPT})
# All includes are relative to the "include" directory # All includes are relative to the "include" directory
include_directories("${PROJECT_SOURCE_DIR}/include") include_directories("${PROJECT_SOURCE_DIR}/include")
# add sources of the wrapper as a "SQLiteCpp" static library # add sources of the wrapper as a "SQLiteCpp" static library
add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT}) add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT})
# make the sqlite3 library part of the interface of the SQLiteCpp wrapper itself (the client app does not need to link to sqlite3) # make the sqlite3 library part of the interface of the SQLiteCpp wrapper itself (the client app does not need to link to sqlite3)
# PR https://github.com/SRombauts/SQLiteCpp/pull/111 "linked SQLiteCpp to sqlite3" commented out since it breaks install step from PR #118 # PR https://github.com/SRombauts/SQLiteCpp/pull/111 "linked SQLiteCpp to sqlite3" commented out since it breaks install step from PR #118
#target_link_libraries(SQLiteCpp PUBLIC sqlite3) #target_link_libraries(SQLiteCpp PUBLIC sqlite3)
if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fPIC") set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fPIC")
endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
# Allow the library to be installed via "make install" and found with "find_package" # Allow the library to be installed via "make install" and found with "find_package"
install(TARGETS SQLiteCpp install(TARGETS SQLiteCpp
EXPORT ${PROJECT_NAME}Config EXPORT ${PROJECT_NAME}Config
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
COMPONENT libraries) COMPONENT libraries)
target_include_directories(SQLiteCpp PUBLIC target_include_directories(SQLiteCpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/>) $<INSTALL_INTERFACE:include/>)
install(DIRECTORY include/ DESTINATION include COMPONENT headers FILES_MATCHING REGEX ".*\\.(hpp|h)$") install(DIRECTORY include/ DESTINATION include COMPONENT headers FILES_MATCHING REGEX ".*\\.(hpp|h)$")
install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake/${PROJECT_NAME}) install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake/${PROJECT_NAME})
## Build provided copy of SQLite3 C library ## ## Build provided copy of SQLite3 C library ##
# TODO # TODO
#find_package(sqlite3) #find_package(sqlite3)
#if(sqlite3_VERSION VERSION_LESS "3.19") #if(sqlite3_VERSION VERSION_LESS "3.19")
# set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT") # set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT")
#endif() #endif()
option(SQLITECPP_USE_ASAN "Use Address Sanitizer." OFF) option(SQLITECPP_USE_ASAN "Use Address Sanitizer." OFF)
if (SQLITECPP_USE_ASAN) if (SQLITECPP_USE_ASAN)
if ((CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 6) OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")) if ((CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 6) OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
message (STATUS "Using Address Sanitizer") message (STATUS "Using Address Sanitizer")
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fsanitize=address -fno-omit-frame-pointer") set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
if (CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
endif () endif ()
endif () endif ()
endif (SQLITECPP_USE_ASAN) endif (SQLITECPP_USE_ASAN)
option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON) option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON)
if (SQLITECPP_INTERNAL_SQLITE) if (SQLITECPP_INTERNAL_SQLITE)
# build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package # build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package
add_subdirectory(sqlite3) add_subdirectory(sqlite3)
target_include_directories(sqlite3 PUBLIC "${PROJECT_SOURCE_DIR}/sqlite3") target_include_directories(sqlite3 PUBLIC "${PROJECT_SOURCE_DIR}/sqlite3")
target_include_directories(SQLiteCpp PRIVATE "${PROJECT_SOURCE_DIR}/sqlite3") target_include_directories(SQLiteCpp PRIVATE "${PROJECT_SOURCE_DIR}/sqlite3")
endif (SQLITECPP_INTERNAL_SQLITE) endif (SQLITECPP_INTERNAL_SQLITE)
# Optional additional targets: # Optional additional targets:
option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." ON) option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." ON)
if (SQLITECPP_RUN_CPPLINT) if (SQLITECPP_RUN_CPPLINT)
find_package(PythonInterp) find_package(PythonInterp)
if (PYTHONINTERP_FOUND) if (PYTHONINTERP_FOUND)
# add a cpplint target to the "all" target # add a cpplint target to the "all" target
add_custom_target(SQLiteCpp_cpplint add_custom_target(SQLiteCpp_cpplint
ALL ALL
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/cpplint.py ${CPPLINT_ARG_OUTPUT} ${CPPLINT_ARG_VERBOSE} ${CPPLINT_ARG_LINELENGTH} ${SQLITECPP_SRC} ${SQLITECPP_INC} COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/cpplint.py ${CPPLINT_ARG_OUTPUT} ${CPPLINT_ARG_VERBOSE} ${CPPLINT_ARG_LINELENGTH} ${SQLITECPP_SRC} ${SQLITECPP_INC}
) )
endif (PYTHONINTERP_FOUND) endif (PYTHONINTERP_FOUND)
else (SQLITECPP_RUN_CPPLINT) else (SQLITECPP_RUN_CPPLINT)
message(STATUS "SQLITECPP_RUN_CPPLINT OFF") message(STATUS "SQLITECPP_RUN_CPPLINT OFF")
endif (SQLITECPP_RUN_CPPLINT) endif (SQLITECPP_RUN_CPPLINT)
option(SQLITECPP_RUN_CPPCHECK "Run cppcheck C++ static analysis tool." ON) option(SQLITECPP_RUN_CPPCHECK "Run cppcheck C++ static analysis tool." ON)
if (SQLITECPP_RUN_CPPCHECK) if (SQLITECPP_RUN_CPPCHECK)
find_program(CPPCHECK_EXECUTABLE NAMES cppcheck) find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
if (CPPCHECK_EXECUTABLE) if (CPPCHECK_EXECUTABLE)
# add a cppcheck target to the "all" target # add a cppcheck target to the "all" target
add_custom_target(SQLiteCpp_cppcheck add_custom_target(SQLiteCpp_cppcheck
ALL ALL
COMMAND ${CPPCHECK_EXECUTABLE} -j 8 cppcheck --enable=style --quiet ${CPPCHECK_ARG_TEMPLATE} ${PROJECT_SOURCE_DIR}/src COMMAND ${CPPCHECK_EXECUTABLE} -j 8 cppcheck --enable=style --quiet ${CPPCHECK_ARG_TEMPLATE} ${PROJECT_SOURCE_DIR}/src
) )
execute_process(COMMAND "${CPPCHECK_EXECUTABLE}" --version OUTPUT_VARIABLE CPPCHECK_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND "${CPPCHECK_EXECUTABLE}" --version OUTPUT_VARIABLE CPPCHECK_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Found Cppcheck: ${CPPCHECK_EXECUTABLE} ${CPPCHECK_VERSION}") message(STATUS "Found Cppcheck: ${CPPCHECK_EXECUTABLE} ${CPPCHECK_VERSION}")
else (CPPCHECK_EXECUTABLE) else (CPPCHECK_EXECUTABLE)
message(STATUS "Could NOT find cppcheck") message(STATUS "Could NOT find cppcheck")
endif (CPPCHECK_EXECUTABLE) endif (CPPCHECK_EXECUTABLE)
else (SQLITECPP_RUN_CPPCHECK) else (SQLITECPP_RUN_CPPCHECK)
message(STATUS "SQLITECPP_RUN_CPPCHECK OFF") message(STATUS "SQLITECPP_RUN_CPPCHECK OFF")
endif (SQLITECPP_RUN_CPPCHECK) endif (SQLITECPP_RUN_CPPCHECK)
option(SQLITECPP_RUN_DOXYGEN "Run Doxygen C++ documentation tool." OFF) option(SQLITECPP_RUN_DOXYGEN "Run Doxygen C++ documentation tool." OFF)
if (SQLITECPP_RUN_DOXYGEN) if (SQLITECPP_RUN_DOXYGEN)
find_package(Doxygen) find_package(Doxygen)
if (DOXYGEN_FOUND) if (DOXYGEN_FOUND)
# add a Doxygen target to the "all" target # add a Doxygen target to the "all" target
add_custom_target(SQLiteCpp_doxygen add_custom_target(SQLiteCpp_doxygen
ALL ALL
COMMAND doxygen Doxyfile > ${DEV_NULL} COMMAND doxygen Doxyfile > ${DEV_NULL}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
) )
endif (DOXYGEN_FOUND) endif (DOXYGEN_FOUND)
else (SQLITECPP_RUN_DOXYGEN) else (SQLITECPP_RUN_DOXYGEN)
message(STATUS "SQLITECPP_RUN_DOXYGEN OFF") message(STATUS "SQLITECPP_RUN_DOXYGEN OFF")
endif (SQLITECPP_RUN_DOXYGEN) endif (SQLITECPP_RUN_DOXYGEN)
option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF) option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
if (SQLITECPP_BUILD_EXAMPLES) if (SQLITECPP_BUILD_EXAMPLES)
# add the basic example executable # add the basic example executable
add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES}) add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES})
target_link_libraries(SQLiteCpp_example1 SQLiteCpp sqlite3) target_link_libraries(SQLiteCpp_example1 SQLiteCpp sqlite3)
# Link target with pthread and dl for linux # Link target with pthread and dl for linux
if (UNIX) if (UNIX)
target_link_libraries(SQLiteCpp_example1 pthread) target_link_libraries(SQLiteCpp_example1 pthread)
if (NOT APPLE) if (NOT APPLE)
target_link_libraries(SQLiteCpp_example1 dl) target_link_libraries(SQLiteCpp_example1 dl)
endif () endif ()
elseif (MSYS OR MINGW) elseif (MSYS OR MINGW)
target_link_libraries(SQLiteCpp_example1 ssp) target_link_libraries(SQLiteCpp_example1 ssp)
endif () endif ()
else (SQLITECPP_BUILD_EXAMPLES) else (SQLITECPP_BUILD_EXAMPLES)
message(STATUS "SQLITECPP_BUILD_EXAMPLES OFF") message(STATUS "SQLITECPP_BUILD_EXAMPLES OFF")
endif (SQLITECPP_BUILD_EXAMPLES) endif (SQLITECPP_BUILD_EXAMPLES)
option(SQLITECPP_BUILD_TESTS "Build and run tests." OFF) option(SQLITECPP_BUILD_TESTS "Build and run tests." OFF)
if (SQLITECPP_BUILD_TESTS) if (SQLITECPP_BUILD_TESTS)
# deactivate some warnings for compiling the gtest library # deactivate some warnings for compiling the gtest library
if (NOT MSVC) if (NOT MSVC)
add_compile_options(-Wno-variadic-macros -Wno-long-long -Wno-switch-enum -Wno-float-equal -Wno-conversion-null -Wno-switch-default -Wno-pedantic) add_compile_options(-Wno-variadic-macros -Wno-long-long -Wno-switch-enum -Wno-float-equal -Wno-conversion-null -Wno-switch-default -Wno-pedantic)
endif (NOT MSVC) endif (NOT MSVC)
# add the subdirectory containing the CMakeLists.txt for the gtest library # add the subdirectory containing the CMakeLists.txt for the gtest library
# TODO: under Linux, uses libgtest-dev if found # TODO: under Linux, uses libgtest-dev if found
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt") if (NOT EXISTS "${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt")
message(FATAL_ERROR "Missing 'googletest' submodule! Either use 'git submodule init' and 'git submodule update' to get googletest according to the README, or deactivate unit tests with -DSQLITECPP_BUILD_TESTS=OFF") message(FATAL_ERROR "Missing 'googletest' submodule! Either use 'git submodule init' and 'git submodule update' to get googletest according to the README, or deactivate unit tests with -DSQLITECPP_BUILD_TESTS=OFF")
endif () endif ()
add_subdirectory(googletest) add_subdirectory(googletest)
include_directories("${PROJECT_SOURCE_DIR}/googletest/googletest/include") include_directories("${PROJECT_SOURCE_DIR}/googletest/googletest/include")
# Add definitions to keep googletest from making the compilation fail # Add definitions to keep googletest from making the compilation fail
if (MSVC) if (MSVC)
if (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919) # OR MSVC_TOOLSET_VERSION EQUAL 141) if (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919) # OR MSVC_TOOLSET_VERSION EQUAL 141)
target_compile_definitions(gtest PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) target_compile_definitions(gtest PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
target_compile_definitions(gtest_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) target_compile_definitions(gtest_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
target_compile_definitions(gmock PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) target_compile_definitions(gmock PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
target_compile_definitions(gmock_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) target_compile_definitions(gmock_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919) endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919)
endif (MSVC) endif (MSVC)
# add the unit test executable # add the unit test executable
add_executable(SQLiteCpp_tests ${SQLITECPP_TESTS}) add_executable(SQLiteCpp_tests ${SQLITECPP_TESTS})
target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3) target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3)
# Link target with dl for linux # Link target with dl for linux
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
target_link_libraries(SQLiteCpp_tests dl) target_link_libraries(SQLiteCpp_tests dl)
endif () endif ()
# add a "test" target: # add a "test" target:
enable_testing() enable_testing()
# does the tests pass? # does the tests pass?
add_test(UnitTests SQLiteCpp_tests) add_test(UnitTests SQLiteCpp_tests)
if (SQLITECPP_BUILD_EXAMPLES) if (SQLITECPP_BUILD_EXAMPLES)
# does the example1 runs successfully? # does the example1 runs successfully?
add_test(Example1Run SQLiteCpp_example1) add_test(Example1Run SQLiteCpp_example1)
endif (SQLITECPP_BUILD_EXAMPLES) endif (SQLITECPP_BUILD_EXAMPLES)
else (SQLITECPP_BUILD_TESTS) else (SQLITECPP_BUILD_TESTS)
message(STATUS "SQLITECPP_BUILD_TESTS OFF") message(STATUS "SQLITECPP_BUILD_TESTS OFF")
endif (SQLITECPP_BUILD_TESTS) endif (SQLITECPP_BUILD_TESTS)