[CMake] find_package vs. include

Eric Noulard eric.noulard at gmail.com
Wed Sep 17 08:22:32 EDT 2008


2008/9/17 Robert Haines <rhaines at manchester.ac.uk>:
> Hi all,
>
> As far as I can tell both (for example) find_package(MPI) and
> include(FindMPI) do the same thing. All the required bits and pieces are set
> and usable for the rest of the build.
>
> Is there any difference under the hood, and should I be using one in
> preference to the other?

'find_package' has many more option than 'include'

 find_package(<package> [major[.minor[.patch]]] [EXACT] [QUIET]
                      [[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]
                      [NAMES name1 [name2 ...]]
                      [CONFIGS config1 [config2 ...]]
                      [HINTS path1 [path2 ... ]]
                      [PATHS path1 [path2 ... ]]
                      [PATH_SUFFIXES suffix1 [suffix2 ...]]
                      [NO_DEFAULT_PATH]
                      [NO_CMAKE_ENVIRONMENT_PATH]
                      [NO_CMAKE_PATH]
                      [NO_SYSTEM_ENVIRONMENT_PATH]
                      [NO_CMAKE_BUILDS_PATH]
                      [NO_CMAKE_SYSTEM_PATH]
                      [CMAKE_FIND_ROOT_PATH_BOTH |
                       ONLY_CMAKE_FIND_ROOT_PATH |
                       NO_CMAKE_FIND_ROOT_PATH])

 include(file1 [OPTIONAL] [RESULT_VARIABLE <VAR>])
include(module [OPTIONAL] [RESULT_VARIABLE <VAR>])

You should read the doc for find_package.

My opinion is that you should use find_package(XXX) for a FindXXX.cmake module.


-- 
Erk


More information about the CMake mailing list