pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
604 stars 91 forks source link

freetype dependency in Windows #87

Closed BigBIueWhale closed 5 months ago

BigBIueWhale commented 5 months ago

By convention I always put the source code of my dependencies in a sub-directory of my project.

I then use add_subdirectory(libs/hello_imgui) for each library that I use.

For example, this is the configuration I used for my hello_imgui project:

cmake_minimum_required(VERSION 3.12)
project(generic_gui_tester)
set(CMAKE_CXX_STANDARD 17)

set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build everything as dlls" FORCE)

add_subdirectory(libs/glfw-3.3.9)
set(HELLOIMGUI_USE_GLFW_OPENGL3 ON CACHE BOOL "Use GLFW and OpenGL3 for HelloImGui" FORCE)
add_subdirectory(libs/hello_imgui)

include_directories(libs/hello_imgui)

add_subdirectory(src)

That basic configuration was enough to get everything to build and run without an internet connection when using hello_imgui version 1.0.0

The latest master versions of hello_imgui seem to require freetype and lunasvg and it wants to download those from the internet.

I tried to take the source code from Freetype GitLab version 2.13.2 and add that source code as a subdirectory.

However it seems that as least on the Windows platform, CMake depends on ZLIB, BZIP2, PNG, HARFBUZZ, BROTLIDEC.

What's a simple way to get my project working on Windows platform without relying on an internet connection during build time?

BigBIueWhale commented 5 months ago

I've realized that the simplest way is just to disable freetype in imgui, set HELLOIMGUI_USE_FREETYPE to OFF.

cmake_minimum_required(VERSION 3.12)
project(generic_gui_tester)
set(CMAKE_CXX_STANDARD 17)

set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build everything as dlls" FORCE)

add_subdirectory(libs/glfw-3.3.9)
set(HELLOIMGUI_USE_GLFW_OPENGL3 ON CACHE BOOL "Use GLFW and OpenGL3 for HelloImGui" FORCE)
set(HELLOIMGUI_USE_FREETYPE OFF CACHE BOOL "Use freetype for imoji support in HelloImGui" FORCE)
add_subdirectory(libs/hello_imgui)

include_directories(libs/hello_imgui)

add_subdirectory(src)
pthom commented 5 months ago

Hello,

With this commit, you can use freetype and lunasvg as CMake target (i.e. call add_subdirectory for them).

So as a conclusion:

What's a simple way to get my project working on Windows platform without relying on an internet connection during build time?

Solution 1: Set HELLOIMGUI_USE_FREETYPE=OFF as you found

Solution 2: Add freetype and lunasvg as submodules and call add_subdirectory on them

Solution 3: Add freetype via a package manager (like vcpkg), and luna_svg as a submodule

pthom commented 5 months ago

However it seems that as least on the Windows platform, CMake depends on ZLIB, BZIP2, PNG, HARFBUZZ, BROTLIDEC.

Those are just warning from Freetype CMake scripts, it still builds fine

BigBIueWhale commented 5 months ago

However it seems that as least on the Windows platform, CMake depends on ZLIB, BZIP2, PNG, HARFBUZZ, BROTLIDEC.

Those are just warning from Freetype CMake scripts, it still builds fine

Thank you for the fix, I tested it and everything now works!

I confirm that I'm now able to successfully provide freetype and luna_svg in an offline manner to hello_imgui library, as of commit: 34742c5cb56b0a4e8f195ff47e46812ad4d101a7.

Here is my now working code:

cmake_minimum_required(VERSION 3.12)
project(generic_gui_tester)
set(CMAKE_CXX_STANDARD 17)

set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build everything as dlls" FORCE)

add_subdirectory(libs/glfw-3.3.9)
add_subdirectory(libs/freetype-VER-2-13-2)
add_subdirectory(libs/lunasvg-2.3.9)
set(HELLOIMGUI_USE_GLFW_OPENGL3 ON CACHE BOOL "Use GLFW and OpenGL3 for HelloImGui" FORCE)
set(HELLOIMGUI_USE_FREETYPE ON CACHE BOOL "Use freetype for imoji support in HelloImGui" FORCE)
add_subdirectory(libs/hello_imgui)

include_directories(libs/hello_imgui)

add_subdirectory(src)

This is my build system on which things are working for me offline:

  1. Compile on Windows 10 22H2
  2. Install Visual Studio 2022 C++ build tools or Visual Studio 22 community
  3. Install CMake- either through Visual Studio 2022 installer or the standalone version 3.26.4 for Windows
  4. Install VS Code and add extensions "C/C++ Extension Pack" by Microsoft, "CMake" by twxs
  5. Install Python 3.11.3 globally on the Windows OS and make sure to check "add to path" so that it's globally available, then do pip install pillow which hello_imgui uses for icon conversion.
  6. Re-open the project with VS Code
  7. Run VS Code command: "CMake: Delete Cache and Reconfigure" and choose "Visual Studio Community 2022 Release- amd64" as the compiler.
  8. At the bottom of the VS Code window (the CMake tab) choose CMake: [Debug] and change to Release.

Here are the contents of my libs folder:

And the extract_libs.bat file:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

:: Get the directory where the batch file is located
SET "BATCH_DIR=%~dp0"
SET "LIBS_DIR=!BATCH_DIR!libs\"

:: Path to 7zip executable
SET "SEVEN_ZIP_PATH=C:\Program Files\7-Zip\7z.exe"

:: Check if 7zip is installed
IF NOT EXIST "!SEVEN_ZIP_PATH!" (
    echo 7-Zip not found at "!SEVEN_ZIP_PATH!"
    exit /b 1
)

echo freetype-VER-2-13-2.tar.gz...
"!SEVEN_ZIP_PATH!" x "!LIBS_DIR!freetype-VER-2-13-2.tar.gz" -o"!LIBS_DIR!"
"!SEVEN_ZIP_PATH!" x "!LIBS_DIR!freetype-VER-2-13-2.tar" -o"!LIBS_DIR!"
DEL "!LIBS_DIR!freetype-VER-2-13-2.tar"

echo Extracting glfw-3.3.9.tar.gz...
"!SEVEN_ZIP_PATH!" x "!LIBS_DIR!glfw-3.3.9.tar.gz" -o"!LIBS_DIR!"
"!SEVEN_ZIP_PATH!" x "!LIBS_DIR!glfw-3.3.9.tar" -o"!LIBS_DIR!"
DEL "!LIBS_DIR!glfw-3.3.9.tar"

echo Extracting hello_imgui-1.0.0.7z...
"!SEVEN_ZIP_PATH!" x "!LIBS_DIR!hello_imgui.7z" -o"!LIBS_DIR!"

echo Extracting lunasvg-2.3.9.tar.gz...
"!SEVEN_ZIP_PATH!" x "!LIBS_DIR!lunasvg-2.3.9.tar.gz" -o"!LIBS_DIR!"
"!SEVEN_ZIP_PATH!" x "!LIBS_DIR!lunasvg-2.3.9.tar" -o"!LIBS_DIR!"
DEL "!LIBS_DIR!lunasvg-2.3.9.tar"

echo Extraction complete.
ENDLOCAL