From 9d8d6538776d50bccca82d7e7db59a5e88aa05ad Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Thu, 12 Feb 2015 18:46:44 -0500 Subject: [PATCH] CMake: Do not try to test for the glibc version when cross-compiling. --- CMakeLists.txt | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acaa451..ec1dd2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,28 +96,30 @@ if (NOT (${OSNAME} STREQUAL "Linux")) return() endif() -set(GLIBC_DETECT_TEST_C - " - #include - int main(int argc, char *argv[]) { - printf(\"%d.%d\", __GLIBC__, __GLIBC_MINOR__); - return 0; - } - ") -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/detect/glibc.c "${GLIBC_DETECT_TEST_C}\n") -try_run(GLIBC_DETECTION GLIBC_COMPILE - ${CMAKE_CURRENT_BINARY_DIR}/detect ${CMAKE_CURRENT_BINARY_DIR}/detect/glibc.c - RUN_OUTPUT_VARIABLE GLIBC_VERSION) -if (GLIBC_VERSION AND GLIBC_COMPILE) - message("glibc version detected as ${GLIBC_VERSION}") - COMPARE_VERSION_STRINGS(${GLIBC_VERSION} "2.17" GLIBC_MUST_LINK_RT) - if (${GLIBC_MUST_LINK_RT} LESS 0) - message("glibc <2.17 detected; linking against librt.") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lrt") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrt") +if (NOT CMAKE_CROSSCOMPILE) + set(GLIBC_DETECT_TEST_C + " + #include + int main(int argc, char *argv[]) { + printf(\"%d.%d\", __GLIBC__, __GLIBC_MINOR__); + return 0; + } + ") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/detect/glibc.c "${GLIBC_DETECT_TEST_C}\n") + try_run(GLIBC_DETECTION GLIBC_COMPILE + ${CMAKE_CURRENT_BINARY_DIR}/detect ${CMAKE_CURRENT_BINARY_DIR}/detect/glibc.c + RUN_OUTPUT_VARIABLE GLIBC_VERSION) + if (GLIBC_VERSION AND GLIBC_COMPILE) + message("glibc version detected as ${GLIBC_VERSION}") + COMPARE_VERSION_STRINGS(${GLIBC_VERSION} "2.17" GLIBC_MUST_LINK_RT) + if (${GLIBC_MUST_LINK_RT} LESS 0) + message("glibc <2.17 detected; linking against librt.") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lrt") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrt") + endif() + else() + message("Could not detect glibc version.") endif() -else() - message("Could not detect glibc version.") endif() if ("$ENV{CROSSCOMPILE_MACHINENAME}" STREQUAL "")