find_library search the windows Path

I set the windowns Path C:\tmp\prebuild

I put the libdatachannel folder into C:\tmp\prebuild
It like this


Then use this

find_package(libdatachannel REQUIRED)
	NAMES datachannel

But the cmake can not find the library until I set the windows path to C:\tmp\prebuild\libdatachannel

someone can tell me why? thanks

CMake does not search the entire filesystem - imagine the configure times if it did!

You don’t have to add the directory to the system PATH though. Just invoke CMake with -DCMAKE_PREFIX_PATH=C:\tmp\prebuild\libdatachannel.

If I have many library to use


Do you have the recommend method to search these?

It is not work .

set(libdatachannel_DIR C:/tmp/prebuild/libdatachannel/)
find_package(libdatachannel REQUIRED)

It still show the error

CMake Error at cmake/FindDataChannel.cmake:8 (find_package):
  By not providing "Findlibdatachannel.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "libdatachannel", but CMake did not find one.

  Could not find a package configuration file provided by "libdatachannel"
  with any of the following names:


  Add the installation prefix of "libdatachannel" to CMAKE_PREFIX_PATH or set
  "libdatachannel_DIR" to a directory containing one of the above files.  If
  "libdatachannel" provides a separate development package or SDK, be sure it
  has been installed.

I have an impression, that it’s case-sensitive, so you should probably do find_package(LibDataChannel REQUIRED).

For the first question:
You either need to add all of those to CMAKE_PREFIX_PATH (it’s a semicolon-separated list),
or re-organize those prebuilds. I tend to install all my prebuilds into the same directory hierarchy, so I typically have only one prefix to care about.

Follow your idea.

list(APPEND CMAKE_PREFIX_PATH "${prefix _PATH}/xx1")
list(APPEND CMAKE_PREFIX_PATH "${prefix _PATH}/xx2")
list(APPEND CMAKE_PREFIX_PATH "${prefix _PATH}/xx3")

find_package(xx1 REQUIRED)
find_package(xx2 REQUIRED)
find_package(xx3 REQUIRED)