# Easily add [SFML 3](https://github.com/SFML/SFML) and [Dear ImGui](https://github.com/ocornut/imgui) to your premake5 projects
<br> This repo contains the repositories for SFML, Dear ImGui, sfml-imgui, flac, vorbis, ogg, and freetype along with premake build scripts. 
This allows your project to build these libraries from source and statically link them to your executible. 
This makes developing on linux easier as most distros don't have SFML 3 in their package managers.
<br><br> I have included `example-project.txt` and `example-workspace.txt` as examples on how to use this project

## How to integrate into your projects
1. Add the repository as a submodule and update its submodules. Replace `<directory-path>` with the path to the directory you want the repo to be cloned to, 
    leaving this out will place this repo into `./imgui-sfml-premake`
```
git submodule add https://gitlab.com/JosephA1997/imgui-sfml-premake.git <directory-path>
git submodule update --init --recursive
```
2. Add this to the top of the lua file that contains the workspace, replace 'path/to' with the directory that you cloned this repo to
```lua
local ogg = require("path/to/premake-scripts/build-ogg")
local imgui = require("path/to/premake-scripts/build-imgui")
local sfml = require("path/to/premake-scripts/sfml/build-sfml")
local flac = require("path/to/premake-scripts/flac/build-flac")
local vorbis = require("path/to/premake-scripts/vorbis/build-vorbis")
local freetype = require("path/to/premake-scripts/freetype/build-freetype")
local imguisfml = require("path/to/premake-scripts/imgui-sfml/build-imgui-sfml")
```
3. In the workspace, add these lines
```lua
filter"system:linux"
    pic"On" -- fix warning when statically linking <relocation against ... in read-only section .text>
filter""
```
4. In the workspace, add these lines to add each dependency as its own project
<br> `<target-directory>` - the directory where the static library will be placed
<br> `<obj-directory>` - the directory where object files will be placed 
```lua
ogg.generateproject(<target-directory>, <obj-directory>)
sfml.generateproject(<target-directory>, <obj-directory>)
flac.generateproject(<target-directory>, <obj-directory>)
imgui.generateproject(<target-directory>, <obj-directory>)
vorbis.generateproject(<target-directory>, <obj-directory>)
freetype.generateproject(<target-directory>, <obj-directory>)
imguisfml.generateproject(<target-directory>, <obj-directory>)
```
5. At the top of each lua file containing a project that needs imgui or sfml, add these lines, replace 'path/to' with the directory that you cloned this repo to. if the project is in the same file as the workspace you can skip this
```lua
local sfml = require("path/to/premake-scripts/build-sfml")
local imgui = require("path/to/premake-scripts/build-imgui")
local imguisfml = require("path/to/premake-scripts/build-imgui-sfml")
```
6. Inside of the projects that need sfml or imgui add these lines 
```lua 
-- link order matters on GCC/Clang
imgui.link()
imguisfml.link()
sfml.link()
```

## Bundled Premake Info
I have included premake5 executibles for windows and linux in the `premake5` directory. Inside you'll also find modules that add support for the ninja build system and to generate a compile_commands.json file for things like clangd
<br><br>
To use premake on windows
```
.\path\to\premake5\premake5.exe
```
And on linux
```
./path/to/premake5/premake5
```
To generate ninja build files, use the `premake-ninja` action
```
premake5 premake-ninja
```
To generate compile_commands.json, use the `ecc` action
```
premake5 ecc
```
<br>
Credits:

* [SFML](https://github.com/SFML/SFML) (zlib/png license)
   Copyright (C) Laurent Gomila

* [Dear ImGui](https://github.com/ocornut/imgui) (MIT License)
   Copyright (c) 2014-2025 Omar Cornut

* [imgui-sfml](https://github.com/SFML/imgui-sfml/) (MIT License)
    <br>Copyright (c) 2016 Elias Daler
    <br>Copyright (c) 2014-2016 Omar Cornut and ImGui contributors
    <br>Copyright (c) 2014 Mischa Aster Alff

* [FreeType](https://github.com/freetype/freetype) (The FreeType Project License)
   Portions of this software are copyright © 2025 The FreeType Project (www.freetype.org). All rights reserved.

* [Ogg](https://github.com/xiph/ogg), [Vorbis](), [FLAC]() (BSD-3-Clause)
   Copyright (c) Xiph.Org Foundation