cmakelists find package
时间: 2023-09-30 21:07:54 浏览: 44
The `find_package` command in CMake is used to locate and load external packages or libraries into a CMake project. The command searches for the specified package and sets up the necessary variables and flags for the package to be used in the project.
The syntax for the `find_package` command is as follows:
```
find_package(<package_name> [version] [EXACT] [QUIET] [MODULE] [REQUIRED] [COMPONENTS <component1> <component2> ...])
```
where:
- `<package_name>`: the name of the package to be located.
- `version` (optional): the version of the package to be located.
- `EXACT` (optional): specifies that the exact version of the package must be found.
- `QUIET` (optional): suppresses the warning messages if the package is not found.
- `MODULE` (optional): specifies that the package is a CMake module instead of a traditional package.
- `REQUIRED` (optional): specifies that the package is required for the project to build.
- `COMPONENTS` (optional): specifies additional components of the package to be located.
For example, to find the `OpenCV` package and its `core` and `imgproc` components, the following `find_package` command can be used:
```
find_package(OpenCV REQUIRED COMPONENTS core imgproc)
```
This command will search for the `OpenCV` package and set up the necessary variables and flags for the `core` and `imgproc` components to be used in the project. If the package is not found, it will generate an error and stop the CMake configuration process.