summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schuh <andreas.schuh.84@gmail.com>2017-08-31 18:53:26 +0100
committerAndreas Schuh <andreas.schuh.84@gmail.com>2017-09-01 11:10:03 +0200
commit57ceb0ecc8bf5c129bf99fa9472b25342daecf9e (patch)
treeb08f8ecedd7db9d380502d01ab4681b494f4fe57
parent7d363535799efffd42812ebece1caced79663482 (diff)
downloadgflags-57ceb0ecc8bf5c129bf99fa9472b25342daecf9e.tar.gz
gflags-57ceb0ecc8bf5c129bf99fa9472b25342daecf9e.tar.bz2
gflags-57ceb0ecc8bf5c129bf99fa9472b25342daecf9e.zip
enh: Move CMake defines to separate header, unused by Bazel
This change avoids having to configure a private .h.in file during the Bazel build such that these files are not available to dependent projects in the GENDIR of the external gflags project.
-rw-r--r--CMakeLists.txt1
-rw-r--r--bazel/gflags.bzl26
-rw-r--r--src/config.h57
-rw-r--r--src/config.h.in114
-rw-r--r--src/defines.h.in48
5 files changed, 117 insertions, 129 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0b46798..922a038 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -352,6 +352,7 @@ else ()
endif ()
set (PRIVATE_HDRS
+ "defines.h"
"config.h"
"util.h"
"mutex.h"
diff --git a/bazel/gflags.bzl b/bazel/gflags.bzl
index cd0edad..7bf91cd 100644
--- a/bazel/gflags.bzl
+++ b/bazel/gflags.bzl
@@ -2,15 +2,9 @@
# Add native rules to configure source files
def gflags_sources(namespace=["google", "gflags"]):
native.genrule(
- name = "config_h",
- srcs = ["src/config.h.in"],
- outs = ["config.h"],
- cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $(<) > $(@)"
- )
- native.genrule(
name = "gflags_declare_h",
srcs = ["src/gflags_declare.h.in"],
- outs = ["include/gflags/gflags_declare.h"],
+ outs = ["gflags_declare.h"],
cmd = ("awk '{ " +
"gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); " +
"gsub(/@(HAVE_STDINT_H|HAVE_SYS_TYPES_H|HAVE_INTTYPES_H|GFLAGS_INTTYPES_FORMAT_C99)@/, \"1\"); " +
@@ -23,7 +17,7 @@ def gflags_sources(namespace=["google", "gflags"]):
native.genrule(
name = gflags_ns_h_file.replace('.', '_'),
srcs = ["src/gflags_ns.h.in"],
- outs = ["include/gflags/" + gflags_ns_h_file],
+ outs = [gflags_ns_h_file],
cmd = ("awk '{ " +
"gsub(/@ns@/, \"" + ns + "\"); " +
"gsub(/@NS@/, \"" + ns.upper() + "\"); " +
@@ -33,7 +27,7 @@ def gflags_sources(namespace=["google", "gflags"]):
native.genrule(
name = "gflags_h",
srcs = ["src/gflags.h.in"],
- outs = ["include/gflags/gflags.h"],
+ outs = ["gflags.h"],
cmd = ("awk '{ " +
"gsub(/@GFLAGS_ATTRIBUTE_UNUSED@/, \"\"); " +
"gsub(/@INCLUDE_GFLAGS_NS_H@/, \"" + '\n'.join(["#include \\\"gflags/{}\\\"".format(hdr) for hdr in gflags_ns_h_files]) + "\"); " +
@@ -42,13 +36,13 @@ def gflags_sources(namespace=["google", "gflags"]):
native.genrule(
name = "gflags_completions_h",
srcs = ["src/gflags_completions.h.in"],
- outs = ["include/gflags/gflags_completions.h"],
+ outs = ["gflags_completions.h"],
cmd = "awk '{ gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); print; }' $(<) > $(@)"
)
hdrs = [":gflags_h", ":gflags_declare_h", ":gflags_completions_h"]
hdrs.extend([':' + hdr.replace('.', '_') for hdr in gflags_ns_h_files])
srcs = [
- ":config_h",
+ "src/config.h",
"src/gflags.cc",
"src/gflags_completions.cc",
"src/gflags_reporting.cc",
@@ -62,6 +56,10 @@ def gflags_sources(namespace=["google", "gflags"]):
def gflags_library(hdrs=[], srcs=[], threads=1):
name = "gflags"
copts = [
+ "-DGFLAGS_BAZEL_BUILD",
+ "-DGFLAGS_INTTYPES_FORMAT_C99",
+ "-DGFLAGS_IS_A_DLL=0",
+ # macros otherwise defined by CMake configured defines.h file
"-DHAVE_STDINT_H",
"-DHAVE_SYS_TYPES_H",
"-DHAVE_INTTYPES_H",
@@ -72,8 +70,6 @@ def gflags_library(hdrs=[], srcs=[], threads=1):
"-DHAVE_STRTOQ",
"-DHAVE_PTHREAD",
"-DHAVE_RWLOCK",
- "-DGFLAGS_INTTYPES_FORMAT_C99",
- "-DGFLAGS_IS_A_DLL=0",
]
linkopts = []
if threads:
@@ -85,8 +81,8 @@ def gflags_library(hdrs=[], srcs=[], threads=1):
name = name,
hdrs = hdrs,
srcs = srcs,
- includes = ["include/"],
copts = copts,
linkopts = linkopts,
- visibility = ["//visibility:public"]
+ visibility = ["//visibility:public"],
+ include_prefix = 'gflags'
)
diff --git a/src/config.h b/src/config.h
new file mode 100644
index 0000000..b90b7e6
--- /dev/null
+++ b/src/config.h
@@ -0,0 +1,57 @@
+// Note: This header file is only used internally. It is not part of public interface!
+
+#ifndef GFLAGS_CONFIG_H_
+#define GFLAGS_CONFIG_H_
+
+
+// ---------------------------------------------------------------------------
+// System checks
+
+// CMake build configuration is written to defines.h file, unused by Bazel build
+#if !defined(GFLAGS_BAZEL_BUILD)
+# include "defines.h"
+#endif
+
+// gcc requires this to get PRId64, etc.
+#if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
+# define __STDC_FORMAT_MACROS 1
+#endif
+
+// ---------------------------------------------------------------------------
+// Path separator
+#ifndef PATH_SEPARATOR
+# ifdef OS_WINDOWS
+# define PATH_SEPARATOR '\\'
+# else
+# define PATH_SEPARATOR '/'
+# endif
+#endif
+
+// ---------------------------------------------------------------------------
+// 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 OS_WINDOWS
+// 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
+
+
+#endif // GFLAGS_CONFIG_H_
diff --git a/src/config.h.in b/src/config.h.in
deleted file mode 100644
index f6d18d8..0000000
--- a/src/config.h.in
+++ /dev/null
@@ -1,114 +0,0 @@
-/* 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!
-
-#ifndef GFLAGS_CONFIG_H_
-#define GFLAGS_CONFIG_H_
-
-
-// ---------------------------------------------------------------------------
-// System checks
-
-// Define if you build this library for a MS Windows OS.
-#cmakedefine OS_WINDOWS
-
-// Define if you have the <stdint.h> header file.
-#cmakedefine HAVE_STDINT_H
-
-// Define if you have the <sys/types.h> header file.
-#cmakedefine HAVE_SYS_TYPES_H
-
-// Define if you have the <inttypes.h> header file.
-#cmakedefine HAVE_INTTYPES_H
-
-// Define if you have the <sys/stat.h> header file.
-#cmakedefine HAVE_SYS_STAT_H
-
-// Define if you have the <unistd.h> header file.
-#cmakedefine HAVE_UNISTD_H
-
-// Define if you have the <fnmatch.h> header file.
-#cmakedefine HAVE_FNMATCH_H
-
-// Define if you have the <shlwapi.h> header file (Windows 2000/XP).
-#cmakedefine HAVE_SHLWAPI_H
-
-// Define if you have the strtoll function.
-#cmakedefine HAVE_STRTOLL
-
-// Define if you have the strtoq function.
-#cmakedefine HAVE_STRTOQ
-
-// Define if you have the <pthread.h> header file.
-#cmakedefine HAVE_PTHREAD
-
-// Define if your pthread library defines the type pthread_rwlock_t
-#cmakedefine HAVE_RWLOCK
-
-// gcc requires this to get PRId64, etc.
-#if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
-# define __STDC_FORMAT_MACROS 1
-#endif
-
-// ---------------------------------------------------------------------------
-// Package information
-
-// Name of package.
-#define PACKAGE @PROJECT_NAME@
-
-// Define to the full name of this package.
-#define PACKAGE_NAME @PACKAGE_NAME@
-
-// Define to the full name and version of this package.
-#define PACKAGE_STRING @PACKAGE_STRING@
-
-// Define to the one symbol short name of this package.
-#define PACKAGE_TARNAME @PACKAGE_TARNAME@
-
-// Define to the version of this package.
-#define PACKAGE_VERSION @PACKAGE_VERSION@
-
-// Version number of package.
-#define VERSION PACKAGE_VERSION
-
-// Define to the address where bug reports for this package should be sent.
-#define PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@
-
-// ---------------------------------------------------------------------------
-// Path separator
-#ifndef PATH_SEPARATOR
-# ifdef OS_WINDOWS
-# define PATH_SEPARATOR '\\'
-# else
-# define PATH_SEPARATOR '/'
-# endif
-#endif
-
-// ---------------------------------------------------------------------------
-// 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 OS_WINDOWS
-// 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
-
-
-#endif // GFLAGS_CONFIG_H_
diff --git a/src/defines.h.in b/src/defines.h.in
new file mode 100644
index 0000000..dfb214e
--- /dev/null
+++ b/src/defines.h.in
@@ -0,0 +1,48 @@
+/* Generated from defines.h.in during build configuration using CMake. */
+
+// Note: This header file is only used internally. It is not part of public interface!
+// Any cmakedefine is defined using the -D flag instead when Bazel is used.
+// For Bazel, this file is thus not used to avoid a private file in $(GENDIR).
+
+#ifndef GFLAGS_DEFINES_H_
+#define GFLAGS_DEFINES_H_
+
+
+// Define if you build this library for a MS Windows OS.
+#cmakedefine OS_WINDOWS
+
+// Define if you have the <stdint.h> header file.
+#cmakedefine HAVE_STDINT_H
+
+// Define if you have the <sys/types.h> header file.
+#cmakedefine HAVE_SYS_TYPES_H
+
+// Define if you have the <inttypes.h> header file.
+#cmakedefine HAVE_INTTYPES_H
+
+// Define if you have the <sys/stat.h> header file.
+#cmakedefine HAVE_SYS_STAT_H
+
+// Define if you have the <unistd.h> header file.
+#cmakedefine HAVE_UNISTD_H
+
+// Define if you have the <fnmatch.h> header file.
+#cmakedefine HAVE_FNMATCH_H
+
+// Define if you have the <shlwapi.h> header file (Windows 2000/XP).
+#cmakedefine HAVE_SHLWAPI_H
+
+// Define if you have the strtoll function.
+#cmakedefine HAVE_STRTOLL
+
+// Define if you have the strtoq function.
+#cmakedefine HAVE_STRTOQ
+
+// Define if you have the <pthread.h> header file.
+#cmakedefine HAVE_PTHREAD
+
+// Define if your pthread library defines the type pthread_rwlock_t
+#cmakedefine HAVE_RWLOCK
+
+
+#endif // GFLAGS_DEFINES_H_