Skip to content

fix(cmake): fix ext_zlib build type switching#35316

Open
tomchon wants to merge 1 commit into
mainfrom
copilot-main-zlib-build-type-fix
Open

fix(cmake): fix ext_zlib build type switching#35316
tomchon wants to merge 1 commit into
mainfrom
copilot-main-zlib-build-type-fix

Conversation

@tomchon
Copy link
Copy Markdown
Contributor

@tomchon tomchon commented May 11, 2026

Summary

Testing

  • cmake -S . -B /tmp/tdengine-copilot-zlib-check -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DBUILD_TEST=OFF -DBUILD_CONTRIB=ON

Add zlib BUILD_BYPRODUCTS and use configure-time CMAKE_BUILD_TYPE so Make generators rebuild ext_zlib when switching build types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 11, 2026 11:48
@tomchon tomchon requested a review from guanshengliang as a code owner May 11, 2026 11:48
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the ext_zlib external project configuration in cmake/external.cmake to use ${CMAKE_BUILD_TYPE} for the build type and adds a BUILD_BYPRODUCTS entry. A review comment points out a potential path mismatch in the BUILD_BYPRODUCTS definition when ${CMAKE_BUILD_TYPE} is empty, suggesting the use of the ${ext_zlib_install} variable to ensure consistency with the installation prefix.

Comment thread cmake/external.cmake
CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON # linking consistent
CMAKE_ARGS -DZLIB_BUILD_SHARED:BOOL=OFF
CMAKE_ARGS -DZLIB_BUILD_TESTING:BOOL=OFF
BUILD_BYPRODUCTS "${TD_EXTERNALS_BASE_DIR}/install/ext_zlib/${CMAKE_BUILD_TYPE}/lib/${ext_zlib_static}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The BUILD_BYPRODUCTS path uses ${CMAKE_BUILD_TYPE}, which can be empty if not explicitly set (e.g., on multi-config generators or when relying on defaults). However, the installation prefix (_ins) passed to the external project in line 197 is defined using TD_CONFIG_NAME, which defaults to Debug when CMAKE_BUILD_TYPE is unset. This mismatch means the byproduct path will not match the actual installation location, causing build errors as CMake won't find the expected file. It is safer and more consistent to use the ${ext_zlib_install} variable which is already set up by the INIT_EXT macro.

    BUILD_BYPRODUCTS "${ext_zlib_install}/lib/${ext_zlib_static}"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Backports the ext_zlib ExternalProject improvements so that switching build types and building with Makefile generators behaves correctly (especially around stamp detection and dependency tracking for the produced static zlib library).

Changes:

  • Pass a build-type value into ext_zlib’s CMAKE_ARGS intended to make stamp files reflect build-type changes.
  • Add BUILD_BYPRODUCTS for the produced zlib static library to fix Makefile-generator dependency tracking.
  • Minor whitespace cleanup around GIT_TAG.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmake/external.cmake
Comment on lines +196 to +201
CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} # use configure-time value so stamp files detect build type changes
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:STRING=${_ins} # let default INSTALL step use
CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON # linking consistent
CMAKE_ARGS -DZLIB_BUILD_SHARED:BOOL=OFF
CMAKE_ARGS -DZLIB_BUILD_TESTING:BOOL=OFF
BUILD_BYPRODUCTS "${TD_EXTERNALS_BASE_DIR}/install/ext_zlib/${CMAKE_BUILD_TYPE}/lib/${ext_zlib_static}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants