In this Today I Learned (TIL) format, I want to very briefly share things I’ve come across and learned from today.
CMake Package Manager
Someone on the SFML Discord was trying to get SFML to play nice with their CMake script which uses CMake Package Manager (CPM). CPM is not a built-in functionality or officially developed by the CMake team itself, but it’s mostly an enhancement of the existing FetchContent
module, and adds version control, caching and more.
While trying to help said person, I got to use it myself for a bit and it’s really quite simple and yet also powerful:
# Include the downloaded CPM file
include(cmake/CPM.cmake)
# Add SFML master branch
CPMAddPackage(
NAME sfml
GITHUB_REPOSITORY SFML/SFML
GIT_TAG master
)
Some things I’ve noticed and might want to investigate further:
- The to-be-built library needs to have install targets for CPM to work correctly
- When you run
cmake --build . --target install
it will currently also install all the third-party target files (e.g. headers, CMake config files, docs, examples, etc.), but I assume there’s some option somewhere
Using Clang with Visual Studio and CMake
Some issues came up in the same conversation about building with Clang on Windows. Waaaay back in the days when Clang wasn’t even officially supported on Windows, I tried my hands on getting it up and running, but failed. These days Clang comes as individual component in the Visual Studio installer or can also be installed via MSYS2 or similar.
If you want to use Clang with Visual Studio and you use CMake, you can do that by picking the correct toolset at configuration time:
mkdir build
cd build
cmake .. -G "Visual Studio 16 2019" -T ClangCL -A x64
cmake --build . --target install --config Debug
Build iOS Apps on Windows
If you don’t fancy developing apps on macOS with Xcode, you can use the iOS Build Environment for Windows developers. It seems to “officially” only be allowed, if your Windows is running on the Apple hardware for example through Boot Camp. Since I’m currently not in the business of creating iOS apps, I haven’t really taken a closer look at it. From the description it seems to be quite popular for Unity games.