Fix further configuration issues with libsyncthing

* Can not use BUNDLED_TARGETS because syncthinginternal is only an
  imported target
* Use INSTALL_INTERFACE generator expression to specify path of
  libsyncthinginternal.a for installation (imported target can not
  be exported apparently)
This commit is contained in:
Martchus 2019-08-06 00:12:58 +02:00
parent 495140cdf9
commit e2037aebc1
1 changed files with 32 additions and 22 deletions

View File

@ -128,8 +128,9 @@ add_custom_command(OUTPUT "${SYNCTHING_PATH}/lib/auto/gui.files.go"
COMMENT "Building Syncthing's assets") COMMENT "Building Syncthing's assets")
# compile Syncthing as static library # compile Syncthing as static library
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a" set(SYNCTHINGINTERNAL_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a")
"${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.h" set(SYNCTHINGINTERNAL_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.h")
add_custom_command(OUTPUT "${SYNCTHINGINTERNAL_LIBRARY_PATH}" "${SYNCTHINGINTERNAL_HEADER_PATH}"
COMMAND "CC=${CMAKE_C_COMPILER}" COMMAND "CC=${CMAKE_C_COMPILER}"
"CXX=${CMAKE_CXX_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}"
"AR=${CMAKE_C_COMPILER_AR}" "AR=${CMAKE_C_COMPILER_AR}"
@ -143,37 +144,41 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a"
-v -buildmode -v -buildmode
c-archive c-archive
-o -o
"${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a" "${SYNCTHINGINTERNAL_LIBRARY_PATH}"
-ldflags "${GO_LINKER_FLAGS}" -ldflags
"${GO_LINKER_FLAGS}"
./c-bindings ./c-bindings
&& &&
"${CMAKE_RANLIB}" "${CMAKE_RANLIB}"
"${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a" "${SYNCTHINGINTERNAL_LIBRARY_PATH}"
DEPENDS ${SRC_FILES_SYNCTHING} DEPENDS ${SRC_FILES_SYNCTHING}
WORKING_DIRECTORY "${SYNCTHING_PATH}" WORKING_DIRECTORY "${SYNCTHING_PATH}"
COMMENT "Building Syncthing itself") COMMENT "Building Syncthing itself")
# apply basic config
include(BasicConfig)
# add imported target for library generated by the Go build system # add imported target for library generated by the Go build system
add_library(syncthinginternal STATIC IMPORTED) add_library(syncthinginternal STATIC IMPORTED)
set_property(TARGET syncthinginternal set_property(TARGET syncthinginternal PROPERTY IMPORTED_LOCATION "${SYNCTHINGINTERNAL_LIBRARY_PATH}")
PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libsyncthinginternal.a") set_property(TARGET syncthinginternal PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SYNCTHING_PATH}/c-bindings")
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) # add additional libraries (not sure if go build could provide this list somehow to make this more generic)
if (WIN32) if (WIN32)
set(SYNCTHING_INTERNAL_LIBS ws2_32 winmm) set(SYNCTHING_INTERNAL_LIBS ws2_32 winmm)
elseif (UNIX) elseif (UNIX)
set(SYNCTHING_INTERNAL_LIBS pthread) set(SYNCTHING_INTERNAL_LIBS pthread)
endif () endif ()
foreach (LIBRARY ${SYNCTHING_INTERNAL_LIBS}) foreach (LIBRARY ${SYNCTHING_INTERNAL_LIBS})
find_library(SYNCTHING_INTERNAL_LIBRARY_PATH_${LIBRARY} ${LIBRARY}) find_library(SYNCTHING_INTERNAL_LIBRARY_PATH_${LIBRARY} ${LIBRARY})
set_property(TARGET syncthinginternal APPEND PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES ${SYNCTHING_INTERNAL_LIBRARY_PATH_${LIBRARY}}) set_property(TARGET syncthinginternal
endforeach () APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES ${SYNCTHING_INTERNAL_LIBRARY_PATH_${LIBRARY}})
endforeach ()
# depend on that imported target # depend on that imported target
list(APPEND PRIVATE_LIBRARIES syncthinginternal) list(APPEND PRIVATE_LIBRARIES $<BUILD_INTERFACE:syncthinginternal>
set(BUNDLED_TARGET syncthinginternal) $<INSTALL_INTERFACE:${LIB_INSTALL_DESTINATION}/libsyncthinginternal.a>)
# find c++utilities # find c++utilities
find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED) find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED)
@ -186,9 +191,14 @@ else ()
endif () endif ()
# include modules to apply configuration # include modules to apply configuration
include(BasicConfig)
include(WindowsResources) include(WindowsResources)
include(LibraryTarget) include(LibraryTarget)
include(TestTarget) include(TestTarget)
include(Doxygen) include(Doxygen)
include(ConfigHeader) include(ConfigHeader)
# create install target for static libsyncthinginternal.a if we're also creating a static libsyncthing.a note: Not possible
# to add syncthinginternal to BUNDLED_TARGETS because it is an import library which apparently can not be exported.
if (NOT BUILD_SHARED_LIBS AND NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
install(FILES "${SYNCTHINGINTERNAL_LIBRARY_PATH}" DESTINATION "lib${SELECTED_LIB_SUFFIX}" COMPONENT binary)
endif ()