diff options
author | Eric Haszlakiewicz <erh+git@nimenees.com> | 2022-05-30 15:30:11 +0000 |
---|---|---|
committer | Eric Haszlakiewicz <erh+git@nimenees.com> | 2022-05-30 15:30:11 +0000 |
commit | 2f0942bdd73a2826273d9bdcf1c279bfe205a9e8 (patch) | |
tree | 462fdaedc10448c13a336e9779a2fff3d7363118 | |
parent | 6ba1adf8efe42742ad2cd542f21bd0109d9ef9dc (diff) | |
download | json-c-2f0942bdd73a2826273d9bdcf1c279bfe205a9e8.tar.gz |
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.
-rw-r--r-- | CMakeLists.txt | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 37a9f97..89cff3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,10 +173,12 @@ check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM) if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF") check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H) if (HAVE_BSD_STDLIB_H) - list(APPEND CMAKE_REQUIRED_LIBRARIES "-lbsd") - link_libraries(bsd) + list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd") unset(HAVE_ARC4RANDOM CACHE) check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM) + if (NOT HAVE_ARC4RANDOM) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd") + endif() endif() endif() @@ -455,6 +457,8 @@ target_include_directories(${PROJECT_NAME} $<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 if (BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS) set(STATIC_LIB ${PROJECT_NAME}-static) @@ -468,6 +472,8 @@ if (BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS) $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> ) + target_link_libraries(${PROJECT_NAME}-static PUBLIC ${CMAKE_REQUIRED_LIBRARIES}) + # rename the static library if (NOT MSVC) set_target_properties(${STATIC_LIB} PROPERTIES @@ -521,6 +527,13 @@ if (UNIX OR MINGW OR CYGWIN) SET(libdir ${CMAKE_INSTALL_FULL_LIBDIR}) SET(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) 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) 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}") |