|
34 | 34 | function(yokai_detect_host_system) |
35 | 35 | set(system_name "Unknown") |
36 | 36 |
|
37 | | - foreach(name Linux;FreeBSD;Android;Windows) |
| 37 | + foreach(name |
| 38 | + "Linux" |
| 39 | + "FreeBSD" |
| 40 | + "Android" |
| 41 | + "Windows" |
| 42 | + ) |
38 | 43 | if (CMAKE_HOST_SYSTEM_NAME MATCHES "${name}") |
39 | | - set(system_name "${CMAKE_SYSTEM_NAME}") |
| 44 | + set(system_name "${CMAKE_HOST_SYSTEM_NAME}") |
40 | 45 | endif() |
41 | 46 | endforeach() |
42 | 47 |
|
43 | | - if (system_name STREQUAL "Unknown") |
| 48 | + if ("${system_name}" STREQUAL "Unknown") |
44 | 49 | set(SYSTEM_Darwin "macOS") |
45 | 50 | set(SYSTEM_MSYS "Windows") |
46 | 51 |
|
47 | | - foreach(name Darwin;MSYS) |
| 52 | + foreach(name |
| 53 | + "Darwin" |
| 54 | + "MSYS" |
| 55 | + ) |
48 | 56 | if ("${CMAKE_HOST_SYSTEM_NAME}" MATCHES "${name}") |
49 | 57 | set(system_name "${SYSTEM_${name}}") |
50 | 58 | endif() |
51 | 59 | endforeach() |
52 | 60 | endif() |
53 | 61 |
|
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) |
63 | 63 |
|
64 | 64 | set(YOKAI_HOST_SYSTEM_NAME "${system_name}" PARENT_SCOPE) |
65 | 65 | 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) |
66 | 70 | endfunction() |
67 | 71 |
|
68 | | -function(yokai_detect_system) |
| 72 | +function(yokai_detect_target_system) |
69 | 73 | yokai_run_detection("TARGET" "SYSTEM" "System.c" "Linux") |
70 | 74 |
|
71 | | - if (system_name STREQUAL "Unknown") |
72 | | - detect_cmake_host_system("system_name") |
73 | | - endif() |
74 | | - |
75 | 75 | set(YOKAI_TARGET_SYSTEM_NAME "${system_name}" PARENT_SCOPE) |
76 | 76 | 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) |
77 | 81 | endfunction() |
78 | 82 |
|
79 | 83 | 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() |
85 | 85 |
|
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) |
91 | 87 | message(WARNING "Assuming the host system is the same as the target: ${YOKAI_TARGET_SYSTEM_NAME}") |
92 | 88 | 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) |
93 | 92 | endif() |
94 | 93 |
|
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) |
96 | 95 | message(WARNING "Assuming the target system is the same as the host: ${YOKAI_TARGET_SYSTEM_NAME}") |
97 | 96 | 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}") |
98 | 106 | endif() |
99 | 107 |
|
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() |
102 | 113 |
|
103 | 114 | 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") |
105 | 119 | endif() |
106 | 120 |
|
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 | | - |
113 | 121 | # This is for systems behaving similarly to a Linux Desktop, |
114 | 122 | # implementing standards like FHS, XDG, GLVND… |
115 | 123 | # Makes possible to do that in CMake code: |
116 | 124 | # > if (YOKAI_HOST_SYSTEM_XDG_COMPATIBILITY) |
117 | 125 | # > 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 | + ) |
120 | 134 | if (YOKAI_${slug}_${name}) |
121 | 135 | set(YOKAI_${slug}_XDG_COMPATIBILITY ON) |
122 | 136 | endif() |
|
0 commit comments