JsonCpp Library Changes, and a Shift to Considering Using CMake

Published January 17, 2021
Advertisement

For my current game under development, The Colon Case, I'll be using the Tiled map editor to build the tile sets and maps. I'll also have lots of other game data, and I plan to store all of it in JSON format.

With my previous game, The Garden of Eating, I decided to use the JsonCpp library to parse JSON files into memory. At that time, I followed the steps on the JsonCpp Wiki to build amalgamated source code, and included the source code directly in my project. For The Colon Case, I wanted to see if I could take the extra step to link to the JsonCpp static library instead. The Wiki has a page describing the steps to build with Visual Studio on Windows.

Attempting this caused a linker error because my project was targeting Win32, whereas the default for CMake was to produce x64 binaries. Since I'm a CMake noob, I struggled for a bit trying to figure out how to build JsonCpp to target Win32. There's a CMake option (-A) to target a specific platform:

cmake -A Win32 -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF ..

Once I got through that issue, I realized that the JsonCpp library apparently went through a major refactoring about 5 years ago. In The Garden of Eating, I was unknowingly referencing the deprecated Reader class. Previously, the source code just included a Doxygen comment to say it was deprecated. In a recent change, the deprecation was reinforced to cause a compiler error. The interesting thing about all of this is that searching for information via Google or on Stack Overflow by and large comes back with outdated results. This is where it's good to go straight to the library's own documentation!

This experience pushed me further towards thinking about using CMake, instead of relying on the Visual Studio environment so heavily. Every time I've looked at CMakeLists files, it has always seemed so daunting. After tinkering around with it for a few hours, I'm finally starting to lean in favour of that direction.

Maybe those who've been using CMake can tell me if I'm wrong, but... It kind of looks like CMake's relationship with C/C++ is very much similar to Gradle and Java, or NPM and JavaScript. I was able to create a starter CMake project that actually checked out specific versions of both SFML and JsonCpp from GitHub, and treat them as external dependencies. And the idea of being able to more easily build my game cross-platform is rather appealing. If I can figure things out further, this really does seem like the way to go...

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement