Jumping Ball Progress
I need to post more updates on my progress. I learned how to use CMake's install features to create an installation folder with header files and dynamic libraries. It took me a while to figure out because CMake's documentation can be unclear at times.
The lines that I added for the installation operation are the following:
set(CMAKE_INSTALL_PREFIX "Jumping Ball")
#message(${CMAKE_INSTALL_RPATH})
install(DIRECTORY "./modules/SDL/build/" DESTINATION "lib")
install(DIRECTORY "./modules/SDL_ttf/build/" DESTINATION "lib")
install(DIRECTORY "./modules/SDL/include/SDL3/" DESTINATION "include/SDL3")
install(DIRECTORY "./modules/SDL_ttf/include/SDL3_ttf/" DESTINATION "include/SDL3_ttf")
install(TARGETS "${PROJECT_NAME}" BUNDLE DESTINATION .)
Every dynamic library is added to the lib folder in the installation directory, which is named "Jumping Ball." Additionally, I needed to configure the rpath to make the library files discoverable.
# Installation use otool -L to figure out rpath set rpath for macos with @loader_path
# set rpath for linux with @executable_path
set(CMAKE_MACOXS_RPATH ON)
set(CMAKE_INSTALL_RPATH "@loader_path/../../../lib")
The @loader_path
keyword points to the MacOS directory of the .app bundle. The dots are used to navigate out of the bundle and into the lib folder to find the library.
Great! Now everything's up and ready. The application can be built and then installed with the help of CMake.
Well, not really...
This is where I spent a lot of time figuring out what was wrong. After carefully examining the otool -L
and otool -l
commands, I discovered that SDL_ttf was looking for libsdl3.1.0.0.dylib, which was not in the build folder of my SDL3 build. I tried creating an alias of the SDL3 dylib, but it didn't work.
To fix it, I made a copy of the SDL3 dylib and renamed it. I created the copy in the build folder of the SDL3 to let CMake copy it during installation. This solution works, but there is a warning because I am using the same library twice.
I had to find a solution. I tried symlink but it ended up in multiple headaches and confusion. I started thinking that using XCode might be the way to fix it. I started working on the XCode project but I changed my mind. Why waste so much time?
I ended up using the copy and rename technique. I wanted to find a better solution but after so many problems and wasted time, I decided to use it.
Well, at least now everything works.
Subscribe to my newsletter
Read articles from Chris Douris directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Chris Douris
Chris Douris
AKA Chris, is a software developer from Athens, Greece. He started programming with basic when he was very young. He lost interest in programming during school years but after an unsuccessful career in audio, he decided focus on what he really loves which is technology. He loves working with older languages like C and wants to start programming electronics and microcontrollers because he wants to get into embedded systems programming.