Added CMake Install.
This commit is contained in:
parent
5c8c4e86b2
commit
4367534a33
13 changed files with 68 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ cmake-build-debug/
|
|||
.idea/
|
||||
|
||||
example/build
|
||||
dist/
|
|
@ -1,5 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.21)
|
||||
project(VWeb)
|
||||
set(version 1.0)
|
||||
project(VWeb VERSION ${version})
|
||||
set(project_lower vweb)
|
||||
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUGSOFT")
|
||||
|
@ -22,9 +25,29 @@ set(SOURCE_FILES
|
|||
include_directories(${CMAKE_SOURCE_DIR}/)
|
||||
add_library(VWeb ${SOURCE_FILES})
|
||||
|
||||
set(mode Release)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(mode Debug)
|
||||
endif ()
|
||||
set(target_file ${CMAKE_SOURCE_DIR}/dist/libVWeb.${mode}.a)
|
||||
add_custom_command(TARGET VWeb POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:VWeb> ${target_file})
|
||||
include(GNUInstallDirs)
|
||||
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
|
||||
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
|
||||
|
||||
install(FILES VWeb.h DESTINATION include/VWeb-${version})
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
LIBRARY DESTINATION lib/$<CONFIG>
|
||||
ARCHIVE DESTINATION lib/$<CONFIG>
|
||||
)
|
||||
install(EXPORT ${PROJECT_NAME}-targets
|
||||
DESTINATION lib/${PROJECT_NAME}-${version})
|
||||
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/pkg/${project_lower}-config.cmake.in
|
||||
${PROJECT_BINARY_DIR}/pkg/${project_lower}-config.cmake @ONLY)
|
||||
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/${project_lower}-config-version.cmake.in
|
||||
${PROJECT_BINARY_DIR}/${project_lower}-config-version.cmake @ONLY)
|
||||
|
||||
install(FILES ${PROJECT_BINARY_DIR}/pkg/${project_lower}-config.cmake
|
||||
${PROJECT_BINARY_DIR}/${project_lower}-config-version.cmake
|
||||
DESTINATION lib/${PROJECT_NAME}-${version})
|
|
@ -30,6 +30,6 @@ bool EPollManager::UpdateEvents(int sock, uint32_t eventType) const {
|
|||
}
|
||||
|
||||
int EPollManager::Wait(int maxEvents, epoll_event *events) const {
|
||||
return epoll_wait(m_EpollID, events, maxEvents, 10);
|
||||
return epoll_wait(m_EpollID, events, maxEvents, -1);
|
||||
}
|
||||
} // namespace VWeb
|
|
@ -45,8 +45,8 @@ SessionManager::SessionManager() {
|
|||
m_Counter = -1;
|
||||
}
|
||||
m_Counter++;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
});
|
||||
}
|
||||
SessionManager::~SessionManager() {
|
||||
|
@ -106,7 +106,7 @@ PreMiddleWareReturn CookieManager::PreHandle(Request &request) {
|
|||
auto &cookies = request.CookieData;
|
||||
if (cookieHeaders.Size() > 0) {
|
||||
auto &values = cookieHeaders.Values();
|
||||
for (auto &rawCookie : cookieHeaders.Values()) {
|
||||
for (auto &rawCookie : values) {
|
||||
auto splitCookies = String::Split(rawCookie, ";");
|
||||
for (auto &cookie : splitCookies) {
|
||||
auto split = String::Split(cookie, "=");
|
||||
|
|
|
@ -8,7 +8,7 @@ Server::Server() {
|
|||
m_ServerConfig->EPoll = CreateRef<EPollManager>();
|
||||
m_ServerConfig->Socket = CreateRef<SocketManager>(m_ServerConfig);
|
||||
m_RequestHandler = CreateRef<RequestHandler>(m_ServerConfig->Socket);
|
||||
auto& middleWare = m_RequestHandler->Middleware();
|
||||
auto &middleWare = m_RequestHandler->Middleware();
|
||||
middleWare->Create<CookieManager>();
|
||||
middleWare->Create<SessionManager>();
|
||||
middleWare->Create<AuthWare>();
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include <VWeb.h>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
namespace VWeb {
|
||||
ThreadPool::ThreadPool(const std::string &name) : m_Name(name) {}
|
||||
ThreadPool::ThreadPool(std::string name) : m_Name(std::move(name)) {}
|
||||
void ThreadPool::Create() {
|
||||
if (m_IsCreated)
|
||||
return;
|
||||
|
@ -10,9 +11,10 @@ void ThreadPool::Create() {
|
|||
m_IsCreated = true;
|
||||
m_Queue.Open();
|
||||
for (int i = 0; i < m_ThreadCount; ++i) {
|
||||
m_Threads.push_back(std::thread(&ThreadPool::Execute, this));
|
||||
};
|
||||
printf("[ThreadPool] >> Created %d Threads for Pool \"%s\"\n", m_ThreadCount, m_Name.c_str());
|
||||
m_Threads.emplace_back(&ThreadPool::Execute, this);
|
||||
}
|
||||
printf("[ThreadPool] >> Created %d Threads for Pool \"%s\"\n", m_ThreadCount,
|
||||
m_Name.c_str());
|
||||
}
|
||||
void ThreadPool::Stop() {
|
||||
m_IsDone = true;
|
||||
|
|
2
VWeb.h
2
VWeb.h
|
@ -164,7 +164,7 @@ struct WorkerJob {
|
|||
};
|
||||
class ThreadPool {
|
||||
public:
|
||||
explicit ThreadPool(const std::string &name);
|
||||
explicit ThreadPool(std::string name);
|
||||
void SetThreadCount(int);
|
||||
void Dispatch(const Ref<WorkerJob> &);
|
||||
void Create();
|
||||
|
|
BIN
dist/libVWeb.Debug.a
vendored
BIN
dist/libVWeb.Debug.a
vendored
Binary file not shown.
BIN
dist/libVWeb.Release.a
vendored
BIN
dist/libVWeb.Release.a
vendored
Binary file not shown.
|
@ -7,9 +7,15 @@ add_executable(VWeb_Example main.cpp)
|
|||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/..)
|
||||
|
||||
set(mode release)
|
||||
set(mode Release)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(mode debug)
|
||||
set(mode Debug)
|
||||
endif ()
|
||||
set(vweb_lib ${CMAKE_SOURCE_DIR}/../dist/libVWeb.${mode}.a)
|
||||
|
||||
SET_SOURCE_FILES_PROPERTIES(
|
||||
main.cpp
|
||||
PROPERTIES OBJECT_DEPENDS ${vweb_lib}
|
||||
)
|
||||
|
||||
target_link_libraries(VWeb_Example Threads::Threads ${vweb_lib})
|
||||
|
|
|
@ -23,6 +23,8 @@ int main() {
|
|||
using namespace VWeb;
|
||||
VWeb::Server server;
|
||||
auto& router = server.GetRouter();
|
||||
// For debugging and profiling more than 1 thread can be hard.
|
||||
server.GetServerConfig()->WorkerThreads = 1;
|
||||
router->Get("/test", [](const Request&, Response& response) {
|
||||
response << "NICE";
|
||||
return true;
|
||||
|
|
9
pkg/vweb-config.cmake.in
Normal file
9
pkg/vweb-config.cmake.in
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Compute installation prefix relative to this file.
|
||||
get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
get_filename_component(_prefix "${_dir}/../.." ABSOLUTE)
|
||||
|
||||
# Import the targets.
|
||||
include("${_prefix}/lib/VWeb-@version@/VWeb-targets.cmake")
|
||||
|
||||
# Report other information.
|
||||
set(VWeb_INCLUDE_DIRS "${_prefix}/include/VWeb-@version@")
|
7
vweb-config-version.cmake.in
Normal file
7
vweb-config-version.cmake.in
Normal file
|
@ -0,0 +1,7 @@
|
|||
set(PACKAGE_VERSION "@version@")
|
||||
if(NOT "${PACKAGE_FIND_VERSION}" VERSION_GREATER "@version@")
|
||||
set(PACKAGE_VERSION_COMPATIBLE 1) # compatible with older
|
||||
if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "@version@")
|
||||
set(PACKAGE_VERSION_EXACT 1) # exact match for this version
|
||||
endif()
|
||||
endif()
|
Loading…
Reference in a new issue