Find_package() questions

I’m using find_package() to reference a global JUCE install in CMakeLists.txt but have a few questions:

  1. Should I re-configure the JUCE build each time I pull a change from JUCE? I assume this is only required if there are changes to module structure or dependencies.

  2. Should I re-build the JUCE install target each time I pull a change from JUCE? I assume this is required so that we refresh the include files.

  3. Should the following be added to the JUCE repo’s .gitignore? Otherwise there are 2303 changed files!

  • /bin
  • /include
  • /lib

If you’re using a global system install, then the workflow basically assumes that you are manually updating this installation every time there are relevant changes. So yes, basically every time there are juce changes you want to incorporate into your global installation, you need to pull the repo, build it, and run cmake --install.

If you want your project to always grab the latest copy of juce, the best way to do that is with FetchContent. Instead of looking for an installation in your system, it will clone the repo (into somewhere inside the build tree) and basically do add_subdirectory. Every time you run cmake configure it will check for updates to its copy of the juce repo.

FetchContent can also be redirected to call find_package, so that it will use a system install instead of cloning the sources. Generally I recommend adding dependencies through FetchContent, as it is more versatile than pure find_package.

/bin, /include, and /lib shouldn’t be in the root of the global juce repo. It sounds like you’ve installed it with the repo root as the prefix, in which case it’s your responsibility to either add those files to the gitignore or manually clean them before pulling changes. A more traditional workflow would be to keep the juce repo somewhere outside the global system directories, and then run cmake --install to install to the system directories.

1 Like

Thanks for the help @benvining, I’ll take a look at FetchContent. Also, your explanation about the prefix makes sense. I think the JUCE doco might need a bit of tweaking.

@reuk - I found the explanation of how to use find_package() in docs/CMake API.md misleading. Could I suggest rewording as follows?

Using find_package

To install JUCE globally on your system, you’ll need to tell CMake where to
place the installed files. This should be a location distinct from the original
JUCE repo.

# Go to JUCE directory
cd /path/to/JUCE/repo
# Configure build with library components only
cmake -B cmake-build-install -DCMAKE_INSTALL_PREFIX=/path/in/which/to/install/JUCE
# Run the installation
cmake --build cmake-build-install --target install

You can usually omit CMAKE_INSTALL_PREFIX and it will default to a place sensible for your system, that find_package will look in by default.

1 Like