~csiro-asl/csiro-asl-ros-drivers/trunk

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File courtesy of the gearbox library, included here to make things easier.

###########################################################
#                                                         #
# Look for low-level C headers, write defines to config.h #
#                                                         #
###########################################################

include( ${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake )
include( ${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake )

set( CONFIG_H src/config.h )

# Only write config.h once
if( WROTE_CONFIG_H_${PROJECT_NAME} )
  message( STATUS "Not writing config.h -- wrote it previously" )
else( WROTE_CONFIG_H_${PROJECT_NAME} )  
  message( STATUS "Writing config.h for ${PROJECT_NAME}" )
  set( WROTE_CONFIG_H_${PROJECT_NAME} TRUE CACHE INTERNAL "Wrote config.h for ${PROJECT_NAME}" )

  file( WRITE ${CONFIG_H} "/* config.h.  Generated by CMakeLists.txt */\n\n" )

  if( WIN32 )
    
    #
    # define some stuff to make MSVC look a bit more like gcc
    #

    # define 'uint' to 'unsigned int' for windows
    file( APPEND ${CONFIG_H} "#ifndef uint\n" )
    file( APPEND ${CONFIG_H} "#define uint unsigned int\n" )
    file( APPEND ${CONFIG_H} "#endif\n\n" )

    file( APPEND ${CONFIG_H} "// MSVC compiler requires this symbol before exposing the (apparently)\n" )
    file( APPEND ${CONFIG_H} "// non-standard symbols M_PI, etc...\n" )
    file( APPEND ${CONFIG_H} "#define _USE_MATH_DEFINES\n\n" )

    file( APPEND ${CONFIG_H} "// Just in case the above line didn't fix it...\n" )
    file( APPEND ${CONFIG_H} "#ifndef M_PI\n" )
    file( APPEND ${CONFIG_H} "#define M_PI 3.14159265358979323846\n" )
    file( APPEND ${CONFIG_H} "#endif\n\n" )

  else( WIN32 )

    #
    # AlexB: I think all these low-level guys are 'nix-specific.
    #        Don't write them for win32.
    #

    check_include_file( termio.h HAVE_TERMIO_H )
    if( HAVE_TERMIO_H )
      set( VAL 1 )
    else( HAVE_TERMIO_H )
      set( VAL 0 )
    endif( HAVE_TERMIO_H )
    file( APPEND ${CONFIG_H} "#define HAVE_TERMIO_H ${VAL}\n\n" )

    check_include_file( linux/input.h HAVE_LINUX_INPUT_H )
    if( HAVE_LINUX_INPUT_H )
      set( VAL 1 )
    else( HAVE_LINUX_INPUT_H )
      set( VAL 0 )
    endif( HAVE_LINUX_INPUT_H )
    file( APPEND ${CONFIG_H} "#define HAVE_LINUX_INPUT_H ${VAL}\n\n" )

    check_include_file( string.h HAVE_STRING_H )
    if( HAVE_STRING_H )
      set( VAL 1 )
    else( HAVE_STRING_H )
      set( VAL 0 )
    endif( HAVE_STRING_H )
    file( APPEND ${CONFIG_H} "#define HAVE_STRING_H ${VAL}\n\n" )

    check_include_file( stdlib.h HAVE_STDLIB_H )
    if( HAVE_STDLIB_H )
      set( VAL 1 )
    else( HAVE_STDLIB_H )
      set( VAL 0 )
    endif( HAVE_STDLIB_H )
    file( APPEND ${CONFIG_H} "#define HAVE_STDLIB_H ${VAL}\n\n" )

    check_include_file( unistd.h HAVE_UNISTD_H )
    if( HAVE_UNISTD_H )
      set( VAL 1 )
    else( HAVE_UNISTD_H )
      set( VAL 0 )
    endif( HAVE_UNISTD_H )
    file( APPEND ${CONFIG_H} "#define HAVE_UNISTD_H ${VAL}\n\n" )

    check_include_file( sys/types.h HAVE_SYS_TYPES_H )
    if( HAVE_SYS_TYPES_H )
      set( VAL 1 )
    else( HAVE_SYS_TYPES_H )
      set( VAL 0 )
    endif( HAVE_SYS_TYPES_H )
    file( APPEND ${CONFIG_H} "#define HAVE_SYS_TYPES_H ${VAL}\n\n" )

    check_include_file( sys/stat.h HAVE_SYS_STAT_H )
    if( HAVE_SYS_STAT_H )
      set( VAL 1 )
    else( HAVE_SYS_STAT_H )
      set( VAL 0 )
    endif( HAVE_SYS_STAT_H )
    file( APPEND ${CONFIG_H} "#define HAVE_SYS_STAT_H ${VAL}\n\n" )

    check_include_file( pthread.h HAVE_PTHREAD_H )
    if( HAVE_PTHREAD_H )
      set( VAL 1 )
    else( HAVE_PTHREAD_H )
      set( VAL 0 )
    endif( HAVE_PTHREAD_H )
    file( APPEND ${CONFIG_H} "#define HAVE_PTHREAD_H ${VAL}\n\n" )

    check_include_file( sys/ioctl.h HAVE_SYS_IOCTL_H )
    if( HAVE_SYS_IOCTL_H )
      set( VAL 1 )
    else( HAVE_SYS_IOCTL_H )
      set( VAL 0 )
    endif( HAVE_SYS_IOCTL_H )
    file( APPEND ${CONFIG_H} "#define HAVE_SYS_IOCTL_H ${VAL}\n\n" )

    check_include_file( fcntl.h HAVE_FCNTL_H )
    if( HAVE_FCNTL_H )
      set( VAL 1 )
    else( HAVE_FCNTL_H )
      set( VAL 0 )
    endif( HAVE_FCNTL_H )
    file( APPEND ${CONFIG_H} "#define HAVE_FCNTL_H ${VAL}\n\n" )

    check_include_file( time.h HAVE_TIME_H )
    if( HAVE_TIME_H )
      set( VAL 1 )
    else( HAVE_TIME_H )
      set( VAL 0 )
    endif( HAVE_TIME_H )
    file( APPEND ${CONFIG_H} "#define HAVE_TIME_H ${VAL}\n\n" )

    check_include_file( errno.h HAVE_ERRNO_H )
    if( HAVE_ERRNO_H )
      set( VAL 1 )
    else( HAVE_ERRNO_H )
      set( VAL 0 )
    endif( HAVE_ERRNO_H )
    file( APPEND ${CONFIG_H} "#define HAVE_ERRNO_H ${VAL}\n\n" )

    check_include_file( zlib.h HAVE_ZLIB_H )
    if( HAVE_ZLIB_H )
      set( VAL 1 )
    else( HAVE_ZLIB_H )
      set( VAL 0 )
    endif( HAVE_ZLIB_H )
    file( APPEND ${CONFIG_H} "#define HAVE_ZLIB_H ${VAL}\n\n" )

    check_include_file( sys/filio.h HAVE_FILIO_H )
    if( HAVE_FILIO_H )
      set( VAL 1 )
    else( HAVE_FILIO_H )
      set( VAL 0 )
    endif( HAVE_FILIO_H )
    file( APPEND ${CONFIG_H} "#define HAVE_FILIO_H ${VAL}\n\n" )

    check_function_exists( strnlen HAVE_STRNLEN )
    if( HAVE_STRNLEN )
      set( VAL 1 )
    else( HAVE_STRNLEN )
      set( VAL 0 )
    endif( HAVE_STRNLEN )
    file( APPEND ${CONFIG_H} "#define HAVE_STRNLEN ${VAL}\n\n" )

  endif( WIN32 )

endif( WROTE_CONFIG_H_${PROJECT_NAME} )