Out of source CMake preset file

Hi,

I am looking for some advice regarding the use of preset files: CMakePresets.json

I am building a 3rd party library for different platforms using a different set of variables for each platform and I want to use CMake presets for maintaining this setup.

How can I make CMake consume a CMakePresets.json outside of the 3rd party library codebase?

  • my-repo
    • CMakePresets.json
    • 3rd-party-library
      • CMakeLists.txt

I’d like to be able to run something like

cmake --preset=my-config -B build-folder -S 3rd-party-library

However if I do that then cmake complains that it could not find the CMakePresets.json file. I am assuming it only searches the 3rd-party-library directory.

What is the best way to achieve my goal?

Regards,
Frederik

I’m pretty sure that isn’t supported. My understanding is that the CMakePresets.json file has to be at the top of the source tree. @kyle.edwards may have more thoughts on whether other scenarios like the one you describe could be supported.

If you don’t plan on sharing your presets file with anyone, if it will only live on your local machine, I’d suggest putting it in the 3rd party library folder as CMakeUserPresets.json.

If you plan on sharing it, I’d suggest forking the 3rd party repo and adding CMakePresets.json to it.

Okay, I still think it would be nice to avoid maintaining a fork for just this particular purpose. Thanks for clarifying!