Commit 57ceb0ec authored by Andreas Schuh's avatar Andreas Schuh

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.
parent 7d363535
...@@ -352,6 +352,7 @@ else () ...@@ -352,6 +352,7 @@ else ()
endif () endif ()
set (PRIVATE_HDRS set (PRIVATE_HDRS
"defines.h"
"config.h" "config.h"
"util.h" "util.h"
"mutex.h" "mutex.h"
......
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Add native rules to configure source files # Add native rules to configure source files
def gflags_sources(namespace=["google", "gflags"]): 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( native.genrule(
name = "gflags_declare_h", name = "gflags_declare_h",
srcs = ["src/gflags_declare.h.in"], srcs = ["src/gflags_declare.h.in"],
outs = ["include/gflags/gflags_declare.h"], outs = ["gflags_declare.h"],
cmd = ("awk '{ " + cmd = ("awk '{ " +
"gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); " + "gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); " +
"gsub(/@(HAVE_STDINT_H|HAVE_SYS_TYPES_H|HAVE_INTTYPES_H|GFLAGS_INTTYPES_FORMAT_C99)@/, \"1\"); " + "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"]): ...@@ -23,7 +17,7 @@ def gflags_sources(namespace=["google", "gflags"]):
native.genrule( native.genrule(
name = gflags_ns_h_file.replace('.', '_'), name = gflags_ns_h_file.replace('.', '_'),
srcs = ["src/gflags_ns.h.in"], srcs = ["src/gflags_ns.h.in"],
outs = ["include/gflags/" + gflags_ns_h_file], outs = [gflags_ns_h_file],
cmd = ("awk '{ " + cmd = ("awk '{ " +
"gsub(/@ns@/, \"" + ns + "\"); " + "gsub(/@ns@/, \"" + ns + "\"); " +
"gsub(/@NS@/, \"" + ns.upper() + "\"); " + "gsub(/@NS@/, \"" + ns.upper() + "\"); " +
...@@ -33,7 +27,7 @@ def gflags_sources(namespace=["google", "gflags"]): ...@@ -33,7 +27,7 @@ def gflags_sources(namespace=["google", "gflags"]):
native.genrule( native.genrule(
name = "gflags_h", name = "gflags_h",
srcs = ["src/gflags.h.in"], srcs = ["src/gflags.h.in"],
outs = ["include/gflags/gflags.h"], outs = ["gflags.h"],
cmd = ("awk '{ " + cmd = ("awk '{ " +
"gsub(/@GFLAGS_ATTRIBUTE_UNUSED@/, \"\"); " + "gsub(/@GFLAGS_ATTRIBUTE_UNUSED@/, \"\"); " +
"gsub(/@INCLUDE_GFLAGS_NS_H@/, \"" + '\n'.join(["#include \\\"gflags/{}\\\"".format(hdr) for hdr in gflags_ns_h_files]) + "\"); " + "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"]): ...@@ -42,13 +36,13 @@ def gflags_sources(namespace=["google", "gflags"]):
native.genrule( native.genrule(
name = "gflags_completions_h", name = "gflags_completions_h",
srcs = ["src/gflags_completions.h.in"], srcs = ["src/gflags_completions.h.in"],
outs = ["include/gflags/gflags_completions.h"], outs = ["gflags_completions.h"],
cmd = "awk '{ gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); print; }' $(<) > $(@)" cmd = "awk '{ gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); print; }' $(<) > $(@)"
) )
hdrs = [":gflags_h", ":gflags_declare_h", ":gflags_completions_h"] hdrs = [":gflags_h", ":gflags_declare_h", ":gflags_completions_h"]
hdrs.extend([':' + hdr.replace('.', '_') for hdr in gflags_ns_h_files]) hdrs.extend([':' + hdr.replace('.', '_') for hdr in gflags_ns_h_files])
srcs = [ srcs = [
":config_h", "src/config.h",
"src/gflags.cc", "src/gflags.cc",
"src/gflags_completions.cc", "src/gflags_completions.cc",
"src/gflags_reporting.cc", "src/gflags_reporting.cc",
...@@ -62,6 +56,10 @@ def gflags_sources(namespace=["google", "gflags"]): ...@@ -62,6 +56,10 @@ def gflags_sources(namespace=["google", "gflags"]):
def gflags_library(hdrs=[], srcs=[], threads=1): def gflags_library(hdrs=[], srcs=[], threads=1):
name = "gflags" name = "gflags"
copts = [ 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_STDINT_H",
"-DHAVE_SYS_TYPES_H", "-DHAVE_SYS_TYPES_H",
"-DHAVE_INTTYPES_H", "-DHAVE_INTTYPES_H",
...@@ -72,8 +70,6 @@ def gflags_library(hdrs=[], srcs=[], threads=1): ...@@ -72,8 +70,6 @@ def gflags_library(hdrs=[], srcs=[], threads=1):
"-DHAVE_STRTOQ", "-DHAVE_STRTOQ",
"-DHAVE_PTHREAD", "-DHAVE_PTHREAD",
"-DHAVE_RWLOCK", "-DHAVE_RWLOCK",
"-DGFLAGS_INTTYPES_FORMAT_C99",
"-DGFLAGS_IS_A_DLL=0",
] ]
linkopts = [] linkopts = []
if threads: if threads:
...@@ -85,8 +81,8 @@ def gflags_library(hdrs=[], srcs=[], threads=1): ...@@ -85,8 +81,8 @@ def gflags_library(hdrs=[], srcs=[], threads=1):
name = name, name = name,
hdrs = hdrs, hdrs = hdrs,
srcs = srcs, srcs = srcs,
includes = ["include/"],
copts = copts, copts = copts,
linkopts = linkopts, linkopts = linkopts,
visibility = ["//visibility:public"] visibility = ["//visibility:public"],
include_prefix = 'gflags'
) )
/* 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! // Note: This header file is only used internally. It is not part of public interface!
#ifndef GFLAGS_CONFIG_H_ #ifndef GFLAGS_CONFIG_H_
...@@ -9,71 +7,16 @@ ...@@ -9,71 +7,16 @@
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// System checks // System checks
// Define if you build this library for a MS Windows OS. // CMake build configuration is written to defines.h file, unused by Bazel build
#cmakedefine OS_WINDOWS #if !defined(GFLAGS_BAZEL_BUILD)
# include "defines.h"
// Define if you have the <stdint.h> header file. #endif
#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. // gcc requires this to get PRId64, etc.
#if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS) #if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
# define __STDC_FORMAT_MACROS 1 # define __STDC_FORMAT_MACROS 1
#endif #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 // Path separator
#ifndef PATH_SEPARATOR #ifndef PATH_SEPARATOR
......
/* 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_
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