summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergiu Dotenco <sergiu.dotenco@th-nuernberg.de>2015-03-26 14:52:15 (GMT)
committerSergiu Dotenco <sergiu.dotenco@gmail.com>2015-07-15 20:34:59 (GMT)
commitb561c94b195124faad2a4aaeeded4f906cfdb8f8 (patch)
tree9bd108e49143ee9e5eb131d5d0acf392d1a20a4d
parentf9def39a465725c1b2a60f64200fba5d1614da36 (diff)
downloadglog-b561c94b195124faad2a4aaeeded4f906cfdb8f8.zip
glog-b561c94b195124faad2a4aaeeded4f906cfdb8f8.tar.gz
glog-b561c94b195124faad2a4aaeeded4f906cfdb8f8.tar.bz2
determine gflags namespace automatically
-rw-r--r--CMakeLists.txt4
-rwxr-xr-xcmake/DetermineGflagsNamespace.cmake69
-rw-r--r--src/demangle_unittest.cc5
-rw-r--r--src/logging_unittest.cc1
-rw-r--r--src/signalhandler_unittest.cc5
-rw-r--r--src/symbolize_unittest.cc5
-rw-r--r--src/utilities_unittest.cc6
7 files changed, 94 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 473c4a5..ffc29a2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,6 +24,8 @@ set (CPACK_PACKAGE_VERSION ${GLOG_VERSION})
option (WITH_GFLAGS "Use gflags" ON)
+list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+
include (CMakePackageConfigHelpers)
include (CPack)
include (CheckCSourceCompiles)
@@ -36,6 +38,7 @@ include (CheckLibraryExists)
include (CheckStructHasMember)
include (CheckSymbolExists)
include (CheckTypeSize)
+include (DetermineGflagsNamespace)
set (CMAKE_THREAD_PREFER_PTHREAD 1)
@@ -44,6 +47,7 @@ if (WITH_GFLAGS)
if (gflags_FOUND)
set (HAVE_LIB_GFLAGS 1)
+ determine_gflags_namespace (gflags_NAMESPACE)
endif (gflags_FOUND)
endif (WITH_GFLAGS)
diff --git a/cmake/DetermineGflagsNamespace.cmake b/cmake/DetermineGflagsNamespace.cmake
new file mode 100755
index 0000000..e5e50cc
--- /dev/null
+++ b/cmake/DetermineGflagsNamespace.cmake
@@ -0,0 +1,69 @@
+macro(determine_gflags_namespace VARIABLE)
+ if (NOT DEFINED "${VARIABLE}")
+ if (CMAKE_REQUIRED_INCLUDES)
+ set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
+ else ()
+ set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
+ endif ()
+
+ set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
+
+ set(_NAMESPACES gflags google)
+ set(_check_code
+"
+#include <gflags/gflags.h>
+
+int main(int argc, char**argv)
+{
+ GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
+}
+")
+ if (NOT CMAKE_REQUIRED_QUIET)
+ message (STATUS "Looking for gflags namespace")
+ endif ()
+ if (${ARGC} EQUAL 3)
+ set (CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
+ endif ()
+
+ set (_check_file
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/DetermineGflagsNamespace.cxx)
+
+ foreach (_namespace ${_NAMESPACES})
+ file (WRITE "${_check_file}" "${_check_code}")
+ try_compile (${VARIABLE}
+ "${CMAKE_BINARY_DIR}" "${_check_file}"
+ COMPILE_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}" -DGFLAGS_NAMESPACE=${_namespace}
+ LINK_LIBRARIES "${gflags_LIBRARIES}"
+ CMAKE_FLAGS -DINCLUDE_DIRECTORIES:STRING="${gflags_INCLUDE_DIR}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ if (${VARIABLE})
+ set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace" FORCE)
+ break ()
+ else ()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining the gflags namespace ${_namespace} failed with the following output:\n"
+ "${OUTPUT}\n\n")
+ endif ()
+ endforeach (_namespace)
+
+ if (${ARGC} EQUAL 3)
+ set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
+ endif ()
+
+ if (${VARIABLE})
+ if (NOT CMAKE_REQUIRED_QUIET)
+ message (STATUS "Looking for gflags namespace - ${${VARIABLE}}")
+ endif ()
+ file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining the gflags namespace passed with the following output:\n"
+ "${OUTPUT}\n\n")
+ else ()
+ if (NOT CMAKE_REQUIRED_QUIET)
+ message (STATUS "Looking for gflags namespace - failed")
+ endif ()
+ set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace")
+ endif ()
+ endif ()
+endmacro ()
diff --git a/src/demangle_unittest.cc b/src/demangle_unittest.cc
index 9d219e6..32f3221 100644
--- a/src/demangle_unittest.cc
+++ b/src/demangle_unittest.cc
@@ -41,6 +41,11 @@
#include "googletest.h"
#include "config.h"
+#ifdef HAVE_LIB_GFLAGS
+#include <gflags/gflags.h>
+using namespace GFLAGS_NAMESPACE;
+#endif
+
GLOG_DEFINE_bool(demangle_filter, false,
"Run demangle_unittest in filter mode");
diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc
index fa6afce..e180567 100644
--- a/src/logging_unittest.cc
+++ b/src/logging_unittest.cc
@@ -61,6 +61,7 @@ DECLARE_string(log_backtrace_at); // logging.cc
#ifdef HAVE_LIB_GFLAGS
#include <gflags/gflags.h>
+using namespace GFLAGS_NAMESPACE;
#endif
#ifdef HAVE_LIB_GMOCK
diff --git a/src/signalhandler_unittest.cc b/src/signalhandler_unittest.cc
index 1cd0fa0..8dae5f5 100644
--- a/src/signalhandler_unittest.cc
+++ b/src/signalhandler_unittest.cc
@@ -41,6 +41,11 @@
#include <string>
#include "glog/logging.h"
+#ifdef HAVE_LIB_GFLAGS
+#include <gflags/gflags.h>
+using namespace gflags;
+#endif
+
using namespace GOOGLE_NAMESPACE;
void* DieInThread(void*) {
diff --git a/src/symbolize_unittest.cc b/src/symbolize_unittest.cc
index f25909d..05cb8a1 100644
--- a/src/symbolize_unittest.cc
+++ b/src/symbolize_unittest.cc
@@ -41,6 +41,11 @@
#include "googletest.h"
#include "config.h"
+#ifdef HAVE_LIB_GFLAGS
+#include <gflags/gflags.h>
+using namespace GFLAGS_NAMESPACE;
+#endif
+
using namespace std;
using namespace GOOGLE_NAMESPACE;
diff --git a/src/utilities_unittest.cc b/src/utilities_unittest.cc
index 7b79619..38e847d 100644
--- a/src/utilities_unittest.cc
+++ b/src/utilities_unittest.cc
@@ -28,11 +28,15 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: Shinichiro Hamaji
-
#include "utilities.h"
#include "googletest.h"
#include "glog/logging.h"
+#ifdef HAVE_LIB_GFLAGS
+#include <gflags/gflags.h>
+using namespace GFLAGS_NAMESPACE;
+#endif
+
using namespace GOOGLE_NAMESPACE;
TEST(utilities, sync_val_compare_and_swap) {