forked from MRPT/mrpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_detect_functions_headers.cmake
105 lines (86 loc) · 3.13 KB
/
script_detect_functions_headers.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
96
97
98
99
100
101
102
103
104
105
# ---------------------------------------------------------------
# "Clasic" function & headers detection:
# ---------------------------------------------------------------
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckTypeSize)
include(CheckSymbolExists)
set(CMAKE_REQUIRED_INCLUDES "math.h")
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_REQUIRED_LIBRARIES "m")
endif()
CHECK_FUNCTION_EXISTS(timegm HAVE_TIMEGM)
CHECK_FUNCTION_EXISTS(_mkgmtime HAVE_MKGMTIME)
CHECK_FUNCTION_EXISTS(alloca HAVE_ALLOCA_FUNC)
CHECK_FUNCTION_EXISTS(gettid HAVE_GETTID)
CHECK_FUNCTION_EXISTS(sincos HAVE_SINCOS)
CHECK_FUNCTION_EXISTS(strtok_r HAVE_STRTOK_R)
CHECK_FUNCTION_EXISTS(_aligned_malloc HAVE_ALIGNED_MALLOC)
CHECK_INCLUDE_FILE("alloca.h" HAVE_ALLOCA_H)
CHECK_INCLUDE_FILE("linux/serial.h" HAVE_LINUX_SERIAL_H)
CHECK_INCLUDE_FILE("linux/input.h" HAVE_LINUX_INPUT_H)
CHECK_INCLUDE_FILE("malloc.h" HAVE_MALLOC_H)
CHECK_INCLUDE_FILE("malloc/malloc.h" HAVE_MALLOC_MALLOC_H)
CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILE("pthread.h" HAVE_PTHREAD_H)
CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
check_symbol_exists(localtime_r "time.h" HAVE_LOCALTIME_R)
if(HAVE_ALLOCA_FUNC OR HAVE_ALLOCA_H)
set(HAVE_ALLOCA 1)
endif()
if(CMAKE_MRPT_HAS_GLUT_SYSTEM)
set(HAVE_FREEGLUT_EXT_H 0)
find_file(FREEGLUTEXT_HFILE GL/freeglut_ext.h)
if(FREEGLUTEXT_HFILE)
mark_as_advanced(FREEGLUTEXT_HFILE)
set(HAVE_FREEGLUT_EXT_H 1)
endif()
else()
set(HAVE_FREEGLUT_EXT_H 1)
endif()
CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE("winsock2.h" HAVE_WINSOCK2_H)
CHECK_INCLUDE_FILES("windows.h;winusb.h" HAVE_WINUSB_H)
# If we want SSE2, check for the expected headers:
if (CMAKE_MRPT_HAS_SSE2)
CHECK_INCLUDE_FILE("emmintrin.h" HAVE_EMMINTRIN_H)
CHECK_INCLUDE_FILE("mmintrin.h" HAVE_MMINTRIN_H)
# If the headers are not found, disable optimizations:
if (NOT HAVE_MMINTRIN_H OR NOT HAVE_EMMINTRIN_H)
set(CMAKE_MRPT_HAS_SSE2 0)
endif()
endif()
# If we want SSE3, check for the expected headers:
if (CMAKE_MRPT_HAS_SSE3)
# JL: Before the CHECK_INCLUDE_FILE() we need to temporarily enable
# the -msse3 flag in GCC or the test program that CMake builds will
# always fail even if the header is present:
if(CMAKE_COMPILER_IS_GNUCXX)
set(TEMP_BACKUP_CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3")
endif()
CHECK_INCLUDE_FILE("pmmintrin.h" HAVE_PMMINTRIN_H)
# Restore from above:
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS ${TEMP_BACKUP_CMAKE_C_FLAGS})
endif()
# If the headers are not found, disable optimizations:
if (NOT HAVE_PMMINTRIN_H)
set(CMAKE_MRPT_HAS_SSE3 0)
endif (NOT )
endif()
# Compiler type sizes:
check_type_size("long double" HAVE_LONG_DOUBLE)
# ---------------------------------------------------------------
# detect endian-ness
# ---------------------------------------------------------------
include(TestBigEndian)
TEST_BIG_ENDIAN(CMAKE_MRPT_IS_BIG_ENDIAN)
# Special systems:
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
set(CMAKE_MRPT_IN_EMSCRIPTEN 1)
else()
set(CMAKE_MRPT_IN_EMSCRIPTEN 0)
endif()