Skip to content

Commit 520fac6

Browse files
committed
Fix C++ SDK CXX11 ABI propagation
1 parent 6a71c1b commit 520fac6

7 files changed

Lines changed: 41 additions & 3 deletions

File tree

.github/scripts/package-client-cpp-manylinux-glibc217.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ cd "${GITHUB_WORKSPACE:?GITHUB_WORKSPACE is not set}"
6969
./mvnw clean package -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests \
7070
-Dspotless.skip=true \
7171
-Dclient.cpp.package.classifier="${PACKAGE_CLASSIFIER}" \
72-
-Diotdb.extra.cxx.flags=-D_GLIBCXX_USE_CXX11_ABI=1
72+
-Diotdb.cxx11.abi=1
7373

7474
SO="iotdb-client/client-cpp/target/install/lib/libiotdb_session.so"
7575
test -f "${SO}"

iotdb-client/client-cpp/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ endif()
3434

3535
set(IOTDB_EXTRA_CXX_FLAGS ""
3636
CACHE STRING "Extra flags appended to CMAKE_CXX_FLAGS")
37+
set(IOTDB_USE_CXX11_ABI ""
38+
CACHE STRING "Set _GLIBCXX_USE_CXX11_ABI for GNU libstdc++ builds (empty keeps toolchain default)")
3739

3840
if(NOT MSVC)
3941
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -O2")
@@ -47,6 +49,10 @@ if(MSVC)
4749
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
4850
endif()
4951

52+
if(IOTDB_USE_CXX11_ABI AND NOT IOTDB_USE_CXX11_ABI MATCHES "^[01]$")
53+
message(FATAL_ERROR "IOTDB_USE_CXX11_ABI must be empty, 0, or 1")
54+
endif()
55+
5056
option(WITH_SSL "Build with OpenSSL support" OFF)
5157
option(BUILD_TESTING "Build IT test executables" OFF)
5258
option(IOTDB_OFFLINE "Disable all network access during configure" OFF)
@@ -116,6 +122,10 @@ endif()
116122
add_dependencies(iotdb_session iotdb_thrift_external iotdb_thrift_codegen)
117123

118124
target_compile_definitions(iotdb_session PRIVATE THRIFT_STATIC_DEFINE IOTDB_BUILDING_SHARED)
125+
if(IOTDB_USE_CXX11_ABI AND NOT MSVC)
126+
target_compile_definitions(iotdb_session PUBLIC
127+
_GLIBCXX_USE_CXX11_ABI=${IOTDB_USE_CXX11_ABI})
128+
endif()
119129

120130
target_include_directories(iotdb_session
121131
PUBLIC
@@ -186,9 +196,16 @@ foreach(_hdr IN LISTS IOTDB_PUBLIC_HEADERS)
186196
endforeach()
187197

188198
set(IOTDB_SESSION_PC_LIBS "-liotdb_session")
199+
set(IOTDB_SESSION_PC_CFLAGS "")
200+
set(IOTDB_SESSION_CXX11_ABI_COMPILE_DEFINITION "")
189201
if(UNIX)
190202
set(IOTDB_SESSION_PC_LIBS "${IOTDB_SESSION_PC_LIBS} -pthread")
191203
endif()
204+
if(IOTDB_USE_CXX11_ABI AND NOT MSVC)
205+
set(IOTDB_SESSION_PC_CFLAGS "-D_GLIBCXX_USE_CXX11_ABI=${IOTDB_USE_CXX11_ABI}")
206+
set(IOTDB_SESSION_CXX11_ABI_COMPILE_DEFINITION
207+
"_GLIBCXX_USE_CXX11_ABI=${IOTDB_USE_CXX11_ABI}")
208+
endif()
192209
configure_file(
193210
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/iotdb-session-config.cmake.in"
194211
"${CMAKE_BINARY_DIR}/package-metadata/cmake/iotdb-session-config.cmake"
@@ -224,6 +241,7 @@ file(WRITE "${CMAKE_BINARY_DIR}/package-metadata/BUILD-INFO.txt"
224241
"cmake.build.type=${CMAKE_BUILD_TYPE}\n"
225242
"with.ssl=${WITH_SSL}\n"
226243
"iotdb.offline=${IOTDB_OFFLINE}\n"
244+
"iotdb.use.cxx11.abi=${IOTDB_USE_CXX11_ABI}\n"
227245
"iotdb.extra.cxx.flags=${IOTDB_EXTRA_CXX_FLAGS}\n")
228246
install(FILES "${CMAKE_BINARY_DIR}/package-metadata/cmake/iotdb-session-config.cmake"
229247
DESTINATION cmake)
@@ -245,6 +263,7 @@ message(STATUS "iotdb_session configuration summary:")
245263
message(STATUS " WITH_SSL = ${WITH_SSL}")
246264
message(STATUS " BUILD_TESTING = ${BUILD_TESTING}")
247265
message(STATUS " IOTDB_OFFLINE = ${IOTDB_OFFLINE}")
266+
message(STATUS " IOTDB_USE_CXX11_ABI = ${IOTDB_USE_CXX11_ABI}")
248267
message(STATUS " IOTDB_DEPS_DIR = ${IOTDB_DEPS_DIR}")
249268
message(STATUS " BOOST_INCLUDE_DIR = ${BOOST_INCLUDE_DIR} (Thrift build only)")
250269
message(STATUS " THRIFT_INCLUDE_DIR = ${THRIFT_INCLUDE_DIR}")

iotdb-client/client-cpp/cmake/FetchThrift.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ if(MSVC)
123123
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL")
124124
else()
125125
set(_thrift_cxxflags "-fPIC")
126+
if(IOTDB_USE_CXX11_ABI)
127+
set(_thrift_cxxflags "${_thrift_cxxflags} -D_GLIBCXX_USE_CXX11_ABI=${IOTDB_USE_CXX11_ABI}")
128+
endif()
126129
list(APPEND _thrift_cmake_args
127130
"-DCMAKE_C_FLAGS=-fPIC"
128131
"-DCMAKE_CXX_FLAGS=${_thrift_cxxflags}")
@@ -139,7 +142,12 @@ endif()
139142
# invoking cmake twice via execute_process and only register a phony
140143
# ExternalProject for dependency ordering.
141144

142-
set(_thrift_stamp "${_thrift_build}/.built-${THRIFT_VERSION}-mdll")
145+
if(IOTDB_USE_CXX11_ABI)
146+
set(_thrift_abi_stamp "-abi${IOTDB_USE_CXX11_ABI}")
147+
else()
148+
set(_thrift_abi_stamp "-abidefault")
149+
endif()
150+
set(_thrift_stamp "${_thrift_build}/.built-${THRIFT_VERSION}-mdll${_thrift_abi_stamp}")
143151
if(NOT EXISTS "${_thrift_stamp}")
144152
file(MAKE_DIRECTORY "${_thrift_build}")
145153
message(STATUS "[Thrift] configuring ${_thrift_dirname}")

iotdb-client/client-cpp/cmake/iotdb-session-config.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ if(NOT TARGET IoTDB::iotdb_session)
3434
add_library(IoTDB::iotdb_session SHARED IMPORTED)
3535
set_target_properties(IoTDB::iotdb_session PROPERTIES
3636
INTERFACE_INCLUDE_DIRECTORIES "${_IOTDB_SESSION_PACKAGE_ROOT}/include")
37+
if("@IOTDB_SESSION_CXX11_ABI_COMPILE_DEFINITION@")
38+
set_target_properties(IoTDB::iotdb_session PROPERTIES
39+
INTERFACE_COMPILE_DEFINITIONS "@IOTDB_SESSION_CXX11_ABI_COMPILE_DEFINITION@")
40+
endif()
3741
if(UNIX)
3842
set_target_properties(IoTDB::iotdb_session PROPERTIES
3943
INTERFACE_LINK_LIBRARIES Threads::Threads)

iotdb-client/client-cpp/cmake/iotdb-session.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Name: iotdb-session-cpp
2323
Description: Apache IoTDB C++ session client
2424
Version: @IOTDB_SESSION_VERSION@
2525
Libs: -L${libdir} @IOTDB_SESSION_PC_LIBS@
26-
Cflags: -I${includedir}
26+
Cflags: -I${includedir} @IOTDB_SESSION_PC_CFLAGS@

iotdb-client/client-cpp/examples/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ELSE()
7878
ENDIF()
7979

8080
if(NOT _iotdb_examples_in_tree)
81+
find_package(iotdb-session CONFIG QUIET PATHS "${IOTDB_SDK_ROOT}" NO_DEFAULT_PATH)
8182
if(WIN32)
8283
set(_iotdb_link_lib "${IOTDB_SDK_ROOT}/lib/iotdb_session.lib")
8384
set(_iotdb_runtime "${IOTDB_SDK_ROOT}/lib/iotdb_session.dll")
@@ -94,6 +95,10 @@ if(NOT _iotdb_examples_in_tree)
9495
"IoTDB SDK not found at ${IOTDB_SDK_ROOT}. "
9596
"Unpack iotdb-session-cpp-<version>-<classifier>.zip so that ${_iotdb_link_lib} exists.")
9697
endif()
98+
99+
if(TARGET IoTDB::iotdb_session)
100+
set(_iotdb_link_lib IoTDB::iotdb_session)
101+
endif()
97102
endif()
98103

99104
ADD_EXECUTABLE(SessionExample SessionExample.cpp)

iotdb-client/client-cpp/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<iotdb.deps.dir>${project.basedir}/third-party</iotdb.deps.dir>
5151
<iotdb.offline>OFF</iotdb.offline>
5252
<with.ssl>OFF</with.ssl>
53+
<iotdb.cxx11.abi/>
5354
<!-- Switched to OFF by the .skipTests profile below. -->
5455
<build.tests>ON</build.tests>
5556
<maven.test.skip>${ctest.skip.tests}</maven.test.skip>
@@ -113,6 +114,7 @@
113114
<option>-DWITH_SSL=${with.ssl}</option>
114115
<option>-DIOTDB_OFFLINE=${iotdb.offline}</option>
115116
<option>-DIOTDB_DEPS_DIR=${iotdb.deps.dir}</option>
117+
<option>-DIOTDB_USE_CXX11_ABI=${iotdb.cxx11.abi}</option>
116118
<option>-DBOOST_INCLUDEDIR=${boost.include.dir}</option>
117119
<option>-DCMAKE_POLICY_DEFAULT_CMP0091=NEW</option>
118120
<option>-DIOTDB_EXTRA_CXX_FLAGS=${iotdb.extra.cxx.flags}</option>

0 commit comments

Comments
 (0)