修改框架为DLL发布

This commit is contained in:
xx
2024-05-28 18:28:11 +08:00
parent d203466193
commit 0fc030a3cf
5 changed files with 118 additions and 90 deletions

View File

@@ -1,14 +1,19 @@
cmake_minimum_required(VERSION 3.5)
project("fastweb")
# 设置自定义配置类型
if(MSVC)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Build config types" FORCE)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugDll;ReleaseDll" CACHE STRING "Build config types" FORCE)
endif()
# C++等级
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# 警告等级
set(FASTWEBCORE ${PROJECT_NAME}core)
# 安装复制
set(CMAKE_INSTALL_ALWAYS_COPY TRUE)
# Recursively get all source files
file(GLOB_RECURSE SOURCE_FILES
@@ -30,7 +35,7 @@ foreach(header IN LISTS HEADER_FILES)
source_group(${header_path_rel_win} FILES "${header}")
endforeach()
set(YLIB ${CMAKE_INSTALL_PREFIX}/../ylib)
include_directories(${PROJECT_SOURCE_DIR}/src)
if(MSVC)
include_directories(${PROJECT_SOURCE_DIR}/src)
@@ -39,7 +44,7 @@ if(MSVC)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/lua)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/soci/include)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/mysql/include/jdbc)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/ylib/include)
include_directories(${YLIB}/include)
add_compile_options(/W3 /wd4819)
else()
include_directories(${PROJECT_SOURCE_DIR}/3rdparty)
@@ -47,58 +52,66 @@ else()
endif()
# Add the executable or library target
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES})
# 根据构建类型添加定义
add_library(${FASTWEBCORE} SHARED ${SOURCE_FILES} ${HEADER_FILES})
set_target_properties(${FASTWEBCORE} PROPERTIES OUTPUT_NAME_DEBUG "${FASTWEBCORE}_d" OUTPUT_NAME_RELEASE ${FASTWEBCORE})
add_executable(${PROJECT_NAME} tests/main.cpp)
link_directories(/usr/lib/x86_64-linux-gnu)
link_directories(/usr/local/lib)
if(MSVC)
target_link_libraries(${PROJECT_NAME}
odbc32.lib
User32.lib
Advapi32.lib
IPHLPAPI.lib
WS2_32.lib
Shell32.lib
${PROJECT_SOURCE_DIR}/3rdparty/libcrypto_static.lib
function(target_link_common_libraries target_name)
target_link_libraries(${target_name}
odbc32.lib
User32.lib
Advapi32.lib
IPHLPAPI.lib
WS2_32.lib
Shell32.lib
${YLIB}/lib/libcrypto_static_win64.lib
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/mysqlcppconn.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/leveldb.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/libzip.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/lua.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/sqlite3.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/ylib.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/zlib.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_core_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_empty_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_odbc_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_core_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_empty_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_odbc_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/mysqlcppconn.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/leveldb.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/libzip.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/lua.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/sqlite3.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/ylib.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/zlib.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_core_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_empty_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_odbc_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_core_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_empty_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_odbc_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/mysqlcppconn.lib>
)
$<$<CONFIG:Debug>:${YLIB}/lib/leveldb_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/libzip_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/lua_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/sqlite3_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/ylib_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/zlib_d.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_core_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_empty_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_odbc_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_core_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_empty_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_odbc_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/mysqlcppconn.lib>
$<$<CONFIG:Release>:${YLIB}/lib/leveldb.lib>
$<$<CONFIG:Release>:${YLIB}/lib/libzip.lib>
$<$<CONFIG:Release>:${YLIB}/lib/lua.lib>
$<$<CONFIG:Release>:${YLIB}/lib/sqlite3.lib>
$<$<CONFIG:Release>:${YLIB}/lib/ylib.lib>
$<$<CONFIG:Release>:${YLIB}/lib/zlib.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_core_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_empty_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_odbc_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_core_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_empty_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_odbc_4_1.lib>
)
endfunction()
target_link_common_libraries(${FASTWEBCORE})
target_link_libraries(${PROJECT_NAME} ${FASTWEBCORE})
else()
target_link_libraries(${PROJECT_NAME}
target_link_libraries(${FASTWEBCORE}
hpsocket
ylib
leveldb
@@ -119,20 +132,21 @@ endif()
######################## 安装 ########################
install(TARGETS ${FASTWEBCORE} DESTINATION bin)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/libcrypto-3-x64.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/libssl-3-x64.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/mysqlcppconn-9-vs14.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/libcrypto-3-x64.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/libssl-3-x64.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/mysqlcppconn-9-vs14.dll>
config.ini
DESTINATION bin)
if(MSVC)
install(FILES
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/libcrypto-3-x64.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/libssl-3-x64.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/mysqlcppconn-9-vs14.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/libcrypto-3-x64.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/libssl-3-x64.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/mysqlcppconn-9-vs14.dll>
DESTINATION bin)
endif()
install(FILES config.ini DESTINATION bin)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/scripts DESTINATION bin)

23
src/core/entry.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include <iostream>
#include "core/fastweb.h"
#include "util/system.h"
#include "core/define.h"
#include "core/config.h"
extern "C" {
__declspec(dllexport) int fastweb(const char* config_filepath)
{
std::cout << "=========== [fastweb engine] ============" << std::endl;
if (sConfig->open(config_filepath) == false)
{
LOG_ERROR("open config failed," + sConfig->last_error());
return -1;
}
if (fastweb::getInstance()->start() == false)
{
LOG_ERROR("fastweb start failed," + fastweb::getInstance()->last_error());
return -1;
}
return 0;
}
}

5
src/core/entry.h Normal file
View File

@@ -0,0 +1,5 @@
extern "C" {
__declspec(dllexport) int fastweb(const char* config_filepath);
}

View File

@@ -1,28 +0,0 @@
#pragma once
#include <iostream>
#include "core/fastweb.h"
#include "util/system.h"
#include "core/define.h"
#include "core/config.h"
int main()
{
std::cout << "=========== [fastweb engine] ============" << std::endl;
if(sConfig->open(system::current_dir() + "/config.ini") == false)
{
LOG_ERROR("open config failed,"+sConfig->last_error());
return -1;
}
if (fastweb::getInstance()->start() == false)
{
LOG_ERROR("fastweb start failed,"+fastweb::getInstance()->last_error());
return -1;
}
LOG_SUCC("success");
while (true)
std::cin.get();
return 0;
}

14
tests/main.cpp Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <iostream>
#include "core/entry.h"
#include "util/system.h"
int main()
{
std::string config_filepath = system::current_dir() + "/config.ini";
if (fastweb(config_filepath.c_str()) != 0)
return -1;
while (true)
std::cin.get();
return 0;
}