CMakeLists.txt 27.2 KB
Newer Older
1
2
3
4
5
#=============================================================================
#
#  Program:   KWSys - Kitware System Library
#  Module:    CMakeLists.txt
#
Brad King's avatar
Brad King committed
6
7
#  Copyright (c) Kitware, Inc., Insight Consortium.  All rights reserved.
#  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8
#
9
10
#     This software is distributed WITHOUT ANY WARRANTY; without even
#     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11
12
13
14
15
16
#     PURPOSE.  See the above copyright notices for more information.
#
#=============================================================================

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

# Typical usage is to import the kwsys directory tree into a
21
22
23
# 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:
24
#
25
26
#  SET(KWSYS_NAMESPACE foosys)
#  SET(KWSYS_USE_Directory 1)    # Enable Directory class.
27
28
29
30
#  SUBDIRS(kwsys)
#
# Optional settings are as follows:
#
31
32
33
#  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.
34
35
36
#
#    Example:
#
Andy Cedilnik's avatar
Andy Cedilnik committed
37
38
#      SET(KWSYS_HEADER_ROOT ${PROJECT_BINARY_DIR})
#      INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
39
40
41
42
43
44
45
46
47
48
49
#
#  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)
#
50
51
52
53
#  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.
54
55
#    Example:
#
56
#      SET(KWSYS_IOS_FORCE_OLD 1)
57
58
59
60
#

# Once configured, kwsys should be used as follows from C or C++ code:
#
61
#  #include <foosys/Directory.hxx>
62
#   ...
63
#  foosys::Directory directory;
64
65
#

66
67
68
69
70
71
72
73
# 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.

74
75
76
77
#-----------------------------------------------------------------------------
# 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.
78
79
IF(NOT KWSYS_NAMESPACE)
  SET(KWSYS_NAMESPACE "kwsys")
80
  SET(KWSYS_STANDALONE 1)
81
82
83
ENDIF(NOT KWSYS_NAMESPACE)

IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
84
  SET(KWSYS_ENABLE_C 1)
85

86
  # Enable all components.
87
  SET(KWSYS_USE_Base64 1)
88
  SET(KWSYS_USE_Directory 1)
Mathieu Malaterre's avatar
Mathieu Malaterre committed
89
  SET(KWSYS_USE_DynamicLoader 1)
Andy Cedilnik's avatar
Andy Cedilnik committed
90
  SET(KWSYS_USE_Glob 1)
91
  SET(KWSYS_USE_Process 1)
92
  SET(KWSYS_USE_RegularExpression 1)
93
  SET(KWSYS_USE_Registry 1)
94
  SET(KWSYS_USE_SystemTools 1)
95
  SET(KWSYS_USE_CommandLineArguments 1)
96
  SET(KWSYS_USE_FundamentalType 1)
97
  SET(KWSYS_USE_Terminal 1)
98
ENDIF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
99
100
101
102

#-----------------------------------------------------------------------------
# The project name is that of the specified namespace.
PROJECT(${KWSYS_NAMESPACE})
103

104
105
# Enable testing if building standalone.
IF(KWSYS_STANDALONE)
106
  INCLUDE(Dart)
107
108
109
110
  MARK_AS_ADVANCED(BUILD_TESTING DART_ROOT TCL_TCLSH)
  IF(BUILD_TESTING)
    ENABLE_TESTING()
  ENDIF(BUILD_TESTING)
111
ENDIF(KWSYS_STANDALONE)
112

113
114
115
# Do full dependency headers.
INCLUDE_REGULAR_EXPRESSION("^.*$")

116
117
118
119
120
121
122
# 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)

123
124
125
126
127
128
129
130
# 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)

131
132
133
134
135
#-----------------------------------------------------------------------------
# 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)
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#-----------------------------------------------------------------------------
# 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.*")
ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX)

154
155
#-----------------------------------------------------------------------------
# Configure the standard library header wrappers based on compiler's
156
157
158
# capabilities and parent project's request.  Enforce 0/1 as only
# possible values for configuration into Configure.hxx.
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/kwsysPlatformCxxTests.cmake)
159

160
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAVE_STD
161
  "Checking whether STL classes are in std namespace" DIRECT)
162

163
IF(KWSYS_IOS_FORCE_OLD)
164
  SET(KWSYS_IOS_USE_ANSI 0)
165
ELSE(KWSYS_IOS_FORCE_OLD)
166
  KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_ANSI
167
    "Checking whether ANSI stream headers are available" DIRECT)
168
ENDIF(KWSYS_IOS_FORCE_OLD)
169

170
IF(KWSYS_IOS_USE_ANSI)
171
  KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAVE_STD
172
    "Checking whether ANSI streams are in std namespace" DIRECT)
173
  KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_USE_SSTREAM
174
    "Checking whether ANSI string stream is available" DIRECT)
175
ELSE(KWSYS_IOS_USE_ANSI)
176
  SET(KWSYS_IOS_HAVE_STD 0)
177
178
179
180
181
182
183
184
  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
185
    "Checking whether strstream.h is available" DIRECT)
186
187
188
189
  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
190
      "Checking whether strstrea.h is available" DIRECT)
191
192
  ENDIF(KWSYS_IOS_USE_STRSTREAM_H)
ENDIF(KWSYS_IOS_USE_SSTREAM)
193

194
195
196
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CSTDDEF
  "Checking whether header cstddef is available" DIRECT)

197
198
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
  -DKWSYS_STL_HAVE_STD=${KWSYS_STL_HAVE_STD})
199
200
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_NEQ_CHAR
  "Checking whether stl string has operator!= for char*" DIRECT)
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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)
216
217
218
219
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)
220
221
222
223
  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)
224
225
226
227
228
229
230
231
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)
232
233
234
235
236
237
238
239
240
241
242
IF(KWSYS_IOS_USE_ANSI)
  # ANSI streams always have string operators.
  SET(KWSYS_STL_STRING_HAVE_OSTREAM 1)
  SET(KWSYS_STL_STRING_HAVE_ISTREAM 1)
ELSE(KWSYS_IOS_USE_ANSI)
  # 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)
ENDIF(KWSYS_IOS_USE_ANSI)
243
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
244

245
246
247
248
249
250
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)
251
252
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
  "Checking whether argument dependent lookup is supported" DIRECT)
253

254
255
256
257
258
IF(UNIX)
  KWSYS_PLATFORM_CXX_TEST(KWSYS_STAT_HAS_ST_MTIM
    "Checking whether struct stat has st_mtim member" DIRECT)
ENDIF(UNIX)

259
IF(KWSYS_USE_FundamentalType)
260
261
262
263
264
265
266
267
268
269
270
271
272
273
  # Determine type sizes.
  INCLUDE(CheckTypeSize)
  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)
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
306
307
308

  # 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)
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328

  # Check signedness of "char" type.
  IF("KWSYS_CHAR_IS_SIGNED" MATCHES "^KWSYS_CHAR_IS_SIGNED$")
    MESSAGE(STATUS "Checking signedness of char")
    TRY_RUN(KWSYS_CHAR_IS_SIGNED KWSYS_CHAR_IS_SIGNED_COMPILED
      ${CMAKE_CURRENT_BINARY_DIR}
      ${CMAKE_CURRENT_SOURCE_DIR}/kwsysPlatformCxxTests.cxx
      COMPILE_DEFINITIONS -DTEST_KWSYS_CHAR_IS_SIGNED)
    IF(KWSYS_CHAR_IS_SIGNED_COMPILED)
      IF(KWSYS_CHAR_IS_SIGNED)
        MESSAGE(STATUS "Checking signedness of char -- signed")
        SET(KWSYS_CHAR_IS_SIGNED 1 CACHE INTERNAL "Whether char is signed.")
      ELSE(KWSYS_CHAR_IS_SIGNED)
        MESSAGE(STATUS "Checking signedness of char -- unsigned")
        SET(KWSYS_CHAR_IS_SIGNED 0 CACHE INTERNAL "Whether char is signed.")
      ENDIF(KWSYS_CHAR_IS_SIGNED)
    ELSE(KWSYS_CHAR_IS_SIGNED_COMPILED)
      MESSAGE(FATAL_ERROR "Checking signedness of char -- failed")
    ENDIF(KWSYS_CHAR_IS_SIGNED_COMPILED)
  ENDIF("KWSYS_CHAR_IS_SIGNED" MATCHES "^KWSYS_CHAR_IS_SIGNED$")
329
330
ENDIF(KWSYS_USE_FundamentalType)

331
332
333
334
335
336
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
337
338
339
340
341
342
343
344
345
346
347
348
349
# 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)

350
351
#-----------------------------------------------------------------------------
# Choose a directory for the generated headers.
352
353
354
355
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}")
356
INCLUDE_DIRECTORIES(${KWSYS_HEADER_ROOT})
357
358
359
360

#-----------------------------------------------------------------------------
# Create STL header wrappers to block warnings in the STL headers and
# give standard names by which they may be included.
361
SET(KWSYS_STL_HEADER_EXTRA_string 1)
362
FOREACH(header algorithm deque iterator list map numeric queue set stack string
363
               utility vector memory functional)
364
365
  # Configure the header wrapper.
  SET(KWSYS_STL_HEADER "${header}")
366
367
368
369
370
371
372
373
374
375
376
377
378
379
  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)
    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
380
                 ${KWSYS_HEADER_DIR}/stl/${header}
381
                 @ONLY IMMEDIATE)
382

383
384
  # Create an install target for the header wrapper.
  IF(KWSYS_HEADER_INSTALL_DIR)
385
386
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}/stl
      FILES ${KWSYS_HEADER_DIR}/stl/${header})
387
388
389
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
ENDFOREACH(header)

390
391
392
393
394
# Provide cstddef header.
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_cstddef.hxx.in
               ${KWSYS_HEADER_DIR}/cstddef
               @ONLY IMMEDIATE)

395
396
397
398
399
#-----------------------------------------------------------------------------
# Create streams header wrappers to give standard names by which they
# may be included.
FOREACH(header iostream fstream sstream iosfwd)
  # Configure the header wrapper.
400
401
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsys_ios_${header}.h.in
                 ${KWSYS_HEADER_DIR}/ios/${header}
402
403
404
405
                 @ONLY IMMEDIATE)

  # Create an install target for the header wrapper.
  IF(KWSYS_HEADER_INSTALL_DIR)
406
407
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}/ios
      FILES ${KWSYS_HEADER_DIR}/ios/${header})
408
409
410
411
412
413
414
  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)
415
SET(KWSYS_H_FILES Configure SharedForward)
416
417
418
419
SET(KWSYS_HXX_FILES Configure String
  hashtable hash_fun hash_map hash_set
  auto_ptr
  )
420

421
422
423
424
# Enforce component dependencies.
IF(KWSYS_USE_SystemTools)
  SET(KWSYS_USE_Directory 1)
ENDIF(KWSYS_USE_SystemTools)
Andy Cedilnik's avatar
Andy Cedilnik committed
425
426
427
428
429
IF(KWSYS_USE_Glob)
  SET(KWSYS_USE_Directory 1)
  SET(KWSYS_USE_SystemTools 1)
  SET(KWSYS_USE_RegularExpression 1)
ENDIF(KWSYS_USE_Glob)
430
431

# Add selected C++ classes.
Mathieu Malaterre's avatar
Mathieu Malaterre committed
432
SET(cppclasses Directory DynamicLoader Glob RegularExpression SystemTools CommandLineArguments Registry)
433
434
435
436
437
FOREACH(cpp ${cppclasses})
  IF(KWSYS_USE_${cpp})
    SET(KWSYS_CLASSES ${KWSYS_CLASSES} ${cpp})
  ENDIF(KWSYS_USE_${cpp})
ENDFOREACH(cpp)
438
439

# Add selected C components.
440
FOREACH(c Process Base64 FundamentalType Terminal)
441
442
443
444
  IF(KWSYS_USE_${c})
    SET(KWSYS_H_FILES ${KWSYS_H_FILES} ${c})
  ENDIF(KWSYS_USE_${c})
ENDFOREACH(c)
445

446
447
448
#-----------------------------------------------------------------------------
# Build a list of sources for the library based on components that are
# included.
449
450
SET(KWSYS_C_SRCS)
SET(KWSYS_CXX_SRCS)
451
452
453

# Add the proper sources for this platform's Process implementation.
IF(KWSYS_USE_Process)
454
  IF(NOT UNIX)
455
    # Use the Windows implementation.  We need the encoded forwarding executable.
456
    SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ProcessWin32.c
457
458
459
460
      ${PROJECT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c)
    SET_SOURCE_FILES_PROPERTIES(
      ${PROJECT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
      PROPERTIES GENERATED 1)
461
  ELSE(NOT UNIX)
462
    # Use the UNIX implementation.
463
    SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ProcessUNIX.c)
464
  ENDIF(NOT UNIX)
465
466
ENDIF(KWSYS_USE_Process)

467
468
469
470
471
472
# Add selected C sources.
FOREACH(c Base64 Terminal)
  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
473

474
475
476
# 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.
477
  SET(KWSYS_CXX_SRCS ${KWSYS_CXX_SRCS} ${c}.cxx)
478

479
480
  # Configure the header for this class.
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${c}.hxx.in ${KWSYS_HEADER_DIR}/${c}.hxx
481
                 @ONLY IMMEDIATE)
482
483
484
485
486
487

  # Create an install target for the header.
  IF(KWSYS_HEADER_INSTALL_DIR)
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
                  FILES  ${KWSYS_HEADER_DIR}/${c}.hxx)
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
488
489
ENDFOREACH(c)

490
491
492
493
# 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
494
                 @ONLY IMMEDIATE)
495
496
497
498
499
500

  # Create an install target for the header.
  IF(KWSYS_HEADER_INSTALL_DIR)
    INSTALL_FILES(${KWSYS_HEADER_INSTALL_DIR}/${KWSYS_NAMESPACE}
                  FILES  ${KWSYS_HEADER_DIR}/${h}.h)
  ENDIF(KWSYS_HEADER_INSTALL_DIR)
501
502
ENDFOREACH(h)

503
504
505
506
# 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
507
508
                 @ONLY IMMEDIATE)

509
510
511
512
513
514
  # Create an install target for the header.
  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)
515

516
517
#-----------------------------------------------------------------------------
# Add the library with the configured name and list of sources.
518
519
520
IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
  ADD_LIBRARY(${KWSYS_NAMESPACE} ${KWSYS_LIBRARY_TYPE}
    ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS})
521
522
523
524
525
  IF(KWSYS_USE_DynamicLoader)
    IF(UNIX)
      TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS})
    ENDIF(UNIX)
  ENDIF(KWSYS_USE_DynamicLoader)
526

527
528
529
530
531
532
533
  # 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)

534
535
  # Create an install target for the library.
  IF(KWSYS_LIBRARY_INSTALL_DIR)
536
537
538
539
540
541
542
543
    IF(VTK_INSTALL_HAS_CMAKE_24)
      INSTALL(TARGETS ${KWSYS_NAMESPACE}
        RUNTIME DESTINATION ${VTK_INSTALL_BIN_DIR_CM24} COMPONENT Runtime
        LIBRARY DESTINATION ${VTK_INSTALL_LIB_DIR_CM24} COMPONENT Runtime
        ARCHIVE DESTINATION ${VTK_INSTALL_LIB_DIR_CM24} COMPONENT Development)
    ELSE(VTK_INSTALL_HAS_CMAKE_24)
      INSTALL_TARGETS(${KWSYS_LIBRARY_INSTALL_DIR} ${KWSYS_NAMESPACE})
    ENDIF(VTK_INSTALL_HAS_CMAKE_24)
544
  ENDIF(KWSYS_LIBRARY_INSTALL_DIR)
545
546
547
548
549
550
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})

551
552
553
554
555
556
557
  # 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)

558
559
560
561
562
  # Create an install target for the library.
  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)
563

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

568
#-----------------------------------------------------------------------------
569
570
571
572
573
# 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)
574
  IF(NOT UNIX)
575
576
577
578
    # 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)
579

580
581
582
583
584
    # 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)
585

586
587
588
589
    SET(CFG_INTDIR "/${CMAKE_CFG_INTDIR}")
    IF(CMAKE_BUILD_TOOL MATCHES "make")
      SET(CFG_INTDIR "")
    ENDIF(CMAKE_BUILD_TOOL MATCHES "make")
590

591
592
593
594
595
596
597
598
    # 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
599
             ${KWSYS_NAMESPACE} ProcessFwd9x
600
601
602
603
604
605
606
        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
607
             ${KWSYS_NAMESPACE} ProcessFwd9x
608
609
610
        OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${KWSYS_NAMESPACE}ProcessFwd9xEnc.c
        DEPENDS ${CMD} ${FWD})
    ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.6)
611

612
613
614
    # Make sure build occurs in proper order.
    ADD_DEPENDENCIES(${KWSYS_NAMESPACE} ${KWSYS_NAMESPACE}ProcessFwd9x
                     ${KWSYS_NAMESPACE}EncodeExecutable)
615
  ENDIF(NOT UNIX)
616
617
618
619
ENDIF(KWSYS_USE_Process)

#-----------------------------------------------------------------------------
# Setup testing if not being built as part of another project.
620
IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
621
  IF(BUILD_TESTING)
622
    # C++ tests
623
624
625
626
    IF(KWSYS_USE_DynamicLoader)
      SET(EXTRA_TESTS
        testDynamicLoader
        )
627
628
      # If kwsys contains the DynamicLoader, need extra library
      ADD_LIBRARY(testDynload MODULE testDynload.c)
629
    ENDIF(KWSYS_USE_DynamicLoader)
630
631
632
633
634
635
    FOREACH(test
        testSystemTools
        testIOS
        testHashSTL
        testCommandLineArguments
        testRegistry
636
        ${EXTRA_TESTS}
637
638
639
640
641
642
643
644
        )
      ADD_EXECUTABLE(${test} ${test}.cxx)
      TARGET_LINK_LIBRARIES(${test} ${KWSYS_NAMESPACE})
    ENDFOREACH(test)
    # C tests
    FOREACH(test
        testProcess
        testFail
645
        testTerminal
646
647
648
649
650
651
652
653
654
655
        )
      ADD_EXECUTABLE(${test} ${test}.c)
      TARGET_LINK_LIBRARIES(${test} ${KWSYS_NAMESPACE}_c)
    ENDFOREACH(test)

    SET(EXEC_DIR "${CMAKE_CURRENT_BINARY_DIR}")
    IF(EXECUTABLE_OUTPUT_PATH)
      SET(EXEC_DIR "${EXECUTABLE_OUTPUT_PATH}")
    ENDIF(EXECUTABLE_OUTPUT_PATH)

656

657
658
    SET(TEST_SYSTEMTOOLS_BIN_FILE
      "${CMAKE_CURRENT_SOURCE_DIR}/testSystemTools.bin")
659
    SET(TEST_SYSTEMTOOLS_SRC_FILE
660
      "${CMAKE_CURRENT_SOURCE_DIR}/testSystemTools.cxx")
661
662
663
664
665
    CONFIGURE_FILE(
      ${PROJECT_SOURCE_DIR}/testSystemTools.h.in
      ${PROJECT_BINARY_DIR}/testSystemTools.h)
    INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})

666
667
668
669
670
    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)
671
    ADD_TEST(kwsys.testSystemTools ${EXEC_DIR}/testSystemTools)
672
673
674
    IF(KWSYS_USE_DynamicLoader)
      ADD_TEST(kwsys.testDynamicLoader ${EXEC_DIR}/testDynamicLoader)
    ENDIF(KWSYS_USE_DynamicLoader)
675
676
677
678
679
680
    ADD_TEST(kwsys.testProcess-1 ${EXEC_DIR}/testProcess 1)
    ADD_TEST(kwsys.testProcess-2 ${EXEC_DIR}/testProcess 2)
    ADD_TEST(kwsys.testProcess-3 ${EXEC_DIR}/testProcess 3)
    ADD_TEST(kwsys.testProcess-4 ${EXEC_DIR}/testProcess 4)
    ADD_TEST(kwsys.testProcess-5 ${EXEC_DIR}/testProcess 5)
    ADD_TEST(kwsys.testProcess-6 ${EXEC_DIR}/testProcess 6)
681
682
683
    IF(NOT CYGWIN)
      ADD_TEST(kwsys.testProcess-7 ${EXEC_DIR}/testProcess 7)
    ENDIF(NOT CYGWIN)
684
685
    ADD_TEST(kwsys.testHashSTL ${EXEC_DIR}/testHashSTL)
    ADD_TEST(kwsys.testRegistry ${EXEC_DIR}/testRegistry)
686
    IF(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY AND KWSYS_STANDALONE)
687
      ADD_TEST(kwsys.testFail ${EXEC_DIR}/testFail)
688
      # We expect test to fail
689
      SET_TESTS_PROPERTIES(kwsys.testFail PROPERTIES WILL_FAIL ON)
690
      GET_TEST_PROPERTY(kwsys.testFail WILL_FAIL wfv)
691
692
      SET_TESTS_PROPERTIES(kwsys.testRegistry PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR;FAIL;Test failed")
      SET_TESTS_PROPERTIES(kwsys.testRegistry PROPERTIES PASS_REGULAR_EXPRESSION "Test passed")
Andy Cedilnik's avatar
Andy Cedilnik committed
693
      MESSAGE(STATUS "GET_TEST_PROPERTY returned: ${wfv}")
694
    ENDIF(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY AND KWSYS_STANDALONE)
695
  ENDIF(BUILD_TESTING)
696
ENDIF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)