<PackageName>_ROOT vs <PackageName>_ROOT_DIR

Hello, there is <PackageName>_ROOT_DIR variable mentioned in the documentation and I’m not sure I understand why should this variable be used if there is already automatic CMake handling done by <PackageName>_ROOT variable.

Is this meant to be <PackageName>_ROOT or should packages actually use the _ROOT_DIR somehow in addition to <PackageName>_ROOT?

Thanks.

Interesting question, I haven’t thought about this before. But the way I read the documentation now actually makes sense to me: Xxx_ROOT_DIR is the result variable that is (should be, for the sake of consistency/convention) set by the FindXxx.cmake module when/if Xxx is found, and Xxx_ROOT is the variable that FindXxx.cmake module will use to get a list of paths/prefixes of potential Xxx whereabouts to know where to look for it.

So, in other words (and with the right “order of use”):

  1. Xxx_ROOT contains the path(s) of where to look for Xxx;
  2. FindXxx.cmake attempts to find Xxx using those paths;
  3. If Xxx is found, then Xxx_ROOT_DIR is set.
2 Likes

@brad.king , maybe we should mention it in cmake-developer(7) and related docs?

Yes, I’d welcome a clarification to the documentation of Xxx_ROOT_DIR in that manual.

@retif’s explanation of the purpose of each variable is correct. However, in general it is not expected that Xxx_ROOT_DIR is set by a find module. It’s documented as a naming convention for modules that choose to provide such a variable.

1 Like

I see. Thanks @retif for the clarification. PR opened here https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10006

There is also Xx_ROOT_DIR mentioned in the Mastering CMake but I didn’t find it sooner.