Allow packaging the C++ client in Debug mode (-Dcmake.build.type=Debug)#17856
Open
JackieTien97 wants to merge 1 commit into
Open
Allow packaging the C++ client in Debug mode (-Dcmake.build.type=Debug)#17856JackieTien97 wants to merge 1 commit into
JackieTien97 wants to merge 1 commit into
Conversation
On non-MSVC platforms src/main/CMakeLists.txt hardcoded "-Wall -g -O2" and the cmake generate step never received -DCMAKE_BUILD_TYPE. Single-config generators (Unix Makefiles) ignore "cmake --build --config", so the cmake.build.type property had no effect on Linux/macOS and the packaged library was always built at -O2.
Pass -DCMAKE_BUILD_TYPE=${cmake.build.type} to the main-library generate step and let the build type drive optimization: keep -Wall -g for every build type, set Release to -O2 (exactly the previous flags, no -DNDEBUG) and Debug to -O0, defaulting to Release when unset. Release output is unchanged; -Dcmake.build.type=Debug now yields an unoptimized, debuggable library. MSVC is unaffected.
|
Caideyipi
reviewed
Jun 8, 2026
| SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g") | ||
| # Release keeps the previous flags exactly (-O2, no -DNDEBUG); Debug is unoptimized | ||
| # (-O0) so the packaged library can be stepped through in a debugger. | ||
| SET(CMAKE_CXX_FLAGS_RELEASE "-O2") |
Collaborator
There was a problem hiding this comment.
This should preserve existing per-config flags instead of replacing them completely. Once the POM passes -DCMAKE_BUILD_TYPE, CMAKE_CXX_FLAGS_RELEASE / CMAKE_CXX_FLAGS_DEBUG are actually used, so these unconditional assignments can discard flags provided by a toolchain file or by the caller, e.g. hardening, sanitizer, ABI, or architecture flags. Could we keep the caller/toolchain-provided value and only adjust the optimization level needed here (-O2 for Release, -O0 for Debug)?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
Make
-Dcmake.build.type=Debugactually produce a debug build of the C++ client library (libiotdb_session).Why
On non-MSVC platforms,
iotdb-client/client-cpp/src/main/CMakeLists.txthardcoded:and the
cmake-generatestep inpom.xmlnever passed-DCMAKE_BUILD_TYPE. Single-config generators (e.g. Unix Makefiles) ignorecmake --build --config, so on Linux/macOS the existingcmake.build.typeproperty was effectively a no-op — the packaged library was always compiled at-O2. Even-DCMAKE_BUILD_TYPE=Debugstayed at-O2, because Debug only appends-gand never removes the hardcoded-O2.How
pom.xml: pass-DCMAKE_BUILD_TYPE=${cmake.build.type}to the main-librarycmake-generateexecution.src/main/CMakeLists.txt: stop hardcoding the optimization level. Keep-Wall -gfor all build types (Release still ships symbols, as before), setCMAKE_CXX_FLAGS_RELEASEto-O2andCMAKE_CXX_FLAGS_DEBUGto-O0, and default toReleasewhen no type is given.Release output is intentionally unchanged (
-g -O2, no-DNDEBUG, asserts still active). MSVC is unaffected — it already selects the configuration viacmake --build --config ${cmake.build.type}.Usage
Verification
Actual
CXX_FLAGSproduced by the configure step (macOS, Unix Makefiles) with these changes:Release-Wall -g -O2 ...-O2(unchanged)Debug-Wall -g -O0 ...-O0A full Debug build of
libiotdb_sessioncompiles and links; the resulting dylib is ~6.7 MB vs ~3.2 MB for Release, consistent with-O0+ debug info.🤖 Generated with Claude Code