Logo

dev-resources.site

for different kinds of informations.

Felt Cute, Might git rm --rf

Published at
8/12/2023
Categories
cpp
cmake
sdl
gamedev
Author
tythos
Categories
4 categories in total
cpp
open
cmake
open
sdl
open
gamedev
open
Author
6 person written this
tythos
open
Felt Cute, Might git rm --rf

Background

A while back, I wrote an article on the evolution of game engines from beginner to intermediate architectures.

https://dev.to/tythos/engines-evolution-10gk

It was based on a series of projects I had worked on during grad school (a little over ten years ago), so there's definitely a lot of dust. My C++ days are largely behind me, but (after a lukewarm interview the other day) it seemed like an appropriate time to brush them off. In addition to a few HackerRank exercises, I decided to update an old project:

https://github.com/Tythos/Alphonse

This led to, among other thing things, a realization that C++ has really started to make a comeback. A lot of people would point to how active the committee is--and, to be clear, things like auto-iteration are an amazing improvement to the quality of life:

for (auto it : []) {}
Enter fullscreen mode Exit fullscreen mode

But what has really struck me is, how potent the combination of submodules (the git construct) and cmake is. They complement each other so well that it's easy to see how isolated and archaic C++ code can suddenly leap into the modern era with an language-agnostic package management and automated, platform-neutral builds.

Dependencies

Based on an explorer project I had put together last month, there's a pretty straightforward pathway for leveraging the latest-and-greatest SDL using this combination of tools:

https://github.com/Tythos/sdlbox

So, the first step is to replace the library dependencies:

We can add cmake dependencies from submodules with two easy modifications to our CMakeLists.txt file:

  • The add_subdirectory imperative, passing exclusive subfolder names:
add_subdirectory(SDL EXCLUDE_FROM_ALL)
add_subdirectory(glew-cmake EXCLUDE_FROM_ALL)
Enter fullscreen mode Exit fullscreen mode
  • The target_link_libraries imperative, passing each library we want to link against. (Note that we also need OpenGL, and that we specify the static variant of glew here--it's a small library, and doing so reduces the DLLs we'll need to copy later.)
target_link_libraries(${PROJECT_NAME} PUBLIC SDL3::SDL3 opengl32 libglew_static)
Enter fullscreen mode Exit fullscreen mode

Source Modifications

In addition to no longer needing glu (farewell! you caused so many compile issues, I can't say I will shed many tears), we also need to update SDL for v3 calls.

  • The SDL_CreateWindow() signature has completely changed, and some parameters are no longer declared anyway

  • Some event enumerations have changed

Since we'll be consolidating runtime resources within the CMake-managed build destination folder, we'll also remove the relative path references from the file reads for .GLSL source.

Building and Running

We can now do the usual CMake two-step:

> cmake -S . -B build
> cmake --build build
Enter fullscreen mode Exit fullscreen mode

This is sufficient to build our project, and now we can git rm -rf msvc our way to happiness!

Before we run, though, we do need to copy in the runtime dependencies. Specifically, there are .GLSL source files and a .DLL to copy over for SDL3:

> copy *.glsl build\Debug
> copy build\SDL\Debug\*.dll build\Debug
Enter fullscreen mode Exit fullscreen mode

(You'll note I'm using Windows/MSVC path assumptions here, but it should be easy to find your own folders regardless. There's probably a way in CMake to do this automatically, which would be great to add later.)

Conclusion

CMake and git submodules mean we never have to worry about maintaining separate projects (including relative paths and versions) for dependencies, and we don't even need to worry about maintaining a .SLN file for Microsoft Visual Studio.

In a more general sense, though, what they mean is C++ is ready for the modern world.

cmake Article's
30 articles in total
Favicon
Fixing libdc1394.so.22: cannot open shared object file (ใ… ๏นใ… )
Favicon
Automate Versioning with Git and CMake
Favicon
vcpkg - how to modify dependencies
Favicon
Getting started with GoogleTest and CMake
Favicon
Building a Desktop C++ Barcode Scanner with Slimmed-Down OpenCV and Webcam
Favicon
Use cosmocc to crossโ€compile a CMake project
Favicon
Improve Productivity with CMake and Compiler Cache Integration
Favicon
Conan: Your Embedded Cross-Compilation Champion
Favicon
Streamlining STM32 Projects: VS Code, CMake and clangd
Favicon
Easily add packages to CMake with CPM
Favicon
Jolt Physics raylib: trying 3D C++ Game Physics Engine
Favicon
Using raylib with Dear ImGui: Game Dev Debugging UI
Favicon
Using Jolt with flecs & Dear ImGui: Game Physics Introspection
Favicon
codemapper: join dev team of this sources analysis tool (C++/Qt5)
Favicon
CMake on SMT32 | Episode 8: build with Docker
Favicon
CMake on SMT32 | Episode 7: unit tests
Favicon
[04/52] MOAR CMAKEZ!
Favicon
How to use Flatbuffers in a C++ project with Conan?
Favicon
[03/52] - CMake and Git Submodules: More Advanced Cases
Favicon
get_cmake_version raise SKBuildError(msg) from err
Favicon
Basic C++ Unit Testing with GTest, CMake, and Submodules
Favicon
Felt Cute, Might git rm --rf
Favicon
Install CMake on Windows
Favicon
Maximizing Automation and Scripting in CMake for Efficient Software Development
Favicon
Include custom CMake modules
Favicon
Build a project on Windows 11 using MinGW
Favicon
Cleanup my dependency management with vcpkg
Favicon
CMake cheat sheet!
Favicon
CPM.cmake to make CMake's FetchContent easier
Favicon
The SYSTEM property from CMake 3.25

Featured ones: