CMake: Do not try to test for the glibc version when cross-compiling.

This commit is contained in:
Nicholas J. Kain 2015-02-12 18:46:44 -05:00
parent b792162113
commit 9d8d653877

View File

@ -96,28 +96,30 @@ if (NOT (${OSNAME} STREQUAL "Linux"))
return() return()
endif() endif()
set(GLIBC_DETECT_TEST_C if (NOT CMAKE_CROSSCOMPILE)
" set(GLIBC_DETECT_TEST_C
#include <stdio.h> "
int main(int argc, char *argv[]) { #include <stdio.h>
printf(\"%d.%d\", __GLIBC__, __GLIBC_MINOR__); int main(int argc, char *argv[]) {
return 0; 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 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/detect/glibc.c "${GLIBC_DETECT_TEST_C}\n")
${CMAKE_CURRENT_BINARY_DIR}/detect ${CMAKE_CURRENT_BINARY_DIR}/detect/glibc.c try_run(GLIBC_DETECTION GLIBC_COMPILE
RUN_OUTPUT_VARIABLE GLIBC_VERSION) ${CMAKE_CURRENT_BINARY_DIR}/detect ${CMAKE_CURRENT_BINARY_DIR}/detect/glibc.c
if (GLIBC_VERSION AND GLIBC_COMPILE) RUN_OUTPUT_VARIABLE GLIBC_VERSION)
message("glibc version detected as ${GLIBC_VERSION}") if (GLIBC_VERSION AND GLIBC_COMPILE)
COMPARE_VERSION_STRINGS(${GLIBC_VERSION} "2.17" GLIBC_MUST_LINK_RT) message("glibc version detected as ${GLIBC_VERSION}")
if (${GLIBC_MUST_LINK_RT} LESS 0) COMPARE_VERSION_STRINGS(${GLIBC_VERSION} "2.17" GLIBC_MUST_LINK_RT)
message("glibc <2.17 detected; linking against librt.") if (${GLIBC_MUST_LINK_RT} LESS 0)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lrt") message("glibc <2.17 detected; linking against librt.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrt") 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() endif()
else()
message("Could not detect glibc version.")
endif() endif()
if ("$ENV{CROSSCOMPILE_MACHINENAME}" STREQUAL "") if ("$ENV{CROSSCOMPILE_MACHINENAME}" STREQUAL "")