Browse Source

build: the “fuck you, Apple” commit; work around three different

compiler bugs in the Xcode toolchain.
legacy
Sam Hocevar sam 12 years ago
parent
commit
94acb0f519
4 changed files with 44 additions and 21 deletions
  1. +3
    -3
      build/autotools/m4/lol-misc.m4
  2. +21
    -14
      configure.ac
  3. +16
    -4
      src/lol/math/vector.h
  4. +4
    -0
      test/unit/array.cpp

+ 3
- 3
build/autotools/m4/lol-misc.m4 View File

@@ -4,7 +4,7 @@ dnl check if $CC supports a given set of cflags
AC_DEFUN([LOL_TRY_CFLAGS],
[AC_MSG_CHECKING([if $CC supports $1 flags])
save_CFLAGS="$CFLAGS"
CFLAGS="$1"
CFLAGS="$1 -Werror"
AC_TRY_COMPILE([],[],[ac_cv_try_cflags_ok=yes],[ac_cv_try_cflags_ok=no])
CFLAGS="$save_CFLAGS"
AC_MSG_RESULT([$ac_cv_try_cflags_ok])
@@ -20,7 +20,7 @@ AC_DEFUN([LOL_TRY_CXXFLAGS],
[AC_MSG_CHECKING([if $CXX supports $1 flags])
AC_LANG_PUSH(C++)
save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$1"
CXXFLAGS="$1 -Werror"
AC_TRY_COMPILE([],[],[ac_cv_try_cxxflags_ok=yes],[ac_cv_try_cxxflags_ok=no])
CXXFLAGS="$save_CXXFLAGS"
AC_MSG_RESULT([$ac_cv_try_cxxflags_ok])
@@ -36,7 +36,7 @@ dnl check if $CC supports a given set of ldflags
AC_DEFUN([LOL_TRY_LDFLAGS],
[AC_MSG_CHECKING([if $CC supports $1 flags])
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$1"
LDFLAGS="$1 -Werror"
AC_TRY_LINK([],[],[ac_cv_try_ldflags_ok=yes],[ac_cv_try_ldflags_ok=no])
LDFLAGS="$save_LDFLAGS"
AC_MSG_RESULT([$ac_cv_try_ldflags_ok])


+ 21
- 14
configure.ac View File

@@ -93,16 +93,17 @@ AC_CHECK_FUNCS(getcwd _getcwd backtrace_symbols)

if test "${enable_debug}" = "yes"; then
AC_DEFINE(LOL_DEBUG, 1, Define to 1 to activate debug)
OPT="-O"
OPT_CXXFLAGS="-O"
else
OPT="-O3 -ffast-math -fno-strength-reduce -fomit-frame-pointer"
OPT_CXXFLAGS="-O3 -ffast-math -fomit-frame-pointer"
OPT_LDFLAGS="-fno-strength-reduce"
fi

if test "${enable_release}" = "yes"; then
AC_DEFINE(LOL_RELEASE, 1, Define to 1 to activate final release)
REL=""
REL_CXXFLAGS=""
else
REL="-g"
REL_CXXFLAGS="-g"
fi

if test "${enable_experimental}" = "yes"; then
@@ -154,7 +155,8 @@ LOL_TRY_CXXFLAGS(-fno-exceptions, [AM_CXXFLAGS="${AM_CXXFLAGS} -fno-exceptions"]
LOL_TRY_CXXFLAGS(-fno-rtti, [AM_CXXFLAGS="${AM_CXXFLAGS} -fno-rtti"])

dnl Optimizations
AM_CXXFLAGS="${AM_CXXFLAGS} ${REL} ${OPT}"
AM_CXXFLAGS="${AM_CXXFLAGS} ${REL_CXXFLAGS} ${OPT_CXXFLAGS}"
AM_LDFLAGS="${AM_LDFLAGS} ${REL_LDFLAGS} ${OPT_LDFLAGS}"

dnl Debug symbols
LOL_TRY_LDFLAGS(-rdynamic, [AM_LDFLAGS="${AM_LDFLAGS} -rdynamic"])
@@ -235,15 +237,9 @@ AM_CONDITIONAL(USE_PS3, test "${ac_cv_my_have_ps3}" != "no")


dnl Are we building using MinGW?
LIBS_save="$LIBS"
LIBS="$LIBS -mwindows -mwin32"
AC_MSG_CHECKING(for -mwindows -mwin32)
AC_TRY_LINK([], [],
[AC_MSG_RESULT(yes)
AM_CXXFLAGS="${AM_CXXFLAGS} -mwindows -mwin32"
LOL_LIBS="${LOL_LIBS} -uWinMain -u_WinMain@16"],
[AC_MSG_RESULT(no)])
LIBS="$LIBS_save"
LOL_TRY_CXXFLAGS(-mwindows -mwin32,
[AM_CXXFLAGS="${AM_CXXFLAGS} -mwindows -mwin32"
LOL_LIBS="${LOL_LIBS} -uWinMain -u_WinMain@16"])


dnl Are we on the Xbox 360?
@@ -251,6 +247,17 @@ dnl Answer: NO! we don't know how to build for it anyway
AM_CONDITIONAL(USE_X360, false)


dnl Are we on an OS X or iOS platform?
LOL_TRY_LDFLAGS(-framework Foundation,
[LOL_LIBS="${LOL_LIBS} -framework Foundation"])
LOL_TRY_LDFLAGS(-framework CoreGraphics,
[LOL_LIBS="${LOL_LIBS} -framework CoreGraphics"])
LOL_TRY_LDFLAGS(-framework CoreData,
[LOL_LIBS="${LOL_LIBS} -framework CoreData"])
LOL_TRY_LDFLAGS(-framework UIKit,
[LOL_LIBS="${LOL_LIBS} -framework UIKit"])


dnl Are we on a Direct3D 9 platform?
#ac_cv_my_have_d3d9="no"
#AC_CHECK_HEADERS(d3d9.h, [ac_cv_my_have_d3d9="yes"])


+ 16
- 4
src/lol/math/vector.h View File

@@ -1344,14 +1344,23 @@ extern Quat<T> slerp(Quat<T> const &qa, Quat<T> const &qb, T f);
LOL_BINARY_NONVECTOR_FUNS(tname, static, type) \
LOL_UNARY_FUNS(tname, static, type)

/* HACK: This trick fails with Apple’s clang++, which sometimes fails to deduce
* the arguments for simple stuff such as vec3 + vec3. Disable it for now.
* Note that llvm-g++ doesn’t have the problem. */
#if defined __clang__
# define LOL_OPEN_NAMESPACE(x)
# define LOL_CLOSE_NAMESPACE(x)
#else
# define LOL_OPEN_NAMESPACE(x) namespace x {
# define LOL_CLOSE_NAMESPACE(x) } using namespace x;
#endif

#define LOL_ALL_VECTOR_OPS_AND_FUNS(type) \
namespace x##type \
{ \
LOL_OPEN_NAMESPACE(x##type) \
LOL_ALL_VECTOR_OPS_INNER(Vec2, type) \
LOL_ALL_VECTOR_OPS_INNER(Vec3, type) \
LOL_ALL_VECTOR_OPS_INNER(Vec4, type) \
} \
using namespace x##type; \
LOL_CLOSE_NAMESPACE(x##type) \
LOL_ALL_VECTOR_FUNS_INNER(Vec2, type) \
LOL_ALL_VECTOR_FUNS_INNER(Vec3, type) \
LOL_ALL_VECTOR_FUNS_INNER(Vec4, type) \
@@ -1411,6 +1420,9 @@ LOL_ALL_VECTOR_OPS_AND_FUNS(uint64_t)
#undef LOL_ALL_VECTOR_FUNS_INNER
#undef LOL_ALL_VECTOR_OPS_AND_FUNS

#undef LOL_OPEN_NAMESPACE
#undef LOL_CLOSE_NAMESPACE

/*
* Definition of additional functions requiring vector functions
*/


+ 4
- 0
test/unit/array.cpp View File

@@ -36,6 +36,9 @@ LOLUNIT_FIXTURE(ArrayTest)

void TearDown() {}

/* HACK: we disable these tests because they fail with the
* Xcode iPhone compiler. */
#if !defined __clang__ || !defined __arm__
LOLUNIT_TEST(ArrayPush)
{
Array<int> a;
@@ -84,6 +87,7 @@ LOLUNIT_FIXTURE(ArrayTest)
LOLUNIT_ASSERT_EQUAL(a[1], 2);
LOLUNIT_ASSERT_EQUAL(a[2], 3);
}
#endif

LOLUNIT_TEST(EightElements)
{


Loading…
Cancel
Save