Define DECLARE_VARIABLE in portability/GFlags.h
[folly.git] / folly / portability / GFlags.h
1 /*
2  * Copyright 2016 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #if FOLLY_HAVE_LIBGFLAGS
20 #include <gflags/gflags.h>
21 #else
22 // glog/logging.h is dependent on this implementation detail
23 // being defined otherwise it undefines all of this -_-....
24 //
25 // Also, this is deliberately expanded such that places using
26 // it directly break loudly. (C will break louder than C++, but oh well)
27 #define DECLARE_VARIABLE() \
28   static_assert(false, "You shouldn't be using GFlags internals.");
29
30 #define FOLLY_DECLARE_FLAG(_type, _name) extern _type FLAGS_##_name
31 #define DECLARE_bool(_name) FOLLY_DECLARE_FLAG(bool, _name)
32 #define DECLARE_double(_name) FOLLY_DECLARE_FLAG(double, _name)
33 #define DECLARE_int32(_name) FOLLY_DECLARE_FLAG(int, _name)
34 #define DECLARE_int64(_name) FOLLY_DECLARE_FLAG(long long, _name)
35 #define DECLARE_uint64(_name) FOLLY_DECLARE_FLAG(unsigned long long, _name)
36 #define DECLARE_string(_name) FOLLY_DECLARE_FLAG(std::string, _name)
37
38 #define FOLLY_DEFINE_FLAG(_type, _name, _default) _type FLAGS_##_name = _default
39 #define DEFINE_bool(_name, _default, _description) \
40   FOLLY_DEFINE_FLAG(bool, _name, _default)
41 #define DEFINE_double(_name, _default, _description) \
42   FOLLY_DEFINE_FLAG(double, _name, _default)
43 #define DEFINE_int32(_name, _default, _description) \
44   FOLLY_DEFINE_FLAG(int, _name, _default)
45 #define DEFINE_int64(_name, _default, _description) \
46   FOLLY_DEFINE_FLAG(long long, _name, _default)
47 #define DEFINE_uint64(_name, _default, _description) \
48   FOLLY_DEFINE_FLAG(unsigned long long, _name, _default)
49 #define DEFINE_string(_name, _default, _description) \
50   FOLLY_DEFINE_FLAG(std::string, _name, _default)
51 #endif