target_link_libraries, linking problem with linking an dll

59 Views Asked by At

I am creating a shiboken binding. and I am getting a weird output.

this is my linking code:

target_include_directories(${bindings_library} PRIVATE ${pyside2_additional_includes})
target_include_directories(${bindings_library} PRIVATE ${pyside2_include_dir})
target_include_directories(${bindings_library} PRIVATE ${python_include_dir})
target_include_directories(${bindings_library} PRIVATE ${shiboken_include_dir})

target_link_libraries(${can_library} INTERFACE businterfaces)
target_link_libraries(${can_library} PRIVATE businterfaces)
target_link_libraries(${can_library} PRIVATE Qt5::Core)
target_link_libraries(${can_library} PRIVATE Qt5::Widgets)
target_link_libraries(${can_library} PRIVATE Qt5::Gui)

target_link_libraries(${bindings_library} PRIVATE ${can_library})
target_link_libraries(${bindings_library} PRIVATE Qt5::Core)
target_link_libraries(${bindings_library} PRIVATE Qt5::Widgets)
target_link_libraries(${bindings_library} PRIVATE Qt5::Gui)
target_link_libraries(${bindings_library} PRIVATE ${pyside2_shared_libraries})
target_link_libraries(${bindings_library} PRIVATE ${shiboken_shared_libraries})

my cmake turns the bindings_library into a .pyd and can_library into a .lib and .dll which should be then included in the ${bindings_library}.pyd but isn't. I am also linking businterfaces (a project that is added to my main cmakelist as a subbdir for my includes) which is linked nice as i will show but is also the reason for the problem, because the can_library.dll also has businterfaces include but when i open them with dependency walker have different contents. the target_link_libraries(${bindings_library} PRIVATE ${can_library}) should link the files.

this is my current output (with businterface.dll open)

The contend of (${can_library}.dll that ins't added to my .pyd (with busintefaces.dll open)

Is the problem 2 businterfaces with different contents? Is there a way to just include the dll in my pyd? I tried normal linking like target_link_libraries(${bindings_library} PRIVATE ${can_library}.lib) and it does't work. is there a deeper problem? this is an example of how the output should look like where everythiing is the same just the bindings_library and can_library dont need businterfaces to work : example

also my businterfaces cmake for better understanding:

cmake_minimum_required(VERSION 3.10)

project(businterfaces)

find_package(Qt5 CONFIG REQUIRED Core SerialPort Network)

set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(INCLUDES
    include
    include/qmqtt
    ftdi
    ${PROJECT_BINARY_DIR}
)

if (BUILD_SHARED_LIBS)
    # Prefix all shared libraries with 'lib'.
    set(CMAKE_SHARED_LIBRARY_PREFIX "")
    # Prefix all static libraries with 'lib'.
    set(CMAKE_STATIC_LIBRARY_PREFIX "")

    set(INCLUDES
        ${INCLUDES}
        ../utilities/include
    )
    message(STATUS "includes: ${INCLUDES}")
endif()

set(SOURCES
    src/skyegselink.cpp
    src/canbusinterface.cpp
    src/canframe.cpp
    src/canmassmessage.cpp
    src/canmqttclient.cpp
    src/lvdsbusinterface.cpp
    src/lvdsmqttclient.cpp
    src/sdrmqttmanager.cpp
    src/slipencdec.cpp
    src/slipdeviceif.cpp
    src/slip_d2xx.cpp
    src/slip_d2xx_thread.cpp
    src/slipserialport.cpp
    src/sliphsserial.cpp
    src/slipsocket.cpp
    src/egselink2control.cpp
    src/egselink2lvds.cpp
    src/egselink2can.cpp
    src/egselink2rs422.cpp
    src/qmqtt/qmqtt_client.cpp
    src/qmqtt/qmqtt_client_p.cpp
    src/qmqtt/qmqtt_frame.cpp
    src/qmqtt/qmqtt_message.cpp
    src/qmqtt/qmqtt_network.cpp
    src/qmqtt/qmqtt_router.cpp
    src/qmqtt/qmqtt_routesubscription.cpp
    src/qmqtt/qmqtt_socket.cpp
    src/qmqtt/qmqtt_ssl_socket.cpp
    src/qmqtt/qmqtt_timer.cpp
    src/qmqtt/qmqtt_websocket.cpp
    src/qmqtt/qmqtt_websocketiodevice.cpp
    src/ksat/ksat_settings.cpp
    src/ksat/ksat_space_tm_frame.cpp
    src/ksat/ksat_space_tc_frame.cpp
    src/ksat/ksat_ccsds_tm_frame.cpp
    src/ksat/ksat_ccsds_tc_frame.cpp
    src/ksat/ksat_message.cpp
    src/ksat/ksat_client.cpp
    src/canksatclient.cpp
)

set(HEADERS
    include/skyegselink.h
    include/canbusinterface.h
    include/canframe.h
    include/canmassmessage.h
    include/canmqttclient.h
    include/lvdsbusinterface.h
    include/lvdsmqttclient.h
    include/sdrmqttmanager.h
    include/slipencdec.h
    include/slipdeviceif.h
    include/slip_d2xx.h
    include/slip_d2xx_thread.h
    include/slipserialport.h
    include/sliphsserial.h
    include/slipsocket.h
    include/egselink2control.h
    include/egselink2lvds.h
    include/egselink2can.h
    include/egselink2rs422.h
    include/qmqtt/qmqtt.h
    include/qmqtt/qmqtt_client.h
    include/qmqtt/qmqtt_client_p.h
    include/qmqtt/qmqtt_frame.h
    include/qmqtt/qmqtt_global.h
    include/qmqtt/qmqtt_message.h
    include/qmqtt/qmqtt_message_p.h
    include/qmqtt/qmqtt_networkinterface.h
    include/qmqtt/qmqtt_network_p.h
    include/qmqtt/qmqtt_routedmessage.h
    include/qmqtt/qmqtt_router.h
    include/qmqtt/qmqtt_routesubscription.h
    include/qmqtt/qmqtt_socketinterface.h
    include/qmqtt/qmqtt_socket_p.h
    include/qmqtt/qmqtt_ssl_socket_p.h
    include/qmqtt/qmqtt_timerinterface.h
    include/qmqtt/qmqtt_timer_p.h
    include/qmqtt/qmqtt_websocketiodevice_p.h
    include/qmqtt/qmqtt_websocket_p.h
    include/ksat/ksat_settings.h
    include/ksat/ksat_space_tm_frame.h
    include/ksat/ksat_space_tc_frame.h
    include/ksat/ksat_ccsds_tm_frame.h
    include/ksat/ksat_ccsds_tc_frame.h
    include/ksat/ksat_message.h
    include/ksat/ksat_client.h
    include/canksatclient.h
    ftdi/ftd2xx.h
)

add_library(businterfaces ${SOURCES} ${HEADERS})

if(WIN32)
    add_library(ftd2xx SHARED IMPORTED)
    set_property(TARGET ftd2xx PROPERTY IMPORTED_IMPLIB ${PROJECT_SOURCE_DIR}/ftdi/windows/ftd2xx.lib)
    set_property(TARGET ftd2xx PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/ftdi/windows/ftd2xx.dll)

    set(FTDI_LIBS
        ftd2xx
        ws2_32
    )
else()
    set(INCLUDES ${INCLUDES}
        ftdi/linux
    )

    set(HEADERS ${HEADERS}
        ftdi/linux/libusb.h
        ftdi/linux/WinTypes.h
    )

    add_library(ftd2xx STATIC IMPORTED)
    set_property(TARGET ftd2xx PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/ftdi/linux/libftd2xx.a)

    set(THREADS_PREFER_PTHREAD_FLAG ON)
    find_package(Threads REQUIRED)

    set(FTDI_LIBS
        ftd2xx
        Threads::Threads
    )
endif()

target_include_directories(businterfaces PUBLIC ${INCLUDES})
target_include_directories(businterfaces PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_definitions(businterfaces PRIVATE QT_DEPRECATED_WARNINGS)
target_compile_definitions(businterfaces PRIVATE _UNICODE)
target_compile_definitions(businterfaces PRIVATE UNICODE)
target_compile_definitions(businterfaces PRIVATE NOMINMAX)

target_link_libraries(businterfaces utilities Qt5::Core Qt5::SerialPort Qt5::Network ${FTDI_LIBS} )

string(TOUPPER ${PROJECT_NAME} UPR_PROJECT_NAME)
include(GenerateExportHeader)
GENERATE_EXPORT_HEADER(${PROJECT_NAME}
    BASE_NAME ${UPR_PROJECT_NAME}
    EXPORT_MACRO_NAME ${UPR_PROJECT_NAME}_EXPORT
    EXPORT_FILE_NAME ${PROJECT_NAME}_export.h
    STATIC_DEFINE ${UPR_PROJECT_NAME}_BUILT_AS_STATIC
)

# Set the target directory for copying the export header
set(EXPORT_HEADER_TARGET_DIR "C:/python/Lib/site-packages/PySide2/examples/cmm-sdk-examples-dev-clone/cants_examples")

# Copy the export header to the target directory
add_custom_command(TARGET businterfaces POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h
    ${EXPORT_HEADER_TARGET_DIR}/${PROJECT_NAME}_export.h
)

# Set the precompile headers property for the target
set_property(TARGET businterfaces APPEND PROPERTY "PRECOMPILE_HEADERS" "$<$<COMPILE_LANGUAGE:CXX>:QtCore;QSerialPort>")

0

There are 0 best solutions below