I have recently returned to the world of C++ and CMake.
Having started a project on MacOS that makes use of SDL2 I found it relatively straightforward to include the SDL2 library in the project by simply "installing" the library on the OS. My project would build and launch without an issue.
I have since had to move over to a Windows machine, and not found the experience to be the same. There are a swath of methodologies, approaches and recommendations. While searching for how to maintain dependencies, such as SDL2, I came across FetchContent_Declare which provided the ability to download dependencies as part of the CMake build. I liked this as it felt very much like NPM style package management. The build would take care of fetching dependencies.
After much messing around, I've managed to setup my build so that it downloads SDL2 and the extensions that I need without any issue and the exe is built. However, when I try to run the exe nothing happens. Running the exe manually (not through Visual Studio Code) I was provided a message stating that SDL2.dll could not be found. I have install commands in my CMake, which copy the dll files to the install directly, but these only take effect when running an install build specifically.
I am guessing that because FetchContent_Declare downloads SDL2 into a location within the build directory, it is explicitly telling the the complier where the require files are for build but then when the exe runs the DLLs are neither in the main directory or available in the path so nothing happens.
With the exception of adding a custom command, to copy the DLLs into the Debug directory, is there an elegant way to let the exe know where the DLLs are?
Note: I will likely want to switch between machines regularly including both Windows & MacOS and want to cross-compile so having this automated and not having to worry about installing libraries is essential.