1From b47f6a50925efb8c8707b1faed5561a4b66ffdb1 Mon Sep 17 00:00:00 2001 2From: Samuel Martin <s.martin49@gmail.com> 3Date: Sun, 24 Apr 2016 18:45:27 +0200 4Subject: [PATCH] Link libyajl{,_s} with libm when isnan is not brought by the 5 libc 6 7Check whether isnan is provided by the libc library, otherwise make sure 8yajl libraries are link against libm. 9 10Note that setting libm as PUBLIC link libraries enable the transitivity 11[1, 2]; therefore it will be automatically passed to target linking 12against libyajl{,_s}. 13 14This patch also makes sure the link libraries will appear in the yajl.pc 15file. 16 17[1] https://cmake.org/cmake/help/v3.5/command/target_link_libraries.html 18[2] https://cmake.org/cmake/help/v3.5/manual/cmake-buildsystem.7.html#target-usage-requirements 19 20Signed-off-by: Samuel Martin <s.martin49@gmail.com> 21--- 22 src/CMakeLists.txt | 10 ++++++++++ 23 src/yajl.pc.cmake | 2 +- 24 2 files changed, 11 insertions(+), 1 deletion(-) 25 26diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt 27index b487bfd..a88698f 100644 28--- a/src/CMakeLists.txt 29+++ b/src/CMakeLists.txt 30@@ -35,11 +35,21 @@ SET (shareDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/share/pkgconfig) 31 # set the output path for libraries 32 SET(LIBRARY_OUTPUT_PATH ${libDir}) 33 34+SET(yajl_lib_link) 35+INCLUDE(CheckLibraryExists) 36+CHECK_LIBRARY_EXISTS(c isnan "" HAVE_LIBC_ISNAN) 37+ 38+IF(NOT HAVE_LIBC_ISNAN) 39+ LIST(APPEND yajl_lib_link "-lm") 40+ENDIF(NOT HAVE_LIBC_ISNAN) 41+ 42 ADD_LIBRARY(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS}) 43 SET_TARGET_PROPERTIES(yajl_s PROPERTIES OUTPUT_NAME yajl) 44+TARGET_LINK_LIBRARIES(yajl_s PUBLIC ${yajl_lib_link}) 45 46 IF(BUILD_SHARED_LIBS) 47 ADD_LIBRARY(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS}) 48+TARGET_LINK_LIBRARIES(yajl PUBLIC ${yajl_lib_link}) 49 50 #### setup shared library version number 51 SET_TARGET_PROPERTIES(yajl PROPERTIES 52diff --git a/src/yajl.pc.cmake b/src/yajl.pc.cmake 53index 6eaca14..4681dd4 100644 54--- a/src/yajl.pc.cmake 55+++ b/src/yajl.pc.cmake 56@@ -6,4 +6,4 @@ Name: Yet Another JSON Library 57 Description: A Portable JSON parsing and serialization library in ANSI C 58 Version: ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO} 59 Cflags: -I${dollar}{includedir} 60-Libs: -L${dollar}{libdir} -lyajl 61+Libs: -L${dollar}{libdir} -lyajl ${yajl_lib_link} 62-- 632.8.0 64 65