What is the best/idiomatic way to allow users to either choose to use a dependency they already have, or to let cmake download it themselves? I’m thinking of doing something like the following, where I use externalproject if I want to use the bundled version and find_package if I want to use the external version:
option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED})
if(USE_BUNDLED_UNIBILIUM)
ExternalProject_Add(unibilium
URL ${UNIBILIUM_URL}
...
)
else()
find_package(unibilium 2.0 REQUIRED)
endif()
The idea is then that the Findunibilium.cmake
finds all necessary libraries and directories and then defines an interface library named unibilium
with those included. Then the main target can add unibilium
as a dependency, which can either be from externalproject we built ourselves or from a system package.
This setup is the best I could come up with, but it feels unwieldy. I’m unsure if there’s a more sophisticated way to solve this. Any input is appreciated. My project has version 3.10 as the minimum required version.