From bd59867bc3465a330f9ed0c25ef326a23121e9c5 Mon Sep 17 00:00:00 2001 From: Anthony Rabine Date: Thu, 25 Apr 2024 23:07:52 +0200 Subject: [PATCH] fix windows build --- shared/library_manager.cpp | 4 +- shared/uuid.h | 4 +- story-editor/CMakeLists.txt | 46 +++++++++++++++++-- story-editor/Dockerfile | 36 +++++++++++---- story-editor/build_win32.sh | 4 +- story-editor/src/gui.cpp | 2 +- story-editor/src/importers/pack_archive.cpp | 14 +++--- .../src/node_editor/node_editor_window.cpp | 2 +- story-editor/src/zip.cpp | 2 +- 9 files changed, 84 insertions(+), 30 deletions(-) diff --git a/shared/library_manager.cpp b/shared/library_manager.cpp index 0d4bc1f..ca9af62 100644 --- a/shared/library_manager.cpp +++ b/shared/library_manager.cpp @@ -34,7 +34,7 @@ void LibraryManager::Scan() { // Si c'est un sous-répertoire, récursivement scanner le contenu std::string uuid = entry.path().filename().generic_string(); - if (UUID::IsValid(uuid)) + if (Uuid::IsValid(uuid)) { std::cout << "Found story directory" << std::endl; // Look for a story.json file in this directory @@ -68,7 +68,7 @@ void LibraryManager::Scan() std::shared_ptr LibraryManager::NewProject() { auto story = std::make_shared(); - std::string uuid = UUID().String(); + std::string uuid = Uuid().String(); story->New(uuid, m_library_path); story->SetDisplayFormat(320, 240); diff --git a/shared/uuid.h b/shared/uuid.h index 3afddcd..b2abb58 100644 --- a/shared/uuid.h +++ b/shared/uuid.h @@ -7,11 +7,11 @@ // Encaasulate the genaeration of a Version 4 UUID object // A Version 4 UUID is a universally unique identifier that is generated using random numbers. -class UUID +class Uuid { public: - UUID() { New(); } + Uuid() { New(); } // Factory method for creating UUID object. void New() diff --git a/story-editor/CMakeLists.txt b/story-editor/CMakeLists.txt index a607cf1..229f62f 100644 --- a/story-editor/CMakeLists.txt +++ b/story-editor/CMakeLists.txt @@ -21,7 +21,9 @@ endif() find_package(OpenGL REQUIRED) -find_package(OpenSSL REQUIRED) + +# set(OPENSSL_ROOT_DIR /libs/openssl) +# find_package(OpenSSL REQUIRED) set(IMGUI_VERSION 1.90) @@ -30,14 +32,46 @@ include(FetchContent) # ========================================================================================================================= # CURL # ========================================================================================================================= -FetchContent_Declare(curl - URL https://github.com/curl/curl/archive/refs/tags/curl-8_6_0.zip + +# Définit les options de cURL pour utiliser mBedTLS +set(CMAKE_USE_OPENSSL OFF) +set(CMAKE_USE_MBEDTLS ON) + +# Télécharge et configure cURL +FetchContent_Declare( + curl + GIT_REPOSITORY https://github.com/curl/curl.git + GIT_TAG curl-8_7_1 ) +FetchContent_GetProperties(curl) +if(NOT curl_POPULATED) + FetchContent_Populate(curl) set(BUILD_CURL_EXE FALSE) set(BUILD_STATIC_LIBS TRUE) -FetchContent_MakeAvailable(curl) + add_subdirectory(${curl_SOURCE_DIR} ${curl_BINARY_DIR}) +endif() + +# Assurez-vous que votre projet trouve les headers de mBedTLS et cURL +include_directories(${mbedtls_SOURCE_DIR}/include) +include_directories(${curl_SOURCE_DIR}/include) + +# FetchContent_Declare(curl +# URL https://github.com/curl/curl/archive/refs/tags/curl-8_6_0.zip +# ) + +# set(CURL_USE_mbedTLS ON CACHE BOOL "Use MBED TLS." FORCE) +# set(BUILD_TESTING OFF CACHE BOOL "No tests build, plz." FORCE) +# set(USE_MANUAL OFF CACHE BOOL "No manuals, plz." FORCE) +# set(BUILD_CURL_EXE OFF CACHE BOOL "No executable, plz. Only the lib" FORCE) +# set(CURL_ENABLE_EXPORT_TARGET OFF CACHE BOOL "No installation build, plz." FORCE) +# set(CURL_DISABLE_IMAPS ON CACHE BOOL "Use MBED TLS." FORCE) +# set(BUILD_CURL_EXE FALSE) +# set(BUILD_STATIC_LIBS TRUE) + +# FetchContent_MakeAvailable(curl) +# include_directories( ${CURL_INCLUDE_DIRS} ) # ========================================================================================================================= # IMGUI and plugins @@ -293,7 +327,9 @@ if(UNIX) elseif(WIN32) target_link_libraries(${STORY_EDITOR_PROJECT} OpenGL::GL - SDL2 + SDL3::SDL3 + SDL3_image::SDL3_image + libcurl_static ws2_32.lib psapi.lib setupapi.lib cfgmgr32.lib advapi32.lib ) endif() diff --git a/story-editor/Dockerfile b/story-editor/Dockerfile index 4bd79e2..25a4ef3 100644 --- a/story-editor/Dockerfile +++ b/story-editor/Dockerfile @@ -1,13 +1,5 @@ -# Multi-stage Docker file -# 1) Developer environment -# 2) nginx stage to serve frontend assets -# This file must be run in the parent directory: -# docker build -t gridwatch-front -f dashboard/Dockerfile . - -# ======================================================= -# 1. Build stage, we need a node environment -# ======================================================= - +# Docker image to cross-build C/C++ programs from a Linux host to a Win64 target +# Also includes nsis to create installer FROM ubuntu:22.04 LABEL Description="Developer environment" @@ -31,3 +23,27 @@ RUN update-alternatives --set x86_64-w64-mingw32-g++ $(update-alternatives --lis RUN update-alternatives --set x86_64-w64-mingw32-gcc $(update-alternatives --list x86_64-w64-mingw32-gcc | grep posix) RUN mkdir /workspace + + +# ======================================================================== +# Build OpenSSL for windows +# Libraries are installed in /libs/ +# ======================================================================== + +ENV OPENSSL_VERSION="3.0.13" + +RUN mkdir -p /libs/openssl + +RUN set -x \ + && wget --no-check-certificate -O /tmp/openssl-${OPENSSL_VERSION}.tar.gz "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz" \ + && tar -xvf /tmp/openssl-${OPENSSL_VERSION}.tar.gz -C /tmp/ \ + && rm -rf /tmp/openssl-${OPENSSL_VERSION}.tar.gz \ + && cd /tmp/openssl-${OPENSSL_VERSION} \ + && ./Configure --cross-compile-prefix=x86_64-w64-mingw32- mingw64 --prefix=/libs/openssl \ + && make \ + && make install \ + && cd .. \ + && rm -rf openssl-${OPENSSL_VERSION} + + ENV PATH /libs/openssl/bin:$PATH + diff --git a/story-editor/build_win32.sh b/story-editor/build_win32.sh index 73bd7da..6f734c5 100755 --- a/story-editor/build_win32.sh +++ b/story-editor/build_win32.sh @@ -6,6 +6,8 @@ docker run \ -c "mkdir -p /workspace/story-editor/build-win32 && \ cd /workspace/story-editor/build-win32 && \ git config --global http.sslverify false && \ - cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64-x86_64.cmake .. && \ + cmake -DOPENSSL_ROOT_DIR=/libs/openssl \ + -DOPENSSL_CRYPTO_LIBRARY=/libs/openssl/lib64 \ + -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64-x86_64.cmake .. && \ make && \ make package" \ No newline at end of file diff --git a/story-editor/src/gui.cpp b/story-editor/src/gui.cpp index 6ec1d72..a227e89 100644 --- a/story-editor/src/gui.cpp +++ b/story-editor/src/gui.cpp @@ -102,7 +102,7 @@ std::string GetDirectory (const std::string& path) Gui::Gui() { - m_executablePath = std::filesystem::current_path(); + m_executablePath = std::filesystem::current_path().generic_string(); std::cout << "PATH: " << m_executablePath << std::endl; } diff --git a/story-editor/src/importers/pack_archive.cpp b/story-editor/src/importers/pack_archive.cpp index 07308b9..44ee92d 100644 --- a/story-editor/src/importers/pack_archive.cpp +++ b/story-editor/src/importers/pack_archive.cpp @@ -168,7 +168,7 @@ void PackArchive::DecipherFiles(const std::string &directory, const std::string { for (const auto & rf : std::filesystem::directory_iterator(directory)) { - std::string oldFile = rf.path(); + std::string oldFile = rf.path().generic_string(); // std::cout << oldFile << std::endl; DecipherFileOnDisk(oldFile); @@ -209,14 +209,14 @@ void PackArchive::DecipherAll(const std::string &packFileName, const std::string for (const auto & entry : std::filesystem::directory_iterator(path)) { std::cout << entry.path() << std::endl; - DecipherFiles(entry.path(), ".bmp"); + DecipherFiles(entry.path().generic_string(), ".bmp"); } path = mPackName + "/sf"; for (const auto & entry : std::filesystem::directory_iterator(path)) { std::cout << entry.path() << std::endl; - DecipherFiles(entry.path(), ".mp3"); + DecipherFiles(entry.path().generic_string(), ".mp3"); } nlohmann::json j; @@ -417,7 +417,7 @@ std::string PackArchive::OpenImage(const std::string &fileName) bool PackArchive::ImportStudioFormat(const std::string &fileName, const std::string &outputDir) { - auto uuid = UUID().String(); + auto uuid = Uuid().String(); std::string basePath = outputDir + "/" + uuid; Unzip(fileName, basePath); @@ -447,9 +447,9 @@ bool PackArchive::ImportStudioFormat(const std::string &fileName, const std::str // Si c'est un sous-répertoire, récursivement scanner le contenu auto rData = std::make_shared(); - rData->file = entry.path().filename(); - rData->type = ResourceManager::ExtentionInfo(entry.path().extension(), 1); - rData->format = ResourceManager::ExtentionInfo(entry.path().extension(), 0); + rData->file = entry.path().filename().generic_string(); + rData->type = ResourceManager::ExtentionInfo(entry.path().extension().generic_string(), 1); + rData->format = ResourceManager::ExtentionInfo(entry.path().extension().generic_string(), 0); res.Add(rData); } } diff --git a/story-editor/src/node_editor/node_editor_window.cpp b/story-editor/src/node_editor/node_editor_window.cpp index 091fccf..c88de56 100644 --- a/story-editor/src/node_editor/node_editor_window.cpp +++ b/story-editor/src/node_editor/node_editor_window.cpp @@ -50,7 +50,7 @@ void NodeEditorWindow::Clear() std::string NodeEditorWindow::GenerateNodeId() { - return UUID().String(); + return Uuid().String(); } diff --git a/story-editor/src/zip.cpp b/story-editor/src/zip.cpp index a7827f4..a6a8380 100644 --- a/story-editor/src/zip.cpp +++ b/story-editor/src/zip.cpp @@ -123,7 +123,7 @@ std::vector Zip::Unzip(std::string const &zipFile, const std::strin if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) continue; if (mz_zip_reader_is_file_a_directory(&zip_archive, i)) continue; // skip directories for now std::string fileName = file_stat.m_filename; // make path relative - std::string destFile = destination_dir + std::filesystem::path::preferred_separator + fileName; // make full dest path + std::string destFile = destination_dir + "/" + fileName; // make full dest path // creates the directory where the file will be decompressed std::filesystem::create_directories(std::filesystem::path(destFile).parent_path());