CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

Confusing warning when setting OPTIONS / name conflict with Find*.cmake files?

Open jhasse opened this issue 4 years ago • 7 comments

I'm trying to add ogg like this:

	CPMAddPackage(NAME ogg
		URL http://downloads.xiph.org/releases/ogg/libogg-1.3.4.tar.xz
		URL_HASH SHA256=c163bc12bc300c401b6aa35907ac682671ea376f13ae0969a220f7ddf71893fe
		OPTIONS "BUILD_TESTING OFF")

Followed by fetching Vorbis after that (using FetchContent for that now). But I'm getting the following warning:

CMake Warning at build/cmake/CPM_0.27.5.cmake:166 (message):
  CPM: ignoring package option for ogg: BUILD_TESTING = ON (OFF)
Call Stack (most recent call first):
  build/cmake/CPM_0.27.5.cmake:242 (CPMCheckIfPackageAlreadyAdded)
  build/CPM_modules/Findogg.cmake:2 (CPMAddPackage)
  build/_deps/vorbis-src/CMakeLists.txt:65 (find_package)


CMake Warning at build/cmake/CPM_0.27.5.cmake:166 (message):
  CPM: ignoring package option for ogg: OFF = ON ()
Call Stack (most recent call first):
  build/cmake/CPM_0.27.5.cmake:242 (CPMCheckIfPackageAlreadyAdded)
  build/CPM_modules/Findogg.cmake:2 (CPMAddPackage)
  build/_deps/vorbis-src/CMakeLists.txt:65 (find_package)

It seems that CPM creates a Findogg.cmake file which results in vorbis not using their bundled FindOgg.cmake file?

jhasse avatar Jan 20 '21 10:01 jhasse

Yes, this is expected behaviour. CPM.cmake creates its own FindXXX.cmake modules, to allow nested dependencies that use find_package for dependency management. Otherwise we could accidentally add the same dependency twice (one through CPM.cmake and one from the system PM).

That warning should not appear though. The "ignoring option" warning should actually appear when adding a dependency that has already been added before, but provided with different options. As we can't add a package twice, we need to ignore any options specified later on. As package options are usually cached and unique to the dependency, there should be no name clash, however BUILD_TESTING is definitely too generic and perhaps confusing CPM due to a name clash. Are you changing the value of BUILD_TESTING somewhere else by chance?

TheLartians avatar Jan 20 '21 10:01 TheLartians

Not explicitly, but include(CTest) sets it, doesn't it?

jhasse avatar Jan 20 '21 10:01 jhasse

Definitely seems so. I would actually recommend to avoid specifying project-wide options in the OPTIONS field of CPMAddPackage, as it assumes they are unique to the dependency. Perhaps use set to change BUILD_TESTING to OFF manually before adding the dependency?

TheLartians avatar Jan 20 '21 10:01 TheLartians

But then I need to set it back to ON after adding the dependency.

jhasse avatar Jan 20 '21 10:01 jhasse

If you only want to unset it for the single package, I'm afraid so. CPMAddPackage actually also sets the global value, as that's the expected behaviour for CMake options (in my understanding they are meant to be project-wide and specified through the command line / CMake GUI). Unfortunately, that's the way CMake options were designed so I'm not sure if there is a better way for CPM.cmake to handle them.

IMO it's also bad practice for packages meant to be dependencies to change their behaviour based on package-wide options, but I understand that we often have no control over that.

TheLartians avatar Jan 20 '21 10:01 TheLartians

"use scoped options" as in OGG_BUILD_TESTING should probably be added to the guidelines

iboB avatar Jan 20 '21 14:01 iboB

Good point, I just updated the wiki!

TheLartians avatar Jan 20 '21 15:01 TheLartians