Skip to content

Commit 3c957cf

Browse files
committed
Add build-time option to set gcc C++ ABI (ported from OIIO) (#995)
1 parent bc0c58b commit 3c957cf

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ ifneq (${USE_LIBCPLUSPLUS},)
187187
MY_CMAKE_FLAGS += -DUSE_LIBCPLUSPLUS:BOOL=${USE_LIBCPLUSPLUS}
188188
endif
189189

190+
ifneq (${GLIBCXX_USE_CXX11_ABI},)
191+
MY_CMAKE_FLAGS += -DGLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}
192+
endif
193+
190194
ifneq (${EXTRA_CPP_ARGS},)
191195
MY_CMAKE_FLAGS += -DEXTRA_CPP_ARGS:STRING="${EXTRA_CPP_ARGS}"
192196
endif
@@ -373,6 +377,7 @@ help:
373377
@echo " MYCC=xx MYCXX=yy Use custom compilers"
374378
@echo " USE_CPP=14 Compile in C++14 mode (default is C++11)"
375379
@echo " USE_LIBCPLUSPLUS=1 Use clang libc++"
380+
@echo " GLIBCXX_USE_CXX11_ABI=1 For gcc, use the new string ABI"
376381
@echo " EXTRA_CPP_ARGS= Additional args to the C++ command"
377382
@echo " USE_NINJA=1 Set up Ninja build (instead of make)"
378383
@echo " USE_CCACHE=0 Disable ccache (even if available)"

src/cmake/compiler.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ option (CLANG_TIDY "Enable clang-tidy" OFF)
2121
set (CLANG_TIDY_CHECKS "-*" CACHE STRING "clang-tidy checks to perform")
2222
set (CLANG_TIDY_ARGS "" CACHE STRING "clang-tidy args")
2323
option (CLANG_TIDY_FIX "Have clang-tidy fix source" OFF)
24+
set (GLIBCXX_USE_CXX11_ABI "" CACHE STRING "For gcc, use the new C++11 library ABI (0|1)")
2425

2526

2627
# Figure out which compiler we're using
@@ -196,6 +197,18 @@ if (USE_LIBCPLUSPLUS AND CMAKE_COMPILER_IS_CLANG)
196197
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
197198
endif ()
198199

200+
# GCC 5+: honor build-time option for whether or not to use new string ABI.
201+
# FIXME: In theory, this should also be needed for clang, if compiling with
202+
# the gcc libstdc++ toolchain. In practice, I could not get things to build
203+
# with clang properly when using this option, and I haven't yet seen a case
204+
# where it's needed. We can return to this and fix for clang if it becomes a
205+
# legit problem later.
206+
if (CMAKE_COMPILER_IS_GNUCC AND NOT ${GCC_VERSION} VERSION_LESS 5.0)
207+
if (NOT ${GLIBCXX_USE_CXX11_ABI} STREQUAL "")
208+
add_definitions ("-D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
209+
endif ()
210+
endif ()
211+
199212

200213
# SIMD and machine architecture options
201214
set (SIMD_COMPILE_FLAGS "")

0 commit comments

Comments
 (0)