Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default search path for find_package in windows using cmake?

Tags:

I am porting some code over to windows and my cmake checks for the package Libavahi using

find_package(Libavahi)

I have the headers, dll, etc. but I'm not sure where to place these such that cmake will find them.

Where can I put these files to be found by cmake? They're in a folder called usr.

I see that the module path is specified using:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

but I'm wondering if there is a default location that will be searched as well

like image 550
JuJoDi Avatar asked Jan 23 '14 17:01

JuJoDi


People also ask

Where does CMake search Find_package?

Search Modes. In this mode, CMake searches for a file called Find<PackageName>. cmake , looking first in the locations listed in the CMAKE_MODULE_PATH , then among the Find Modules provided by the CMake installation. If the file is found, it is read and processed by CMake.

Where are CMake modules located?

Allowing CMakeLists files to make use of reusable modules enables the entire community to share reusable sections of code. For CMake, these sections are called cmake-modules and can be found in the Modules subdirectory of your installation.

What is CMake module path?

Semicolon-separated list of directories specifying a search path for CMake modules to be loaded by the include() or find_package() commands before checking the default modules that come with CMake. By default it is empty, it is intended to be set by the project.


1 Answers

The CMake manual fully specifies the rather complicated search order for the different find_* commands. Unfortunately, since Windows lacks a default directory structure à la /usr/local/lib, it is hard to come up with reasonable defaults here.

One of the most reliable ways of managing directories is through environment variable hints. You simply add an $ENV{MY_VAR} to the HINTS section of the find command and then document that environment variable in your project's readme. Most users that are capable of compiling a C++ program know how to use environment variables, and it is way more convenient than having to give the path on the command line every time (although it never hurts to leave that as an additional option).

For find_package CMake offers a special mechanism on Windows called the package registry. CMake maintains a list of package information in the Windows registry under HKEY_CURRENT_USER\Software\Kitware\CMake\Packages\. Packages build from source can register there using the export command. Other projects build later on the same machine will then be able to find that package without additional configuration. This is quite powerful if you need to build a lot of interdependent projects from source on the same machine.

Update: Starting with version 3.12, CMake now implicitly considers the <PackageName>_Root environment variable a HINT for every find_package call.

like image 169
ComicSansMS Avatar answered Nov 10 '22 20:11

ComicSansMS