FR: Cmake: add cmake_minimum_required to all CMakeLists.txt

Adding some form of cmake_minimum_required (VERSION x.xx) at the top of your CMakeLists.txt is suggested practice, and will generally help users navigate setting up with Cmake and JUCE. Simply put, this prevents unnecessary breakage and highlights expectations for which Cmake version to use.

Cmake itself suggests it:
image

Hm, the more I dig the more I see some disparity: some of the CMakeLists.txt have it, some do not.

Basically, in my case, I’m trying to build just the DemoRunner via Cmake. This project doesn’t have the minimum. I noticed a few others are like that as well, although I’m not sure if that’s intentional.

For the JUCE 6 CMake support, our strategy was to add cmake_minimum_required only to files that are intended to be used for project generation. Specifically, that’s the top-level CMakeLists, and the templates in examples/CMake.

The CMakeLists for the DemoRunner, Projucer etc. are not intended to be used in complete isolation, because they depend on other parts of the JUCE repo, such as the modules. Instead, they can be built using commands like the following:

cd /path/to/JUCE
cmake . -B cmake-build-full -D JUCE_BUILD_EXTRAS=ON
cmake --build cmake-build-full --target DemoRunner

Noted, and thanks for explaining.

Just a quick correction to your example script, it looks like the last command should include the examples option:

cmake . -B cmake-build-full -D JUCE_BUILD_EXTRAS=ON -D JUCE_BUILD_EXAMPLES=ON