Skip to content

Commit 839cacb

Browse files
committed
yokai: rework of the architecture and system detection
1 parent bef5e94 commit 839cacb

2 files changed

Lines changed: 75 additions & 53 deletions

File tree

‎cmake/Yokai/Architecture.cmake‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@
2828
# Architecture detection.
2929
################################################################################
3030

31-
# When adding a new architecture, look at all the places YOKAI_TARGET_ARCH is used.
31+
# When adding a new architecture, look at all the places YOKAI_HOST_ARCH
32+
# and YOKAI_TARGET_ARCH are used.
3233

3334
option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON)
3435
mark_as_advanced(USE_ARCH_INTRINSICS)
3536

36-
function(yokai_detect_arch)
37+
function(yokai_detect_target_arch)
3738
yokai_run_detection("TARGET" "ARCH" "Architecture.c" "")
3839

3940
set(YOKAI_TARGET_ARCH_NAME "${arch_name}" PARENT_SCOPE)
4041
set(YOKAI_TARGET_ARCH_NAME_UPPER "${arch_name_upper}" PARENT_SCOPE)
4142

42-
message(STATUS "Detected target architecture: ${arch_name}")
43-
4443
add_definitions(-DYOKAI_ARCH_${arch_name_upper})
44+
45+
# Makes possible to do that in CMake code:
46+
# > if (YOKAI_TARGET_ARCH_AMD64)
47+
set("YOKAI_TARGET_ARCH_${arch_name_upper}" ON PARENT_SCOPE)
4548
endfunction()
4649

4750
function(yokai_set_arch_intrinsics name)
@@ -50,9 +53,6 @@ function(yokai_set_arch_intrinsics name)
5053
add_definitions(-DYOKAI_USE_ARCH_INTRINSICS_${name_upper})
5154
endfunction()
5255

53-
option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON)
54-
mark_as_advanced(USE_ARCH_INTRINSICS)
55-
5656
function(yokai_set_intrinsics)
5757
if (USE_ARCH_INTRINSICS)
5858
# Makes possible to do that in C++ code:
@@ -61,7 +61,6 @@ function(yokai_set_intrinsics)
6161

6262
# Makes possible to do that in C++ code:
6363
# > if defined(YOKAI_USE_ARCH_INTRINSICS_AMD64)
64-
# > if defined(YOKAI_USE_ARCH_INTRINSICS_I686)
6564
yokai_set_arch_intrinsics("${YOKAI_TARGET_ARCH_NAME}")
6665

6766
set(amd64_PARENT "i686")
@@ -76,14 +75,23 @@ function(yokai_set_intrinsics)
7675
endif()
7776
endfunction()
7877

79-
yokai_detect_arch()
80-
yokai_set_intrinsics()
78+
yokai_detect_target_arch()
8179

82-
# Makes possible to do that in CMake code:
83-
# > if (YOKAI_TARGET_ARCH_ARM64)
84-
set("YOKAI_TARGET_ARCH_${YOKAI_TARGET_ARCH_NAME_UPPER}" ON)
80+
if (YOKAI_HOST_ARCH_UNKNOWN)
81+
message(WARNING "Unknown host architecture")
82+
else()
83+
message(STATUS "Detected host architecture: ${YOKAI_HOST_ARCH_NAME}")
84+
endif()
85+
86+
if (YOKAI_TARGET_ARCH_UNKNOWN)
87+
message(WARNING "Unknown target architecture")
88+
else()
89+
message(STATUS "Detected target architecture: ${YOKAI_TARGET_ARCH_NAME}")
90+
endif()
8591

8692
if (YOKAI_SOURCE_GENERATOR)
8793
# Add printable strings to the executable.
8894
yokai_add_buildinfo("char*" "YOKAI_ARCH_STRING" "\"${YOKAI_TARGET_ARCH_NAME}\"")
8995
endif()
96+
97+
yokai_set_intrinsics()

‎cmake/Yokai/System.cmake‎

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,89 +34,103 @@
3434
function(yokai_detect_host_system)
3535
set(system_name "Unknown")
3636

37-
foreach(name Linux;FreeBSD;Android;Windows)
37+
foreach(name
38+
"Linux"
39+
"FreeBSD"
40+
"Android"
41+
"Windows"
42+
)
3843
if (CMAKE_HOST_SYSTEM_NAME MATCHES "${name}")
39-
set(system_name "${CMAKE_SYSTEM_NAME}")
44+
set(system_name "${CMAKE_HOST_SYSTEM_NAME}")
4045
endif()
4146
endforeach()
4247

43-
if (system_name STREQUAL "Unknown")
48+
if ("${system_name}" STREQUAL "Unknown")
4449
set(SYSTEM_Darwin "macOS")
4550
set(SYSTEM_MSYS "Windows")
4651

47-
foreach(name Darwin;MSYS)
52+
foreach(name
53+
"Darwin"
54+
"MSYS"
55+
)
4856
if ("${CMAKE_HOST_SYSTEM_NAME}" MATCHES "${name}")
4957
set(system_name "${SYSTEM_${name}}")
5058
endif()
5159
endforeach()
5260
endif()
5361

54-
if (system_name STREQUAL "Unknown")
55-
message(WARNING "Host system detection failed, may misdetect the target as the host.")
56-
57-
if (WIN32)
58-
set(system_name "Windows")
59-
elseif (APPLE)
60-
set(system_name "macOS")
61-
endif()
62-
endif()
62+
string(TOUPPER "${system_name}" system_name_upper)
6363

6464
set(YOKAI_HOST_SYSTEM_NAME "${system_name}" PARENT_SCOPE)
6565
set(YOKAI_HOST_SYSTEM_NAME_UPPER "${system_name_upper}" PARENT_SCOPE)
66+
67+
# Makes possible to do that in CMake code:
68+
# > if (YOKAI_HOST_SYSTEM_LINUX)
69+
set(YOKAI_HOST_SYSTEM_${system_name_upper} ON PARENT_SCOPE)
6670
endfunction()
6771

68-
function(yokai_detect_system)
72+
function(yokai_detect_target_system)
6973
yokai_run_detection("TARGET" "SYSTEM" "System.c" "Linux")
7074

71-
if (system_name STREQUAL "Unknown")
72-
detect_cmake_host_system("system_name")
73-
endif()
74-
7575
set(YOKAI_TARGET_SYSTEM_NAME "${system_name}" PARENT_SCOPE)
7676
set(YOKAI_TARGET_SYSTEM_NAME_UPPER "${system_name_upper}" PARENT_SCOPE)
77+
78+
# Makes possible to do that in CMake code:
79+
# > if (YOKAI_TARGET_SYSTEM_LINUX)
80+
set(YOKAI_TARGET_SYSTEM_${system_name_upper} ON PARENT_SCOPE)
7781
endfunction()
7882

7983
yokai_detect_host_system()
80-
yokai_detect_system()
81-
82-
if ("${YOKAI_HOST_SYSTEM_NAME}" STREQUAL "Unknown")
83-
message(WARNING "Unknown host system")
84-
endif()
84+
yokai_detect_target_system()
8585

86-
if ("${YOKAI_TARGET_SYSTEM_NAME}" STREQUAL "Unknown")
87-
message(WARNING "Unknown target system")
88-
endif()
89-
90-
if ("${YOKAI_HOST_SYSTEM_NAME}" STREQUAL "Unknown" AND NOT "${YOKAI_TARGET_SYSTEM_NAME}" STREQUAL "Unknown")
86+
if (YOKAI_HOST_SYSTEM_UNKNOWN AND NOT YOKAI_TARGET_SYSTEM_UNKNOWN)
9187
message(WARNING "Assuming the host system is the same as the target: ${YOKAI_TARGET_SYSTEM_NAME}")
9288
set(YOKAI_HOST_SYSTEM_NAME "${YOKAI_TARGET_SYSTEM_NAME}")
89+
set(YOKAI_HOST_SYSTEM_NAME_UPPER "${YOKAI_TARGET_SYSTEM_NAME_UPPER}")
90+
set(YOKAI_HOST_SYSTEM_${YOKAI_HOST_SYSTEM_NAME_UPPER} ON)
91+
unset(YOKAI_HOST_SYSTEM_UNKNOWN)
9392
endif()
9493

95-
if ("${YOKAI_TARGET_SYSTEM_NAME}" STREQUAL "Unknown" AND NOT "${YOKAI_HOST_SYSTEM_NAME}" STREQUAL "Unknown")
94+
if (YOKAI_TARGET_SYSTEM_UNKNOWN AND NOT YOKAI_HOST_SYSTEM_UNKNOWN)
9695
message(WARNING "Assuming the target system is the same as the host: ${YOKAI_TARGET_SYSTEM_NAME}")
9796
set(YOKAI_TARGET_SYSTEM_NAME "${YOKAI_HOST_SYSTEM_NAME}")
97+
set(YOKAI_TARGET_SYSTEM_NAME_UPPER "${YOKAI_HOST_SYSTEM_NAME_UPPER}")
98+
set(YOKAI_TARGET_SYSTEM_${YOKAI_TARGET_SYSTEM_NAME_UPPER} ON)
99+
unset(YOKAI_TARGET_SYSTEM_UNKNOWN)
100+
endif()
101+
102+
if (YOKAI_HOST_SYSTEM_UNKNOWN)
103+
message(WARNING "Unknown host system")
104+
else()
105+
message(STATUS "Detected host system: ${YOKAI_HOST_SYSTEM_NAME}")
98106
endif()
99107

100-
message(STATUS "Detected host system: ${YOKAI_HOST_SYSTEM_NAME}")
101-
message(STATUS "Detected target system: ${YOKAI_TARGET_SYSTEM_NAME}")
108+
if (YOKAI_TARGET_SYSTEM_UNKNOWN)
109+
message(WARNING "Unknown target system")
110+
else()
111+
message(STATUS "Detected target system: ${YOKAI_TARGET_SYSTEM_NAME}")
112+
endif()
102113

103114
if (NOT "${YOKAI_HOST_SYSTEM_NAME}" STREQUAL "${YOKAI_TARGET_SYSTEM_NAME}")
104-
message(STATUS "Detected cross-compilation")
115+
message(STATUS "Detected system cross-compilation")
116+
set(YOKAI_SYSTEM_CROSS ON)
117+
else()
118+
message(STATUS "No system cross-compilation detected")
105119
endif()
106120

107-
# Makes possible to do that in CMake code:
108-
# > if (YOKAI_HOST_SYSTEM_LINUX)
109-
# > if (YOKAI_TARGET_SYSTEM_WINDOWS)
110-
set("YOKAI_HOST_SYSTEM_${YOKAI_HOST_SYSTEM_NAME_UPPER}" ON)
111-
set("YOKAI_TARGET_SYSTEM_${YOKAI_TARGET_SYSTEM_NAME_UPPER}" ON)
112-
113121
# This is for systems behaving similarly to a Linux Desktop,
114122
# implementing standards like FHS, XDG, GLVND…
115123
# Makes possible to do that in CMake code:
116124
# > if (YOKAI_HOST_SYSTEM_XDG_COMPATIBILITY)
117125
# > if (YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY)
118-
foreach(name LINUX;FREEBSD)
119-
foreach(slug HOST_SYSTEM;TARGET_SYSTEM)
126+
foreach(name
127+
"LINUX"
128+
"FREEBSD"
129+
)
130+
foreach(slug
131+
"HOST_SYSTEM"
132+
"TARGET_SYSTEM"
133+
)
120134
if (YOKAI_${slug}_${name})
121135
set(YOKAI_${slug}_XDG_COMPATIBILITY ON)
122136
endif()

0 commit comments

Comments
 (0)