diff --git a/cpp/configure.in b/cpp/configure.in index cc86cdfd..b05f9183 100644 --- a/cpp/configure.in +++ b/cpp/configure.in @@ -16,7 +16,7 @@ AC_PROG_CC AC_MSG_CHECKING([if C++ API is enabled]) AC_ARG_ENABLE(cxx, AS_HELP_STRING([--disable-cxx], - [don't build C++ API]) ) + [don't build C++ API]) ) #' AC_MSG_RESULT([$enable_cxx]) if test "$enable_cxx" != "no"; then AC_PROG_CXX @@ -50,15 +50,41 @@ AC_CACHE_CHECK([for __sync_* atomic operations], msgpack_cv_atomic_ops, [ ], [], msgpack_cv_atomic_ops="yes") ]) if test "$msgpack_cv_atomic_ops" != "yes"; then - AC_MSG_NOTICE([__sync_* atomic operations are not found. Use libstdc++ instead. + if test "$enable_cxx" = "no"; then + AC_MSG_ERROR([__sync_* atomic operations are not found. Try to enable C++ support. +If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to +add CFLAGS="-march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows: + + $ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686" + ]) + fi + + AC_LANG_PUSH([C++]) + AC_CACHE_CHECK([for __gnu_cxx::__exchange_and_add], msgpack_cv_gcc_cxx_atomic_ops, [ + AC_TRY_LINK([ + #include + int atomic_sub(int i) { return __gnu_cxx::__exchange_and_add(&i, -1); } + int atomic_add(int i) { return __gnu_cxx::__exchange_and_add(&i, 1); } + ], [], msgpack_cv_gcc_cxx_atomic_ops="yes") + ]) + AC_LANG_POP([C++]) + + if test "$msgpack_cv_gcc_cxx_atomic_ops" != "yes"; then + AC_MSG_ERROR([__sync_* atomic operations nor __gnu_cxx::__exchange_and_add are not found. If you are using gcc >= 4.1 and the default target CPU architecture is "i386", try to add CFLAGS="-march=i686" and CXXFLAGS="-march=i686" options to ./configure as follows: $ ./configure CFLAGS="-march=i686" CXXFLAGS="-march=i686" ]) + + else + enable_gcc_cxx_atomic=yes + fi fi +AM_CONDITIONAL(ENABLE_GCC_CXX_ATOMIC, test "$enable_gcc_cxx_atomic" = "yes") + major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index d96217a5..4a5dae26 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -10,10 +10,15 @@ libmsgpack_la_SOURCES = \ if ENABLE_CXX libmsgpack_la_SOURCES += \ - object.cpp \ + object.cpp +endif + +if ENABLE_GCC_CXX_ATOMIC +libmsgpack_la_SOURCES += \ gcc_atomic.cpp endif + # -version-info CURRENT:REVISION:AGE libmsgpack_la_LDFLAGS = -version-info 3:0:0