Commit b2180eb5 authored by Andreas Schuh's avatar Andreas Schuh

Fix build on Windows using Visual Studio. Add gflags_config.h.

parent efc6908b
......@@ -27,6 +27,7 @@ version_numbers (
# ----------------------------------------------------------------------------
# configure options
option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)
set (GFLAGS_SHARED_LIBS ${BUILD_SHARED_LIBS})
set (GFLAGS_NAMESPACE "gflags" CACHE STRING "C++ namespace identifier of gflags library.")
mark_as_advanced (GFLAGS_NAMESPACE)
......@@ -83,10 +84,17 @@ if (Threads_FOUND)
endif ()
endif ()
if (BUILD_SHARED_LIBS)
set (GFLAGS_SHARED 1)
else ()
set (GFLAGS_SHARED 0)
endif ()
# ----------------------------------------------------------------------------
# source files - excluding root subdirectory and/or .in suffix
set (PUBLIC_HDRS
"gflags.h"
"gflags_config.h"
"gflags_declare.h"
"gflags_completions.h"
)
......@@ -126,7 +134,7 @@ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
# ----------------------------------------------------------------------------
# add library target
if (WIN32)
if (WIN32 AND BUILD_SHARED_LIBS)
add_definitions (-DGFLAGS_DLL_EXPORT)
endif ()
include_directories ("${PROJECT_SOURCE_DIR}/src")
......
/* Generated from config.h.in during configuration using CMake. */
/* Generated from config.h.in during build configuration using CMake. */
// Note: This header file is only used internally. It is not part of public interface!
#include "gflags_config.h"
// ---------------------------------------------------------------------------
// Meta-information
// Additional meta-information
// Name of package.
#define PACKAGE @PROJECT_NAME@
......@@ -24,16 +28,9 @@
// Define to the address where bug reports for this package should be sent.
#define PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@
// ---------------------------------------------------------------------------
// Namespace for gflags symbols.
#define GFLAGS_NAMESPACE @GFLAGS_NAMESPACE@
// ---------------------------------------------------------------------------
// Available system headers
// Whether sources are compiled on a Windows system
#define WINDOWS (defined(_WIN32) || defined(WIN32) || defined(_WINDOWS))
// Define to 1 if you have the <fnmatch.h> header file.
#define HAVE_FNMATCH_H @HAVE_FNMATCH_H@
......@@ -62,29 +59,18 @@
// ---------------------------------------------------------------------------
// Path separator
#ifndef PATH_SEPARATOR
# define PATH_SEPARATOR '/'
#endif
#define PATH_SEPARATOR '/'
// ---------------------------------------------------------------------------
// Windows-specific definitions
#if !defined(GFLAGS_DLL_DECL)
# if defined(_MSC_VER)
# if defined(GFLAGS_DLL_EXPORT)
# define GFLAGS_DLL_DECL __declspec(dllexport)
# else
# define GFLAGS_DLL_DECL __declspec(dllimport)
# endif
# else
# define GFLAGS_DLL_DECL
# endif
#endif
#if WINDOWS
// Windows port
#ifdef _WIN32
// This must be defined before the windows.h is included.
// It's needed for mutex.h, to give access to the TryLock method.
# if !defined(_WIN32_WINNT) && !(defined( __MINGW32__) || defined(__MINGW64__))
# define _WIN32_WINNT 0x0400
# endif
# if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
# endif
# include "windows_port.h"
#endif
......@@ -1498,7 +1498,7 @@ const char* ProgramInvocationName() { // like the GNU libc fn
}
const char* ProgramInvocationShortName() { // like the GNU libc fn
const char* slash = strrchr(argv0, '/');
#ifdef WINDOWS
#ifdef _WINDOWS
if (!slash) slash = strrchr(argv0, '\\');
#endif
return slash ? slash + 1 : argv0;
......
......@@ -78,36 +78,14 @@
#ifndef GFLAGS_GFLAGS_H_
#define GFLAGS_GFLAGS_H_
#if !defined(GFLAGS_DLL_DECL)
# if defined(_MSC_VER)
# if defined(GFLAGS_DLL_EXPORT)
# define GFLAGS_DLL_DECL __declspec(dllexport)
# else
# define GFLAGS_DLL_DECL __declspec(dllimport)
# endif
# else
# define GFLAGS_DLL_DECL
# endif
#endif
// We always want to export defined variables, dll or no
#if !defined(GFLAGS_DLL_DEFINE_FLAG)
# if defined(_MSC_VER)
# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllimport)
# else
# define GFLAGS_DLL_DEFINE_FLAG
# endif
#endif
#include <string>
#include <vector>
#include <@GFLAGS_NAMESPACE@/gflags_declare.h> // IWYU pragma: export
#include "gflags_config.h"
#include "gflags_declare.h" // IWYU pragma: export
namespace @GFLAGS_NAMESPACE@ {
namespace GFLAGS_NAMESPACE {
// --------------------------------------------------------------------
......@@ -156,7 +134,7 @@ extern bool RegisterFlagValidator(const std::string* flag,
// Convenience macro for the registration of a flag validator
#define DEFINE_validator(name, validator) \
static const bool name##_validator_registered = \
@GFLAGS_NAMESPACE@::RegisterFlagValidator(&FLAGS_##name, validator)
GFLAGS_NAMESPACE::RegisterFlagValidator(&FLAGS_##name, validator)
// --------------------------------------------------------------------
......@@ -306,7 +284,7 @@ class GFLAGS_DLL_DECL FlagSaver {
FlagSaver(const FlagSaver&); // no copying!
void operator=(const FlagSaver&);
}
@__ATTRIBUTE__UNUSED@;
GFLAGS__ATTRIBUTE__UNUSED;
// --------------------------------------------------------------------
// Some deprecated or hopefully-soon-to-be-deprecated functions.
......@@ -464,7 +442,7 @@ class GFLAGS_DLL_DECL FlagRegisterer {
extern const char kStrippedFlagHelp[];
} // namespace @GFLAGS_NAMESPACE@
} // namespace GFLAGS_NAMESPACE
#ifndef SWIG // In swig, ignore the main flag declarations
......@@ -472,7 +450,7 @@ extern const char kStrippedFlagHelp[];
#if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0
// Need this construct to avoid the 'defined but not used' warning.
#define MAYBE_STRIPPED_HELP(txt) \
(false ? (txt) : @GFLAGS_NAMESPACE@::kStrippedFlagHelp)
(false ? (txt) : GFLAGS_NAMESPACE::kStrippedFlagHelp)
#else
#define MAYBE_STRIPPED_HELP(txt) txt
#endif
......@@ -494,7 +472,7 @@ extern const char kStrippedFlagHelp[];
/* We always want to export defined variables, dll or no */ \
GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \
type FLAGS_no##name = FLAGS_nono##name; \
static @GFLAGS_NAMESPACE@::FlagRegisterer o_##name( \
static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
#name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \
&FLAGS_##name, &FLAGS_no##name); \
} \
......@@ -527,15 +505,15 @@ GFLAGS_DLL_DECL bool IsBoolFlag(bool from);
DEFINE_VARIABLE(bool, B, name, val, txt)
#define DEFINE_int32(name, val, txt) \
DEFINE_VARIABLE(@GFLAGS_NAMESPACE@::int32, I, \
DEFINE_VARIABLE(GFLAGS_NAMESPACE::int32, I, \
name, val, txt)
#define DEFINE_int64(name, val, txt) \
DEFINE_VARIABLE(@GFLAGS_NAMESPACE@::int64, I64, \
DEFINE_VARIABLE(GFLAGS_NAMESPACE::int64, I64, \
name, val, txt)
#define DEFINE_uint64(name,val, txt) \
DEFINE_VARIABLE(@GFLAGS_NAMESPACE@::uint64, U64, \
DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint64, U64, \
name, val, txt)
#define DEFINE_double(name, val, txt) \
......@@ -576,7 +554,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; \
......
/* Generated from gflags_config.h.in during build configuration using CMake. */
#ifndef GFLAGS_GFLAGS_CONFIG_H_
#define GFLAGS_GFLAGS_CONFIG_H_
// ---------------------------------------------------------------------------
// Meta-information
// Version number of gflags library.
#define GFLAGS_VERSION_STRING "@PACKAGE_VERSION@"
#define GFLAGS_VERSION_MAJOR @PACKAGE_VERSION_MAJOR@ ///< Major version number.
#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@
// ---------------------------------------------------------------------------
// Unused attribute declaration for GNU GCC.
#define GFLAGS__ATTRIBUTE__UNUSED @GFLAGS__ATTRIBUTE_UNUSED@
// ---------------------------------------------------------------------------
// Windows DLL import/export.
#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
#else
# define GFLAGS_DLL_DECL
#endif
// We always want to export defined variables, dll or no
#if defined(_MSC_VER)
# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
#else
# define GFLAGS_DLL_DEFINE_FLAG
#endif
#endif // GFLAGS_GFLAGS_CONFIG_H_
\ No newline at end of file
......@@ -40,8 +40,6 @@
#ifndef GFLAGS_WINDOWS_PORT_H_
#define GFLAGS_WINDOWS_PORT_H_
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN /* We always want minimal includes */
#endif
......@@ -76,7 +74,7 @@ inline void setenv(const char* name, const char* value, int) {
value = kFakeZero;
// Apparently the semantics of putenv() is that the input
// must live forever, so we leak memory here. :-(
const int nameval_len = strlen(name) + 1 + strlen(value) + 1;
const size_t nameval_len = strlen(name) + 1 + strlen(value) + 1;
char* nameval = reinterpret_cast<char*>(malloc(nameval_len));
snprintf(nameval, nameval_len, "%s=%s", name, value);
_putenv(nameval);
......@@ -111,6 +109,4 @@ inline void setenv(const char* name, const char* value, int) {
#define PATH_MAX 1024
#endif
#endif /* _WIN32 */
#endif /* GFLAGS_WINDOWS_PORT_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment