Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,37 @@ endif()

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>)
# cpp-httplib is vendored (single header) and fully hidden behind the library
# (pimpl), so it is only needed when building the library itself.
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/third_party)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_LIST})
include(GNUInstallDirs)
include(GenerateExportHeader)

generate_export_header(${PROJECT_NAME}
BASE_NAME TGBOT
EXPORT_MACRO_NAME TGBOT_API
NO_EXPORT_MACRO_NAME TGBOT_NO_EXPORT
DEPRECATED_MACRO_NAME TGBOT_DEPRECATED
STATIC_DEFINE TGBOT_STATIC_DEFINE
INCLUDE_GUARD_NAME TGBOT_EXPORT_H
EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/include/tgbot/export.h)

if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PUBLIC TGBOT_STATIC_DEFINE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep direct static Windows consumers from importing DLL symbols

This PUBLIC define only reaches consumers that link the exported CMake target. If TgBot is installed/built as a static Windows library and then consumed directly via include paths plus TgBot.lib (as the existing samples/README direct-link flow allows), the generated export.h takes its non-static branch and marks TGBOT_API as __declspec(dllimport), whereas the old header left it empty unless TGBOT_DLL was explicitly defined. That makes those direct static consumers look for DLL import symbols instead of the static definitions, so they can fail at link time unless every caller manually adds TGBOT_STATIC_DEFINE.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how can i avoid it

endif()

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/tgbot/export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tgbot)
install(EXPORT ${PROJECT_NAME}-targets
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}Config.cmake
Expand All @@ -115,7 +133,3 @@ if(BUILD_DOCUMENTATION)
VERBATIM)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/html/ TYPE DOC)
endif()

if(BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PUBLIC TGBOT_DLL)
endif()
28 changes: 0 additions & 28 deletions include/tgbot/export.h

This file was deleted.

Loading