mirror of
https://github.com/json-c/json-c.git
synced 2026-04-08 14:59:06 +08:00
Specify dependent libraries, including -lbsd, in a more consistent way so linking against a static json-c works better. Related issue #766
Use target_link_libraries, plus fill in Libs.private in json-c.pc so pkg-config --static --libs works appropriately. Also, only link against libbsd when arc4random is actually found there.
This commit is contained in:
@@ -173,10 +173,12 @@ check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM)
|
|||||||
if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF")
|
if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF")
|
||||||
check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H)
|
check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H)
|
||||||
if (HAVE_BSD_STDLIB_H)
|
if (HAVE_BSD_STDLIB_H)
|
||||||
list(APPEND CMAKE_REQUIRED_LIBRARIES "-lbsd")
|
list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd")
|
||||||
link_libraries(bsd)
|
|
||||||
unset(HAVE_ARC4RANDOM CACHE)
|
unset(HAVE_ARC4RANDOM CACHE)
|
||||||
check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM)
|
check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM)
|
||||||
|
if (NOT HAVE_ARC4RANDOM)
|
||||||
|
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -455,6 +457,8 @@ target_include_directories(${PROJECT_NAME}
|
|||||||
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_REQUIRED_LIBRARIES})
|
||||||
|
|
||||||
# Allow to build static and shared libraries at the same time
|
# Allow to build static and shared libraries at the same time
|
||||||
if (BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS)
|
if (BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS)
|
||||||
set(STATIC_LIB ${PROJECT_NAME}-static)
|
set(STATIC_LIB ${PROJECT_NAME}-static)
|
||||||
@@ -468,6 +472,8 @@ if (BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS)
|
|||||||
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME}-static PUBLIC ${CMAKE_REQUIRED_LIBRARIES})
|
||||||
|
|
||||||
# rename the static library
|
# rename the static library
|
||||||
if (NOT MSVC)
|
if (NOT MSVC)
|
||||||
set_target_properties(${STATIC_LIB} PROPERTIES
|
set_target_properties(${STATIC_LIB} PROPERTIES
|
||||||
@@ -521,6 +527,13 @@ if (UNIX OR MINGW OR CYGWIN)
|
|||||||
SET(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
|
SET(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||||
SET(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
|
SET(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
|
||||||
SET(VERSION ${PROJECT_VERSION})
|
SET(VERSION ${PROJECT_VERSION})
|
||||||
|
|
||||||
|
# Linking against the static json-c requires
|
||||||
|
# dependent packages to include additional libs:
|
||||||
|
SET(LIBS_LIST ${CMAKE_REQUIRED_LIBRARIES})
|
||||||
|
list(TRANSFORM LIBS_LIST PREPEND "-l")
|
||||||
|
string(REPLACE ";" " " LIBS "${LIBS_LIST}")
|
||||||
|
|
||||||
configure_file(json-c.pc.in json-c.pc @ONLY)
|
configure_file(json-c.pc.in json-c.pc @ONLY)
|
||||||
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
|
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
|
||||||
install(FILES ${PROJECT_BINARY_DIR}/json-c.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}")
|
install(FILES ${PROJECT_BINARY_DIR}/json-c.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}")
|
||||||
|
|||||||
Reference in New Issue
Block a user