folly: fix sysMembarrier() with newer kernel headers
[folly.git] / folly / portability / GFlags.h
1 /*
2  * Copyright 2017 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 #include <folly/portability/Config.h>
20
21 #if !FOLLY_HAVE_LIBGFLAGS
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, _shortType, _name) \
31   namespace fL##_shortType {                         \
32     extern _type FLAGS_##_name;                      \
33   }                                                  \
34   using fL##_shortType::FLAGS_##_name
35
36 #define DECLARE_bool(_name) FOLLY_DECLARE_FLAG(bool, B, _name)
37 #define DECLARE_double(_name) FOLLY_DECLARE_FLAG(double, D, _name)
38 #define DECLARE_int32(_name) FOLLY_DECLARE_FLAG(int, I, _name)
39 #define DECLARE_int64(_name) FOLLY_DECLARE_FLAG(long long, I64, _name)
40 #define DECLARE_uint64(_name) FOLLY_DECLARE_FLAG(unsigned long long, U64, _name)
41 #define DECLARE_string(_name) FOLLY_DECLARE_FLAG(std::string, S, _name)
42
43 #define FOLLY_DEFINE_FLAG(_type, _shortType, _name, _default) \
44   namespace fL##_shortType {                                  \
45     _type FLAGS_##_name = _default;                           \
46   }                                                           \
47   using fL##_shortType::FLAGS_##_name
48
49 #define DEFINE_bool(_name, _default, _description) \
50   FOLLY_DEFINE_FLAG(bool, B, _name, _default)
51 #define DEFINE_double(_name, _default, _description) \
52   FOLLY_DEFINE_FLAG(double, D, _name, _default)
53 #define DEFINE_int32(_name, _default, _description) \
54   FOLLY_DEFINE_FLAG(int, I, _name, _default)
55 #define DEFINE_int64(_name, _default, _description) \
56   FOLLY_DEFINE_FLAG(long long, I64, _name, _default)
57 #define DEFINE_uint64(_name, _default, _description) \
58   FOLLY_DEFINE_FLAG(unsigned long long, U64, _name, _default)
59 #define DEFINE_string(_name, _default, _description) \
60   FOLLY_DEFINE_FLAG(std::string, S, _name, _default)
61
62 namespace google {
63 class FlagSaver {};
64 }
65
66 #else
67 #include <gflags/gflags.h>
68 #endif