Generate and install export header with CMake and remove vendored export.h#15
Generate and install export header with CMake and remove vendored export.h#15Royna2544 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12f069f1cc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| 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) |
There was a problem hiding this comment.
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 👍 / 👎.
Motivation
include/tgbot/export.hwith a CMake-generated export header to centralize symbol visibility handling and avoid maintaining platform-specific macros by hand.Description
include(GenerateExportHeader)andgenerate_export_header(...)to produce the export header into the build tree at${CMAKE_CURRENT_BINARY_DIR}/include/tgbot/export.hwith macrosTGBOT_API,TGBOT_NO_EXPORT,TGBOT_DEPRECATED, andTGBOT_STATIC_DEFINE.$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>totarget_include_directories(${PROJECT_NAME} PUBLIC ...)so consumers and the target can find the generated header.install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/tgbot/export.h ...)and removed the repository copyinclude/tgbot/export.hfrom source.NOT BUILD_SHARED_LIBS) defineTGBOT_STATIC_DEFINEon the target viatarget_compile_definitions(...)and removed the previous manualTGBOT_DLLhandling at the bottom of the file.Testing
ctestwhenENABLE_TESTSwas enabled; the test suite completed successfully.Codex Task