-1

I am currently developing some C++ GUI application using wxWidgets (although the GUI framework doesn't really matter here) and thus far have been developing this on my own, which was working well. This project has a few other dependencies as well (OpenGL, mainly, and then a few smaller ones like GoogleTest, etc.).

I am at a stage now where potentially other people will join the project (mainly students, not necessarily with a strong software engineering background) so it would be good to have a reproducible development environment where someone can pull / clone the repo, run some magic installation step and have the project set up and running on their machine.

Usually this wouldn't be a problem, there are plenty of solutions out there to cover this, but I have found that non of these work well in my current case. Let me elaborate on what isn't working for me:

  • Building from source is important to me. I can get with relying on some libraries being available (like OpenGL), but everything else should be build from source, not coming through a package manager like conan or vcpkg (mainly because I am using some obscure libraries that are not available, but also because it just makes sense to build your dependencies from source, see also: https://www.youtube.com/watch?v=54uVTkhinDE&ab_channel=CppCon)

  • I use CMake, naturally using something like subproject or fetchContent as part of CMake to build dependencies, then, would make sense. In-fact, I have used fetchContent but soon realised that not all libraries can be build with this capabilities. This has lead to ugly hacks to mack libraries work but this is far from reliable and actually causes more issues now than it solves. There is a bit of discussion on this, including my answer, here: https://stackoverflow.com/questions/66736809/wxwidgets-and-fetch-content-in-cmake

  • Docker would be another logical step, my experience with it is limited but I can see that it may have issues communicating a GUI through docker, there seem to be also some suggestions that Docker is not suitable for this task: Build docker images for GUI applications in Linux

  • Of course, there is the good old bash (unix) or powershell (win) approach, write a script that builds everything for you. This requires several (at least two) scripts if I want to target both unix and windows and also doesn't feel like a 21st-century approach. Yes, cross-platform is important to me and I want to have a single place / instruction set that is responsible for installing third-party libraries as part of the build

  • My least favourite option: Require that everything is already installed on the development PC which the software is then linking against (or throwing errors if the libraries are not available). As mentioned previously, my target audience are postgraduate students with not necessarily a software engineering background, this approach seems to be just creating more issues and questions which hopefully could be addressed by providing some form of automatic setup routine.

So my specific question is, in order to avoid this become an opinion-driven thread, is there a way which allows for an automatic third-party library compilation / installation stage while the software is build? I really like the fetchContent solution as it will build in either debug or release mode depending on my CMake settings, but I would be ok settling for one build type if it could be automated. My requirements are that this could happen automatically (downloading, unpacking, compilation, installation, etc.) after which the actual software can just include the libraries during the build and linking stage.

If I have missed something in the points above (especially on Docker, as I am not too familiar with it, perhaps GUI development is possible using volumes and sharing executables this way?), I would also appreciate comments on the approaches described above can be used for cross-platform gui development.

3
  • One option may be to build your complete development environment inside a VM then export a good, working image with the correct versions of everything installed and configured as needed (remember to remove any passwords/secrets/etc) and distribute that to anybody collaborating on the project. Commented Aug 23, 2022 at 16:22
  • How far down do you go with building libraries from source? All the way to libc? Commented Aug 23, 2022 at 19:36
  • Well, good point ... Let's put it this way, I assume a C++ compiler (and its runtime libraries) to be available. Everything else I assume to be project-specific dependencies which I want to build from source.
    – tom
    Commented Aug 23, 2022 at 21:11

1 Answer 1

2

This is difficult. C++ is difficult. Cross-platform is difficult. GUI is difficult.

You mentioned the idea to have platform-specific scripts, and that this increases maintenance burden. CMake is intended to serve as a platform- and build-system independent scripting language, but as you have discovered this sometimes means it is very hard to use. Especially dependency management is hard. CMake is the quasi-standard for including C++ libraries, but there are also some C++-specific package managers like Conan that try to bring more of that NPM/Cargo/Maven experience to C++.

Docker is a great tool if you want to encapsulate a Linux-based build system (compilers, dependencies), but not a great tool for running GUI programs. Your non-Linux users would have to install a separate Xserver. At this point, the easiest way to make native cross-platform GUI apps is to build a Linux app which Windows 11 users can run via WSL2 in an “it just works” experience. Containers can also complicate using an IDE, unless the IDE explicitly supports remote development or even has specific support for Docker. In particular, think about issues like debugging the software.

I think that you'll have to settle on a combination of tools. It probably makes sense to use CMake as much as possible, but you'll have to settle for platform-specific scripts for some details. Instead of duplicating the logic of those scripts in Bash + Powershell (or worse, CMD), it probably makes sense to require that developers have a recent-ish Python version installed so that you can write the script in Python. Then you only need a thin Shell/CMD wrapper for conveniently invoking that script. I would avoid containers, unless you want an isolated build process – but that means you'll have to carefully manage dynamic libraries yourself if you want to run the software outside of the container. And unless you want to use Windows containers (ugh), this will add additional difficulties due to needing cross-compilation.

1
  • Python scripts is what I used in the past for dependency management (before stumbling across fetchContent) but you are right, this might be the best way forward, I was just curious if I was missing anything here. The issue then becomes keeping DLLs / SOs up to date and next to the build, wxWidgets changes its DLL filenames based on debug and unicode settings so that would then also have to be correctly caught by CMake ... maybe there is no good solution to this problem, but your input is appreciated!
    – tom
    Commented Aug 23, 2022 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.