CMakeLists.txt 41.9 KB
Newer Older
1
#=============================================================================
2
3
# KWSys - Kitware System Library
# Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
#
5
6
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
7
#
8
9
10
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
11
12
13
14
#=============================================================================

# The Kitware System Library is intended to be included in other
# projects.  It is completely configurable in that the library's
15
16
# namespace can be configured and the components that are included can
# be selected invididually.
17
18

# Typical usage is to import the kwsys directory tree into a
19
20
21
# subdirectory under a parent project and enable the classes that will
# be used.  All classes are disabled by default.  The CMake listfile
# above this one configures the library as follows:
22
#
23
24
#  SET(KWSYS_NAMESPACE foosys)
#  SET(KWSYS_USE_Directory 1)    # Enable Directory class.
25
26
27
28
#  SUBDIRS(kwsys)
#
# Optional settings are as follows:
#
29
30
31
#  KWSYS_HEADER_ROOT = The directory into which to generate the kwsys headers.
#                      A directory called "${KWSYS_NAMESPACE}" will be
#                      created under this root directory to hold the files.
32
33
34
#
#    Example:
#
Andy Cedilnik's avatar
Andy Cedilnik committed
35
36
#      SET(KWSYS_HEADER_ROOT ${PROJECT_BINARY_DIR})
#      INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
37
#
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#  KWSYS_IOS_FORCE_OLD = Force use of old non-ANSI C++ streams even if
#                        new streams are available.  This may be used
#                        by projects that cannot configure their
#                        streams library.
#    Example:
#
#      SET(KWSYS_IOS_FORCE_OLD 1)
#
#
# Optional settings to setup install rules work in one of two ways.
# The modern way utilizes the CMake 2.4 INSTALL command.  Settings
# for this mode are as follows:
#
#  KWSYS_INSTALL_BIN_DIR     = The installation target directories into
#  KWSYS_INSTALL_LIB_DIR       which the libraries and headers from
#  KWSYS_INSTALL_INCLUDE_DIR   kwsys should be installed by a "make install".
#                              The values should be specified relative to
#                              the installation prefix and NOT start with '/'.
56
57
#  KWSYS_INSTALL_DOC_DIR     = The installation target directory for documentation
#                              such as copyright information.
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#
#  KWSYS_INSTALL_COMPONENT_NAME_RUNTIME     = Name of runtime and development
#  KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT   installation components.
#                                             If not given the install rules
#                                             will not be in any component.
#
#    Example:
#
#      SET(KWSYS_INSTALL_BIN_DIR bin)
#      SET(KWSYS_INSTALL_LIB_DIR lib)
#      SET(KWSYS_INSTALL_INCLUDE_DIR include)
#      SET(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME Runtime)
#      SET(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT Development)
#
# The old way uses the original CMake INSTALL_* commands.  Settings
# for this mode are as follows:
#
75
76
77
78
79
80
81
82
83
84
#  KWSYS_LIBRARY_INSTALL_DIR = The installation target directories into
#  KWSYS_HEADER_INSTALL_DIR    which the libraries and headers from
#                              kwsys should be installed by a "make install".
#                              The values should be specified relative to
#                              the installation prefix and start with a '/'.
#    Example:
#
#      SET(KWSYS_LIBRARY_INSTALL_DIR /lib)
#      SET(KWSYS_HEADER_INSTALL_DIR /include)
#
85
86
87
88
89
# The modern way will be used whenever the INSTALL command is
# available.  If the settings are not available the old names will be
# used to construct them.  The old way will be used whenever the
# INSTALL command is not available.  If the settings are not available
# the new names will be used to construct them.
90
91
92

# Once configured, kwsys should be used as follows from C or C++ code:
#
93
#  #include <foosys/Directory.hxx>
94
#   ...
95
#  foosys::Directory directory;
96
97
#

98
99
100
101
102
103
104
105
# NOTE: This library is intended for internal use by Kitware-driven
# projects.  In order to keep it simple no attempt will be made to
# maintain backward compatibility when changes are made to KWSys.
# When an incompatible change is made Kitware's projects that use
# KWSys will be fixed, but no notification will necessarily be sent to
# any outside mailing list and no documentation of the change will be
# written.

106
107
108
109
110
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5 FATAL_ERROR)

# Allow empty endif() and such with CMake 2.4.
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS 1)

111
112
113
114
#-----------------------------------------------------------------------------
# If a namespace is not specified, use "kwsys" and enable testing.
# This should be the case only when kwsys is not included inside
# another project and is being tested.
115
116
IF(NOT KWSYS_NAMESPACE)
  SET(KWSYS_NAMESPACE "kwsys")
117
  SET(KWSYS_STANDALONE 1)
118
ENDIF(NOT KWSYS_NAMESPACE)
119
120
121
122
123
IF(KWSYS_STANDALONE)
  IF(COMMAND CMAKE_POLICY)
    CMAKE_POLICY(SET CMP0003 NEW)
  ENDIF(COMMAND CMAKE_POLICY)
ENDIF(KWSYS_STANDALONE)
124

125
126
127
128
#-----------------------------------------------------------------------------
# The project name is that of the specified namespace.
PROJECT(${KWSYS_NAMESPACE})

129
130
131
132
133
134
135
136
137
138
# Some properties we set only with CMake 2.6 and above.
IF(COMMAND SET_PROPERTY)
  MACRO(KWSYS_SET_PROPERTY)
    SET_PROPERTY(${ARGV})
  ENDMACRO(KWSYS_SET_PROPERTY)
ELSE(COMMAND SET_PROPERTY)
  MACRO(KWSYS_SET_PROPERTY)
  ENDMACRO(KWSYS_SET_PROPERTY)
ENDIF(COMMAND SET_PROPERTY)

139
140
141
142
143
144
145
# Tell CMake how to follow dependencies of sources in this directory.
IF(COMMAND SET_PROPERTY)
  SET_PROPERTY(DIRECTORY
    PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
    "KWSYS_HEADER(%)=<${KWSYS_NAMESPACE}/%>"
    )
ENDIF(COMMAND SET_PROPERTY)
146
147
148
149
150
151
# add option to disable memory cleanup at exit of putenv memory
IF(DEFINED KWSYS_DO_NOT_CLEAN_PUTENV)
  SET(KWSYS_DO_NOT_CLEAN_PUTENV 1)
ELSE(DEFINED KWSYS_DO_NOT_CLEAN_PUTENV)
  SET(KWSYS_DO_NOT_CLEAN_PUTENV 0)
ENDIF(DEFINED KWSYS_DO_NOT_CLEAN_PUTENV)
152

153
# Select library components.
154
IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
155
  SET(KWSYS_ENABLE_C 1)
156
  # Enable all components.
157
  SET(KWSYS_USE_Base64 1)
158
  SET(KWSYS_USE_Directory 1)
Mathieu Malaterre's avatar
Mathieu Malaterre committed
159
  SET(KWSYS_USE_DynamicLoader 1)
Andy Cedilnik's avatar
Andy Cedilnik committed
160
  SET(KWSYS_USE_Glob 1)
161
  SET(KWSYS_USE_MD5 1)
162
  SET(KWSYS_USE_Process 1)
163
  SET(KWSYS_USE_RegularExpression 1)
164
  SET(KWSYS_USE_Registry 1)
165
  SET(KWSYS_USE_System 1)
166
  SET(KWSYS_USE_SystemTools 1)
167
  SET(KWSYS_USE_CommandLineArguments 1)
168
  SET(KWSYS_USE_FundamentalType 1)
169
  SET(KWSYS_USE_Terminal 1)
170
  SET(KWSYS_USE_IOStream 1)
171
  SET(KWSYS_USE_DateStamp 1)
172
  SET(KWSYS_USE_String 1)
173
  SET(KWSYS_USE_SystemInformation 1)
174
  SET(KWSYS_USE_CPU 1)
175
ENDIF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
176
177
178
179
180
181
182
183
184
185
186
187
188

# Enforce component dependencies.
IF(KWSYS_USE_SystemTools)
  SET(KWSYS_USE_Directory 1)
ENDIF(KWSYS_USE_SystemTools)
IF(KWSYS_USE_Glob)
  SET(KWSYS_USE_Directory 1)
  SET(KWSYS_USE_SystemTools 1)
  SET(KWSYS_USE_RegularExpression 1)
ENDIF(KWSYS_USE_Glob)
IF(KWSYS_USE_Process)
  SET(KWSYS_USE_System 1)
ENDIF(KWSYS_USE_Process)
189
190
191
192
IF(KWSYS_USE_SystemInformation)
  SET(KWSYS_USE_FundamentalType 1)
  SET(KWSYS_USE_Process 1)
ENDIF(KWSYS_USE_SystemInformation)
193

Brad King's avatar
Brad King committed
194
195
196
197
198
199
200
# Setup the large file support default.
IF(KWSYS_LFS_DISABLE)
  SET(KWSYS_LFS_REQUESTED 0)
ELSE(KWSYS_LFS_DISABLE)
  SET(KWSYS_LFS_REQUESTED 1)
ENDIF(KWSYS_LFS_DISABLE)

201
202
# Enable testing if building standalone.
IF(KWSYS_STANDALONE)
203
  INCLUDE(Dart)
204
205
206
207
  MARK_AS_ADVANCED(BUILD_TESTING DART_ROOT TCL_TCLSH)
  IF(BUILD_TESTING)
    ENABLE_TESTING()
  ENDIF(BUILD_TESTING)
208
ENDIF(KWSYS_STANDALONE)
209

210
# Include helper macros.
211
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/kwsysPlatformTests.cmake)
212
INCLUDE(CheckTypeSize)
213

214
215
216
# Do full dependency headers.
INCLUDE_REGULAR_EXPRESSION("^.*$")

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# Choose which kind of install commands to use.
IF(COMMAND INSTALL)
  # Use new KWSYS_INSTALL_*_DIR variable names to control installation.
  # Take defaults from the old names.  Note that there was no old name
  # for the bin dir, so we take the old lib dir name so DLLs will be
  # installed in a compatible way for old code.
  IF(NOT KWSYS_INSTALL_INCLUDE_DIR)
    STRING(REGEX REPLACE "^/" "" KWSYS_INSTALL_INCLUDE_DIR
      "${KWSYS_HEADER_INSTALL_DIR}")
  ENDIF(NOT KWSYS_INSTALL_INCLUDE_DIR)
  IF(NOT KWSYS_INSTALL_LIB_DIR)
    STRING(REGEX REPLACE "^/" "" KWSYS_INSTALL_LIB_DIR
      "${KWSYS_LIBRARY_INSTALL_DIR}")
  ENDIF(NOT KWSYS_INSTALL_LIB_DIR)
  IF(NOT KWSYS_INSTALL_BIN_DIR)
    STRING(REGEX REPLACE "^/" "" KWSYS_INSTALL_BIN_DIR
      "${KWSYS_LIBRARY_INSTALL_DIR}")
  ENDIF(NOT KWSYS_INSTALL_BIN_DIR)

236
237
238
239
240
241
242
243
  # Setup header install rules.
  SET(KWSYS_INSTALL_INCLUDE_OPTIONS)
  IF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)
    SET(KWSYS_INSTALL_INCLUDE_OPTIONS ${KWSYS_INSTALL_INCLUDE_OPTIONS}
      COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT}
      )
  ENDIF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
  # Setup library install rules.
  SET(KWSYS_INSTALL_LIBRARY_RULE)
  IF(KWSYS_INSTALL_LIB_DIR)
    # Install the shared library to the lib directory.
    SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
      LIBRARY DESTINATION ${KWSYS_INSTALL_LIB_DIR}
      )
    # Assign the shared library to the runtime component.
    IF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
      SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
        COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_RUNTIME}
        )
    ENDIF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)

    # Install the archive to the lib directory.
    SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
      ARCHIVE DESTINATION ${KWSYS_INSTALL_LIB_DIR}
      )
    # Assign the archive to the development component.
    IF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)
      SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
        COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT}
        )
    ENDIF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)
  ENDIF(KWSYS_INSTALL_LIB_DIR)
  IF(KWSYS_INSTALL_BIN_DIR)
    # Install the runtime library to the bin directory.
    SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
      RUNTIME DESTINATION ${KWSYS_INSTALL_BIN_DIR}
      )
    # Assign the runtime library to the runtime component.
    IF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
      SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
        COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_RUNTIME}
        )
    ENDIF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
  ENDIF(KWSYS_INSTALL_BIN_DIR)

  # Do not support old KWSYS_*_INSTALL_DIR variable names.
  SET(KWSYS_HEADER_INSTALL_DIR)
  SET(KWSYS_LIBRARY_INSTALL_DIR)

ELSE(COMMAND INSTALL)
  # Use old KWSYS_*_INSTALL_DIR variable names.
  # Take defaults from the new names.
  IF(KWSYS_INSTALL_LIB_DIR)
    IF(NOT KWSYS_LIBRARY_INSTALL_DIR)
      SET(KWSYS_LIBRARY_INSTALL_DIR "/${KWSYS_INSTALL_LIB_DIR}")
    ENDIF(NOT KWSYS_LIBRARY_INSTALL_DIR)
  ENDIF(KWSYS_INSTALL_LIB_DIR)
  IF(KWSYS_INSTALL_INCLUDE_DIR)
    IF(NOT KWSYS_HEADER_INSTALL_DIR)
      SET(KWSYS_HEADER_INSTALL_DIR "/${KWSYS_INSTALL_INCLUDE_DIR}")
    ENDIF(NOT KWSYS_HEADER_INSTALL_DIR)
  ENDIF(KWSYS_INSTALL_INCLUDE_DIR)

  # Do not support new KWSYS_INSTALL_*_DIR variable names.
  SET(KWSYS_INSTALL_BIN_DIR)
  SET(KWSYS_INSTALL_INCLUDE_DIR)
  SET(KWSYS_INSTALL_LIB_DIR)
ENDIF(COMMAND INSTALL)

306
307
308
309
310
311
312
# Work-around for CMake 1.6.7 bug in custom command dependencies when
# there is no executable output path.
IF(NOT EXECUTABLE_OUTPUT_PATH)
  SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}" CACHE PATH
      "Output directory for executables.")
ENDIF(NOT EXECUTABLE_OUTPUT_PATH)

313
314
315
316
317
318
319
320
# Generated source files will need this header.
STRING(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}"
  KWSYS_IN_SOURCE_BUILD)
IF(NOT KWSYS_IN_SOURCE_BUILD)
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsysPrivate.h
    ${PROJECT_BINARY_DIR}/kwsysPrivate.h COPY_ONLY IMMEDIATE)
ENDIF(NOT KWSYS_IN_SOURCE_BUILD)

321
322
323
324
325
#-----------------------------------------------------------------------------
# We require ANSI support from the C compiler.  Add any needed flags.
IF(CMAKE_ANSI_CFLAGS)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
ENDIF(CMAKE_ANSI_CFLAGS)
326

327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#-----------------------------------------------------------------------------
# Adjust compiler flags for some platforms.
IF(NOT CMAKE_COMPILER_IS_GNUCXX)
  IF(CMAKE_SYSTEM MATCHES "OSF1-V.*")
    STRING(REGEX MATCH "-timplicit_local"
      KWSYS_CXX_FLAGS_HAVE_IMPLICIT_LOCAL "${CMAKE_CXX_FLAGS}")
    STRING(REGEX MATCH "-no_implicit_include"
      KWSYS_CXX_FLAGS_HAVE_NO_IMPLICIT_INCLUDE "${CMAKE_CXX_FLAGS}")
    IF(NOT KWSYS_CXX_FLAGS_HAVE_IMPLICIT_LOCAL)
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local")
    ENDIF(NOT KWSYS_CXX_FLAGS_HAVE_IMPLICIT_LOCAL)
    IF(NOT KWSYS_CXX_FLAGS_HAVE_NO_IMPLICIT_INCLUDE)
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no_implicit_include")
    ENDIF(NOT KWSYS_CXX_FLAGS_HAVE_NO_IMPLICIT_INCLUDE)
  ENDIF(CMAKE_SYSTEM MATCHES "OSF1-V.*")
342
343
344
  IF(CMAKE_SYSTEM MATCHES "HP-UX")
    SET(KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS "+p")
  ENDIF(CMAKE_SYSTEM MATCHES "HP-UX")
345
346
ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX)

347
348
#-----------------------------------------------------------------------------
# Configure Large File Support.
349
350
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CSTDIO
  "Checking whether header cstdio is available" DIRECT)
351
352
353
354
355
356
SET(KWSYS_LFS_AVAILABLE 0)
IF(KWSYS_LFS_REQUESTED)
  # Large File Support is requested.
  SET(KWSYS_LFS_REQUESTED 1)

  # Check for large file support.
357
358
  SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
    -DKWSYS_CXX_HAS_CSTDIO=${KWSYS_CXX_HAS_CSTDIO})
359
360
  KWSYS_PLATFORM_CXX_TEST_RUN(KWSYS_LFS_WORKS
    "Checking for Large File Support" DIRECT)
361
  SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
362
363
364
365
366
367
368
369
370

  IF(KWSYS_LFS_WORKS)
    SET(KWSYS_LFS_AVAILABLE 1)
  ENDIF(KWSYS_LFS_WORKS)
ELSE(KWSYS_LFS_REQUESTED)
  # Large File Support is not requested.
  SET(KWSYS_LFS_REQUESTED 0)
ENDIF(KWSYS_LFS_REQUESTED)

371
372
#-----------------------------------------------------------------------------
# Configure the standard library header wrappers based on compiler's
373
374
# capabilities and parent project's request.  Enforce 0/1 as only
# possible values for configuration into Configure.hxx.
375

376
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAVE_STD
377
  "Checking whether STL classes are in std namespace" DIRECT)
378

379
IF(KWSYS_IOS_FORCE_OLD)
380
  SET(KWSYS_IOS_USE_ANSI 0)
381
ELSE(KWSYS_IOS_FORCE_OLD)
382
  KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_ANSI
383
    "Checking whether ANSI stream headers are available" DIRECT)
384
ENDIF(KWSYS_IOS_FORCE_OLD)
385

386
IF(KWSYS_IOS_USE_ANSI)
387
  KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAVE_STD
388
    "Checking whether ANSI streams are in std namespace" DIRECT)
389
  KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_SSTREAM
390
    "Checking whether ANSI string stream is available" DIRECT)
391
ELSE(KWSYS_IOS_USE_ANSI)
392
  SET(KWSYS_IOS_HAVE_STD 0)
393
394
395
396
397
398
399
400
  SET(KWSYS_IOS_USE_SSTREAM 0)
ENDIF(KWSYS_IOS_USE_ANSI)

IF(KWSYS_IOS_USE_SSTREAM)
  SET(KWSYS_IOS_USE_STRSTREAM_H 0)
  SET(KWSYS_IOS_USE_STRSTREA_H 0)
ELSE(KWSYS_IOS_USE_SSTREAM)
  KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_STRSTREAM_H
401
    "Checking whether strstream.h is available" DIRECT)
402
403
404
405
  IF(KWSYS_IOS_USE_STRSTREAM_H)
    SET(KWSYS_IOS_USE_STRSTREA_H 0)
  ELSE(KWSYS_IOS_USE_STRSTREAM_H)
    KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_STRSTREA_H
406
      "Checking whether strstrea.h is available" DIRECT)
407
408
  ENDIF(KWSYS_IOS_USE_STRSTREAM_H)
ENDIF(KWSYS_IOS_USE_SSTREAM)
409

410
411
412
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CSTDDEF
  "Checking whether header cstddef is available" DIRECT)

413
414
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
  -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD})
415
416
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_NEQ_CHAR
  "Checking whether stl string has operator!= for char*" DIRECT)
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ITERATOR_TRAITS
  "Checking whether stl has iterator_traits" DIRECT)
IF(KWSYS_STL_HAS_ITERATOR_TRAITS)
  SET(KWSYS_STL_HAS_ITERATOR_CATEGORY 0)
  SET(KWSYS_STL_HAS___ITERATOR_CATEGORY 0)
ELSE(KWSYS_STL_HAS_ITERATOR_TRAITS)
  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ITERATOR_CATEGORY
    "Checking whether stl has old iterator_category" DIRECT)
  IF(KWSYS_STL_HAS_ITERATOR_CATEGORY)
    SET(KWSYS_STL_HAS___ITERATOR_CATEGORY 0)
  ELSE(KWSYS_STL_HAS_ITERATOR_CATEGORY)
    KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS___ITERATOR_CATEGORY
      "Checking whether stl has internal __iterator_category" DIRECT)
  ENDIF(KWSYS_STL_HAS_ITERATOR_CATEGORY)
ENDIF(KWSYS_STL_HAS_ITERATOR_TRAITS)
432
433
434
435
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_TEMPLATE
  "Checking whether stl has standard template allocator" DIRECT)
IF(KWSYS_STL_HAS_ALLOCATOR_TEMPLATE)
  SET(KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE 0)
436
437
438
439
  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_REBIND
    "Checking for rebind member of stl allocator" DIRECT)
  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
    "Checking for non-standard argument to stl allocator<>::max_size" DIRECT)
440
441
442
443
444
445
446
447
ELSE(KWSYS_STL_HAS_ALLOCATOR_TEMPLATE)
  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
    "Checking whether stl has old non-template allocator" DIRECT)
  SET(KWSYS_STL_HAS_ALLOCATOR_REBIND 0)
  SET(KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT 0)
ENDIF(KWSYS_STL_HAS_ALLOCATOR_TEMPLATE)
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_ALLOCATOR_OBJECTS
  "Checking whether stl containers support allocator objects." DIRECT)
448
IF(KWSYS_IOS_USE_ANSI AND NOT WATCOM)
449
450
451
  # ANSI streams always have string operators.
  SET(KWSYS_STL_STRING_HAVE_OSTREAM 1)
  SET(KWSYS_STL_STRING_HAVE_ISTREAM 1)
452
ELSE(KWSYS_IOS_USE_ANSI AND NOT WATCOM)
453
454
455
456
457
  # There may not be string operators for old streams.
  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_OSTREAM
    "Checking whether stl string has ostream operator<<" DIRECT)
  KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_ISTREAM
    "Checking whether stl string has istream operator>>" DIRECT)
458
ENDIF(KWSYS_IOS_USE_ANSI AND NOT WATCOM)
459
460
461
462
463
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
  -DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI}
  -DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD})
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAVE_BINARY
  "Checking whether ios has binary openmode" DIRECT)
464
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
465

466
467
468
469
470
471
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
  "Checking whether \"<>\" is needed for template friends" INVERT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_MEMBER_TEMPLATES
  "Checking for member template support" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_FULL_SPECIALIZATION
  "Checking for standard template specialization syntax" DIRECT)
472
473
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
  "Checking whether argument dependent lookup is supported" DIRECT)
474

475
476
477
478
479
IF(UNIX)
  KWSYS_PLATFORM_CXX_TEST(KWSYS_STAT_HAS_ST_MTIM
    "Checking whether struct stat has st_mtim member" DIRECT)
ENDIF(UNIX)

480
IF(KWSYS_USE_FundamentalType)
481
482
483
484
485
486
487
488
489
490
491
492
493
  # Determine type sizes.
  CHECK_TYPE_SIZE("char"      KWSYS_SIZEOF_CHAR)
  CHECK_TYPE_SIZE("short"     KWSYS_SIZEOF_SHORT)
  CHECK_TYPE_SIZE("int"       KWSYS_SIZEOF_INT)
  CHECK_TYPE_SIZE("long"      KWSYS_SIZEOF_LONG)
  CHECK_TYPE_SIZE("long long" KWSYS_SIZEOF_LONG_LONG)
  CHECK_TYPE_SIZE("__int64"   KWSYS_SIZEOF___INT64)
  IF(NOT KWSYS_SIZEOF_LONG_LONG)
    SET(KWSYS_SIZEOF_LONG_LONG 0)
  ENDIF(NOT KWSYS_SIZEOF_LONG_LONG)
  IF(NOT KWSYS_SIZEOF___INT64)
    SET(KWSYS_SIZEOF___INT64 0)
  ENDIF(NOT KWSYS_SIZEOF___INT64)
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528

  # Check uniqueness of types.
  IF(KWSYS_SIZEOF___INT64)
    KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_AND___INT64
      "Checking whether long and __int64 are the same type" DIRECT)
    IF(KWSYS_SIZEOF_LONG_LONG)
      KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_LONG_AND___INT64
        "Checking whether long long and __int64 are the same type" DIRECT)
    ENDIF(KWSYS_SIZEOF_LONG_LONG)
  ENDIF(KWSYS_SIZEOF___INT64)

  # Enable the "long long" type if it is available.  It is standard in
  # C99 and C++03 but not in earlier standards.
  IF(KWSYS_SIZEOF_LONG_LONG)
    SET(KWSYS_USE_LONG_LONG 1)
  ELSE(KWSYS_SIZEOF_LONG_LONG)
    SET(KWSYS_USE_LONG_LONG 0)
  ENDIF(KWSYS_SIZEOF_LONG_LONG)

  # Enable the "__int64" type if it is available and unique.  It is not
  # standard.
  SET(KWSYS_USE___INT64 0)
  IF(KWSYS_SIZEOF___INT64)
    IF(NOT KWSYS_CXX_SAME_LONG_AND___INT64)
      IF(NOT KWSYS_CXX_SAME_LONG_LONG_AND___INT64)
        SET(KWSYS_USE___INT64 1)
      ENDIF(NOT KWSYS_CXX_SAME_LONG_LONG_AND___INT64)
    ENDIF(NOT KWSYS_CXX_SAME_LONG_AND___INT64)
  ENDIF(KWSYS_SIZEOF___INT64)
  IF(KWSYS_USE___INT64)
    KWSYS_PLATFORM_CXX_TEST(KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
      "Checking whether unsigned __int64 can convert to double" DIRECT)
  ELSE(KWSYS_USE___INT64)
    SET(KWSYS_CAN_CONVERT_UI64_TO_DOUBLE 1)
  ENDIF(KWSYS_USE___INT64)
529
530

  # Check signedness of "char" type.
531
532
  KWSYS_PLATFORM_CXX_TEST_RUN(KWSYS_CHAR_IS_SIGNED
    "Checking whether char is signed" DIRECT)
533
534
ENDIF(KWSYS_USE_FundamentalType)

535
536
IF(KWSYS_USE_IOStream)
  # Determine whether iostreams support long long.
537
538
539
  KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_LONG_LONG
    "Checking whether C++ compiler has 'long long'" DIRECT)
  IF(KWSYS_CXX_HAS_LONG_LONG)
540
541
542
543
544
545
546
547
    SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
      -DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI}
      -DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD})
    KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM_LONG_LONG
      "Checking if istream supports long long" DIRECT)
    KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM_LONG_LONG
      "Checking if ostream supports long long" DIRECT)
    SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
548
  ELSE()
549
550
    SET(KWSYS_IOS_HAS_ISTREAM_LONG_LONG 0)
    SET(KWSYS_IOS_HAS_OSTREAM_LONG_LONG 0)
551
  ENDIF()
552
553
ENDIF(KWSYS_USE_IOStream)

554
555
556
557
558
559
IF(KWSYS_NAMESPACE MATCHES "^kwsys$")
  SET(KWSYS_NAME_IS_KWSYS 1)
ELSE(KWSYS_NAMESPACE MATCHES "^kwsys$")
  SET(KWSYS_NAME_IS_KWSYS 0)
ENDIF(KWSYS_NAMESPACE MATCHES "^kwsys$")

Brad King's avatar
Brad King committed
560
561
562
563
564
565
566
567
568
569
570
571
572
# Choose default shared/static build if not specified.
IF(KWSYS_BUILD_SHARED MATCHES "^KWSYS_BUILD_SHARED$")
  SET(KWSYS_BUILD_SHARED ${BUILD_SHARED_LIBS})
ENDIF(KWSYS_BUILD_SHARED MATCHES "^KWSYS_BUILD_SHARED$")

IF(KWSYS_BUILD_SHARED)
  SET(KWSYS_BUILD_SHARED 1)
  SET(KWSYS_LIBRARY_TYPE SHARED)
ELSE(KWSYS_BUILD_SHARED)
  SET(KWSYS_BUILD_SHARED 0)
  SET(KWSYS_LIBRARY_TYPE STATIC)
ENDIF(KWSYS_BUILD_SHARED)

573
574
#-----------------------------------------------------------------------------
# Choose a directory for the generated headers.
575
576
577
578
IF(NOT KWSYS_HEADER_ROOT)
  SET(KWSYS_HEADER_ROOT "${PROJECT_BINARY_DIR}")
ENDIF(NOT KWSYS_HEADER_ROOT)
SET(KWSYS_HEADER_DIR "${KWSYS_HEADER_ROOT}/${KWSYS_NAMESPACE}")
579
INCLUDE_DIRECTORIES(${KWSYS_HEADER_ROOT})
580

581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
#-----------------------------------------------------------------------------
IF(KWSYS_INSTALL_DOC_DIR)
  # Assign the license to the runtime component since it must be
  # distributed with binary forms of this software.
  IF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
    SET(KWSYS_INSTALL_LICENSE_OPTIONS ${KWSYS_INSTALL_LICENSE_OPTIONS}
      COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_RUNTIME}
      )
  ENDIF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)

  # Install the license under the documentation directory.
  INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt
    DESTINATION ${KWSYS_INSTALL_DOC_DIR}/${KWSYS_NAMESPACE}
    ${KWSYS_INSTALL_LICENSE_OPTIONS})
ENDIF(KWSYS_INSTALL_DOC_DIR)

597
598
599
#-----------------------------------------------------------------------------
# Create STL header wrappers to block warnings in the STL headers and
# give standard names by which they may be included.
600
SET(KWSYS_STL_HEADER_EXTRA_string 1)
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
FOREACH(header
  algorithm
  deque
  exception
  functional
  iterator
  list
  map
  memory
  new
  numeric
  queue
  set
  stack
  stdexcept
  string
  utility
  vector
  )
620
621
  # Configure the header wrapper.
  SET(KWSYS_STL_HEADER "${header}")
622
623
624
625
626
627
  IF(KWSYS_STL_HEADER_EXTRA_${header})
    SET(KWSYS_STL_HEADER_EXTRA
      "#define ${KWSYS_NAMESPACE}_stl_${header}_including_hxx\n# include <${KWSYS_NAMESPACE}/stl/${header}.hxx>\n#undef ${KWSYS_NAMESPACE}_stl_${header}_including_hxx\n")
    CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_stl_${header}.hxx.in
                   ${KWSYS_HEADER_DIR}/stl/${header}.hxx
                   @ONLY IMMEDIATE)
628
629
    IF(KWSYS_INSTALL_INCLUDE_DIR)
      INSTALL(FILES ${KWSYS_HEADER_DIR}/stl/${header}.hxx
630
631
        DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}/stl
        ${KWSYS_INSTALL_INCLUDE_OPTIONS})
632
    ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
633
634
635
636
637
638
639
640
    IF(KWSYS_HEADER_INSTALL_DIR)
      INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}/stl
        FILES ${KWSYS_HEADER_DIR}/stl/${header}.hxx)
    ENDIF(KWSYS_HEADER_INSTALL_DIR)
  ELSE(KWSYS_STL_HEADER_EXTRA_${header})
    SET(KWSYS_STL_HEADER_EXTRA "")
  ENDIF(KWSYS_STL_HEADER_EXTRA_${header})
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_stl.hxx.in
641
                 ${KWSYS_HEADER_DIR}/stl/${header}
642
                 @ONLY IMMEDIATE)
643

644
  # Create an install target for the header wrapper.
645
646
  IF(KWSYS_INSTALL_INCLUDE_DIR)
    INSTALL(FILES ${KWSYS_HEADER_DIR}/stl/${header}
647
648
      DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}/stl
      ${KWSYS_INSTALL_INCLUDE_OPTIONS})
649
  ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
650
  IF(KWSYS_HEADER_INSTALL_DIR)
651
652
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}/stl
      FILES ${KWSYS_HEADER_DIR}/stl/${header})
653
654
655
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
ENDFOREACH(header)

656
657
658
659
# Provide cstddef header.
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_cstddef.hxx.in
               ${KWSYS_HEADER_DIR}/cstddef
               @ONLY IMMEDIATE)
660
661
662
663
664
665
666
667
668
IF(KWSYS_INSTALL_INCLUDE_DIR)
  INSTALL(FILES ${KWSYS_HEADER_DIR}/cstddef
    DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}
    ${KWSYS_INSTALL_INCLUDE_OPTIONS})
  IF(KWSYS_HEADER_INSTALL_DIR)
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
      FILES ${KWSYS_HEADER_DIR}/cstddef)
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
669

670
671
672
673
674
#-----------------------------------------------------------------------------
# Create streams header wrappers to give standard names by which they
# may be included.
FOREACH(header iostream fstream sstream iosfwd)
  # Configure the header wrapper.
675
676
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_ios_${header}.h.in
                 ${KWSYS_HEADER_DIR}/ios/${header}
677
678
679
                 @ONLY IMMEDIATE)

  # Create an install target for the header wrapper.
680
681
  IF(KWSYS_INSTALL_INCLUDE_DIR)
    INSTALL(FILES ${KWSYS_HEADER_DIR}/ios/${header}
682
683
      DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}/ios
      ${KWSYS_INSTALL_INCLUDE_OPTIONS})
684
  ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
685
  IF(KWSYS_HEADER_INSTALL_DIR)
686
687
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}/ios
      FILES ${KWSYS_HEADER_DIR}/ios/${header})
688
689
690
691
692
693
694
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
ENDFOREACH(header)

#-----------------------------------------------------------------------------
# Build a list of classes and headers we need to implement the
# selected components.  Initialize with required components.
SET(KWSYS_CLASSES)
695
SET(KWSYS_H_FILES Configure SharedForward)
696
697
698
699
SET(KWSYS_HXX_FILES Configure String
  hashtable hash_fun hash_map hash_set
  auto_ptr
  )
700
701

# Add selected C++ classes.
702
703
SET(cppclasses
  Directory DynamicLoader Glob RegularExpression SystemTools
704
  CommandLineArguments Registry IOStream SystemInformation
705
  )
706
707
FOREACH(cpp ${cppclasses})
  IF(KWSYS_USE_${cpp})
708
    # Use the corresponding class.
709
    SET(KWSYS_CLASSES ${KWSYS_CLASSES} ${cpp})
710
711

    # Load component-specific CMake code.
712
    IF(EXISTS ${PROJECT_SOURCE_DIR}/kwsys${cpp}.cmake)
713
      INCLUDE(${PROJECT_SOURCE_DIR}/kwsys${cpp}.cmake)
714
    ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/kwsys${cpp}.cmake)
715
716
  ENDIF(KWSYS_USE_${cpp})
ENDFOREACH(cpp)
717
718

# Add selected C components.
719
720
721
FOREACH(c
    Process Base64 FundamentalType MD5 Terminal System DateStamp String CPU
    )
722
  IF(KWSYS_USE_${c})
723
    # Use the corresponding header file.
724
    SET(KWSYS_H_FILES ${KWSYS_H_FILES} ${c})
725
726

    # Load component-specific CMake code.
727
    IF(EXISTS ${PROJECT_SOURCE_DIR}/kwsys${c}.cmake)
728
      INCLUDE(${PROJECT_SOURCE_DIR}/kwsys${c}.cmake)
729
    ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/kwsys${c}.cmake)
730
731
  ENDIF(KWSYS_USE_${c})
ENDFOREACH(c)
732

733
734
735
#-----------------------------------------------------------------------------
# Build a list of sources for the library based on components that are
# included.
736
737
SET(KWSYS_C_SRCS)
SET(KWSYS_CXX_SRCS)
738
739
740

# Add the proper sources for this platform's Process implementation.
IF(KWSYS_USE_Process)
741
  IF(NOT UNIX)
742
    # Use the Windows implementation.  We need the encoded forwarding executable.
743
    SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ProcessWin32.c
744
745
746
747
      ${PROJECT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c)
    SET_SOURCE_FILES_PROPERTIES(
      ${PROJECT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
      PROPERTIES GENERATED 1)
748
  ELSE(NOT UNIX)
749
    # Use the UNIX implementation.
750
    SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ProcessUNIX.c)
751
752
753
754
755
756
757
758
759

    # Help ProcessUNIX.c compile properly on all platforms.
    KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_PTRDIFF_T
      "Checking whether C compiler has ptrdiff_t in stddef.h" DIRECT)
    KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_SSIZE_T
      "Checking whether C compiler has ssize_t in unistd.h" DIRECT)
    SET_SOURCE_FILES_PROPERTIES(ProcessUNIX.c PROPERTIES
      COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T}"
      )
760
  ENDIF(NOT UNIX)
761
762
ENDIF(KWSYS_USE_Process)

763
# Add selected C sources.
764
FOREACH(c Base64 MD5 Terminal System String)
765
766
767
768
  IF(KWSYS_USE_${c})
    SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ${c}.c)
  ENDIF(KWSYS_USE_${c})
ENDFOREACH(c)
Andy Cedilnik's avatar
Andy Cedilnik committed
769

770
771
772
# Configure headers of C++ classes and construct the list of sources.
FOREACH(c ${KWSYS_CLASSES})
  # Add this source to the list of source files for the library.
773
  SET(KWSYS_CXX_SRCS ${KWSYS_CXX_SRCS} ${c}.cxx)
774

775
776
  # Configure the header for this class.
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${c}.hxx.in ${KWSYS_HEADER_DIR}/${c}.hxx
777
                 @ONLY IMMEDIATE)
778
  SET(KWSYS_CXX_SRCS ${KWSYS_CXX_SRCS} ${KWSYS_HEADER_DIR}/${c}.hxx)
779
780

  # Create an install target for the header.
781
782
  IF(KWSYS_INSTALL_INCLUDE_DIR)
    INSTALL(FILES ${KWSYS_HEADER_DIR}/${c}.hxx
783
784
      DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}
      ${KWSYS_INSTALL_INCLUDE_OPTIONS})
785
  ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
786
787
788
789
  IF(KWSYS_HEADER_INSTALL_DIR)
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
                  FILES  ${KWSYS_HEADER_DIR}/${c}.hxx)
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
790
791
ENDFOREACH(c)

792
793
794
795
# Configure C headers.
FOREACH(h ${KWSYS_H_FILES})
  # Configure the header into the given directory.
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.h.in ${KWSYS_HEADER_DIR}/${h}.h
796
                 @ONLY IMMEDIATE)
797
  SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ${KWSYS_HEADER_DIR}/${h}.h)
798
799

  # Create an install target for the header.
800
801
  IF(KWSYS_INSTALL_INCLUDE_DIR)
    INSTALL(FILES ${KWSYS_HEADER_DIR}/${h}.h
802
803
      DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}
      ${KWSYS_INSTALL_INCLUDE_OPTIONS})
804
  ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
805
806
807
808
  IF(KWSYS_HEADER_INSTALL_DIR)
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
                  FILES  ${KWSYS_HEADER_DIR}/${h}.h)
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
809
810
ENDFOREACH(h)

811
812
813
814
# Configure other C++ headers.
FOREACH(h ${KWSYS_HXX_FILES})
  # Configure the header into the given directory.
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${h}.hxx.in ${KWSYS_HEADER_DIR}/${h}.hxx
815
                 @ONLY IMMEDIATE)
816
  SET(KWSYS_CXX_SRCS ${KWSYS_CXX_SRCS} ${KWSYS_HEADER_DIR}/${h}.hxx)
817

818
  # Create an install target for the header.
819
820
  IF(KWSYS_INSTALL_INCLUDE_DIR)
    INSTALL(FILES ${KWSYS_HEADER_DIR}/${h}.hxx
821
822
      DESTINATION ${KWSYS_INSTALL_INCLUDE_DIR}/${KWSYS_NAMESPACE}
      ${KWSYS_INSTALL_INCLUDE_OPTIONS})
823
  ENDIF(KWSYS_INSTALL_INCLUDE_DIR)
824
825
826
827
828
  IF(KWSYS_HEADER_INSTALL_DIR)
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
                  FILES  ${KWSYS_HEADER_DIR}/${h}.hxx)
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
ENDFOREACH(h)
829

830
831
#-----------------------------------------------------------------------------
# Add the library with the configured name and list of sources.
832
833
834
IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
  ADD_LIBRARY(${KWSYS_NAMESPACE} ${KWSYS_LIBRARY_TYPE}
    ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS})
835
  KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY LABELS ${KWSYS_LABELS_LIB})
836
837
  IF(KWSYS_USE_DynamicLoader)
    IF(UNIX)
838
      TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS})
839
840
    ENDIF(UNIX)
  ENDIF(KWSYS_USE_DynamicLoader)
841
842
843
844
  
  IF(KWSYS_USE_SystemInformation AND WIN32)
    TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32)
  ENDIF(KWSYS_USE_SystemInformation AND WIN32)
845

846
847
848
849
850
851
852
  # Apply user-defined target properties to the library.
  IF(KWSYS_PROPERTIES_CXX)
    SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE} PROPERTIES
      ${KWSYS_PROPERTIES_CXX}
      )
  ENDIF(KWSYS_PROPERTIES_CXX)

853
  # Create an install target for the library.
854
855
856
  IF(KWSYS_INSTALL_LIBRARY_RULE)
    INSTALL(TARGETS ${KWSYS_NAMESPACE} ${KWSYS_INSTALL_LIBRARY_RULE})
  ENDIF(KWSYS_INSTALL_LIBRARY_RULE)
857
  IF(KWSYS_LIBRARY_INSTALL_DIR)
858
    INSTALL_TARGETS(${KWSYS_LIBRARY_INSTALL_DIR} ${KWSYS_NAMESPACE})
859
  ENDIF(KWSYS_LIBRARY_INSTALL_DIR)
860
861
862
863
864
ENDIF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)

# Add a C-only library if requested.
IF(KWSYS_ENABLE_C AND KWSYS_C_SRCS)
  ADD_LIBRARY(${KWSYS_NAMESPACE}_c ${KWSYS_LIBRARY_TYPE} ${KWSYS_C_SRCS})
865
  KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}_c PROPERTY LABELS ${KWSYS_LABELS_LIB})
866

867
868
869
870
871
872
873
  # Apply user-defined target properties to the library.
  IF(KWSYS_PROPERTIES_C)
    SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE} PROPERTIES
      ${KWSYS_PROPERTIES_C}
      )
  ENDIF(KWSYS_PROPERTIES_C)

874
  # Create an install target for the library.
875
876
877
  IF(KWSYS_INSTALL_LIBRARY_RULE)
    INSTALL(TARGETS ${KWSYS_NAMESPACE}_c ${KWSYS_INSTALL_LIBRARY_RULE})
  ENDIF(KWSYS_INSTALL_LIBRARY_RULE)
878
879
880
881
  IF(KWSYS_LIBRARY_INSTALL_DIR)
    INSTALL_TARGETS(${KWSYS_LIBRARY_INSTALL_DIR} ${KWSYS_NAMESPACE}_c)
  ENDIF(KWSYS_LIBRARY_INSTALL_DIR)
ENDIF(KWSYS_ENABLE_C AND KWSYS_C_SRCS)
882

883
# For building kwsys itself, we use a macro defined on the command
884
# line to configure the namespace in the C and C++ source files.
885
ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}")
886

887
888
889
890
891
892
IF(KWSYS_USE_String)
  # Activate code in "String.c".  See the comment in the source.
  SET_SOURCE_FILES_PROPERTIES(String.c PROPERTIES
    COMPILE_FLAGS "-DKWSYS_STRING_C")
ENDIF(KWSYS_USE_String)

893
#-----------------------------------------------------------------------------
894
895
896
897
898
# Process execution on windows needs to build a forwarding executable
# that works around a Win9x bug.  We encode the executable into a C
# file and build it into the library.  Win9x platforms reproduce the
# executable into a temporary directory when it is needed.
IF(KWSYS_USE_Process)
899
  IF(NOT UNIX)
900
901
902
903
    # Build the forwarding executable itself and a program that will
    # encode it into a C file.
    ADD_EXECUTABLE(${KWSYS_NAMESPACE}ProcessFwd9x ProcessFwd9x.c)
    ADD_EXECUTABLE(${KWSYS_NAMESPACE}EncodeExecutable EncodeExecutable.c)
904
905
    KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}ProcessFwd9x PROPERTY LABELS ${KWSYS_LABELS_EXE})
    KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}EncodeExecutable PROPERTY LABELS ${KWSYS_LABELS_EXE})
906

907
908
909
910
911
    # Construct the location of the executable to be encoded.
    SET(BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
    IF(EXECUTABLE_OUTPUT_PATH)
      SET(BIN_DIR ${EXECUTABLE_OUTPUT_PATH})
    ENDIF(EXECUTABLE_OUTPUT_PATH)
912

913
914
915
916
    SET(CFG_INTDIR "/${CMAKE_CFG_INTDIR}")
    IF(CMAKE_BUILD_TOOL MATCHES "make")
      SET(CFG_INTDIR "")
    ENDIF(CMAKE_BUILD_TOOL MATCHES "make")
917

918
919
920
921
922
923
924
925
    # Take advantage of a better custom command syntax if possible.
    SET(CMD ${BIN_DIR}${CFG_INTDIR}/${KWSYS_NAMESPACE}EncodeExecutable.exe)
    SET(FWD ${BIN_DIR}${CFG_INTDIR}/${KWSYS_NAMESPACE}ProcessFwd9x.exe)
    IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
      ADD_CUSTOM_COMMAND(
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
        COMMAND ${CMD}
        ARGS ${FWD} ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
926
             ${KWSYS_NAMESPACE} ProcessFwd9x
927
928
929
930
931
932
933
        DEPENDS ${CMD} ${FWD})
    ELSE("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
      ADD_CUSTOM_COMMAND(
        TARGET ${KWSYS_NAMESPACE}
        SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/ProcessFwd9x.c
        COMMAND ${CMD}
        ARGS ${FWD} ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
934
             ${KWSYS_NAMESPACE} ProcessFwd9x
935
936
937
        OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
        DEPENDS ${CMD} ${FWD})
    ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
938

939
940
941
    # Make sure build occurs in proper order.
    ADD_DEPENDENCIES(${KWSYS_NAMESPACE} ${KWSYS_NAMESPACE}ProcessFwd9x
                     ${KWSYS_NAMESPACE}EncodeExecutable)
942
  ENDIF(NOT UNIX)
943
944
945
946
ENDIF(KWSYS_USE_Process)

#-----------------------------------------------------------------------------
# Setup testing if not being built as part of another project.
947
IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
948
  IF(BUILD_TESTING)
949
    # Compute the location of executables.
950
951
952
953
954
    SET(EXEC_DIR "${CMAKE_CURRENT_BINARY_DIR}")
    IF(EXECUTABLE_OUTPUT_PATH)
      SET(EXEC_DIR "${EXECUTABLE_OUTPUT_PATH}")
    ENDIF(EXECUTABLE_OUTPUT_PATH)

955
956
    # C tests
    SET(KWSYS_C_TESTS
957
      testEncode
958
959
960
961
962
963
964
965
966
967
      testTerminal
      )
    IF(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY AND KWSYS_STANDALONE)
      SET(KWSYS_C_TESTS ${KWSYS_C_TESTS} testFail)
    ENDIF(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY AND KWSYS_STANDALONE)
    CREATE_TEST_SOURCELIST(
      KWSYS_C_TEST_SRCS ${KWSYS_NAMESPACE}TestsC.c
      ${KWSYS_C_TESTS}
      )
    ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsC ${KWSYS_C_TEST_SRCS})
968
    KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsC PROPERTY LABELS ${KWSYS_LABELS_EXE})
969
970
971
    TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsC ${KWSYS_NAMESPACE}_c)
    FOREACH(test ${KWSYS_C_TESTS})
      ADD_TEST(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsC ${test} ${KWSYS_TEST_ARGS_${test}})
972
      KWSYS_SET_PROPERTY(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST})
973
974
975
    ENDFOREACH(test)

    # C++ tests
976
977
978
979
980
981
982
    IF(NOT WATCOM)
      SET(KWSYS_CXX_TESTS
        testAutoPtr
        testHashSTL
        )
    ENDIF(NOT WATCOM)
    SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
983
984
985
986
987
988
      testRegistry
      testIOS
      testSystemTools
      testCommandLineArguments
      testCommandLineArguments1
      )
Bill Hoffman's avatar
Bill Hoffman committed
989
990
991
    IF(KWSYS_USE_SystemInformation)
      SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testSystemInformation)
    ENDIF(KWSYS_USE_SystemInformation)
992
993
994
995
    IF(KWSYS_USE_DynamicLoader)
      SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testDynamicLoader)
      # If kwsys contains the DynamicLoader, need extra library
      ADD_LIBRARY(${KWSYS_NAMESPACE}TestDynload MODULE testDynload.c)
996
      KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestDynload PROPERTY LABELS ${KWSYS_LABELS_LIB})
997
998
999
1000
1001
1002
    ENDIF(KWSYS_USE_DynamicLoader)
    CREATE_TEST_SOURCELIST(
      KWSYS_CXX_TEST_SRCS ${KWSYS_NAMESPACE}TestsCxx.cxx
      ${KWSYS_CXX_TESTS}
      )
    ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_CXX_TEST_SRCS})
1003
    KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY LABELS ${KWSYS_LABELS_EXE})
1004
    TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_NAMESPACE})
1005
1006
    SET(TEST_SYSTEMTOOLS_BIN_FILE
      "${CMAKE_CURRENT_SOURCE_DIR}/testSystemTools.bin")
1007
    SET(TEST_SYSTEMTOOLS_SRC_FILE
1008
      "${CMAKE_CURRENT_SOURCE_DIR}/testSystemTools.cxx")
1009
1010
1011
1012
1013
    CONFIGURE_FILE(
      ${PROJECT_SOURCE_DIR}/testSystemTools.h.in
      ${PROJECT_BINARY_DIR}/testSystemTools.h)
    INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})

1014
1015
1016
1017
1018
    IF(CTEST_TEST_KWSYS)
      CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/ExtraTest.cmake.in"
        "${CMAKE_CURRENT_BINARY_DIR}/ExtraTest.cmake")
      SET_DIRECTORY_PROPERTIES(PROPERTIES TEST_INCLUDE_FILE "${CMAKE_CURRENT_BINARY_DIR}/ExtraTest.cmake")
    ENDIF(CTEST_TEST_KWSYS)
1019
1020

    SET(KWSYS_TEST_ARGS_testCommandLineArguments
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
      --another-bool-variable
      --long3=opt
      --set-bool-arg1
      -SSS ken brad bill andy
      --some-bool-variable=true
      --some-double-variable12.5
      --some-int-variable 14
      "--some-string-variable=test string with space"
      --some-multi-argument 5 1 8 3 7 1 3 9 7 1
      -N 12.5 -SS=andy -N 1.31 -N 22
      -SS=bill -BBtrue -SS=brad
1032
      -BBtrue
1033
1034
1035
1036
      -BBfalse
      -SS=ken
      -A
      -C=test
1037
1038
1039
      --long2 hello
      )
    SET(KWSYS_TEST_ARGS_testCommandLineArguments1
1040
1041
1042
1043
1044
1045
      --ignored
      -n 24
      --second-ignored
      "-m=test value"
      third-ignored
      -p
1046
1047
1048
1049
      some junk at the end
      )
    FOREACH(test ${KWSYS_CXX_TESTS})
      ADD_TEST(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsCxx ${test} ${KWSYS_TEST_ARGS_${test}})
1050
      KWSYS_SET_PROPERTY(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST})
1051
1052
1053
1054
    ENDFOREACH(test)

    # Process tests.
    ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestProcess testProcess.c)
1055
    KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestProcess PROPERTY LABELS ${KWSYS_LABELS_EXE})
1056
1057
1058
1059
1060
1061
    TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestProcess ${KWSYS_NAMESPACE}_c)
    IF(NOT CYGWIN)
      SET(KWSYS_TEST_PROCESS_7 7)
    ENDIF(NOT CYGWIN)
    FOREACH(n 1 2 3 4 5 6 ${KWSYS_TEST_PROCESS_7})
      ADD_TEST(kwsys.testProcess-${n} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestProcess ${n})
1062
      KWSYS_SET_PROPERTY(TEST kwsys.testProcess-${n} PROPERTY LABELS ${KWSYS_LABELS_TEST})
1063
1064
    ENDFOREACH(n)

1065
1066
1067
1068
1069
    # Test SharedForward
    CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/testSharedForward.c.in
                   ${PROJECT_BINARY_DIR}/testSharedForward.c @ONLY IMMEDIATE)
    ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestSharedForward
                   ${PROJECT_BINARY_DIR}/testSharedForward.c)
1070
    KWSYS_SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestSharedForward PROPERTY LABELS ${KWSYS_LABELS_EXE})
1071
    ADD_TEST(kwsys.testSharedForward ${EXEC_DIR}/${KWSYS_NAMESPACE}TestSharedForward 1)
1072
    KWSYS_SET_PROPERTY(TEST kwsys.testSharedForward PROPERTY LABELS ${KWSYS_LABELS_TEST})
1073

1074
    # Configure some test properties.
1075
    IF(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY AND KWSYS_STANDALONE)
1076
      # We expect test to fail
1077
      SET_TESTS_PROPERTIES(kwsys.testFail PROPERTIES WILL_FAIL ON)
1078
      GET_TEST_PROPERTY(kwsys.testFail WILL_FAIL wfv)
1079
      SET_TESTS_PROPERTIES(kwsys.testRegistry PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR_NOT_VALGRIND;FAIL;Test failed")
1080
      SET_TESTS_PROPERTIES(kwsys.testRegistry PROPERTIES PASS_REGULAR_EXPRESSION "Test passed")
1081
      SET_TESTS_PROPERTIES(kwsys.testFail PROPERTIES MEASUREMENT "Some Key=Some Value")
Andy Cedilnik's avatar
Andy Cedilnik committed
1082
      MESSAGE(STATUS "GET_TEST_PROPERTY returned: ${wfv}")
1083
    ENDIF(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY AND KWSYS_STANDALONE)
1084
  ENDIF(BUILD_TESTING)
1085
ENDIF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)