[cmake-developers] Debugging find_package() search behavior?

Robert Dailey rcdailey.lists at gmail.com
Tue Aug 29 10:27:25 EDT 2017


I want to clarify my post since I've spent some more time on this.

find_package() doesn't seem to work intuitively on Windows. On Linux,
for example, installation prefixes are like "/usr/local", so if I'm
building & installing a library in linux, you'd get a structure like:

/usr/local/include
/usr/local/lib
/usr/local/bin

On Windows, if I make the prefix "C:/Program Files", then you get:

C:/Program Files/include
C:/Program Files/lib
C:/Program Files/bin

This is not the idiomatic way to install libraries on windows.
Instead, it should be:

C:/Program Files/MyLibrary/include
C:/Program Files/MyLibrary/lib
C:/Program Files/MyLibrary/bin

I can achieve this during installation by setting my
CMAKE_INSTALL_PREFIX to "C:/Program Files/MyLibrary", however
CMAKE_INSTALL_PREFIX seems like it should be different when used with
find_package().

After doing tons of reading, the search behavior for find_package() is
very confusing outside of linux. Combined with CMAKE_FIND_ROOT_PATH, I
have no idea what the heck these should be on Windows.

Suppose I want to use a super build to build a lot of third party
libraries and install them relative to my CMAKE_BINARY_DIR, and
completely ignore system root paths for find_package() searching. My
first instinct would be to do this:

-D CMAKE_FIND_ROOT_PATH=${CMAKE_BINARY_DIR}/installed_libraries
-D CMAKE_INSTALL_PREFIX=${name_of_library}

Note that there are two goals:

1. The library being built must install its files to
${CMAKE_BINARY_DIR}/installed_libraries/${name_of_library}
2. Any find_package() invocations made by the library being built
should search within ${CMAKE_BINARY_DIR}/installed_libraries

I'm relying on the two variables above to control this behavior, but
CMAKE_INSTALL_PREFIX doesn't work well for both purposes. I can't make
it relative on Windows because it puts it somewhere random on my
filesystem, I think in program files. I'm not sure what
CMAKE_INSTALL_PREFIX does if it isn't an absolute path (but based on
linux behavior it should just append to the end of
CMAKE_FIND_ROOT_PATH I think?)

How can I get the proper install & find_package behavior on Windows
based on the requirements above?

On Sun, Aug 27, 2017 at 2:55 PM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
> So I'm trying to get CMake to find a package, and it isn't finding it.
> I am setting CMAKE_PREFIX_PATH to try to get it to find it. Is there a
> way I can view the search paths & prefixes that CMake is using with
> each find_package() call? I tried enabling debug and trace output, but
> neither of these seem to show any detail of what happens internally
> with find_package() searches.
>
> Thanks in advance.


More information about the cmake-developers mailing list