How to use cmake in a Platform.sh build hook

Goal

Sometimes a library may require cmake in order to compile. By default you only have make available. An example would be libgit2 how would you get this to work on platform.sh ?

Assumptions

You will need:

Steps

1. Add at the beginning of your build hook in .platform.app.yaml

Setting VERSION to the version of cmake you want.

export VERSION="3.16.0-rc4"
wget https://github.com/Kitware/CMake/releases/download/v$VERSION/cmake-$VERSION-Linux-x86_64.tar.gz
tar xzf cmake-$VERSION-Linux-x86_64.tar.gz
export PATH=$PATH:/$PWD/cmake-$VERSION-Linux-x86_64/bin

2. Potentially cleanup at the end of the build step if you don’t want cmake in production

rm -rf /$PWD/cmake-$VERSION-Linux-x86_64

Conclusion

Any dependencies that require cmake in their build should very probably work now.