Skip to content

Generate and install export header with CMake and remove vendored export.h#15

Open
Royna2544 wants to merge 1 commit into
masterfrom
codex/add-cmake-generate_export_header-usage
Open

Generate and install export header with CMake and remove vendored export.h#15
Royna2544 wants to merge 1 commit into
masterfrom
codex/add-cmake-generate_export_header-usage

Conversation

@Royna2544

Copy link
Copy Markdown
Owner

Motivation

  • Replace a hand-written include/tgbot/export.h with a CMake-generated export header to centralize symbol visibility handling and avoid maintaining platform-specific macros by hand.

Description

  • Added include(GenerateExportHeader) and generate_export_header(...) to produce the export header into the build tree at ${CMAKE_CURRENT_BINARY_DIR}/include/tgbot/export.h with macros TGBOT_API, TGBOT_NO_EXPORT, TGBOT_DEPRECATED, and TGBOT_STATIC_DEFINE.
  • Added the build include directory $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> to target_include_directories(${PROJECT_NAME} PUBLIC ...) so consumers and the target can find the generated header.
  • Install the generated header with install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/tgbot/export.h ...) and removed the repository copy include/tgbot/export.h from source.
  • When building static libraries (NOT BUILD_SHARED_LIBS) define TGBOT_STATIC_DEFINE on the target via target_compile_definitions(...) and removed the previous manual TGBOT_DLL handling at the bottom of the file.

Testing

  • Configured and built the project with CMake to verify header generation and include paths for both static and shared configurations; the configuration and build succeeded.
  • Ran unit tests with ctest when ENABLE_TESTS was enabled; the test suite completed successfully.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread CMakeLists.txt
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant