@ -10,16 +10,24 @@ adds compile definitions thereof. Namely:
- x 8 6 _ 6 4
- x 8 6
- i a 6 4
- m i p s 6 4
- m i p s
- p p c 6 4
- p p c
- r i s c v
- r i s c v 6 4
- l o o n g a r c h 6 4
- w a s m
U n s u p p o r t e d a r c h i t e c t u r e s :
- A R M v 2 - 6
- m 6 8 k
- P I C
T h i s f i l e W I L L N O T d e t e c t e n d i a n - n e s s f o r y o u .
T h i s f i l e i s b a s e d o f f o f Y u z u a n d D y n a r m i c .
T O D O : a d d S P A R C
] ]
include ( CheckSymbolExists )
# m u l t i a r c h b u i l d s a r e a s p e c i a l c a s e a n d a l s o v e r y d i f f i c u l t
# t h i s i s w h a t I h a v e f o r n o w , b u t i t ' s n o t i d e a l
@ -40,13 +48,18 @@ if (CMAKE_OSX_ARCHITECTURES)
return ( )
endif ( )
include ( CheckSymbolExists )
function ( detect_architecture symbol arch )
# T h e o u t p u t v a r i a b l e n e e d s t o b e u n s e t b e t w e e n i n v o c a t i o n s o t h e r w i s e
# C M a k e ' s c r a z y s c o p e r u l e s w i l l k e e p i t d e f i n e d
unset ( SYMBOL_EXISTS CACHE )
if ( NOT DEFINED ARCHITECTURE )
set ( CMAKE_REQUIRED_QUIET 1 )
check_symbol_exists ( "${symbol}" "" ARCHITECTURE_ ${ arch } )
check_symbol_exists ( "${symbol}" "" SYMBOL_EXISTS )
unset ( CMAKE_REQUIRED_QUIET )
if ( ARCHITECTURE_ ${ arch } )
if ( SYMBOL_EXISTS )
set ( ARCHITECTURE "${arch}" PARENT_SCOPE )
set ( ARCHITECTURE_ ${ arch } 1 PARENT_SCOPE )
add_definitions ( -DARCHITECTURE_ ${ arch } =1 )
@ -54,43 +67,159 @@ function(detect_architecture symbol arch)
endif ( )
endfunction ( )
detect_architecture ( "__ARM64__" arm64 )
detect_architecture ( "__aarch64__" arm64 )
detect_architecture ( "_M_ARM64" arm64 )
detect_architecture ( "__arm__" arm )
detect_architecture ( "__TARGET_ARCH_ARM" arm )
detect_architecture ( "_M_ARM" arm )
detect_architecture ( "__x86_64" x86_64 )
detect_architecture ( "__x86_64__" x86_64 )
detect_architecture ( "__amd64" x86_64 )
detect_architecture ( "_M_X64" x86_64 )
function ( detect_architecture_symbols )
if ( DEFINED ARCHITECTURE )
return ( )
endif ( )
detect_architecture ( "__i386" x86 )
detect_architecture ( "__i386__" x86 )
detect_architecture ( "_M_IX86" x86 )
set ( oneValueArgs ARCH )
set ( multiValueArgs SYMBOLS )
detect_architecture ( "__ia64" ia64 )
detect_architecture ( "__ia64__" ia64 )
detect_architecture ( "_M_IA64" ia64 )
cmake_parse_arguments ( ARGS "" "${oneValueArgs}" "${multiValueArgs}"
" $ { A R G N } " )
detect_architecture ( "__mips" mips )
detect_architecture ( "__mips__" mips )
detect_architecture ( "_M_MRX000" mips )
set ( arch "${ARGS_ARCH}" )
foreach ( symbol ${ ARGS_SYMBOLS } )
detect_architecture ( "${symbol}" "${arch}" )
detect_architecture ( "__ppc64__" ppc64 )
detect_architecture ( "__powerpc64__" ppc64 )
if ( ARCHITECTURE_ ${ arch } )
message ( DEBUG "[DetectArchitecture] Found architecture symbol ${symbol} for ${arch}" )
set ( ARCHITECTURE "${arch}" PARENT_SCOPE )
set ( ARCHITECTURE_ ${ arch } 1 PARENT_SCOPE )
add_definitions ( -DARCHITECTURE_ ${ arch } =1 )
detect_architecture ( "__ppc__" ppc )
detect_architecture ( "__ppc" ppc )
detect_architecture ( "__powerpc__" ppc )
detect_architecture ( "_ARCH_COM" ppc )
detect_architecture ( "_ARCH_PWR" ppc )
detect_architecture ( "_ARCH_PPC" ppc )
detect_architecture ( "_M_MPPC" ppc )
detect_architecture ( "_M_PPC" ppc )
return ( )
endif ( )
endforeach ( )
endfunction ( )
detect_architecture ( "__riscv" riscv )
function ( DetectArchitecture )
# a r c h e s h e r e a r e p u t i n a s a n e d e f a u l t o r d e r o f i m p o r t a n c e
# n o t a b l y , a m d 6 4 , a r m 6 4 , a n d riscv ( in order ) a r e B Y F A R t h e m o s t c o m m o n
# m i p s i s p r e t t y p o p u l a r i n e m b e d d e d
# p p c 6 4 i s p r e t t y p o p u l a r i n s u p e r c o m p u t i n g
# s p a r c i s u h
# i a 6 4 e x i s t s
# t h e r e s t e x i s t , b u t a r e p r o b a b l y l e s s p o p u l a r t h a n i a 6 4
detect_architecture_symbols (
A R C H a r m 6 4
S Y M B O L S
" _ _ A R M 6 4 _ _ "
" _ _ a a r c h 6 4 _ _ "
" _ M _ A R M 6 4 " )
detect_architecture_symbols (
A R C H x 8 6 _ 6 4
S Y M B O L S
" _ _ x 8 6 _ 6 4 "
" _ _ x 8 6 _ 6 4 _ _ "
" _ _ a m d 6 4 "
" _ M _ X 6 4 "
" _ M _ A M D 6 4 " )
# r i s c v i s i n t e r e s t i n g s i n c e i t g e n e r a l l y d o e s n o t d e f i n e a r i s c v 6 4 - s p e c i f i c s y m b o l
# W e c a n , h o w e v e r , c h e c k f o r t h e r v 3 2 z c f e x t e n s i o n w h i c h i s g o o d e n o u g h o f a h e u r i s t i c o n G C C
detect_architecture_symbols (
A R C H r i s c v
S Y M B O L S
" _ _ r i s c v _ z c f " )
# i f z c f d o e s n ' t e x i s t w e c a n s a f e l y a s s u m e i t ' s r i s c v 6 4
detect_architecture_symbols (
A R C H r i s c v 6 4
S Y M B O L S
" _ _ r i s c v " )
detect_architecture_symbols (
A R C H x 8 6
S Y M B O L S
" _ _ i 3 8 6 "
" _ _ i 3 8 6 _ _ "
" _ M _ I X 8 6 " )
detect_architecture_symbols (
A R C H a r m
S Y M B O L S
" _ _ a r m _ _ "
" _ _ T A R G E T _ A R C H _ A R M "
" _ M _ A R M " )
detect_architecture_symbols (
A R C H i a 6 4
S Y M B O L S
" _ _ i a 6 4 "
" _ _ i a 6 4 _ _ "
" _ M _ I A 6 4 " )
# m i p s i s p r o b a b l y t h e l e a s t f u n t o d e t e c t d u e t o m i c r o M I P S
# B e c a u s e m i c r o M I P S i s s u c h c a n c e r I ' m c o n s i d e r i n g i t o u t o f s c o p e f o r n o w
detect_architecture_symbols (
A R C H m i p s 6 4
S Y M B O L S
" _ _ m i p s 6 4 " )
detect_architecture_symbols (
A R C H m i p s
S Y M B O L S
" _ _ m i p s "
" _ _ m i p s _ _ "
" _ M _ M R X 0 0 0 " )
detect_architecture_symbols (
A R C H p p c 6 4
S Y M B O L S
" _ _ p p c 6 4 _ _ "
" _ _ p o w e r p c 6 4 _ _ "
" _ A R C H _ P P C 6 4 "
" _ M _ P P C 6 4 " )
detect_architecture_symbols (
A R C H p p c
S Y M B O L S
" _ _ p p c _ _ "
" _ _ p p c "
" _ _ p o w e r p c _ _ "
" _ A R C H _ C O M "
" _ A R C H _ P W R "
" _ A R C H _ P P C "
" _ M _ M P P C "
" _ M _ P P C " )
detect_architecture_symbols (
A R C H s p a r c 6 4
S Y M B O L S
" _ _ s p a r c _ v 9 _ _ " )
detect_architecture_symbols (
A R C H s p a r c
S Y M B O L S
" _ _ s p a r c _ _ "
" _ _ s p a r c " )
# I d o n ' t a c t u a l l y k n o w a b o u t l o o n g a r c h 3 2 s i n c e c r o s s d e v d o e s n o t s u p p o r t i t , o n l y 6 4
detect_architecture_symbols (
A R C H l o o n g a r c h 6 4
S Y M B O L S
" _ _ l o o n g a r c h _ _ "
" _ _ l o o n g a r c h 6 4 " )
detect_architecture_symbols (
A R C H w a s m
S Y M B O L S
" _ _ E M S C R I P T E N _ _ " )
# " g e n e r i c " t a r g e t
# I f y o u h a v e r e a c h e d t h i s p o i n t , y o u ' r e o n s o m e a s - o f - y e t u n s u p p o r t e d a r c h i t e c t u r e .
# S e e t h e d o c s u p a b o v e f o r k n o w n u n s u p p o r t e d a r c h i t e c t u r e s
# I f y o u ' r e n o t i n t h e l i s t . . . I t h i n k y o u k n o w w h a t y o u ' r e d o i n g .
if ( NOT DEFINED ARCHITECTURE )
set ( ARCHITECTURE "GENERIC" )
set ( ARCHITECTURE_GENERIC 1 )
add_definitions ( -DARCHITECTURE_GENERIC=1 )
endif ( )
detect_architecture ( "__EMSCRIPTEN__" wasm )
message ( STATUS "[DetectArchitecture] Target architecture: ${ARCHITECTURE}" )
set ( ARCHITECTURE "${ARCHITECTURE}" PARENT_SCOPE )
set ( ARCHITECTURE_ ${ ARCHITECTURE } 1 PARENT_SCOPE )
endfunction ( )