Skip to content

Commit

Permalink
Define ARCH_STRING via CMake on Linux, BSD etc.
Browse files Browse the repository at this point in the history
This is ioquake/ioq3#129, adapted for the OpenJK codebase.

GNU and *BSD platforms have a built-in way to determine endianness,
so all architectures except x86_64 are in fact treated identically,
except that their ARCH_STRING is different. The ARCH_STRING must always
be identical to the Architecture from CMake, otherwise the engine will
not find its cgame, game and ui plugins under their expected names
and startup will fail. If we pass it in from CMake, then an identical
value is guaranteed, and we can get rid of an increasingly long list of
defined(__some_cpu__) tests.

The one remaining quirk is that we test the predefined macro __x86_64__
(on Linux and other GNU platforms) or __amd64__ (on *BSD) to determine
whether to define idx64; I've kept that, but separated it from the
ARCH_STRING.

OpenJK does not distinguish between GNU and *BSD platforms in its build
system, so unlike my similar ioquake3 patch, I've included an untested
version of the same change for *BSD. Windows and OS X only support a
few architectures anyway, so keeping the list up to date is less of a
burden there.
  • Loading branch information
smcv committed Jul 26, 2015
1 parent 75c2c45 commit 6e8a0b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 70 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Expand Up @@ -158,6 +158,10 @@ if (APPLE)
set(SharedDefines "MACOS_X")
endif()

if (NOT WIN32 AND NOT APPLE)
set(SharedDefines "ARCH_STRING=\"${Architecture}\"")
endif()

# Compiler settings
if(MSVC)

Expand Down
47 changes: 11 additions & 36 deletions code/qcommon/q_platform.h
Expand Up @@ -131,36 +131,12 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.

#define PATH_SEP '/'

#if !defined(ARCH_STRING)
#error ARCH_STRING should be defined by the build system
#endif

#if defined(__i386__)
#define ARCH_STRING "i386"
#elif defined(__x86_64__)
#if defined(__x86_64__)
#define idx64
#define ARCH_STRING "x86_64"
#elif defined(__powerpc64__)
#define ARCH_STRING "ppc64"
#elif defined(__powerpc__)
#define ARCH_STRING "ppc"
#elif defined(__s390__)
#define ARCH_STRING "s390"
#elif defined(__s390x__)
#define ARCH_STRING "s390x"
#elif defined(__ia64__)
#define ARCH_STRING "ia64"
#elif defined(__alpha__)
#define ARCH_STRING "alpha"
#elif defined(__sparc__)
#define ARCH_STRING "sparc"
#elif defined(__arm__)
#define ARCH_STRING "arm"
#elif defined(__cris__)
#define ARCH_STRING "cris"
#elif defined(__hppa__)
#define ARCH_STRING "hppa"
#elif defined(__mips__)
#define ARCH_STRING "mips"
#elif defined(__sh__)
#define ARCH_STRING "sh"
#endif

#if __FLOAT_WORD_ORDER == __BIG_ENDIAN
Expand Down Expand Up @@ -191,16 +167,15 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.

#define QINLINE inline
#define PATH_SEP '/'

#if defined(__i386__)
#define ARCH_STRING "i386"
#elif defined(__amd64__)

#if !defined(ARCH_STRING)
#error ARCH_STRING should be defined by the build system
#endif

#if defined(__amd64__)
#define idx64
#define ARCH_STRING "amd64"
#elif defined(__axp__)
#define ARCH_STRING "alpha"
#endif

#if BYTE_ORDER == BIG_ENDIAN
#define Q3_BIG_ENDIAN
#else
Expand Down
43 changes: 9 additions & 34 deletions codemp/qcommon/q_platform.h
Expand Up @@ -131,36 +131,12 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.

#define PATH_SEP '/'

#if !defined(ARCH_STRING)
#error ARCH_STRING should be defined by the build system
#endif

#if defined(__i386__)
#define ARCH_STRING "i386"
#elif defined(__x86_64__)
#if defined(__x86_64__)
#define idx64
#define ARCH_STRING "x86_64"
#elif defined(__powerpc64__)
#define ARCH_STRING "ppc64"
#elif defined(__powerpc__)
#define ARCH_STRING "ppc"
#elif defined(__s390__)
#define ARCH_STRING "s390"
#elif defined(__s390x__)
#define ARCH_STRING "s390x"
#elif defined(__ia64__)
#define ARCH_STRING "ia64"
#elif defined(__alpha__)
#define ARCH_STRING "alpha"
#elif defined(__sparc__)
#define ARCH_STRING "sparc"
#elif defined(__arm__)
#define ARCH_STRING "arm"
#elif defined(__cris__)
#define ARCH_STRING "cris"
#elif defined(__hppa__)
#define ARCH_STRING "hppa"
#elif defined(__mips__)
#define ARCH_STRING "mips"
#elif defined(__sh__)
#define ARCH_STRING "sh"
#endif

#if __FLOAT_WORD_ORDER == __BIG_ENDIAN
Expand Down Expand Up @@ -192,13 +168,12 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#define QINLINE inline
#define PATH_SEP '/'

#if defined(__i386__)
#define ARCH_STRING "i386"
#elif defined(__amd64__)
#if !defined(ARCH_STRING)
#error ARCH_STRING should be defined by the build system
#endif

#if defined(__amd64__)
#define idx64
#define ARCH_STRING "amd64"
#elif defined(__axp__)
#define ARCH_STRING "alpha"
#endif

#if BYTE_ORDER == BIG_ENDIAN
Expand Down

0 comments on commit 6e8a0b7

Please sign in to comment.