JackieTien97 opened a new pull request, #17856:
URL: https://github.com/apache/iotdb/pull/17856
## What
Make `-Dcmake.build.type=Debug` actually produce a debug build of the C++
client library (`libiotdb_session`).
## Why
On non-MSVC platforms, `iotdb-client/client-cpp/src/main/CMakeLists.txt`
hardcoded:
```cmake
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -O2")
```
and the `cmake-generate` step in `pom.xml` never passed
`-DCMAKE_BUILD_TYPE`. Single-config generators (e.g. *Unix Makefiles*) ignore
`cmake --build --config`, so on Linux/macOS the existing `cmake.build.type`
property was effectively a no-op — the packaged library was always compiled at
`-O2`. Even `-DCMAKE_BUILD_TYPE=Debug` stayed at `-O2`, because Debug only
appends `-g` and never removes the hardcoded `-O2`.
## How
- **`pom.xml`**: pass `-DCMAKE_BUILD_TYPE=${cmake.build.type}` to the
main-library `cmake-generate` execution.
- **`src/main/CMakeLists.txt`**: stop hardcoding the optimization level.
Keep `-Wall -g` for all build types (Release still ships symbols, as before),
set `CMAKE_CXX_FLAGS_RELEASE` to `-O2` and `CMAKE_CXX_FLAGS_DEBUG` to `-O0`,
and default to `Release` when no type is given.
Release output is intentionally **unchanged** (`-g -O2`, no `-DNDEBUG`,
asserts still active). MSVC is unaffected — it already selects the
configuration via `cmake --build --config ${cmake.build.type}`.
## Usage
```bash
# Release (default, unchanged)
mvn clean package -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests
# Debug package
mvn clean package -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests
-Dcmake.build.type=Debug
```
## Verification
Actual `CXX_FLAGS` produced by the configure step (macOS, Unix Makefiles)
with these changes:
| build type | resulting flags | opt level |
|---|---|---|
| default / `Release` | `-Wall -g -O2 ...` | `-O2` (unchanged) |
| `Debug` | `-Wall -g -O0 ...` | `-O0` |
A full Debug build of `libiotdb_session` compiles and links; the resulting
dylib is ~6.7 MB vs ~3.2 MB for Release, consistent with `-O0` + debug info.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]