From 9ee1ee929c9239779c395ca11dfca3bc1836f9a6 Mon Sep 17 00:00:00 2001 From: antao Date: Thu, 27 Dec 2018 17:45:15 +0800 Subject: [PATCH] Update the drogon_ctl command to support sqlite3 --- CMakeLists.txt | 2 +- drogon_ctl/create_project.cc | 11 +++++++-- drogon_ctl/templates/FindSQLite3.csp | 37 ++++++++++++++++++++++++++++ drogon_ctl/templates/cmake.csp | 7 ++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 drogon_ctl/templates/FindSQLite3.csp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5de4c93f..9d2faf19 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ if (SQLITE3_FOUND) link_libraries(${SQLITE3_LIBRARIES}) aux_source_directory(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl DIR_SRCS) set(USE_ORM TRUE) -endif (SQLITE3_FOUND) +endif() message(STATUS ${DIR_SRCS}) diff --git a/drogon_ctl/create_project.cc b/drogon_ctl/create_project.cc index 9cb43f9e..2c2aa3e8 100644 --- a/drogon_ctl/create_project.cc +++ b/drogon_ctl/create_project.cc @@ -62,12 +62,17 @@ static void newJsonFindFile(std::ofstream &jsonFile) jsonFile << templ->genText(); } -static void newMySQLFindFile(std::ofstream &jsonFile) +static void newMySQLFindFile(std::ofstream &mysqlFile) { auto templ = DrTemplateBase::newTemplate("FindMySQL.csp"); - jsonFile << templ->genText(); + mysqlFile << templ->genText(); } +static void newSQLite3FindFile(std::ofstream &sqlite3File) +{ + auto templ = DrTemplateBase::newTemplate("FindSQLite3.csp"); + sqlite3File << templ->genText(); +} static void newConfigFile(std::ofstream &configFile) { @@ -108,6 +113,8 @@ void create_project::createProject(const std::string &projectName) newUuidFindFile(uuidFile); std::ofstream mysqlFile("cmake_modules/FindMySQL.cmake", std::ofstream::out); newMySQLFindFile(mysqlFile); + std::ofstream sqlite3File("cmake_modules/FindSQLite3.cmake", std::ofstream::out); + newSQLite3FindFile(sqlite3File); std::ofstream gitFile(".gitignore", std::ofstream::out); newGitIgFile(gitFile); diff --git a/drogon_ctl/templates/FindSQLite3.csp b/drogon_ctl/templates/FindSQLite3.csp new file mode 100644 index 00000000..9c99ae5c --- /dev/null +++ b/drogon_ctl/templates/FindSQLite3.csp @@ -0,0 +1,37 @@ +# Copyright (C) 2007-2009 LuaDist. +# Created by Peter Kapec +# Redistribution and use of this file is allowed according to the terms of the MIT license. +# For details see the COPYRIGHT file distributed with LuaDist. +# Note: +# Searching headers and libraries is very simple and is NOT as powerful as scripts +# distributed with CMake, because LuaDist defines directories to search for. +# Everyone is encouraged to contact the author with improvements. Maybe this file +# becomes part of CMake distribution sometimes. + +# - Find sqlite3 +# Find the native SQLITE3 headers and libraries. +# +# SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc. +# SQLITE3_LIBRARIES - List of libraries when using sqlite. +# SQLITE3_FOUND - True if sqlite found. + +# Look for the header file. +FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) + +# Look for the library. +FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3) + +# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR) + +# Copy the results to the output variables. +IF(SQLITE3_FOUND) + SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY}) + SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR}) +ELSE(SQLITE3_FOUND) + SET(SQLITE3_LIBRARIES) + SET(SQLITE3_INCLUDE_DIRS) +ENDIF(SQLITE3_FOUND) + +MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES) diff --git a/drogon_ctl/templates/cmake.csp b/drogon_ctl/templates/cmake.csp index 1eb69c57..bd214400 100644 --- a/drogon_ctl/templates/cmake.csp +++ b/drogon_ctl/templates/cmake.csp @@ -75,6 +75,13 @@ if(MYSQL_FOUND) endif() endif() +#Find sqlite3. +find_package (SQLite3) +if (SQLITE3_FOUND) + include_directories(${SQLITE3_INCLUDE_DIRS}) + link_libraries(${SQLITE3_LIBRARIES}) +endif() + AUX_SOURCE_DIRECTORY(./ SRC_DIR) AUX_SOURCE_DIRECTORY(controllers CTL_SRC) AUX_SOURCE_DIRECTORY(filters FILTER_SRC)