determine gflags namespace automatically
This commit is contained in:
parent
f9def39a46
commit
b561c94b19
@ -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)
|
||||
|
||||
|
||||
69
cmake/DetermineGflagsNamespace.cmake
Executable file
69
cmake/DetermineGflagsNamespace.cmake
Executable file
@ -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 ()
|
||||
@ -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");
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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*) {
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user