include (CheckCSourceCompiles)
include (CheckCXXCompilerFlag)
include (CheckCXXSourceCompiles)
+include (CheckCXXSourceRuns)
include (CheckFunctionExists)
include (CheckIncludeFile)
include (CheckIncludeFileCXX)
include (CheckSymbolExists)
include (CheckTypeSize)
include (CMakePackageConfigHelpers)
+include (CMakePushCheckState)
include (CPack)
include (CTest)
include (DetermineGflagsNamespace)
check_symbol_exists (snprintf stdio.h HAVE_SNPRINTF)
check_library_exists (unwind get_static_proc_name "" HAVE_LIB_UNWIND)
+check_library_exists (DbgHelp UnDecorateSymbolName "" HAVE_DBGHELP)
find_library (UNWIND_LIBRARY NAMES unwind DOC "unwind library")
mark_as_advanced (UNWIND_LIBRARY)
set (ac_cv_cxx_using_operator 0)
endif (HAVE_USING_OPERATOR)
+if (HAVE_EXECINFO_H)
+ set (HAVE_STACKTRACE 1)
+endif (HAVE_EXECINFO_H)
+
+if (WIN32 OR CYGWIN)
+ cmake_push_check_state (RESET)
+ set (CMAKE_REQUIRED_LIBRARIES DbgHelp)
+
+ check_cxx_source_runs ([=[
+ #include <windows.h>
+ #include <dbghelp.h>
+ #include <cstdlib>
+
+ void foobar() { }
+
+ int main()
+ {
+ HANDLE process = GetCurrentProcess();
+
+ if (!SymInitialize(process, NULL, TRUE))
+ return EXIT_FAILURE;
+
+ char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
+ SYMBOL_INFO *symbol = reinterpret_cast<SYMBOL_INFO *>(buf);
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
+ symbol->MaxNameLen = MAX_SYM_NAME;
+
+ void* const pc = reinterpret_cast<void*>(&foobar);
+ BOOL ret = SymFromAddr(process, reinterpret_cast<DWORD64>(pc), 0, symbol);
+
+ return ret ? EXIT_SUCCESS : EXIT_FAILURE;
+ }
+ ]=] HAVE_SYMBOLIZE)
+
+ cmake_pop_check_state ()
+
+ if (HAVE_SYMBOLIZE)
+ set (HAVE_STACKTRACE 1)
+ endif (HAVE_SYMBOLIZE)
+elseif (UNIX OR (APPLE AND HAVE_DLADDR))
+ set (HAVE_SYMBOLIZE 1)
+endif (WIN32 OR CYGWIN)
+
set (SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
if (WITH_THREADS AND Threads_FOUND)
target_link_libraries (glog PUBLIC ${UNWIND_LIBRARY})
endif (UNWIND_LIBRARY)
+if (HAVE_DBGHELP)
+ target_link_libraries (glog PUBLIC DbgHelp)
+endif (HAVE_DBGHELP)
+
if (HAVE_PTHREAD)
target_link_libraries (glog PUBLIC ${CMAKE_THREAD_LIBS_INIT})
endif (HAVE_PTHREAD)
"GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS=${_IMPORT}")
endif (NOT BUILD_SHARED_LIBS)
-if (HAVE_EXECINFO_H)
- set (HAVE_STACKTRACE 1)
-endif (HAVE_EXECINFO_H)
-
-if (WIN32)
- set (HAVE_STACKTRACE 1)
- set (HAVE_SYMBOLIZE 1)
-endif (WIN32)
-
-if (UNIX OR (APPLE AND HAVE_DLADDR))
- set (HAVE_SYMBOLIZE 1)
-endif (UNIX OR (APPLE AND HAVE_DLADDR))
-
# Unit testing
if (BUILD_TESTING)
// file is opened successfully, returns the file descriptor. Otherwise,
// returns -1. |out_file_name_size| is the size of the file name buffer
// (including the null-terminator).
-typedef int (*SymbolizeOpenObjectFileCallback)(uint64_t pc,
- uint64_t &start_address,
- uint64_t &base_address,
+typedef int (*SymbolizeOpenObjectFileCallback)(uint64 pc,
+ uint64 &start_address,
+ uint64 &base_address,
char *out_file_name,
int out_file_name_size);
void InstallSymbolizeOpenObjectFileCallback(
#endif
}
-# elif defined(OS_WINDOWS)
+# elif defined(OS_WINDOWS) || defined(OS_CYGWIN)
+#ifdef _MSC_VER
#include <intrin.h>
#pragma intrinsic(_ReturnAddress)
+#endif
struct Foo {
static void func(int x);
}
__declspec(noinline) void TestWithReturnAddress() {
- void *return_address = _ReturnAddress();
+ void *return_address =
+#ifdef __GNUC__ // Cygwin and MinGW support
+ __builtin_return_address(0)
+#else
+ _ReturnAddress()
+#endif
+ ;
const char *symbol = TrySymbolize(return_address);
CHECK(symbol != NULL);
CHECK_STREQ(symbol, "main");
TestWithPCInsideNonInlineFunction();
TestWithReturnAddress();
return RUN_ALL_TESTS();
-# elif defined(OS_WINDOWS)
+# elif defined(OS_WINDOWS) || defined(OS_CYGWIN)
TestWithReturnAddress();
return RUN_ALL_TESTS();
# else // OS_WINDOWS