Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Experimental Linux support #1002

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 81 additions & 72 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,50 @@ find_package(Boost REQUIRED COMPONENTS log)
add_subdirectory(vendor/fmt)
add_subdirectory(vendor/libtorrent)
add_subdirectory(vendor/nlohmann-json)
add_subdirectory(vendor/sentry-crashpad)
#add_subdirectory(vendor/sentry-crashpad)
add_subdirectory(vendor/wx)

gitversion_install()
gitversion_showvariable(BranchName GITVERSION_VAR_BRANCHNAME)
gitversion_showvariable(MajorMinorPatch GITVERSION_VAR_VERSION)
gitversion_showvariable(Major GITVERSION_VAR_VERSION_MAJOR)
gitversion_showvariable(Minor GITVERSION_VAR_VERSION_MINOR)
gitversion_showvariable(Patch GITVERSION_VAR_VERSION_PATCH)
gitversion_showvariable(SemVer GITVERSION_VAR_SEMVER)
gitversion_showvariable(ShortSha GITVERSION_VAR_SHORTSHA)

# Get git commitish from dependencies
git_abbreviated_hash(${CMAKE_SOURCE_DIR}/vendor/fmt PICO_FMT_GIT_COMMITISH)
git_abbreviated_hash(${CMAKE_SOURCE_DIR}/vendor/libtorrent PICO_LIBTORRENT_GIT_COMMITISH)
git_abbreviated_hash(${CMAKE_SOURCE_DIR}/vendor/nlohmann-json PICO_NLOHMANN_JSON_GIT_COMMITISH)
git_abbreviated_hash(${CMAKE_SOURCE_DIR}/vendor/wx PICO_WX_GIT_COMMITISH)
#gitversion_install()
#gitversion_showvariable(BranchName GITVERSION_VAR_BRANCHNAME)
#gitversion_showvariable(MajorMinorPatch GITVERSION_VAR_VERSION)
#gitversion_showvariable(Major GITVERSION_VAR_VERSION_MAJOR)
#gitversion_showvariable(Minor GITVERSION_VAR_VERSION_MINOR)
#gitversion_showvariable(Patch GITVERSION_VAR_VERSION_PATCH)
#gitversion_showvariable(SemVer GITVERSION_VAR_SEMVER)
#gitversion_showvariable(ShortSha GITVERSION_VAR_SHORTSHA)
#
## Get git commitish from dependencies
#git_abbreviated_hash(${CMAKE_SOURCE_DIR}/vendor/fmt PICO_FMT_GIT_COMMITISH)
#git_abbreviated_hash(${CMAKE_SOURCE_DIR}/vendor/libtorrent PICO_LIBTORRENT_GIT_COMMITISH)
#git_abbreviated_hash(${CMAKE_SOURCE_DIR}/vendor/nlohmann-json PICO_NLOHMANN_JSON_GIT_COMMITISH)
#git_abbreviated_hash(${CMAKE_SOURCE_DIR}/vendor/wx PICO_WX_GIT_COMMITISH)

# Generate buildinfo file
configure_file("${CMAKE_SOURCE_DIR}/src/picotorrent/buildinfo.cpp.in" "${CMAKE_SOURCE_DIR}/src/picotorrent/buildinfo.cpp" @ONLY)

# Debug flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi")
if (WIN32)
# Debug flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi")

# Release flags
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /MAP /OPT:REF /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /MAP /OPT:REF /OPT:ICF")
# Release flags
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /MAP /OPT:REF /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /MAP /OPT:REF /OPT:ICF")
endif()

add_library(
sqlite
STATIC
src/sqlite/sqlite3
)

target_link_libraries(
sqlite
PRIVATE
dl
pthread
)

target_include_directories(
sqlite
INTERFACE
Expand Down Expand Up @@ -121,7 +130,7 @@ target_link_libraries(

add_executable(
PicoTorrent
WIN32
#MACOSX_BUNDLE

src/picotorrent/application
src/picotorrent/buildinfo
Expand Down Expand Up @@ -198,29 +207,29 @@ add_executable(
target_compile_definitions(
PicoTorrent
PRIVATE
-D_UNICODE
-D_WIN32
-D_WIN32_WINNT=0x0600
-DNOMINMAX
#-D_UNICODE
#-D_WIN32
#-D_WIN32_WINNT=0x0600
#-DNOMINMAX
-DPICOJSON_USE_INT64
-DUNICODE
-DWIN32
-DWIN32_LEAN_AND_MEAN
#-DUNICODE
#-DWIN32
#-DWIN32_LEAN_AND_MEAN

-DLIBPICO_API_EXPORT

-DPICO_GIT_COMMITISH=${GITVERSION_VAR_SHORTSHA}
-DPICO_VERSION_MAJOR=${GITVERSION_VAR_VERSION_MAJOR}
-DPICO_VERSION_MINOR=${GITVERSION_VAR_VERSION_MINOR}
-DPICO_VERSION_PATCH=${GITVERSION_VAR_VERSION_PATCH}
#-DPICO_GIT_COMMITISH=${GITVERSION_VAR_SHORTSHA}
#-DPICO_VERSION_MAJOR=${GITVERSION_VAR_VERSION_MAJOR}
#-DPICO_VERSION_MINOR=${GITVERSION_VAR_VERSION_MINOR}
#-DPICO_VERSION_PATCH=${GITVERSION_VAR_VERSION_PATCH}

-DPICO_FMT_GIT_COMMITISH=${PICO_FMT_GIT_COMMITISH}
-DPICO_LIBTORRENT_GIT_COMMITISH=${PICO_LIBTORRENT_GIT_COMMITISH}
-DPICO_NLOHMANN_JSON_GIT_COMMITISH=${PICO_NLOHMANN_JSON_GIT_COMMITISH}
-DPICO_WX_GIT_COMMITISH=${PICO_WX_GIT_COMMITISH}
#-DPICO_FMT_GIT_COMMITISH=${PICO_FMT_GIT_COMMITISH}
#-DPICO_LIBTORRENT_GIT_COMMITISH=${PICO_LIBTORRENT_GIT_COMMITISH}
#-DPICO_NLOHMANN_JSON_GIT_COMMITISH=${PICO_NLOHMANN_JSON_GIT_COMMITISH}
#-DPICO_WX_GIT_COMMITISH=${PICO_WX_GIT_COMMITISH}
)

target_compile_options(PicoTorrent PRIVATE /guard:cf /W4 /WX)
#target_compile_options(PicoTorrent PRIVATE /guard:cf /W4 /WX)

target_include_directories(
PicoTorrent
Expand All @@ -237,22 +246,22 @@ target_link_libraries(
${Boost_LIBRARIES}

# wxWidgets
wxcore wxbase wxpropgrid
wxcore wxbase wxnet wxpropgrid

# Windows
Comctl32
crypt32
iphlpapi
legacy_stdio_definitions
propsys
shlwapi
wininet
winhttp
# Comctl32
# crypt32
# iphlpapi
# legacy_stdio_definitions
# propsys
# shlwapi
# wininet
# winhttp

# Crashpad
crashpad_client
crashpad_util
mini_chromium
#crashpad_client
#crashpad_util
#mini_chromium

# fmt
fmt
Expand All @@ -269,35 +278,35 @@ target_link_libraries(
set_property(TARGET PicoTorrent PROPERTY ENABLE_EXPORTS 1)

# Plugins
add_library(
Plugin_Filters
SHARED
src/plugins/filters/filters
)
#add_library(
# Plugin_Filters
# SHARED
# src/plugins/filters/filters
#)

target_include_directories(Plugin_Filters PRIVATE include)
target_link_libraries(Plugin_Filters PRIVATE PicoTorrent)
#target_include_directories(Plugin_Filters PRIVATE include)
#target_link_libraries(Plugin_Filters PRIVATE PicoTorrent)

add_library(
Plugin_Updater
SHARED
src/plugins/updater/updater
)
#add_library(
# Plugin_Updater
# SHARED
# src/plugins/updater/updater
#)

target_compile_definitions(Plugin_Updater PRIVATE -D_WIN32 -DUNICODE -DWIN32_LEAN_AND_MEAN)
target_include_directories(Plugin_Updater PRIVATE include)
target_link_libraries(Plugin_Updater PRIVATE PicoTorrent Comctl32)
#target_compile_definitions(Plugin_Updater PRIVATE -D_WIN32 -DUNICODE -DWIN32_LEAN_AND_MEAN)
#target_include_directories(Plugin_Updater PRIVATE include)
#target_link_libraries(Plugin_Updater PRIVATE PicoTorrent Comctl32)

# Copy Crashpad handler
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:crashpad_handler>
$<TARGET_FILE_DIR:PicoTorrent>
)
#add_custom_command(
# TARGET PicoTorrent POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# $<TARGET_FILE:crashpad_handler>
# $<TARGET_FILE_DIR:PicoTorrent>
#)

# Generate coredb
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND PicoTorrent-coredb "${CMAKE_SOURCE_DIR}/lang" $<TARGET_FILE_DIR:PicoTorrent>
COMMAND PicoTorrent-coredb "${CMAKE_SOURCE_DIR}/lang" "${CMAKE_SOURCE_DIR}/res/dbmigrations" $<TARGET_FILE_DIR:PicoTorrent>
)
4 changes: 4 additions & 0 deletions include/libpico.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
return init_func(v,a); \
}

#ifdef _WIN32
#if defined(LIBPICO_API_EXPORT)
#define LIBPICO_API_FUNCTION \
extern "C" __declspec(dllexport)
#else
#define LIBPICO_API_FUNCTION \
extern "C" __declspec(dllimport)
#endif
#else
#define LIBPICO_API_FUNCTION
#endif

typedef struct libpico_config_t libpico_config_t;
typedef struct libpico_http_response_t libpico_http_response_t;
Expand Down
104 changes: 80 additions & 24 deletions src/l10n/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,68 @@ using nlohmann::json;
const char* translations_table_sql = "CREATE TABLE translations (id INTEGER PRIMARY KEY, locale TEXT NOT NULL, key TEXT NOT NULL, value TEXT, UNIQUE(locale, key));";
const char* insert_translation_sql = "INSERT INTO translations (locale, key, value) VALUES (?, ?, ?);";

int main(int argc, char* argv[])
{
std::cout << "generating l10n database" << std::endl;
const char* migrations_table_sql = "CREATE TABLE migrations (id TEXT PRIMARY KEY, content TEXT NOT NULL)";
const char * insert_migration_sql = "INSERT INTO migrations (id, content) VALUES (?, ?);";

for (int i = 0; i < argc; i++)
bool insert_migrations(fs::path const& path, sqlite3* db)
{
if (sqlite3_exec(db, migrations_table_sql, nullptr, nullptr, nullptr) != SQLITE_OK)
{
std::cout << argv[i] << std::endl;
std::cerr << "could not create migrations table" << std::endl;
return false;
}

if (argc < 3)
sqlite3_stmt* stmt;
sqlite3_prepare_v2(db, insert_migration_sql, -1, &stmt, nullptr);

for (fs::path p : fs::directory_iterator(path))
{
std::cerr << "incorrect number of arguments" << std::endl;
return 1;
}
std::string migration = p.filename().string();
auto ext_pos = migration.find_last_of('.');

fs::path input_dir = argv[1];
fs::path output_file = fs::path(argv[2]) / "coredb.sqlite";
if (ext_pos != std::string::npos)
{
migration = migration.substr(0, ext_pos);
}

if (fs::exists(output_file))
{
std::cout << "removing existing database... rebuilding" << std::endl;
fs::remove(output_file);
std::cout << "inserting migration " << migration << std::endl;

std::ifstream in(p);
std::string content(
(std::istreambuf_iterator<char>(in)),
std::istreambuf_iterator<char>());

sqlite3_bind_text(stmt, 1, migration.c_str(), static_cast<int>(migration.size()), SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, content.c_str(), static_cast<int>(content.size()), SQLITE_TRANSIENT);

int res = sqlite3_step(stmt);

if (res != SQLITE_ROW && res != SQLITE_DONE)
{
std::cerr << "error when inserting migration data: " << sqlite3_errmsg(sqlite3_db_handle(stmt)) << std::endl;
return false;
}

sqlite3_reset(stmt);
}

sqlite3* db;
sqlite3_open(output_file.string().c_str(), &db);
sqlite3_finalize(stmt);

return true;
}

bool insert_translations(fs::path const& path, sqlite3* db)
{
if (sqlite3_exec(db, translations_table_sql, nullptr, nullptr, nullptr) != SQLITE_OK)
{
std::cerr << "could not create translations table" << std::endl;
return 1;
return false;
}

sqlite3_stmt* stmt;
sqlite3_prepare_v2(db, insert_translation_sql, -1, &stmt, nullptr);

sqlite3_exec(db, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);

for (fs::path p : fs::directory_iterator(input_dir))
for (fs::path p : fs::directory_iterator(path))
{
std::string loc = p.filename().string();
auto ext_pos = loc.find_last_of('.');
Expand Down Expand Up @@ -80,17 +103,50 @@ int main(int argc, char* argv[])
{
std::cerr << "error when inserting translation data: " << sqlite3_errmsg(sqlite3_db_handle(stmt)) << std::endl;
std::cerr << " - " << loc << std::endl << " - " << key << std::endl;
return 1;
return false;
}

sqlite3_reset(stmt);
}
}

sqlite3_finalize(stmt);

return true;
}

int main(int argc, char* argv[])
{
std::cout << "generating coredb" << std::endl;

for (int i = 0; i < argc; i++)
{
std::cout << argv[i] << std::endl;
}

if (argc < 3)
{
std::cerr << "incorrect number of arguments" << std::endl;
return 1;
}

fs::path output_file = fs::path(argv[3]) / "coredb.sqlite";

if (fs::exists(output_file))
{
std::cout << "removing existing database... rebuilding" << std::endl;
fs::remove(output_file);
}

sqlite3* db;
sqlite3_open(output_file.string().c_str(), &db);
sqlite3_exec(db, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);

insert_migrations(argv[2], db);
insert_translations(argv[1], db);

sqlite3_exec(db, "END TRANSACTION", nullptr, nullptr, nullptr);
sqlite3_exec(db, "VACUUM", nullptr, nullptr, nullptr);

sqlite3_finalize(stmt);
sqlite3_close(db);

return 0;
Expand Down
Loading