summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schuh <andreas.schuh.84@gmail.com>2014-03-18 22:03:10 +0000
committerAndreas Schuh <andreas.schuh.84@gmail.com>2014-03-18 22:03:10 +0000
commit492ac156bc6b6e8dfbb8c93c6bdb5d57b346f925 (patch)
tree4cde051e1865c82aec443fbb6bff1456a36ee727 /src
parentcf92ec3bf01476f72ad48eb20cfcaceadf25ee6b (diff)
downloadgflags-492ac156bc6b6e8dfbb8c93c6bdb5d57b346f925.tar.gz
gflags-492ac156bc6b6e8dfbb8c93c6bdb5d57b346f925.tar.bz2
gflags-492ac156bc6b6e8dfbb8c93c6bdb5d57b346f925.zip
Fix DLL build on Windows and use PathMatchSpec instead of fnmatch.
Expose as few system variables as possible through public interface. Perform STRIP_FLAGS_HELP test using CMake instead of Bash. Change file path separator used by gflags_reporting.cc to backslash on Windwos.
Diffstat (limited to 'src')
-rw-r--r--src/config.h.in116
-rw-r--r--src/gflags.cc24
-rw-r--r--src/gflags.h139
-rw-r--r--src/gflags_declare.h.in126
-rw-r--r--src/gflags_reporting.cc9
5 files changed, 209 insertions, 205 deletions
diff --git a/src/config.h.in b/src/config.h.in
index 5d16df0..bf81745 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -2,10 +2,86 @@
// Note: This header file is only used internally. It is not part of public interface!
-#include "gflags_declare.h" // system checks
+// Whether gflags library is shared. Used for DLL import declaration.
+#define GFLAGS_IS_A_DLL @GFLAGS_IS_A_DLL@
// ---------------------------------------------------------------------------
-// Additional meta-information
+// System checks
+
+// Define if you have the <stdint.h> header file.
+#cmakedefine GFLAGS_HAVE_STDINT_H
+
+// Define if you have the <sys/types.h> header file.
+#cmakedefine GFLAGS_HAVE_SYS_TYPES_H
+
+// Define if you have the <inttypes.h> header file.
+#cmakedefine GFLAGS_HAVE_INTTYPES_H
+
+// Define if you have the <sys/stat.h> header file.
+#cmakedefine GFLAGS_HAVE_SYS_STAT_H
+
+// Define if you have the <unistd.h> header file.
+#cmakedefine GFLAGS_HAVE_UNISTD_H
+
+// Define if you have the <fnmatch.h> header file.
+#cmakedefine GFLAGS_HAVE_FNMATCH_H
+
+// Define if you have the <shlwapi.h> header file (Windows 2000/XP).
+#cmakedefine GFLAGS_HAVE_SHLWAPI_H
+
+// Define if you have the strtoll function.
+#cmakedefine GFLAGS_HAVE_STRTOLL
+
+// Define if you have the strtoq function.
+#cmakedefine GFLAGS_HAVE_STRTOQ
+
+// Define if you have the <pthread.h> header file.
+#cmakedefine GFLAGS_HAVE_PTHREAD
+
+// Define if your pthread library defines the type pthread_rwlock_t
+#cmakedefine GFLAGS_HAVE_RWLOCK
+
+// Backwards compatibility in case users defined these macros themselves
+// or allow users to use these more general macros if the gflags library
+// is build as part of a user project, e.g., included as Git submodule
+#if defined(HAVE_STDINT_H) && !defined(GFLAGS_HAVE_STDINT_H)
+# define GFLAGS_HAVE_STDINT_H
+#endif
+#if defined(HAVE_SYS_TYPES_H) && !defined(GFLAGS_HAVE_SYS_TYPES_H)
+# define GFLAGS_HAVE_SYS_TYPES_H
+#endif
+#if defined(HAVE_INTTYPES_H) && !defined(GFLAGS_HAVE_INTTYPES_H)
+# define GFLAGS_HAVE_INTTYPES_H
+#endif
+#if defined(HAVE_SYS_STAT_H) && !defined(GFLAGS_HAVE_SYS_STAT_H)
+# define GFLAGS_HAVE_SYS_STAT_H
+#endif
+#if defined(HAVE_UNISTD_H) && !defined(GFLAGS_HAVE_UNISTD_H)
+# define GFLAGS_HAVE_UNISTD_H
+#endif
+#if defined(HAVE_FNMATCH_H) && !defined(GFLAGS_HAVE_FNMATCH_H)
+# define GFLAGS_HAVE_FNMATCH_H
+#endif
+#if defined(HAVE_STRTOLL) && !defined(GFLAGS_HAVE_STRTOLL)
+# define GFLAGS_HAVE_STRTOLL
+#endif
+#if defined(HAVE_STRTOLQ) && !defined(GFLAGS_HAVE_STRTOLQ)
+# define GFLAGS_HAVE_STRTOLQ
+#endif
+#if defined(HAVE_PTHREAD) && !defined(GFLAGS_HAVE_PTHREAD)
+# define GFLAGS_HAVE_PTHREAD
+#endif
+#if defined(HAVE_RWLOCK) && !defined(GFLAGS_HAVE_RWLOCK)
+# define GFLAGS_HAVE_RWLOCK
+#endif
+
+// gcc requires this to get PRId64, etc.
+#if defined(GFLAGS_HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
+# define __STDC_FORMAT_MACROS 1
+#endif
+
+// ---------------------------------------------------------------------------
+// Package information
// Name of package.
#define PACKAGE @PROJECT_NAME@
@@ -30,10 +106,42 @@
// ---------------------------------------------------------------------------
// Path separator
-#define PATH_SEPARATOR '/'
+#ifndef PATH_SEPARATOR
+# if _WIN32
+# define PATH_SEPARATOR '\\'
+# else
+# define PATH_SEPARATOR '/'
+# endif
+#endif
// ---------------------------------------------------------------------------
-// Windows port
+// Windows
+
+// Always export symbols when compiling a shared library as this file is only
+// included by internal modules when building the gflags library itself.
+// The gflags_declare.h header file will set it to import these symbols otherwise.
+#ifndef GFLAGS_DLL_DECL
+# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
+# define GFLAGS_DLL_DECL __declspec(dllexport)
+# else
+# define GFLAGS_DLL_DECL
+# endif
+#endif
+// Flags defined by the gflags library itself must be exported
+#ifndef GFLAGS_DLL_DEFINE_FLAG
+# define GFLAGS_DLL_DEFINE_FLAG GFLAGS_DLL_DECL
+#endif
+
#ifdef _WIN32
+// The unittests import the symbols of the shared gflags library
+# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
+# define GFLAGS_DLL_DECL_FOR_UNITTESTS __declspec(dllimport)
+# endif
# include "windows_port.h"
#endif
+
+// Export of STL class instantiations -- no extern keyword to not trigger a warning
+// \sa http://support.microsoft.com/default.aspx?scid=KB;EN-US;168958
+#if GFLAGS_IS_A_DLL && defined(_MSC_VER) && _MSC_VER >= 1100
+# define GFLAGS_EXTERN_STL
+#endif \ No newline at end of file
diff --git a/src/gflags.cc b/src/gflags.cc
index 7033876..dc1616d 100644
--- a/src/gflags.cc
+++ b/src/gflags.cc
@@ -93,8 +93,11 @@
#include <assert.h>
#include <ctype.h>
#include <errno.h>
-#ifdef GFLAGS_HAVE_FNMATCH_H
+#if defined(GFLAGS_HAVE_FNMATCH_H)
# include <fnmatch.h>
+#elif defined(GFLAGS_HAVE_SHLWAPI_H)
+# include <shlwapi.h>
+# pragma comment(lib, "shlwapi.lib")
#endif
#include <stdarg.h> // For va_list and related operations
#include <stdio.h>
@@ -109,12 +112,6 @@
#include "mutex.h"
#include "util.h"
-// Export the following flags only if the gflags library is a DLL
-#ifndef GFLAGS_SHARED_LIBS
-# undef GFLAGS_DLL_DEFINE_FLAG
-# define GFLAGS_DLL_DEFINE_FLAG
-#endif
-
// Special flags, type 1: the 'recursive' flags. They set another flag's val.
DEFINE_string(flagfile, "", "load flags from file");
DEFINE_string(fromenv, "", "set flags from the environment"
@@ -1310,13 +1307,12 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked(
// We try matching both against the full argv0 and basename(argv0)
if (glob == ProgramInvocationName() // small optimization
|| glob == ProgramInvocationShortName()
-#ifdef GFLAGS_HAVE_FNMATCH_H
- || fnmatch(glob.c_str(),
- ProgramInvocationName(),
- FNM_PATHNAME) == 0
- || fnmatch(glob.c_str(),
- ProgramInvocationShortName(),
- FNM_PATHNAME) == 0
+#if defined(GFLAGS_HAVE_FNMATCH_H)
+ || fnmatch(glob.c_str(), ProgramInvocationName(), FNM_PATHNAME) == 0
+ || fnmatch(glob.c_str(), ProgramInvocationShortName(), FNM_PATHNAME) == 0
+#elif defined(GFLAGS_HAVE_SHLWAPI_H)
+ || PathMatchSpec(glob.c_str(), ProgramInvocationName())
+ || PathMatchSpec(glob.c_str(), ProgramInvocationShortName())
#endif
) {
flags_are_relevant = true;
diff --git a/src/gflags.h b/src/gflags.h
index 41f53d9..550eca2 100644
--- a/src/gflags.h
+++ b/src/gflags.h
@@ -84,11 +84,13 @@
#include "gflags_declare.h" // IWYU pragma: export
-// Export/import STL instantiations used as data members of exported classes
-// \sa http://support.microsoft.com/default.aspx?scid=KB;EN-US;168958
-#ifdef GFLAGS_EXTERN_STL
- GFLAGS_EXTERN_STL template class GFLAGS_DLL_DECL std::allocator<char>;
- GFLAGS_EXTERN_STL template class GFLAGS_DLL_DECL std::basic_string<char>;
+// We always want to export variables defined in user code
+#ifndef GFLAGS_DLL_DEFINE_FLAG
+# ifdef _MSC_VER
+# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
+# else
+# define GFLAGS_DLL_DEFINE_FLAG
+# endif
#endif
@@ -124,19 +126,12 @@ namespace GFLAGS_NAMESPACE {
// Returns true if successfully registered, false if not (because the
// first argument doesn't point to a command-line flag, or because a
// validator is already registered for this flag).
-extern bool RegisterFlagValidator(const bool* flag,
- bool (*validate_fn)(const char*, bool));
-extern bool RegisterFlagValidator(const int32* flag,
- bool (*validate_fn)(const char*, int32));
-extern bool RegisterFlagValidator(const int64* flag,
- bool (*validate_fn)(const char*, int64));
-extern bool RegisterFlagValidator(const uint64* flag,
- bool (*validate_fn)(const char*, uint64));
-extern bool RegisterFlagValidator(const double* flag,
- bool (*validate_fn)(const char*, double));
-extern bool RegisterFlagValidator(const std::string* flag,
- bool (*validate_fn)(const char*,
- const std::string&));
+extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const bool* flag, bool (*validate_fn)(const char*, bool));
+extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int32* flag, bool (*validate_fn)(const char*, int32));
+extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int64* flag, bool (*validate_fn)(const char*, int64));
+extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const uint64* flag, bool (*validate_fn)(const char*, uint64));
+extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const double* flag, bool (*validate_fn)(const char*, double));
+extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const std::string* flag, bool (*validate_fn)(const char*, const std::string&));
// Convenience macro for the registration of a flag validator
#define DEFINE_validator(name, validator) \
@@ -154,7 +149,12 @@ extern bool RegisterFlagValidator(const std::string* flag,
// In addition to accessing flags, you can also access argv[0] (the program
// name) and argv (the entire commandline), which we sock away a copy of.
// These variables are static, so you should only set them once.
-
+#ifdef _MSC_VER
+# pragma warning(push)
+// The solution offered at http://support.microsoft.com/default.aspx?scid=KB;EN-US;168958
+// is not really desireable as we don't want to explicitly instantiate/export any STL types
+# pragma warning(disable: 4251)
+#endif
struct GFLAGS_DLL_DECL CommandLineFlagInfo {
std::string name; // the name of the flag
std::string type; // the type of the flag: int32, etc
@@ -162,46 +162,49 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo {
std::string current_value; // the current value, as a string
std::string default_value; // the default value, as a string
std::string filename; // 'cleaned' version of filename holding the flag
- bool has_validator_fn; // true if RegisterFlagValidator called on this flag
- bool is_default; // true if the flag has the default value and
- // has not been set explicitly from the cmdline
- // or via SetCommandLineOption
- const void* flag_ptr; // pointer to the flag's current value (i.e. FLAGS_foo)
+ bool has_validator_fn; // true if RegisterFlagValidator called on this flag
+ bool is_default; // true if the flag has the default value and
+ // has not been set explicitly from the cmdline
+ // or via SetCommandLineOption
+ const void* flag_ptr; // pointer to the flag's current value (i.e. FLAGS_foo)
};
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
// Using this inside of a validator is a recipe for a deadlock.
// TODO(user) Fix locking when validators are running, to make it safe to
// call validators during ParseAllFlags.
// Also make sure then to uncomment the corresponding unit test in
// gflags_unittest.sh
-extern void GetAllFlags(std::vector<CommandLineFlagInfo>* OUTPUT);
+extern GFLAGS_DLL_DECL void GetAllFlags(std::vector<CommandLineFlagInfo>* OUTPUT);
// These two are actually defined in gflags_reporting.cc.
-extern void ShowUsageWithFlags(const char *argv0); // what --help does
-extern void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict);
+extern GFLAGS_DLL_DECL void ShowUsageWithFlags(const char *argv0); // what --help does
+extern GFLAGS_DLL_DECL void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict);
// Create a descriptive string for a flag.
// Goes to some trouble to make pretty line breaks.
-extern std::string DescribeOneFlag(const CommandLineFlagInfo& flag);
+extern GFLAGS_DLL_DECL std::string DescribeOneFlag(const CommandLineFlagInfo& flag);
// Thread-hostile; meant to be called before any threads are spawned.
-extern void SetArgv(int argc, const char** argv);
+extern GFLAGS_DLL_DECL void SetArgv(int argc, const char** argv);
// The following functions are thread-safe as long as SetArgv() is
// only called before any threads start.
-extern const std::vector<std::string>& GetArgvs();
-extern const char* GetArgv(); // all of argv as a string
-extern const char* GetArgv0(); // only argv0
-extern uint32 GetArgvSum(); // simple checksum of argv
-extern const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set
-extern const char* ProgramInvocationShortName(); // basename(argv0)
+extern GFLAGS_DLL_DECL const std::vector<std::string>& GetArgvs();
+extern GFLAGS_DLL_DECL const char* GetArgv(); // all of argv as a string
+extern GFLAGS_DLL_DECL const char* GetArgv0(); // only argv0
+extern GFLAGS_DLL_DECL uint32 GetArgvSum(); // simple checksum of argv
+extern GFLAGS_DLL_DECL const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set
+extern GFLAGS_DLL_DECL const char* ProgramInvocationShortName(); // basename(argv0)
// ProgramUsage() is thread-safe as long as SetUsageMessage() is only
// called before any threads start.
-extern const char* ProgramUsage(); // string set by SetUsageMessage()
+extern GFLAGS_DLL_DECL const char* ProgramUsage(); // string set by SetUsageMessage()
// VersionString() is thread-safe as long as SetVersionString() is only
// called before any threads start.
-extern const char* VersionString(); // string set by SetVersionString()
+extern GFLAGS_DLL_DECL const char* VersionString(); // string set by SetVersionString()
@@ -215,17 +218,16 @@ extern const char* VersionString(); // string set by SetVersionString()
// Return true iff the flagname was found.
// OUTPUT is set to the flag's value, or unchanged if we return false.
-extern bool GetCommandLineOption(const char* name, std::string* OUTPUT);
+extern GFLAGS_DLL_DECL bool GetCommandLineOption(const char* name, std::string* OUTPUT);
// Return true iff the flagname was found. OUTPUT is set to the flag's
// CommandLineFlagInfo or unchanged if we return false.
-extern bool GetCommandLineFlagInfo(const char* name,
- CommandLineFlagInfo* OUTPUT);
+extern GFLAGS_DLL_DECL bool GetCommandLineFlagInfo(const char* name, CommandLineFlagInfo* OUTPUT);
// Return the CommandLineFlagInfo of the flagname. exit() if name not found.
// Example usage, to check if a flag's value is currently the default value:
// if (GetCommandLineFlagInfoOrDie("foo").is_default) ...
-extern CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name);
+extern GFLAGS_DLL_DECL CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name);
enum GFLAGS_DLL_DECL FlagSettingMode {
// update the flag's value (can call this multiple times).
@@ -247,9 +249,8 @@ enum GFLAGS_DLL_DECL FlagSettingMode {
// non-empty else.
// SetCommandLineOption uses set_mode == SET_FLAGS_VALUE (the common case)
-extern std::string SetCommandLineOption(const char* name, const char* value);
-extern std::string SetCommandLineOptionWithMode(const char* name, const char* value,
- FlagSettingMode set_mode);
+extern GFLAGS_DLL_DECL std::string SetCommandLineOption (const char* name, const char* value);
+extern GFLAGS_DLL_DECL std::string SetCommandLineOptionWithMode(const char* name, const char* value, FlagSettingMode set_mode);
// --------------------------------------------------------------------
@@ -297,17 +298,17 @@ GFLAGS_ATTRIBUTE_UNUSED;
// Some deprecated or hopefully-soon-to-be-deprecated functions.
// This is often used for logging. TODO(csilvers): figure out a better way
-extern std::string CommandlineFlagsIntoString();
+extern GFLAGS_DLL_DECL std::string CommandlineFlagsIntoString();
// Usually where this is used, a FlagSaver should be used instead.
-extern bool ReadFlagsFromString(const std::string& flagfilecontents,
- const char* prog_name,
- bool errors_are_fatal); // uses SET_FLAGS_VALUE
+extern GFLAGS_DLL_DECL
+bool ReadFlagsFromString(const std::string& flagfilecontents,
+ const char* prog_name,
+ bool errors_are_fatal); // uses SET_FLAGS_VALUE
// These let you manually implement --flagfile functionality.
// DEPRECATED.
-extern bool AppendFlagsIntoFile(const std::string& filename, const char* prog_name);
-extern bool ReadFromFlagsFile(const std::string& filename, const char* prog_name,
- bool errors_are_fatal); // uses SET_FLAGS_VALUE
+extern GFLAGS_DLL_DECL bool AppendFlagsIntoFile(const std::string& filename, const char* prog_name);
+extern GFLAGS_DLL_DECL bool ReadFromFlagsFile(const std::string& filename, const char* prog_name, bool errors_are_fatal); // uses SET_FLAGS_VALUE
// --------------------------------------------------------------------
@@ -318,12 +319,12 @@ extern bool ReadFromFlagsFile(const std::string& filename, const char* prog_name
// Otherwise, return the value. NOTE: for booleans, for true use
// 't' or 'T' or 'true' or '1', for false 'f' or 'F' or 'false' or '0'.
-extern bool BoolFromEnv(const char *varname, bool defval);
-extern int32 Int32FromEnv(const char *varname, int32 defval);
-extern int64 Int64FromEnv(const char *varname, int64 defval);
-extern uint64 Uint64FromEnv(const char *varname, uint64 defval);
-extern double DoubleFromEnv(const char *varname, double defval);
-extern const char *StringFromEnv(const char *varname, const char *defval);
+extern GFLAGS_DLL_DECL bool BoolFromEnv(const char *varname, bool defval);
+extern GFLAGS_DLL_DECL int32 Int32FromEnv(const char *varname, int32 defval);
+extern GFLAGS_DLL_DECL int64 Int64FromEnv(const char *varname, int64 defval);
+extern GFLAGS_DLL_DECL uint64 Uint64FromEnv(const char *varname, uint64 defval);
+extern GFLAGS_DLL_DECL double DoubleFromEnv(const char *varname, double defval);
+extern GFLAGS_DLL_DECL const char *StringFromEnv(const char *varname, const char *defval);
// --------------------------------------------------------------------
@@ -335,12 +336,12 @@ extern const char *StringFromEnv(const char *varname, const char *defval);
// SetUsageMessage(usage);
// Do not include commandline flags in the usage: we do that for you!
// Thread-hostile; meant to be called before any threads are spawned.
-extern void SetUsageMessage(const std::string& usage);
+extern GFLAGS_DLL_DECL void SetUsageMessage(const std::string& usage);
// Sets the version string, which is emitted with --version.
// For instance: SetVersionString("1.3");
// Thread-hostile; meant to be called before any threads are spawned.
-extern void SetVersionString(const std::string& version);
+extern GFLAGS_DLL_DECL void SetVersionString(const std::string& version);
// Looks for flags in argv and parses them. Rearranges argv to put
@@ -350,7 +351,7 @@ extern void SetVersionString(const std::string& version);
// of the first non-flag argument.
// See top-of-file for more details on this function.
#ifndef SWIG // In swig, use ParseCommandLineFlagsScript() instead.
-extern uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags);
+extern GFLAGS_DLL_DECL uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags);
#endif
@@ -364,18 +365,18 @@ extern uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags);
// defined more than once in the command line or flag file, the last
// definition is used. Returns the index (into argv) of the first
// non-flag argument. (If remove_flags is true, will always return 1.)
-extern uint32 ParseCommandLineNonHelpFlags(int *argc, char*** argv,
- bool remove_flags);
+extern GFLAGS_DLL_DECL uint32 ParseCommandLineNonHelpFlags(int *argc, char*** argv, bool remove_flags);
+
// This is actually defined in gflags_reporting.cc.
// This function is misnamed (it also handles --version, etc.), but
// it's too late to change that now. :-(
-extern void HandleCommandLineHelpFlags(); // in gflags_reporting.cc
+extern GFLAGS_DLL_DECL void HandleCommandLineHelpFlags(); // in gflags_reporting.cc
// Allow command line reparsing. Disables the error normally
// generated when an unknown flag is found, since it may be found in a
// later parse. Thread-hostile; meant to be called before any threads
// are spawned.
-extern void AllowCommandLineReparsing();
+extern GFLAGS_DLL_DECL void AllowCommandLineReparsing();
// Reparse the flags that have not yet been recognized. Only flags
// registered since the last parse will be recognized. Any flag value
@@ -383,7 +384,7 @@ extern void AllowCommandLineReparsing();
// separate command line argument that follows the flag argument.
// Intended for handling flags from dynamically loaded libraries,
// since their flags are not registered until they are loaded.
-extern void ReparseCommandLineNonHelpFlags();
+extern GFLAGS_DLL_DECL void ReparseCommandLineNonHelpFlags();
// Clean up memory allocated by flags. This is only needed to reduce
// the quantity of "potentially leaked" reports emitted by memory
@@ -394,7 +395,7 @@ extern void ReparseCommandLineNonHelpFlags();
// called will have unexpected consequences. This is not safe to run
// when multiple threads might be running: the function is
// thread-hostile.
-extern void ShutDownCommandLineFlags();
+extern GFLAGS_DLL_DECL void ShutDownCommandLineFlags();
// --------------------------------------------------------------------
@@ -425,7 +426,7 @@ extern void ShutDownCommandLineFlags();
// directly. The idea is that DEFINE puts the flag in the weird
// namespace, and DECLARE imports the flag from there into the current
// namespace. The net result is to force people to use DECLARE to get
-// access to a flag, rather than saying "extern bool FLAGS_whatever;"
+// access to a flag, rather than saying "extern GFLAGS_DLL_DECL bool FLAGS_whatever;"
// or some such instead. We want this so we can put extra
// functionality (like sanity-checking) in DECLARE if we want, and
// make sure it is picked up everywhere.
@@ -446,7 +447,7 @@ class GFLAGS_DLL_DECL FlagRegisterer {
// binary file. This can reduce the size of the resulting binary
// somewhat, and may also be useful for security reasons.
-extern const char kStrippedFlagHelp[];
+extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[];
} // namespace GFLAGS_NAMESPACE
@@ -561,7 +562,7 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot,
clstring* const FLAGS_no##name = ::fLS:: \
dont_pass0toDEFINE_string(s_##name[0].s, \
val); \
- static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
+ static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
#name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name)); \
extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \
diff --git a/src/gflags_declare.h.in b/src/gflags_declare.h.in
index a9b7b6a..91ceb51 100644
--- a/src/gflags_declare.h.in
+++ b/src/gflags_declare.h.in
@@ -47,9 +47,6 @@
#define GFLAGS_VERSION_MINOR @PACKAGE_VERSION_MINOR@ ///< Minor version number.
#define GFLAGS_VERSION_PATCH @PACKAGE_VERSION_PATCH@ ///< Version patch number.
-// Whether gflags library is shared. Used for DLL import declaration.
-#cmakedefine GFLAGS_SHARED_LIBS
-
// ---------------------------------------------------------------------------
// Namespace for gflags symbols.
#define GFLAGS_NAMESPACE @GFLAGS_NAMESPACE@
@@ -60,148 +57,49 @@
// ---------------------------------------------------------------------------
// Windows DLL import/export.
+
+// We always want to import the symbols of the gflags library
#ifndef GFLAGS_DLL_DECL
-# if defined(_MSC_VER) && defined(GFLAGS_SHARED_LIBS)
-# ifdef GFLAGS_DLL_EXPORT
-# define GFLAGS_DLL_DECL __declspec(dllexport)
-# else
-# define GFLAGS_DLL_DECL __declspec(dllimport)
-# endif
+# if @GFLAGS_IS_A_DLL@ && defined(_MSC_VER)
+# define GFLAGS_DLL_DECL __declspec(dllimport)
# else
# define GFLAGS_DLL_DECL
# endif
#endif
-// By default, we always want to export defined variables, assuming
-// that the DEFINE_FLAG macros are used within shared modules.
-#ifndef GFLAGS_DLL_DEFINE_FLAG
-# if defined(_MSC_VER)
-# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
-# else
-# define GFLAGS_DLL_DEFINE_FLAG
-# endif
-#endif
-
-// By default, we always want to export defined variables, assuming
-// that the DECLARE_FLAG macros are used within shared modules.
+// We always want to import variables declared in user code
#ifndef GFLAGS_DLL_DECLARE_FLAG
-# if defined(_MSC_VER)
+# ifdef _MSC_VER
# define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
# else
# define GFLAGS_DLL_DECLARE_FLAG
# endif
#endif
-// Export/import of STL class instantiations
-// \sa http://support.microsoft.com/default.aspx?scid=KB;EN-US;168958
-#if defined(GFLAGS_SHARED_LIBS) && defined(_MSC_VER) && _MSC_VER >= 1100
-# ifdef GFLAGS_DLL_EXPORT
-# define GFLAGS_EXTERN_STL
-# else
-# define GFLAGS_EXTERN_STL extern
-# endif
-#endif
-
-// ---------------------------------------------------------------------------
-// Available system headers
-
-// Define if you have the <stdint.h> header file.
-#cmakedefine GFLAGS_HAVE_STDINT_H
-
-// Define if you have the <sys/types.h> header file.
-#cmakedefine GFLAGS_HAVE_SYS_TYPES_H
-
-// Define if you have the <inttypes.h> header file.
-#cmakedefine GFLAGS_HAVE_INTTYPES_H
-
-// Define if you have the <sys/stat.h> header file.
-#cmakedefine GFLAGS_HAVE_SYS_STAT_H
-
-// Define if you have the <unistd.h> header file.
-#cmakedefine GFLAGS_HAVE_UNISTD_H
-
-// Define if you have the <fnmatch.h> header file.
-#cmakedefine GFLAGS_HAVE_FNMATCH_H
-
-// Define if you have the strtoll function.
-#cmakedefine GFLAGS_HAVE_STRTOLL
-
-// Define if you have the strtoq function.
-#cmakedefine GFLAGS_HAVE_STRTOQ
-
-// Define if you have the <pthread.h> header file.
-#cmakedefine GFLAGS_HAVE_PTHREAD
-
-// Define if your pthread library defines the type pthread_rwlock_t
-#cmakedefine GFLAGS_HAVE_RWLOCK
-
-// Backwards compatibility in case users defined these macros themselves
-// or allow users to use these more general macros if the gflags library
-// is build as part of a user project, e.g., included as Git submodule
-#if defined(HAVE_STDINT_H) && !defined(GFLAGS_HAVE_STDINT_H)
-# define GFLAGS_HAVE_STDINT_H
-#endif
-#if defined(HAVE_SYS_TYPES_H) && !defined(GFLAGS_HAVE_SYS_TYPES_H)
-# define GFLAGS_HAVE_SYS_TYPES_H
-#endif
-#if defined(HAVE_INTTYPES_H) && !defined(GFLAGS_HAVE_INTTYPES_H)
-# define GFLAGS_HAVE_INTTYPES_H
-#endif
-#if defined(HAVE_SYS_STAT_H) && !defined(GFLAGS_HAVE_SYS_STAT_H)
-# define GFLAGS_HAVE_SYS_STAT_H
-#endif
-#if defined(HAVE_UNISTD_H) && !defined(GFLAGS_HAVE_UNISTD_H)
-# define GFLAGS_HAVE_UNISTD_H
-#endif
-#if defined(HAVE_FNMATCH_H) && !defined(GFLAGS_HAVE_FNMATCH_H)
-# define GFLAGS_HAVE_FNMATCH_H
-#endif
-#if defined(HAVE_STRTOLL) && !defined(GFLAGS_HAVE_STRTOLL)
-# define GFLAGS_HAVE_STRTOLL
-#endif
-#if defined(HAVE_STRTOLQ) && !defined(GFLAGS_HAVE_STRTOLQ)
-# define GFLAGS_HAVE_STRTOLQ
-#endif
-#if defined(HAVE_PTHREAD) && !defined(GFLAGS_HAVE_PTHREAD)
-# define GFLAGS_HAVE_PTHREAD
-#endif
-#if defined(HAVE_RWLOCK) && !defined(GFLAGS_HAVE_RWLOCK)
-# define GFLAGS_HAVE_RWLOCK
-#endif
-
-// gcc requires this to get PRId64, etc.
-#if defined(GFLAGS_HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
-# define __STDC_FORMAT_MACROS 1
-#endif
-
// ---------------------------------------------------------------------------
// Flag types
#include <string>
-#if defined(GFLAGS_HAVE_STDINT_H)
+#if @GFLAGS_HAVE_STDINT_H@
# include <stdint.h> // the normal place uint32_t is defined
-#elif defined(GFLAGS_HAVE_SYS_TYPES_H)
+#elif @GFLAGS_HAVE_SYS_TYPES_H@
# include <sys/types.h> // the normal place u_int32_t is defined
-#elif defined(GFLAGS_HAVE_INTTYPES_H)
+#elif @GFLAGS_HAVE_INTTYPES_H@
# include <inttypes.h> // a third place for uint32_t or u_int32_t
#endif
-#cmakedefine GFLAGS_INTTYPES_FORMAT_C99
-#cmakedefine GFLAGS_INTTYPES_FORMAT_BSD
-#cmakedefine GFLAGS_INTTYPES_FORMAT_VC7
-
namespace GFLAGS_NAMESPACE {
-#if defined(GFLAGS_INTTYPES_FORMAT_C99)
+#if @GFLAGS_INTTYPES_FORMAT_C99@ // C99
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
-#elif defined(GFLAGS_INTTYPES_FORMAT_BSD)
+#elif @GFLAGS_INTTYPES_FORMAT_BSD@ // BSD
typedef int32_t int32;
typedef u_int32_t uint32;
typedef int64_t int64;
typedef u_int64_t uint64;
-#elif defined(GFLAGS_INTTYPES_FORMAT_VC7) // Windows
+#elif @GFLAGS_INTTYPES_FORMAT_VC7@ // Windows
typedef __int32 int32;
typedef unsigned __int32 uint32;
typedef __int64 int64;
diff --git a/src/gflags_reporting.cc b/src/gflags_reporting.cc
index a33c553..9cc41a7 100644
--- a/src/gflags_reporting.cc
+++ b/src/gflags_reporting.cc
@@ -246,7 +246,7 @@ static bool FileMatchesSubstring(const string& filename,
// the string to be at the beginning of a directory component.
// That should match the first directory component as well, so
// we allow '/foo' to match a filename of 'foo'.
- if (!target->empty() && (*target)[0] == '/' &&
+ if (!target->empty() && (*target)[0] == PATH_SEPARATOR &&
strncmp(filename.c_str(), target->c_str() + 1,
strlen(target->c_str() + 1)) == 0)
return true;
@@ -352,7 +352,8 @@ static void ShowVersion() {
static void AppendPrognameStrings(vector<string>* substrings,
const char* progname) {
- string r("/");
+ string r("");
+ r += PATH_SEPARATOR;
r += progname;
substrings->push_back(r + ".");
substrings->push_back(r + "-main.");
@@ -387,7 +388,7 @@ void HandleCommandLineHelpFlags() {
gflags_exitfunc(1);
} else if (!FLAGS_helpon.empty()) {
- string restrict = "/" + FLAGS_helpon + ".";
+ string restrict = PATH_SEPARATOR + FLAGS_helpon + ".";
ShowUsageWithFlagsRestrict(progname, restrict.c_str());
gflags_exitfunc(1);
@@ -409,7 +410,7 @@ void HandleCommandLineHelpFlags() {
++flag) {
if (!FileMatchesSubstring(flag->filename, substrings))
continue;
- const string package = Dirname(flag->filename) + "/";
+ const string package = Dirname(flag->filename) + PATH_SEPARATOR;
if (package != last_package) {
ShowUsageWithFlagsRestrict(progname, package.c_str());
VLOG(7) << "Found package: " << package;