1 # - FindOptionalPackage
2 # Enable or disable optional packages. Also force optional packages.
4 # This module defines the following macros:
5 # find_required_package : find a required package, can not be disabled
6 # find_suggested_package : find a suggested package - required but can be disabled
7 # find_optional_package : find an optional package - required only if enabled
10 #=============================================================================
11 # Copyright 2011 Nils Andresen <nils@nils-andresen.de>
13 # Licensed under the Apache License, Version 2.0 (the "License");
14 # you may not use this file except in compliance with the License.
15 # You may obtain a copy of the License at
17 # http://www.apache.org/licenses/LICENSE-2.0
19 # Unless required by applicable law or agreed to in writing, software
20 # distributed under the License is distributed on an "AS IS" BASIS,
21 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 # See the License for the specific language governing permissions and
23 # limitations under the License.
24 #=============================================================================
26 macro(find_required_package _normal_package)
27 find_package(${_normal_package} REQUIRED)
28 endmacro(find_required_package)
30 macro(find_suggested_package _normal_package)
31 string(TOUPPER ${_normal_package} _upper_package)
32 option(WITH_${_upper_package} "Add dependency to ${_normal_package} - recommended" ON)
34 if(WITH_${_upper_package})
35 message(STATUS "Finding suggested package ${_normal_package}.")
36 message(STATUS " Disable this using \"-DWITH_${_upper_package}=OFF\".")
37 find_package(${_normal_package} REQUIRED)
38 endif(WITH_${_upper_package})
39 endmacro(find_suggested_package)
41 macro(find_optional_package _normal_package)
42 string(TOUPPER ${_normal_package} _upper_package)
43 option(WITH_${_upper_package} "Add dependency to ${_normal_package}" OFF)
45 if(WITH_${_upper_package})
46 find_package(${_normal_package} REQUIRED)
47 else(WITH_${_upper_package})
48 message(STATUS "Skipping optional package ${_normal_package}.")
49 message(STATUS " Enable this using \"-DWITH_${_upper_package}=ON\".")
50 endif(WITH_${_upper_package})
51 endmacro(find_optional_package)