CrucibleCheck.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
include_guard(GLOBAL) include(CheckCXXSourceCompiles) function(crucible_check_platform_is_64_bit) message(STATUS "Checking if target system is 64-bit...") set(CMAKE_REQUIRED_QUIET TRUE) check_cxx_source_compiles( " #include <climits> static_assert(sizeof(void *) == 8); static_assert(CHAR_BIT == 8); int main() { return 0; } " CRUCIBLE_PLATFORM_IS_64_BIT) if(CRUCIBLE_PLATFORM_IS_64_BIT) message(STATUS " Yes!") else() message(FATAL_ERROR "Crucible only supports 64-bit targets") endif() endfunction() function(crucible_check_platform_is_posix_like) message(STATUS "Checking if target system is POSIX-like...") if(UNIX) set(CRUCIBLE_PLATFORM_IS_POSIX_LIKE TRUE CACHE INTERNAL "") message(STATUS " Yes!") else() message(STATUS " No!") endif() endfunction() function(crucible_check_platform_is_windows_like) message(STATUS "Checking if target system is Windows-like...") if(WIN32) set(CRUCIBLE_PLATFORM_IS_WINDOWS_LIKE TRUE CACHE INTERNAL "") message(STATUS " Yes!") else() message(STATUS " No!") endif() endfunction() function(crucible_check_platform_has_dirent_d_namlen) message(STATUS "Checking if target system has `struct dirent::d_namlen`...") set(CMAKE_REQUIRED_QUIET TRUE) check_cxx_source_compiles( " #include <dirent.h> int main() { struct ::dirent entry; entry.d_namlen = 0; return 0; } " CRUCIBLE_PLATFORM_HAS_DIRENT_D_NAMLEN) if(CRUCIBLE_PLATFORM_HAS_DIRENT_D_NAMLEN) message(STATUS " Yes!") else() message(STATUS " No!") endif() endfunction() function(crucible_check_platform_path_separator) message(STATUS "Checking platform native path separator...") # Might break, but CMake has no other way to get this information file(TO_NATIVE_PATH "/" PLATFORM_PATH_SEPARATOR) # Double-escape because if it's `\`, the C++ compiler will _also_ parse it as an escape sequence string(REPLACE "\\" "\\\\" PLATFORM_PATH_SEPARATOR_ESCAPED "${PLATFORM_PATH_SEPARATOR}") set(CRUCIBLE_PLATFORM_PATH_SEPARATOR "${PLATFORM_PATH_SEPARATOR_ESCAPED}" CACHE INTERNAL "") message(STATUS " ${CRUCIBLE_PLATFORM_PATH_SEPARATOR}") endfunction() function(crucible_check_platform_newline_sequence) message(STATUS "Checking platform native newline sequence...") if(WIN32) set(CRUCIBLE_PLATFORM_NEWLINE_SEQUENCE "\\r\\n" CACHE INTERNAL "") else() set(CRUCIBLE_PLATFORM_NEWLINE_SEQUENCE "\\n" CACHE INTERNAL "") endif() message(STATUS " ${CRUCIBLE_PLATFORM_NEWLINE_SEQUENCE}") endfunction()