Imported Upstream version 1.33.2
[platform/upstream/grpc.git] / cmake / gflags.cmake
1 # Copyright 2017 gRPC authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 if(gRPC_GFLAGS_PROVIDER STREQUAL "module")
16   if(NOT GFLAGS_ROOT_DIR)
17     set(GFLAGS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gflags)
18   endif()
19   if(EXISTS "${GFLAGS_ROOT_DIR}/CMakeLists.txt")
20     add_subdirectory(${GFLAGS_ROOT_DIR} third_party/gflags)
21     set(_gRPC_GFLAGS_LIBRARIES gflags::gflags)
22   else()
23     message(WARNING "gRPC_GFLAGS_PROVIDER is \"module\" but GFLAGS_ROOT_DIR is wrong")
24   endif()
25 elseif(gRPC_GFLAGS_PROVIDER STREQUAL "package")
26   # Use "CONFIG" as there is no built-in cmake module for gflags.
27   find_package(gflags REQUIRED CONFIG)
28   if(TARGET gflags::gflags)
29     set(_gRPC_GFLAGS_LIBRARIES gflags::gflags)
30   endif()
31   set(_gRPC_FIND_GFLAGS "if(NOT gflags_FOUND)\n  find_package(gflags CONFIG)\nendif()")
32 elseif(gRPC_GFLAGS_PROVIDER STREQUAL "none")
33   # gflags is a test-only dependency and can be avoided if we're not building tests.
34 endif()