优化编译选项,统一放入 config.h.in, 以便知道实际使用配置

This commit is contained in:
fasiondog 2023-10-03 01:34:03 +08:00
parent 7badeb3c39
commit a30627f2b3
7 changed files with 78 additions and 38 deletions

View File

@ -34,6 +34,21 @@
// 启用MSVC内存泄漏检查
#define ENABLE_MSVC_LEAK_DETECT ${ENABLE_MSVC_LEAK_DETECT}
// 启用发送用户使用信息
#define HKU_ENABLE_SEND_FEEDBACK ${HKU_ENABLE_SEND_FEEDBACK}
// 启用 hdf5 K线数据引擎
#define HKU_ENABLE_HDF5_KDATA ${HKU_ENABLE_HDF5_KDATA}
// 启用 MySQL K线数据引擎
#define HKU_ENABLE_MYSQL_KDATA ${HKU_ENABLE_MYSQL_KDATA}
// 启用 SQLite K线数据引擎
#define HKU_ENABLE_SQLITE_KDATA ${HKU_ENABLE_SQLITE_KDATA}
// 启用通达信本地 K线数据引擎
#define HKU_ENABLE_TDX_KDATA ${HKU_ENABLE_TDX_KDATA}
// clang-format on
#endif /* HIKYUU_CONFIG_H_ */

View File

@ -12,8 +12,13 @@
#endif
#include <iostream>
#include <H5public.h>
#include <fmt/format.h>
#include "config.h"
#if HKU_ENABLE_HDF5_KDATA
#include <H5public.h>
#endif
#include "Log.h"
#include "hikyuu.h"
#include "GlobalInitializer.h"
@ -53,7 +58,7 @@ void GlobalInitializer::init() {
set_log_level(INFO);
#endif
#ifdef HKU_ENABLE_SEND_FEEDBACK
#if HKU_ENABLE_SEND_FEEDBACK
sendFeedback();
#endif
@ -71,7 +76,10 @@ void GlobalInitializer::clean() {
IndicatorImp::releaseDynEngine();
StockManager::quit();
DataDriverFactory::release();
#if HKU_ENABLE_HDF5_KDATA
H5close();
#endif
#if USE_SPDLOG_LOGGER
spdlog::drop_all();

View File

@ -12,24 +12,24 @@
#include "DataDriverFactory.h"
#include "KDataDriver.h"
#if defined(HKU_ENABLE_SQLITE_KDATA) || defined(HKU_ENABLE_HDF5_KDATA)
#if HKU_ENABLE_SQLITE_KDATA || HKU_ENABLE_HDF5_KDATA
#include "base_info/sqlite/SQLiteBaseInfoDriver.h"
#endif
#ifdef HKU_ENABLE_HDF5_KDATA
#if HKU_ENABLE_HDF5_KDATA
#include "kdata/hdf5/H5KDataDriver.h"
#endif
#ifdef HKU_ENABLE_MYSQL_KDATA
#if HKU_ENABLE_MYSQL_KDATA
#include "base_info/mysql/MySQLBaseInfoDriver.h"
#include "kdata/mysql/MySQLKDataDriver.h"
#endif
#ifdef HKU_ENABLE_TDX_KDATA
#if HKU_ENABLE_TDX_KDATA
#include "kdata/tdx/TdxKDataDriver.h"
#endif
#ifdef HKU_ENABLE_SQLITE_KDATA
#if HKU_ENABLE_SQLITE_KDATA
#include "kdata/sqlite/SQLiteKDataDriver.h"
#endif
@ -44,11 +44,11 @@ map<string, KDataDriverConnectPoolPtr>* DataDriverFactory::m_kdataDriverPools{nu
void DataDriverFactory::init() {
m_baseInfoDrivers = new map<string, BaseInfoDriverPtr>();
#if defined(HKU_ENABLE_SQLITE_KDATA) || defined(HKU_ENABLE_HDF5_KDATA)
#if HKU_ENABLE_SQLITE_KDATA || HKU_ENABLE_HDF5_KDATA
DataDriverFactory::regBaseInfoDriver(make_shared<SQLiteBaseInfoDriver>());
#endif
#ifdef HKU_ENABLE_MYSQL_KDATA
#if HKU_ENABLE_MYSQL_KDATA
DataDriverFactory::regBaseInfoDriver(make_shared<MySQLBaseInfoDriver>());
#endif
@ -60,19 +60,19 @@ void DataDriverFactory::init() {
DataDriverFactory::regKDataDriver(make_shared<KDataTempCsvDriver>());
#ifdef HKU_ENABLE_TDX_KDATA
#if HKU_ENABLE_TDX_KDATA
DataDriverFactory::regKDataDriver(make_shared<TdxKDataDriver>());
#endif
#ifdef HKU_ENABLE_HDF5_KDATA
#if HKU_ENABLE_HDF5_KDATA
DataDriverFactory::regKDataDriver(make_shared<H5KDataDriver>());
#endif
#ifdef HKU_ENABLE_MYSQL_KDATA
#if HKU_ENABLE_MYSQL_KDATA
DataDriverFactory::regKDataDriver(make_shared<MySQLKDataDriver>());
#endif
#ifdef HKU_ENABLE_SQLITE_KDATA
#if HKU_ENABLE_SQLITE_KDATA
DataDriverFactory::regKDataDriver(make_shared<SQLiteKDataDriver>());
#endif
}

View File

@ -37,9 +37,13 @@ target("hikyuu")
if is_plat("windows") then
if is_mode("release") then
add_defines("HKU_API=__declspec(dllexport)")
add_packages("hdf5")
else
add_packages("hdf5_D")
end
if get_config("hdf5") then
if is_mode("release") then
add_packages("hdf5")
else
add_packages("hdf5_D")
end
end
if get_config("mysql") then
add_packages("mysql")
@ -47,20 +51,24 @@ target("hikyuu")
end
if is_plat("linux", "cross") then
add_packages("hdf5")
if get_config("hdf5") then
add_packages("hdf5")
end
if get_config("mysql") then
add_packages("mysql")
end
end
if is_plat("macosx") then
-- add_linkdirs("/usr/local/opt/libiconv/lib")
add_packages("mysqlclient")
add_links("iconv")
add_includedirs("/usr/local/opt/hdf5/include")
add_linkdirs("/usr/local/opt/hdf5/lib")
add_links("hdf5", "hdf5_cpp")
add_links("sqlite3")
add_links("iconv", "sqlite3")
if get_config("mysql") then
add_packages("mysqlclient")
end
if get_config("hdf5") then
add_includedirs("/usr/local/opt/hdf5/include")
add_linkdirs("/usr/local/opt/hdf5/lib")
add_links("hdf5", "hdf5_cpp")
end
end
add_headerfiles("../(hikyuu/**.h)|**doc.h")

View File

@ -8,7 +8,8 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest/doctest.h"
#if !defined(HKU_ENABLE_HDF5_KDATA)
#include <hikyuu/config.h>
#if !HKU_ENABLE_HDF5_KDATA
#error test program only for hdf5 engine! You must config --hdf5=y
#endif

View File

@ -7,7 +7,9 @@
#include "doctest/doctest.h"
#ifdef HKU_ENABLE_MYSQL_KDATA
#include <hikyuu/config.h>
#if HKU_ENABLE_MYSQL_KDATA
#include <hikyuu/StockManager.h>
#include <hikyuu/utilities/ConnectPool.h>

View File

@ -5,7 +5,6 @@ option("hdf5")
set_showmenu(true)
set_category("hikyuu")
set_description("Enable hdf5 kdata engine.")
add_defines("HKU_ENABLE_HDF5_KDATA")
option_end()
option("mysql")
@ -13,7 +12,6 @@ option("mysql")
set_showmenu(true)
set_category("hikyuu")
set_description("Enable mysql kdata engine.")
add_defines("HKU_ENABLE_MYSQL_KDATA")
if is_plat("macosx") then
if os.exists("/usr/local/opt/mysql-client/lib") then
add_includedirs("/usr/local/opt/mysql-client/include/mysql")
@ -43,7 +41,6 @@ option("sqlite")
set_showmenu(true)
set_category("hikyuu")
set_description("Enable sqlite kdata engine.")
add_defines("HKU_ENABLE_SQLITE_KDATA")
option_end()
option("tdx")
@ -51,7 +48,6 @@ option("tdx")
set_showmenu(true)
set_category("hikyuu")
set_description("Enable tdx kdata engine.")
add_defines("HKU_ENABLE_TDX_KDATA")
option_end()
option("feedback")
@ -59,7 +55,6 @@ option("feedback")
set_showmenu(true)
set_category("hikyuu")
set_description("Enable send feedback.")
add_defines("HKU_ENABLE_SEND_FEEDBACK")
option_end()
@ -90,6 +85,12 @@ set_configvar("SUPPORT_XML_ARCHIVE", 1)
set_configvar("SUPPORT_BINARY_ARCHIVE", 1)
set_configvar("HKU_DISABLE_ASSERT", 0)
set_configvar("ENABLE_MSVC_LEAK_DETECT", 0)
set_configvar("HKU_ENABLE_SEND_FEEDBACK", get_config("feedback") and 1 or 0)
set_configvar("HKU_ENABLE_HDF5_KDATA", get_config("hdf5") and 1 or 0)
set_configvar("HKU_ENABLE_MYSQL_KDATA", get_config("mysql") and 1 or 0)
set_configvar("HKU_ENABLE_SQLITE_KDATA", get_config("sqlite") and 1 or 0)
set_configvar("HKU_ENABLE_TDX_KDATA", get_config("tdx") and 1 or 0)
-- set warning all as error
if is_plat("windows") then
@ -112,24 +113,29 @@ end
add_repositories("project-repo hikyuu_extern_libs")
if is_plat("windows") then
-- add_repositories("project-repo hikyuu_extern_libs")
if is_mode("release") then
add_requires("hdf5 " .. hdf5_version)
else
add_requires("hdf5_D " .. hdf5_version)
if get_config("hdf5") then
if is_mode("release") then
add_requires("hdf5 " .. hdf5_version)
else
add_requires("hdf5_D " .. hdf5_version)
end
end
if get_config("mysql") then
add_requires("mysql " .. mysql_version)
end
elseif is_plat("linux", "cross") then
add_requires("hdf5 " .. hdf5_version, { system = false })
if get_config("hdf5") then
add_requires("hdf5 " .. hdf5_version, { system = false })
end
if get_config("mysql") then
add_requires("mysql " .. mysql_version, { system = false })
end
elseif is_plat("macosx") then
add_requires("brew::hdf5")
if get_config("hdf5") then
add_requires("brew::hdf5")
end
if get_config("mysql") then
add_requires("brew::mysql-client")
end