From 031e79e77e4bc4c2dda3327a4f3a5ba637723ff4 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 30 Sep 2011 23:01:24 +0200 Subject: [PATCH] Fix linking error: clock_gettime not found I decided to reimplement AC_SEARCH_LIB from autotools in the process, as I consider it a very nifty feature. --- cmake/Conky.cmake | 22 ++++++++++++++++++++++ cmake/ConkyPlatformChecks.cmake | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/cmake/Conky.cmake b/cmake/Conky.cmake index d9910ed6..6b528fc1 100644 --- a/cmake/Conky.cmake +++ b/cmake/Conky.cmake @@ -61,6 +61,7 @@ set(conky_libs ${CMAKE_THREAD_LIBS_INIT}) set(conky_includes ${CMAKE_BINARY_DIR}) add_definitions(-D_GNU_SOURCE) # Standard definitions +set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE") # Do version stuff set(VERSION_MAJOR "2") @@ -112,3 +113,24 @@ endif(RELEASE) set(COPYRIGHT "Copyright Brenden Matthews, et al, 2005-2010") +macro(AC_SEARCH_LIBS FUNCTION_NAME INCLUDES TARGET_VAR) + if("${TARGET_VAR}" MATCHES "^${TARGET_VAR}$") + unset(AC_SEARCH_LIBS_TMP CACHE) + check_symbol_exists(${FUNCTION_NAME} ${INCLUDES} AC_SEARCH_LIBS_TMP) + if(${AC_SEARCH_LIBS_TMP}) + set(${TARGET_VAR} "" CACHE INTERNAL "Library containing ${FUNCTION_NAME}") + return() + endif(${AC_SEARCH_LIBS_TMP}) + + foreach(LIB ${ARGN}) + unset(AC_SEARCH_LIBS_TMP CACHE) + unset(AC_SEARCH_LIBS_FOUND CACHE) + find_library(AC_SEARCH_LIBS_TMP ${LIB}) + check_library_exists(${LIB} ${FUNCTION_NAME} ${AC_SEARCH_LIBS_TMP} AC_SEARCH_LIBS_FOUND) + if(${AC_SEARCH_LIBS_FOUND}) + set(${TARGET_VAR} ${AC_SEARCH_LIBS_TMP} CACHE INTERNAL "Library containing ${FUNCTION_NAME}") + break() + endif(${AC_SEARCH_LIBS_FOUND}) + endforeach(LIB) + endif("${TARGET_VAR}" MATCHES "^${TARGET_VAR}$") +endmacro(AC_SEARCH_LIBS) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index 38159525..959555fd 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -23,6 +23,7 @@ include(FindPkgConfig) include(CheckFunctionExists) include(CheckIncludeFile) +include(CheckSymbolExists) # Check for some headers check_include_files(sys/statfs.h HAVE_SYS_STATFS_H) @@ -33,6 +34,12 @@ check_include_files(dirent.h HAVE_DIRENT_H) # Check for some functions check_function_exists(strndup HAVE_STRNDUP) +AC_SEARCH_LIBS(clock_gettime "time.h" CLOCK_GETTIME_LIB "rt") +if(NOT CLOCK_GETTIME_LIB) + message(FATAL_ERROR "clock_gettime not found.") +endif(NOT CLOCK_GETTIME_LIB) +set(conky_libs ${conky_libs} ${CLOCK_GETTIME_LIB}) + # standard path to search for includes set(INCLUDE_SEARCH_PATH /usr/include /usr/local/include)