mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2024-12-23 21:25:43 +00:00
Split tawashi into lib+executable to enable unit testing
This commit is contained in:
parent
bcb800ffef
commit
e1687c96ff
45 changed files with 175 additions and 78 deletions
|
@ -1,12 +1,21 @@
|
|||
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
|
||||
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||
project(tawashi_top)
|
||||
project(tawashi_top VERSION 0.1.3 LANGUAGES NONE)
|
||||
|
||||
set(TAWASHI_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(TAWASHI_GEN_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
|
||||
set(TAWASHI_CONFIG_PATH "etc" CACHE STRING "Path where config file will be located, absolute or relative to the install prefix")
|
||||
set(TAWASHI_CONFIG_FILE "${PROJECT_NAME}.ini" CACHE STRING "Filename of the config file in TAWASHI_CONFIG_PATH")
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/tawashiConfig.h.in"
|
||||
"${TAWASHI_GEN_INCLUDE_DIR}/tawashiConfig.h"
|
||||
)
|
||||
|
||||
add_subdirectory(lib/incredis)
|
||||
add_subdirectory(lib/mstch)
|
||||
add_subdirectory(lib/houdini)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(src/tawashi_implem)
|
||||
add_subdirectory(src/tawashi)
|
||||
|
||||
install(DIRECTORY html DESTINATION .)
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
project(tawashi VERSION 0.1.3 LANGUAGES CXX)
|
||||
|
||||
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options filesystem system)
|
||||
find_package(SourceHighlight REQUIRED)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(TAWASHI_CONFIG_PATH "etc" CACHE STRING "Path where config file will be located, absolute or relative to the install prefix")
|
||||
set(TAWASHI_CONFIG_FILE "${PROJECT_NAME}.ini" CACHE STRING "Filename of the config file in TAWASHI_CONFIG_PATH")
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
split_get_vars.cpp
|
||||
response.cpp
|
||||
submit_paste_response.cpp
|
||||
get_env.cpp
|
||||
cgi_environment_vars.cpp
|
||||
cgi_env.cpp
|
||||
num_to_token.cpp
|
||||
cgi_post.cpp
|
||||
escapist.cpp
|
||||
index_response.cpp
|
||||
pastie_response.cpp
|
||||
ini_file.cpp
|
||||
pathname/pathname.cpp
|
||||
response_factory.cpp
|
||||
list_highlight_langs.cpp
|
||||
settings_bag.cpp
|
||||
sanitized_utf8.cpp
|
||||
)
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.h.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}Config.h"
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
|
||||
PRIVATE ${TAWASHI_SOURCE_ROOT}/lib/kakoune
|
||||
PRIVATE ${TAWASHI_SOURCE_ROOT}/lib/mstch/include
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||
PRIVATE ${Boost_INCLUDE_DIRS}
|
||||
PRIVATE ${TAWASHI_SOURCE_ROOT}/lib/better-enums
|
||||
PRIVATE ${SourceHighlight_INCLUDE_DIR}
|
||||
PRIVATE ${TAWASHI_SOURCE_ROOT}/lib/utf8_v2_3_4/source
|
||||
PRIVATE ${TAWASHI_SOURCE_ROOT}/lib/spdlog/include
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${Boost_LIBRARIES}
|
||||
PRIVATE incredis
|
||||
PRIVATE ${SourceHighlight_LIBRARIES}
|
||||
PRIVATE mstch
|
||||
PRIVATE houdini
|
||||
PRIVATE pthread
|
||||
)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1
|
||||
PRIVATE $<$<CONFIG:Debug>:SPDLOG_DEBUG_ON>
|
||||
PRIVATE $<$<CONFIG:Debug>:SPDLOG_TRACE_ON>
|
||||
)
|
||||
target_compile_options(${PROJECT_NAME}
|
||||
PRIVATE -fdiagnostics-color=always
|
||||
)
|
||||
|
||||
set_target_properties(
|
||||
${PROJECT_NAME}
|
||||
PROPERTIES SUFFIX .cgi
|
||||
)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
LIBRARY DESTINATION lib
|
||||
RUNTIME DESTINATION bin
|
||||
ARCHIVE DESTINATION lib/static
|
||||
)
|
27
src/tawashi/CMakeLists.txt
Normal file
27
src/tawashi/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
project(tawashi LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE tawashi_implem
|
||||
)
|
||||
|
||||
set_target_properties(
|
||||
${PROJECT_NAME}
|
||||
PROPERTIES SUFFIX .cgi
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${TAWASHI_GEN_INCLUDE_DIR}
|
||||
#hack - add duckhandy to the project instead of picking from inside redis
|
||||
PRIVATE ${TAWASHI_SOURCE_ROOT}/lib/incredis/lib/duckhandy/include
|
||||
)
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
LIBRARY DESTINATION lib
|
||||
RUNTIME DESTINATION bin
|
||||
ARCHIVE DESTINATION lib/static
|
||||
)
|
57
src/tawashi_implem/CMakeLists.txt
Normal file
57
src/tawashi_implem/CMakeLists.txt
Normal file
|
@ -0,0 +1,57 @@
|
|||
project(tawashi_implem LANGUAGES CXX)
|
||||
|
||||
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options filesystem system)
|
||||
find_package(SourceHighlight REQUIRED)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC
|
||||
split_get_vars.cpp
|
||||
response.cpp
|
||||
submit_paste_response.cpp
|
||||
get_env.cpp
|
||||
cgi_environment_vars.cpp
|
||||
cgi_env.cpp
|
||||
num_to_token.cpp
|
||||
cgi_post.cpp
|
||||
escapist.cpp
|
||||
index_response.cpp
|
||||
pastie_response.cpp
|
||||
ini_file.cpp
|
||||
pathname/pathname.cpp
|
||||
response_factory.cpp
|
||||
list_highlight_langs.cpp
|
||||
settings_bag.cpp
|
||||
sanitized_utf8.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${TAWASHI_GEN_INCLUDE_DIR}
|
||||
PUBLIC ${TAWASHI_SOURCE_ROOT}/lib/kakoune
|
||||
PUBLIC ${TAWASHI_SOURCE_ROOT}/lib/mstch/include
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||
PUBLIC ${Boost_INCLUDE_DIRS}
|
||||
PUBLIC ${TAWASHI_SOURCE_ROOT}/lib/better-enums
|
||||
PRIVATE ${SourceHighlight_INCLUDE_DIR}
|
||||
PRIVATE ${TAWASHI_SOURCE_ROOT}/lib/utf8_v2_3_4/source
|
||||
PUBLIC ${TAWASHI_SOURCE_ROOT}/lib/spdlog/include
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${Boost_LIBRARIES}
|
||||
PRIVATE incredis
|
||||
PRIVATE ${SourceHighlight_LIBRARIES}
|
||||
PUBLIC mstch
|
||||
PRIVATE houdini
|
||||
PRIVATE pthread
|
||||
)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1
|
||||
PUBLIC $<$<CONFIG:Debug>:SPDLOG_DEBUG_ON>
|
||||
PUBLIC $<$<CONFIG:Debug>:SPDLOG_TRACE_ON>
|
||||
)
|
||||
target_compile_options(${PROJECT_NAME}
|
||||
PRIVATE -fdiagnostics-color=always
|
||||
)
|
52
src/tawashi_implem/logger.hpp
Normal file
52
src/tawashi_implem/logger.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* Copyright 2017, Michele Santullo
|
||||
* This file is part of "tawashi".
|
||||
*
|
||||
* "tawashi" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "tawashi" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <ostream>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <cassert>
|
||||
#include <ciso646>
|
||||
|
||||
namespace tawashi {
|
||||
class Logger {
|
||||
public:
|
||||
explicit Logger (std::ostream* parStream);
|
||||
~Logger() noexcept;
|
||||
|
||||
template <typename... Args>
|
||||
void log (int parLevel, const boost::string_ref& parFormat, Args&&... parArgs);
|
||||
|
||||
private:
|
||||
static const constexpr int LogLevels = 3;
|
||||
|
||||
std::array<std::ostream*, LogLevels> m_outs;
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
void Logger::log (int parLevel, const boost::string_ref& parFormat, Args&&... parArgs) {
|
||||
assert(parLevel >= 0 and parLevel < LogLevels);
|
||||
if (nullptr == m_outs[parLevel])
|
||||
return;
|
||||
|
||||
bool percentage_seq = false;
|
||||
for (auto chara : parFormat) {
|
||||
if (percentage_seq) {
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
}
|
||||
} //namespace tawashi
|
28
src/tawashi_implem/spdlog.hpp
Normal file
28
src/tawashi_implem/spdlog.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Copyright 2017, Michele Santullo
|
||||
* This file is part of "tawashi".
|
||||
*
|
||||
* "tawashi" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "tawashi" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
namespace spdlog {
|
||||
template <typename OStream>
|
||||
inline OStream& operator<< (OStream& parOS, const boost::string_ref& parStr) {
|
||||
return parOS << parStr;
|
||||
}
|
||||
} //namespace spdlog
|
Loading…
Reference in a new issue