From de3dba7ce45558211fb0cab1d6efc4653811f293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Fri, 15 Apr 2022 21:05:47 -0400 Subject: [PATCH] cmake/c: respect OPENDHT_STATIC/SHARED flags --- CMakeLists.txt | 25 ++++++++++++++++--------- tools/CMakeLists.txt | 9 ++++++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2d8447a..a79ee272 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,15 +403,23 @@ if (OPENDHT_SHARED) endif () if (OPENDHT_C) - add_library (opendht-c SHARED - c/opendht.cpp - c/opendht_c.h - ) - target_compile_definitions(opendht-c PRIVATE OPENDHT_C_BUILD) if (OPENDHT_SHARED) - target_link_libraries(opendht-c opendht) - else () - target_link_libraries(opendht-c opendht-static) + add_library (opendht-c SHARED + c/opendht.cpp + c/opendht_c.h + ) + target_compile_definitions(opendht-c PRIVATE OPENDHT_C_BUILD) + target_link_libraries(opendht-c PRIVATE opendht) + install (TARGETS opendht-c DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT opendht-c) + endif () + + if (OPENDHT_STATIC) + add_library (opendht-c-static STATIC + c/opendht.cpp + c/opendht_c.h + ) + target_link_libraries(opendht-c-static PRIVATE opendht-static) + install (TARGETS opendht-c-static DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT opendht-c-static) endif () # PkgConfig module @@ -420,7 +428,6 @@ if (OPENDHT_C) opendht-c.pc @ONLY ) - install (TARGETS opendht-c DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT opendht-c) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/opendht-c.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install (FILES c/opendht_c.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/opendht) endif () diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a0af8045..b56507d0 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,7 +1,9 @@ if (OPENDHT_SHARED) set (OPENDHT_LIBS opendht) + set (OPENDHT_C_LIBS opendht-c) else () set (OPENDHT_LIBS opendht-static) + set (OPENDHT_C_LIBS opendht-c-static) if (MSVC) set (MSC_COMPAT_SOURCES ${MSC_COMPAT_DIR}/wingetopt.c) endif () @@ -9,8 +11,8 @@ endif () function (configure_tool name extra_files) add_executable (${name} ${name}.cpp ${extra_files}) - target_link_libraries (${name} LINK_PUBLIC ${READLINE_LIBRARIES}) - target_link_libraries (${name} LINK_PUBLIC ${OPENDHT_LIBS}) + add_dependencies(${name} ${OPENDHT_LIBS}) + target_link_libraries (${name} LINK_PUBLIC ${OPENDHT_LIBS} ${READLINE_LIBRARIES}) if (MSVC) target_sources(${name} PRIVATE ${MSC_COMPAT_SOURCES}) target_include_directories (${name} PRIVATE ${MSC_COMPAT_DIR}) @@ -29,7 +31,8 @@ endif () if (OPENDHT_C) add_executable (dhtcnode dhtcnode.c) - target_link_libraries (dhtcnode LINK_PUBLIC opendht-c ${READLINE_LIBRARIES}) + add_dependencies(dhtcnode ${OPENDHT_C_LIBS}) + target_link_libraries (dhtcnode LINK_PUBLIC ${OPENDHT_C_LIBS} ${READLINE_LIBRARIES}) target_include_directories (dhtcnode SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/c) endif () -- GitLab