Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable LOGURU_STACKTRACES cmake variable by default on non-windows platforms using glibc #254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,36 @@ endif()
# --- determine if linking 'dl' is required
# ----------------------------------------------------------

# loguru.cpp implicitly enables stacktraces on non-windows systems w/ glibc
# so the following checks are needed to establish the CMake vars default value
if((NOT DEFINED LOGURU_STACKTRACES) AND (NOT WIN32 AND NOT CYGWIN))
message(STATUS "checking for glibc")
# Create temp file for testing if the current compiler uses glibc
file(WRITE "${PROJECT_BINARY_DIR}/test_for_glibc.cpp" [[
#include <cstdio>
#define RESULT 1
#ifdef __GLIBC__
#define RESULT 0
#endif
int main() { return RESULT; }
]])
# Attempt to compile and run the glibc tester program
try_run(_try_run_result _try_run_compile_result
${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/test_for_glibc.cpp
)
if (_try_run_result EQUAL 0)
message(STATUS "checking for glibc - found")
message(STATUS
"glibc was found on a non-Windows system, LOGURU_STACKTRACES will be "
"enabled by default. "
"Set -DLOGURU_STACKTRACES=FALSE to explicitly disable stacktraces")
set(LOGURU_STACKTRACES 1)
else()
message(STATUS "checking for glibc - not found")
endif()
endif()

if (LOGURU_STACKTRACES AND (NOT CMAKE_DL_LIBS))
message(WARNING
"Stack traces requested but the required 'dl' library was not found. "
Expand Down