Implement CMake build system #316
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here is a summary of what this does:
Auto Submodule Initiatilazation
The project requires some tools which are not present/part of the repository.
But it fetches them via git-submodules, which complicates a bit a few things.
Using the CMake build, this complication goes away, at it automatically handles these tools for you.
Trigger condition:
if(PVSNESLIB_AUTO_SUBMODULES) # Default: ONYou have the option to opt-out of course, but by default CMake will take care of setting up all the submodules for you.
cmake -DPVSNESLIB_AUTO_SUBMODULES=OFFto disable)The whole automation is basically running just one simple command:
In other words, it initializes any submodules if they do not exist, and if they exists it makes sure they are updated to the version exact commit hash recorded in superproject. And yes, it does that recursively as well.
Now this works because the project is embedding submodules by pointing to specific commits, not branches! This is important. See:
$ git ls-tree HEAD | grep commit 160000 commit a1b2c3d4... compiler/tcc 160000 commit e5f6g7h8... compiler/wla-dxThis is important, because it makes the whole thing to work with just one command:
cmake -B build. So you don't have to explicitely remember to "do sth with submodules". They "just work" during the build.Auto Dependrency Management
The project has a complex dependency chain:
now imagine what is happening if you are in the middle of this and not very familiar with all of these steps. Wouldn't be great if you didn't have to care at all? Here's is where CMake comes, as it defines an order:
And if something fails, you see why:
e.g. let's say you try you build the minimum stuff, but submodules (for some reason, you might have manually deleted them) are not there and you have disabled the automation during build:
What happens is:
But it's very uncommon for a failure to happen due to the order of things, since each target has explicitely defined dependency (e.g. if you select, for some reason, to build only the tools):
In that case, building only the tools
cmake --build build --target toolsWhat happens is that:
Easy builds
Building the project itself
If you intend to contribute to the the project itself or build and study its examples, then this is super easy now.
There are many targets, but the 3 main ones are:
minimal,examples_only,everythingBut there are others as well, use
guideto see them all:Building your game
After having the project build somewhere in your disk, export a ENV variable to its location:
export PVSNESLIB_HOME="/your/project/location"Then:
In the
src/main.cyou write your game's logic.So it looks like this:
Then create the
hdr.asm. You can basically copy-paste this, but change only theNAME.Pay attention to it, because it has to be exactly 21 characters at the
.SNESHEADERsection:Also create the
data.asmeven there are no graphics or audio assets:and last but not least the
CMakeLists.txt:So to build it:
And voila, you have SNES rom:
Fixing macOS sed issue
In Linux, this works fine:
but in Darwin, it doesn't:
this is because macOS uses BSD verions of
sedwhich requires a backup extension argument.so in general, in the code this is fixed based on this pattern:
-i.bak: Creates backup with.bakextension (required by BSD sed)&& rm -f file.bak: Removes backup file after successful editSo in the end we have same behavior on both Linux and macOS.
Release and versions
I think (and take this with a grain of salt) that there are 4 main places where the version is to be found:
But there is also README of course, which has a hardcoded link there.
And also the changelog for devkitsnes/readme.txt.
For the readmes, the process will continue to be manual. No automation there, as it will over-complicate things for no good reason. Just remember to modify them per version bump.
Individual tools, will remain having their own processes and their own Makefiles.
That said, to update the new version you will have to do only this:
But there is also a whole Release target that does all of these and more automatically for you. So let's pretend we want to bump the version up to 4.5.0. Here's the steps:
CMakeLists.txtand especially:This will create these variables:
So the propagation chain will look like this:
Indeed building created in my machine:
./release/pvsneslib_4.5.0_64b_darwin.tar.gzI have an arm64 mac, so I fixed the CMake file and it detects the arch properly now,
./release/pvsneslib_4.5.0_arm64_darwin.tar.gz.