-
Notifications
You must be signed in to change notification settings - Fork 0
Build & Usage
This is a detailed guide on how to build and use Onyx by compiling yourself via CMake, in case the precompiled binaries don't work for you. Make sure you have CMake installed.
First, clone the repository to some folder: git clone https://github.com/jopo86/onyx.git <dir>
Open the new folder in a terminal or VSCode or whatever you want to get ready to build it. But first, there are four other dependencies we must build. I will add these as submodules soon, but for now we need to build each of them. One of the dependencies does not use CMake and only has a Makefile, so you will need to have the tools to install this (make
or mingw-make
).
First, we will build GLFW. Clone GLFW to some folder: git clone https://github.com/glfw/glfw.git <dir>
. From the folder it was cloned to, create a build folder and CD to it. From the build folder, create CMake files. I'm going to use MinGW makefiles (if on Linux use Unix Makefiles
): cmake -G "MinGW Makefiles" ../
. Then build: cmake --build .
. Now you should have libglfw3.a
in the build folder (it may be stuck under a src
folder, GLFW does that for some reason, you can find it I believe in you). Copy libglfw3.a
and paste it into the lib
directory where you cloned Onyx to.
You may encounter some trouble building GLFW specifically on Linux if you don't have all the required development kits installed. I would just ask ChatGPT about any errors lol
Next, we will build FreeType. Go to this SourceForge link and download the latest version. After unzipping, enter the folder and do exactly the same as before - create a build folder, create CMake files, build. Then copy and paste libfreetype.a
into the lib
directory where you cloned Onyx to.
Unfortunately, FreeType depends on two other libraries, so we have to install those two. The first is zlib, which can be downloaded (direct download) from here. Same process, make the build folder, blah blah blah, copy libzlib.a
(may be libz.a
) to the lib
dir.
The final library that FreeType depends on is BZip2 which, like I said, does not use CMake, so we have to use its pre-made Makefile - it worked for me, hope it will for you too. Direct Download The folder has a Makefile
in it, so either on Linux or WSL, run make
and hope for the best. Its makefile does give you some info along the way. Once that is finished, you should have a libbz2.a
(I believe not in its own directory, instead piled with everything else) that you can copy and paste to you know where.
Great, we're done with the dependencies! Now we can get back to Onyx, navigate to the build folder (or create one if it is no longer included on the repo), generate CMake files once again (either MinGW or Unix makefiles) with cmake -G "MinGW Makefiles" ../
, and then build with cmake --build .
. Now you can run ./test
(or test.exe
for Windows, not WSL) and should see the demo run!
Now, once you have compiled it, let's get into how you can use Onyx. You should probably first create an organized Onyx folder with the directories, include
, lib
, and resources
. In include
, you can copy & paste everything from the include
folder in the Onyx repository, and then create another folder inside include
, Onyx
, and copy & paste all the header files from the src
folder in the Onyx repository. In the lib
directory, copy and paste all your compiled libraries - that's GLFW, FreeType, Zlib, BZip2, and Onyx itself. Then you can just copy & paste everything from the resources
folder in the Onyx repository into your resources
folder. Now, create a src
folder and start writing code using Onyx! To compile your project, just make sure to tell the compiler about your include/lib directories as well as the specific libraries you will be using. Here's a sample CMakeLists.txt
for a project that used directories, lib-linux
and lib-win64
for cross-platform compilation (you can just omit the if/else/endif and pick the link commands for your platform):
cmake_minimum_required(VERSION 3.13) # to allow target_link_directories
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(card-mania VERSION 0.0.0)
file(GLOB_RECURSE SOURCE_FILES ${CMAKE_SOURCE_DIR}/src/*.cpp)
add_executable(a ${SOURCE_FILES})
target_include_directories(a PUBLIC ${CMAKE_SOURCE_DIR}/include/)
if(WIN32) # Windows system
target_link_directories(a PUBLIC ${CMAKE_SOURCE_DIR}/lib-win64/)
target_link_libraries(a PUBLIC onyx opengl32 glfw3 freetype bz2 zlib)
else() # UNIX System (this won't work on MacOS, you'll need to add more else branches for that)
target_link_directories(a PUBLIC ${CMAKE_SOURCE_DIR}/lib-linux/)
target_link_libraries(a PUBLIC onyx GL glfw3 X11 freetype bz2 z)
endif()
Be sure to put onyx
before everything else, glfw3
before X11
(Linux only), and freetype
before bz2
and zlib
/z
, because sometimes the order of dependencies matters.
With that, you should be able to build with CMake in the same way we have before by creating and using a build
directory!
mkdir build
cd build
cmake ../ # or `cmake -G "Unix Makefiles" ../` (UNIX) or `cmake -G "MinGW Makefiles"` (Windows)
cmake --build .