Use imported target for libsyncthinginternal

This way the pkg-config file can be generated correctly.
This commit is contained in:
Martchus 2019-08-05 19:10:57 +02:00
parent 7b668ca02c
commit 495140cdf9
1 changed files with 19 additions and 17 deletions

View File

@ -153,18 +153,27 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a"
WORKING_DIRECTORY "${SYNCTHING_PATH}"
COMMENT "Building Syncthing itself")
# do not use this library directly but depend on it
list(APPEND PRIVATE_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a")
# add imported target for library generated by the Go build system
add_library(syncthinginternal STATIC IMPORTED)
set_property(TARGET syncthinginternal
PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a")
set_property(TARGET syncthinginternal
PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SYNCTHING_PATH}/c-bindings")
# add additional libraries (not sure if go build could provide this list somehow to make this more generic)
if (WIN32)
list(APPEND PRIVATE_LIBRARIES -lws2_32 -lwinmm)
elseif (UNIX)
list(APPEND PRIVATE_LIBRARIES -lpthread)
endif ()
# add additional libraries (not sure if go build could provide this list somehow to make this more generic)
if (WIN32)
set(SYNCTHING_INTERNAL_LIBS ws2_32 winmm)
elseif (UNIX)
set(SYNCTHING_INTERNAL_LIBS pthread)
endif ()
foreach (LIBRARY ${SYNCTHING_INTERNAL_LIBS})
find_library(SYNCTHING_INTERNAL_LIBRARY_PATH_${LIBRARY} ${LIBRARY})
set_property(TARGET syncthinginternal APPEND PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES ${SYNCTHING_INTERNAL_LIBRARY_PATH_${LIBRARY}})
endforeach ()
# ensure we can find c_bindings.h from Syncthing's source tree when building the interface
list(APPEND PRIVATE_INCLUDE_DIRS "${SYNCTHING_PATH}/c-bindings")
# depend on that imported target
list(APPEND PRIVATE_LIBRARIES syncthinginternal)
set(BUNDLED_TARGET syncthinginternal)
# find c++utilities
find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED)
@ -183,10 +192,3 @@ include(LibraryTarget)
include(TestTarget)
include(Doxygen)
include(ConfigHeader)
# create install target for static libsyncthinginternal.a if we're also creating a static libsyncthing.a
if (BUILD_STATIC_LIBS AND NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a"
DESTINATION "lib${SELECTED_LIB_SUFFIX}"
COMPONENT binary)
endif ()