CMakeLists.txt 143 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
2
# a macro for tests that have a simple format where the name matches the
# directory and project
3
4
5
6
macro(ADD_TEST_MACRO NAME)
  if(${ARGC} GREATER 1)
    set(_test_command --test-command ${ARGN})
  endif()
7
8
  string(REPLACE "." "/" dir "${NAME}")
  string(REGEX REPLACE "[^.]*\\." "" proj "${NAME}")
9
  add_test(NAME "${NAME}" COMMAND "${CMAKE_CTEST_COMMAND}"
Ken Martin's avatar
Ken Martin committed
10
    --build-and-test
11
12
    "${CMake_SOURCE_DIR}/Tests/${dir}"
    "${CMake_BINARY_DIR}/Tests/${dir}"
Ken Martin's avatar
Ken Martin committed
13
    --build-two-config
14
    ${build_generator_args}
15
    --build-project ${proj}
16
    ${${NAME}_CTEST_OPTIONS}
17
    --build-options ${build_options}
18
    ${${NAME}_BUILD_OPTIONS}
19
20
    ${_test_command})
  unset(_test_command)
21
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${dir}")
22
endmacro()
Ken Martin's avatar
Ken Martin committed
23

24
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
25

26
# Fake a user home directory to avoid polluting the real one.
27
28
29
30
31
if(DEFINED ENV{HOME} AND NOT CTEST_NO_TEST_HOME)
  set(TEST_HOME "${CMake_BINARY_DIR}/Tests/CMakeFiles/TestHome")
  file(MAKE_DIRECTORY "${TEST_HOME}")
  file(WRITE "${TEST_HOME}/.cvspass" ":pserver:anoncvs@www.cmake.org:/cvsroot/KWSys A\n")
  set(TEST_HOME_ENV_CODE "# Fake a user home directory to avoid polluting the real one.
32
33
# But provide original ENV{HOME} value in ENV{CTEST_REAL_HOME} for tests that
# need access to the real HOME directory.
34
35
36
if(NOT DEFINED ENV{CTEST_REAL_HOME})
  set(ENV{CTEST_REAL_HOME} \"\$ENV{HOME}\")
endif()
37
set(ENV{HOME} \"${TEST_HOME}\")
38
")
39
endif()
40

41
42
43
44
45
46
47
48
49
50
51
52
# 3.9 or later provides a definitive answer to whether we are multi-config
# through a global property. Prior to 3.9, CMAKE_CONFIGURATION_TYPES being set
# is assumed to mean multi-config, but developers might modify it so it is
# technically not as reliable.
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
  get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
elseif(CMAKE_CONFIGURATION_TYPES)
  set(_isMultiConfig True)
else()
  set(_isMultiConfig False)
endif()

53
# Choose a default configuration for CTest tests.
54
set(CTestTest_CONFIG Debug)
55
if(NOT _isMultiConfig AND CMAKE_BUILD_TYPE)
56
57
  set(CTestTest_CONFIG ${CMAKE_BUILD_TYPE})
endif()
58

59
configure_file(${CMake_SOURCE_DIR}/Tests/EnforceConfig.cmake.in
60
               ${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake @ONLY)
61

62
# Testing
63
if(BUILD_TESTING)
64
  set(CMake_TEST_DEVENV "")
65
66
  if(CMAKE_VS_DEVENV_COMMAND)
    set(CMake_TEST_DEVENV "${CMAKE_VS_DEVENV_COMMAND}")
67
  elseif(CMAKE_GENERATOR MATCHES "Visual Studio 9 " AND
68
69
70
71
      NOT CMAKE_MAKE_PROGRAM MATCHES "[mM][sS][bB][uU][iI][lL][dD]\\.[eE][xX][eE]")
    set(CMake_TEST_DEVENV "${CMAKE_MAKE_PROGRAM}")
  endif()

72
  if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
73
    set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "")
74
  else()
75
    set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
76
  endif()
77

78
79
80
81
  if(NOT CMake_TEST_EXTERNAL_CMAKE)
    if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles" OR ("${CMAKE_GENERATOR}" MATCHES Ninja AND NOT WIN32))
      set(TEST_CompileCommandOutput 1)
    endif()
82
  endif()
83

84
  set(MAKE_IS_GNU )
85
86
  if(CMAKE_MAKE_PROGRAM MATCHES make)
    execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} no_such_target --version
87
88
89
90
91
92
93
94
95
96
      RESULT_VARIABLE res OUTPUT_VARIABLE out ERROR_VARIABLE out)
    if("${res}" STREQUAL "0")
      if("${out}" MATCHES "GNU")
        set(MAKE_IS_GNU 1)
      endif()
    endif()
  endif()

  # some old versions of make simply cannot handle spaces in paths
  if (MAKE_IS_GNU OR
97
      CMAKE_MAKE_PROGRAM MATCHES "nmake|gmake|wmake" OR
98
      CMAKE_GENERATOR MATCHES "Visual Studio|Xcode|Borland")
99
100
101
102
103
    set(MAKE_SUPPORTS_SPACES 1)
  else()
    set(MAKE_SUPPORTS_SPACES 0)
  endif()

104
105
106
107
108
109
110
111
112
113
114
  # assume no resources building to test
  set(CMake_TEST_RESOURCES FALSE)
  # for windows and cygwin assume we have resources
  if(WIN32 OR CYGWIN)
    set(CMake_TEST_RESOURCES TRUE)
  endif()
  # for borland and watcom there is no resource support
  if(WATCOM OR BORLAND)
    set(CMake_TEST_RESOURCES FALSE)
  endif()

115
  set(build_generator_args
116
    --build-generator ${CMAKE_GENERATOR}
117
    )
118
119
120
121
122
  if(CMAKE_GENERATOR_PLATFORM)
    list(APPEND build_generator_args
      --build-generator-platform ${CMAKE_GENERATOR_PLATFORM}
      )
  endif()
123
  if(CMAKE_GENERATOR_TOOLSET)
124
    list(APPEND build_generator_args
125
      --build-generator-toolset ${CMAKE_GENERATOR_TOOLSET}
126
127
      )
  endif()
128

129
  set(build_options)
130
131
  if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
    list(APPEND build_options -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
132
  endif()
133

134
135
  # Look for rpmbuild to use for tests.
  # The tool does not work with spaces in the path.
136
  if(NOT CMAKE_CURRENT_BINARY_DIR MATCHES " ")
137
138
139
140
141
    find_program(RPMBUILD_EXECUTABLE NAMES rpmbuild)
  else()
    set(RPMBUILD_EXECUTABLE "RPMBUILD_EXECUTABLE-NOTFOUND")
  endif()

142
143
144
145
146
147
  if(RPMBUILD_EXECUTABLE)
    set(CPACK_BINARY_RPM ON)
  else()
    set(CPACK_BINARY_RPM OFF)
  endif()

148
  # Look for dpkg to use for tests.
149
150
151
152
153
154
155
156
  find_program(DPKG_EXECUTABLE NAMES dpkg)

  if(DPKG_EXECUTABLE)
    set(CPACK_BINARY_DEB ON)
  else()
    set(CPACK_BINARY_DEB OFF)
  endif()

Alex Turbov's avatar
Alex Turbov committed
157
158
159
160
161
162
163
164
165
  # Look for NuGet to use for tests.
  find_program(NUGET_EXECUTABLE NAMES NuGet nuget)

  if(NUGET_EXECUTABLE)
    set(CPACK_BINARY_NUGET ON)
  else()
    set(CPACK_BINARY_NUGET OFF)
  endif()

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
  if(WIN32)
    # Macro to search for available Windows CE SDKs in the windows Registry
    macro(select_wince_sdk selected_reg selected_sdk)
      if(CMAKE_HOST_WIN32)
        execute_process(COMMAND reg QUERY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows CE Tools\\SDKs"
                    OUTPUT_VARIABLE sdk_reg
                    ERROR_VARIABLE my_err)
        string(REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Wow6432Node\\\\Microsoft\\\\Windows CE Tools\\\\SDKs\\\\"  ";" sdk_list "${sdk_reg}")
        list(LENGTH sdk_list sdk_list_len)
        if (${sdk_list_len} GREATER 1)
          list(GET sdk_list 1 _sdk) # The first entry is always empty due to the regex replace above
          string(STRIP ${_sdk} _sdk) # Make sure there is no newline in the SDK name
        endif()
        # Build a key to be used by get_filename_component that is pointing to the SDK directory
        set(_reg "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows CE Tools\\SDKs\\${_sdk}]")
        # Set return values
        set(${selected_reg} ${_reg})
        set(${selected_sdk} ${_sdk})
      endif(CMAKE_HOST_WIN32)
    endmacro(select_wince_sdk)

    set(reg_vs10 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0;InstallDir]")
    set(reg_vs11 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0;InstallDir]")
    set(reg_vs12 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\12.0;InstallDir]")
    set(reg_vs14 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0;InstallDir]")
    set(reg_ws80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]")
    set(reg_ws81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.1;InstallationFolder]")
    set(reg_ws10_0 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\Setup\\Build Tools for Windows 10;srcPath]")
    set(reg_wp80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\WindowsPhone\\v8.0;InstallationFolder]")
    set(reg_wp81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\WindowsPhone\\v8.1;InstallationFolder]")
    select_wince_sdk(reg_wince wince_sdk)
    set(reg_tegra "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;sdkRoot]")
    set(reg_nasm "[HKEY_CURRENT_USER\\SOFTWARE\\nasm]")
    foreach(reg vs10 vs11 vs12 vs14 ws80 ws81 ws10_0 wp80 wp81 wince tegra nasm)
      get_filename_component(r "${reg_${reg}}" ABSOLUTE)
      if(IS_DIRECTORY "${r}" AND NOT "${r}" STREQUAL "/registry")
        set(${reg} 1)
      else()
        set(${reg} 0)
      endif()
    endforeach()
  endif()

209
210
211
  #---------------------------------------------------------------------------
  # Add tests below here.

212
213
  if(NOT CMake_TEST_EXTERNAL_CMAKE)
    add_subdirectory(CMakeLib)
jdavidberger's avatar
jdavidberger committed
214

215
    add_subdirectory(CMakeServerLib)
216
  endif()
217
218
  add_subdirectory(CMakeOnly)
  add_subdirectory(RunCMake)
219

220
  add_subdirectory(FindPackageModeMakefileTest)
221

222
  # Collect a list of all test build directories.
223
  set(TEST_BUILD_DIRS)
224

225
  # Should the long tests be run?
226
  option(CMAKE_RUN_LONG_TESTS
227
    "Should the long tests be run (such as Bootstrap)." ON)
228
  mark_as_advanced(CMAKE_RUN_LONG_TESTS)
229

230
231
  if (CMAKE_RUN_LONG_TESTS)
    option(CTEST_TEST_CTEST
232
      "Should the tests that run a full sub ctest process be run?"
233
      OFF)
234
    mark_as_advanced(CTEST_TEST_CTEST)
235
  endif ()
236

237
238
239
240
  # Should tests that use CVS be run?
  #
  set(do_cvs_tests 0)

241
242
  if(EXISTS ${CMAKE_ROOT}/Modules/FindCVS.cmake)
    find_package(CVS QUIET)
243
  else()
244
    find_program(CVS_EXECUTABLE NAMES cvs)
245
  endif()
246

247
248
  if(CVS_EXECUTABLE)
    set(do_cvs_tests 1)
249
  endif()
250

251
252
253
  if(do_cvs_tests AND NOT UNIX)
    if("${CVS_EXECUTABLE}" MATCHES "cygwin")
      set(do_cvs_tests 0)
254
255
    endif()
  endif()
256

257
258
259
260
261
262
263
264
265
266
267
  # Should CPack tests be run? By default, yes, but...
  #
  # Disable packaging test on Apple 10.3 and below. PackageMaker starts
  # DiskManagementTool as root and disowns it
  # (http://lists.apple.com/archives/installer-dev/2005/Jul/msg00005.html).
  # It is left holding open pipe handles and preventing ProcessUNIX from
  # detecting end-of-data even after its immediate child exits. Then
  # the test hangs until it times out and is killed. This is a
  # well-known bug in kwsys process execution that I would love to get
  # time to fix.
  #
268
  option(CTEST_TEST_CPACK
269
270
    "Should the tests that use '--build-target package' be run?"
    ON)
271
272
  mark_as_advanced(CTEST_TEST_CPACK)
  set(CTEST_TEST_OSX_ARCH 0)
273
  set(CMake_TEST_XCODE_VERSION 0)
274
275
  if(APPLE)
    execute_process(
276
277
278
279
      COMMAND sw_vers -productVersion
      OUTPUT_VARIABLE OSX_VERSION
      OUTPUT_STRIP_TRAILING_WHITESPACE
      )
280
    if(OSX_VERSION VERSION_LESS 10.4)
281
282
283
      message(STATUS "Forcing CTEST_TEST_CPACK=OFF on OSX < 10.4")
      message(STATUS "OSX_VERSION='${OSX_VERSION}'")
      set(CTEST_TEST_CPACK OFF)
284
    else()
285
      set(CTEST_TEST_OSX_ARCH 1)
286
    endif()
287
288
289
290
291
292
293
294
295
296
297
    if(XCODE_VERSION)
      set(CMake_TEST_XCODE_VERSION "${XCODE_VERSION}")
    else()
      execute_process(
        COMMAND xcodebuild -version
        OUTPUT_VARIABLE _version ERROR_VARIABLE _version
        )
      if(_version MATCHES "^Xcode ([0-9]+(\\.[0-9]+)*)")
        set(CMake_TEST_XCODE_VERSION "${CMAKE_MATCH_1}")
      endif()
    endif()
298
299
300
301
    if(NOT CMake_TEST_XCODE_VERSION VERSION_LESS 10)
      # Since Xcode 10 we do not have two supported architectures for the host.
      set(CTEST_TEST_OSX_ARCH 0)
    endif()
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
    if(CMAKE_OSX_SYSROOT)
      execute_process(
        COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version ProductName
        OUTPUT_VARIABLE _stdout
        OUTPUT_STRIP_TRAILING_WHITESPACE
        ERROR_VARIABLE _stderr
        RESULT_VARIABLE _failed
        )
      if(NOT _failed)
        set(CMAKE_OSX_SDKPRODUCT "${_stdout}")
      endif()

      execute_process(
        COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion
        OUTPUT_VARIABLE _stdout
        OUTPUT_STRIP_TRAILING_WHITESPACE
        ERROR_VARIABLE _stderr
        RESULT_VARIABLE _failed
        )
      if(NOT _failed)
        set(CMAKE_OSX_SDKVERSION "${_stdout}")
      endif()
    endif()
325
  endif()
326

327
328
  # Use 1500 or CTEST_TEST_TIMEOUT for long test timeout value,
  # whichever is greater.
329
330
331
  set(CMAKE_LONG_TEST_TIMEOUT 1500)
  if(CTEST_TEST_TIMEOUT)
    set(CMAKE_LONG_TEST_TIMEOUT ${CTEST_TEST_TIMEOUT})
332
  endif()
333
334
  if(CMAKE_LONG_TEST_TIMEOUT LESS 1500)
    set(CMAKE_LONG_TEST_TIMEOUT 1500)
335
  endif()
336

337
  add_test(NAME CMake.Copyright
338
    COMMAND ${CMAKE_CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeCopyright.cmake)
339

340
  # add a bunch of standard build-and-test style tests
Ken Martin's avatar
Ken Martin committed
341
342
  ADD_TEST_MACRO(CommandLineTest CommandLineTest)
  ADD_TEST_MACRO(FindPackageTest FindPackageTest)
Bill Hoffman's avatar
Bill Hoffman committed
343
  ADD_TEST_MACRO(FindModulesExecuteAll FindModulesExecuteAll)
Ken Martin's avatar
Ken Martin committed
344
345
346
347
  ADD_TEST_MACRO(StringFileTest StringFileTest)
  ADD_TEST_MACRO(TryCompile TryCompile)
  ADD_TEST_MACRO(SystemInformation SystemInformation)
  ADD_TEST_MACRO(MathTest MathTest)
348
  ADD_TEST_MACRO(CompileFeatures CompileFeatures)
349
  ADD_TEST_MACRO(CMakeCommands.target_compile_features)
350

351
  if(CMake_TEST_RESOURCES)
352
    ADD_TEST_MACRO(VSResource VSResource)
353
354
355
    if (CMAKE_GENERATOR MATCHES "Ninja")
      add_test_macro(VSResourceNinjaForceRSP VSResourceNinjaForceRSP)
    endif ()
356
  endif()
357
  ADD_TEST_MACRO(MSManifest MSManifest)
Ken Martin's avatar
Ken Martin committed
358
359
  ADD_TEST_MACRO(Simple Simple)
  ADD_TEST_MACRO(PreOrder PreOrder)
360
  ADD_TEST_MACRO(MissingSourceFile MissingSourceFile)
361
  set_tests_properties(MissingSourceFile PROPERTIES
362
    PASS_REGULAR_EXPRESSION "CMake Error at CMakeLists.txt:3 \\(add_executable\\):[ \r\n]*Cannot find source file:[ \r\n]*DoesNotExist/MissingSourceFile.c")
363
364
365
366
367
368
369
370
  if(CMake_TEST_XCODE_VERSION AND CMAKE_OSX_SDKVERSION AND CMAKE_OSX_SDKPRODUCT)
    if((NOT CMake_TEST_XCODE_VERSION VERSION_LESS 6.1) AND
       ((NOT CMAKE_OSX_SDKPRODUCT STREQUAL "Mac OS X") OR
        (NOT CMAKE_OSX_SDKVERSION VERSION_LESS 10.10)))
      if(CMAKE_GENERATOR STREQUAL "Xcode")
        ADD_TEST_MACRO(SwiftMix SwiftMix)
        ADD_TEST_MACRO(SwiftOnly SwiftOnly)
      endif()
371
372
    endif()
  endif()
373
  if(CMAKE_Fortran_COMPILER)
374
    ADD_TEST_MACRO(FortranOnly FortranOnly)
375
  endif()
376
377
378
379
380
381
  # test Visual Studio GNU Fortran mixing with cmake_add_fortran_subdirectory
  # run this project if we have a working fortran compiler or
  # the test is enabled with CMAKE_TEST_CMAKE_ADD_FORTRAN cache variable.
  # If you enable the test, CMake should find the MinGW fortran install,
  # or in some cases you might need to set the PATH so that cmake can find
  # the gfortran from mingw.
382
383
  if(CMAKE_Fortran_COMPILER OR CMAKE_TEST_CMAKE_ADD_FORTRAN)
    set(CMAKE_SKIP_VSGNUFortran FALSE)
384
385
    # disable test for apple builds using ifort if they are building
    # more than one architecture, as ifort does not support that.
386
387
388
389
390
391
392
393
    if(APPLE AND (CMAKE_Fortran_COMPILER MATCHES ifort))
      list(LENGTH CMAKE_OSX_ARCHITECTURES len)
      if("${len}" GREATER 1)
        message(STATUS "Skip VSGNUFortran for ifort dual cpu mac build")
        set(CMAKE_SKIP_VSGNUFortran TRUE)
      endif()
    endif()
    if((CMAKE_C_COMPILER MATCHES lsb)
394
        AND (CMAKE_Fortran_COMPILER MATCHES ifort))
395
396
397
398
      message(STATUS "Skip VSGNUFortran for ifort and lsb compilers")
      set(CMAKE_SKIP_VSGNUFortran TRUE)
    endif()
    if(NOT CMAKE_SKIP_VSGNUFortran)
399
      ADD_TEST_MACRO(VSGNUFortran ${CMAKE_CMAKE_COMMAND} -P runtest.cmake)
400
401
    endif()
  endif()
402

403
  if(${CMAKE_GENERATOR} MATCHES "Visual Studio ([^9]|[9][0-9])")
404
    ADD_TEST_MACRO(CSharpOnly CSharpOnly)
405
    ADD_TEST_MACRO(CSharpLinkToCxx CSharpLinkToCxx)
406
    ADD_TEST_MACRO(CSharpLinkFromCxx CSharpLinkFromCxx)
407
  endif()
408

Ken Martin's avatar
Ken Martin committed
409
410
  ADD_TEST_MACRO(COnly COnly)
  ADD_TEST_MACRO(CxxOnly CxxOnly)
411
  ADD_TEST_MACRO(CxxSubdirC CxxSubdirC)
412
  ADD_TEST_MACRO(IPO COnly/COnly)
413
  ADD_TEST_MACRO(OutDir runtime/OutDir)
414
  ADD_TEST_MACRO(OutName exe.OutName.exe)
Brad King's avatar
Brad King committed
415
  ADD_TEST_MACRO(ObjectLibrary UseCshared)
Ken Martin's avatar
Ken Martin committed
416
417
  ADD_TEST_MACRO(NewlineArgs NewlineArgs)
  ADD_TEST_MACRO(SetLang SetLang)
418
  ADD_TEST_MACRO(EmptyProperty EmptyProperty)
419
  ADD_TEST_MACRO(ExternalOBJ ExternalOBJ)
420
421
422
  if(NOT CMake_TEST_EXTERNAL_CMAKE)
    ADD_TEST_MACRO(LoadCommand LoadedCommand)
  endif()
423
  ADD_TEST_MACRO(LinkDirectory bin/LinkDirectory)
424
  ADD_TEST_MACRO(LinkLanguage LinkLanguage)
425
426
  ADD_TEST_MACRO(LinkLine LinkLine)
  ADD_TEST_MACRO(MacroTest miniMacroTest)
427
  ADD_TEST_MACRO(FunctionTest miniFunctionTest)
428
  ADD_TEST_MACRO(ReturnTest ReturnTest)
429
  ADD_TEST_MACRO(Properties Properties)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
430
  ADD_TEST_MACRO(Assembler HelloAsm)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
431
  ADD_TEST_MACRO(SourceGroups SourceGroups)
432
  ADD_TEST_MACRO(Preprocess Preprocess)
433
  set(ExportImport_BUILD_OPTIONS -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
434
  ADD_TEST_MACRO(ExportImport ExportImport)
Brad King's avatar
Brad King committed
435
  ADD_TEST_MACRO(Unset Unset)
436
  ADD_TEST_MACRO(PolicyScope PolicyScope)
437
  ADD_TEST_MACRO(EmptyLibrary EmptyLibrary)
438
  ADD_TEST_MACRO(CompileDefinitions CompileDefinitions)
439
440
441
  if(CMAKE_Fortran_COMPILER)
    set(CompileOptions_BUILD_OPTIONS -DTEST_FORTRAN=1)
  endif()
442
  ADD_TEST_MACRO(CompileOptions CompileOptions)
443
  ADD_TEST_MACRO(CompatibleInterface CompatibleInterface)
444
  ADD_TEST_MACRO(AliasTarget AliasTarget)
445
  ADD_TEST_MACRO(StagingPrefix StagingPrefix)
446
  ADD_TEST_MACRO(ImportedSameName ImportedSameName)
447
  ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary)
448
449
450
451
  if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
    set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
    ADD_TEST_MACRO(ConfigSources ConfigSources)
  endif()
452
  ADD_TEST_MACRO(SourcesProperty SourcesProperty)
453
  ADD_TEST_MACRO(SourceFileProperty SourceFileProperty)
454
455
456
  if (NOT CMAKE_GENERATOR STREQUAL "Xcode")
    ADD_TEST_MACRO(SourceFileIncludeDirProperty SourceFileIncludeDirProperty)
  endif()
457
  if(CMAKE_CXX_COMPILER_ID STREQUAL GNU
458
      AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
459
460
461
    set(runCxxDialectTest 1)
  endif()
  if(CMAKE_CXX_COMPILER_ID STREQUAL Clang
462
        AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4 AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
463
464
465
466
467
468
469
    if(NOT APPLE OR POLICY CMP0025)
      set(runCxxDialectTest 1)
    endif()
  endif()
  if(runCxxDialectTest)
    ADD_TEST_MACRO(CxxDialect CxxDialect)
  endif()
470
  set_tests_properties(EmptyLibrary PROPERTIES
471
    PASS_REGULAR_EXPRESSION "CMake Error: CMake can not determine linker language for target: test")
472
  ADD_TEST_MACRO(CrossCompile CrossCompile)
473
  set_tests_properties(CrossCompile PROPERTIES
474
    PASS_REGULAR_EXPRESSION "TRY_RUN.. invoked in cross-compiling mode")
475
  if("${CMAKE_GENERATOR}" MATCHES "Make")
476
    ADD_TEST_MACRO(Policy0002 Policy0002)
477
  endif()
478
  if(CTEST_TEST_OSX_ARCH)
479
    ADD_TEST_MACRO(Architecture Architecture)
480
    set_tests_properties(Architecture PROPERTIES
481
      PASS_REGULAR_EXPRESSION "(file is not of required architecture|does not match cputype|not the architecture being linked)")
482
  endif()
483

484
  list(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX})
485

486
487
488
489
  if(NOT DEFINED CMake_TEST_Qt4)
    set(CMake_TEST_Qt4 1)
  endif()
  if(CMake_TEST_Qt4 AND NOT QT4_FOUND)
490
    find_package(Qt4 QUIET)
491
  endif()
492

493
  if(CMake_TEST_Qt4 AND QT4_FOUND)
494
495
496
497
    # test whether the Qt4 which has been found works, on some machines
    # which run nightly builds there were errors like "wrong file format"
    # for libQtCore.so. So first check it works, and only if it does add
    # the automoc test.
498
499
500
    include(CheckCXXSourceCompiles)
    set(_save_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
    set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
501

502
503
    set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES})
    set(CMAKE_REQUIRED_LIBRARIES ${QT_QTCORE_LIBRARIES})
504
505
506
507

    CHECK_CXX_SOURCE_COMPILES("#include <QCoreApplication>\n int main() {return (qApp == 0 ? 0 : 1); }\n"
                              QT4_WORKS)

508
509
510
    set(CMAKE_REQUIRED_INCLUDES "${_save_CMAKE_REQUIRED_INCLUDES}")
    set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}")
  endif()
511

512
  # run test for BundleUtilities on supported platforms/compilers
513
  if(MSVC OR
514
     MINGW OR
515
516
     CMAKE_SYSTEM_NAME MATCHES "Linux" OR
     CMAKE_SYSTEM_NAME MATCHES "Darwin")
517
  if(NOT "${CMAKE_GENERATOR}" STREQUAL "Watcom WMake")
518

519
    add_test(BundleUtilities ${CMAKE_CTEST_COMMAND}
520
521
522
      --build-and-test
      "${CMake_SOURCE_DIR}/Tests/BundleUtilities"
      "${CMake_BINARY_DIR}/Tests/BundleUtilities"
523
      ${build_generator_args}
524
      --build-project BundleUtilities
525
      --build-options ${build_options}
526
      )
527
    list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities")
528
529
530

    # run test for DeployQt4 on supported platforms/compilers (which depends on BundleUtilities)
    # this test also depends on the existence of the standard qtiff plugin
531
    if(QT4_WORKS AND QT_QTSQL_FOUND)
532
      add_test(Qt4Deploy ${CMAKE_CTEST_COMMAND}
533
534
535
        --build-and-test
        "${CMake_SOURCE_DIR}/Tests/Qt4Deploy"
        "${CMake_BINARY_DIR}/Tests/Qt4Deploy"
536
        ${build_generator_args}
537
        --build-project Qt4Deploy
538
        --build-options ${build_options}
539
        -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
540
        -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
541
        )
542
      list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Deploy")
543
544
    endif()

545
546
  endif()
  endif()
547

548
549
550
551
  set(CMAKE_BUILD_TEST_SOURCE_DIR "${CMake_SOURCE_DIR}/Tests/COnly")
  set(CMAKE_BUILD_TEST_BINARY_DIR "${CMake_BINARY_DIR}/Tests/CMakeBuildCOnly")
  set(CMAKE_BUILD_TEST_EXE COnly)
  configure_file("${CMake_SOURCE_DIR}/Tests/CMakeBuildTest.cmake.in"
552
    "${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake" @ONLY)
553
  add_test(CMakeBuildTest ${CMAKE_CMAKE_COMMAND} -P
554
    "${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake")
555
  list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
556
  # now do it again for a project that has two project commands
557
558
559
560
  set(CMAKE_BUILD_TEST_SOURCE_DIR "${CMake_SOURCE_DIR}/Tests/DoubleProject")
  set(CMAKE_BUILD_TEST_BINARY_DIR "${CMake_BINARY_DIR}/Tests/DoubleProject")
  set(CMAKE_BUILD_TEST_EXE just_silly)
  configure_file("${CMake_SOURCE_DIR}/Tests/CMakeBuildTest.cmake.in"
561
    "${CMake_BINARY_DIR}/Tests/CMakeBuildDoubleProjectTest.cmake" @ONLY)
562
  add_test(CMakeDoubleProject ${CMAKE_CMAKE_COMMAND} -P
563
    "${CMake_BINARY_DIR}/Tests/CMakeBuildDoubleProjectTest.cmake")
564
  list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
565

Brad King's avatar
Brad King committed
566
567
  ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)

568
569
570
571
572
573
574
575
576
577
578
  set(Module.CheckIPOSupported-C_BUILD_OPTIONS -DCMake_TEST_IPO_WORKS_C=${CMake_TEST_IPO_WORKS_C})
  ADD_TEST_MACRO(Module.CheckIPOSupported-C CheckIPOSupported-C)

  set(Module.CheckIPOSupported-CXX_BUILD_OPTIONS -DCMake_TEST_IPO_WORKS_CXX=${CMake_TEST_IPO_WORKS_CXX})
  ADD_TEST_MACRO(Module.CheckIPOSupported-CXX CheckIPOSupported-CXX)

  if(CMAKE_Fortran_COMPILER)
    set(Module.CheckIPOSupported-Fortran_BUILD_OPTIONS -DCMake_TEST_IPO_WORKS_Fortran=${CMake_TEST_IPO_WORKS_Fortran})
    ADD_TEST_MACRO(Module.CheckIPOSupported-Fortran CheckIPOSupported-Fortran)
  endif()

579
580
581
582
  add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/Module/ExternalData"
    "${CMake_BINARY_DIR}/Tests/Module/ExternalData"
583
    ${build_generator_args}
584
    --build-project ExternalDataTest
585
    --build-noclean
586
    --force-new-ctest-process
587
588
    --build-options ${build_options}
      -DMAKE_SUPPORTS_SPACES=${MAKE_SUPPORTS_SPACES}
589
590
591
592
    --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
    )
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Module/ExternalData")

593
  ADD_TEST_MACRO(Module.FindDependency FindDependency)
594

595
596
  ADD_TEST_MACRO(Module.WriteCompilerDetectionHeader WriteCompilerDetectionHeader)

597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
  if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
    include(CheckCXXCompilerFlag)
    check_cxx_compiler_flag(-fPIE run_pic_test)
  else()
    if (CMAKE_CXX_COMPILER_ID MATCHES "PGI"
        OR CMAKE_CXX_COMPILER_ID MATCHES "PathScale"
        OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
      set(run_pic_test 0)
    else()
      set(run_pic_test 1)
    endif()
  endif()

  if (run_pic_test)
    ADD_TEST_MACRO(PositionIndependentTargets PositionIndependentTargets)
  endif()

614
615
616
617
618
619
620
621
622
623
  if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") AND
    (NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 4.2) AND
    (CMAKE_SYSTEM_NAME MATCHES "Linux"))

    include(CheckCXXCompilerFlag)
    check_cxx_compiler_flag(
      -fvisibility-inlines-hidden run_inlines_hidden_test)
  endif()

  if(run_inlines_hidden_test)
624
    add_test(Visibility ${CMAKE_CTEST_COMMAND}
625
      --build-and-test
626
627
      "${CMake_SOURCE_DIR}/Tests/Visibility"
      "${CMake_BINARY_DIR}/Tests/Visibility"
628
      ${build_generator_args}
629
      --build-project Visibility
630
631
632
      --build-options ${build_options}
    )
    list(APPEND TEST_BUILD_DIRS
633
      "${CMake_BINARY_DIR}/Tests/Visibility"
634
635
636
    )
  endif()

637
  add_test(LinkFlags-prepare
638
639
640
641
    ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/LinkFlags"
    "${CMake_BINARY_DIR}/Tests/LinkFlags"
642
    ${build_generator_args}
643
644
    --build-project LinkFlags
    --build-target LinkFlags
645
646
    --build-options ${build_options}
      -DTEST_CONFIG=\${CTEST_CONFIGURATION_TYPE}
647
    )
648
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LinkFlags")
649

650
651
  macro(ADD_LINK_FLAGS_TEST name depends)
    add_test(LinkFlags-${name}
652
653
654
      ${CMAKE_CMAKE_COMMAND} --build "${CMake_BINARY_DIR}/Tests/LinkFlags"
      --target LinkFlags_${name} --config \${CTEST_CONFIGURATION_TYPE}
      )
655
    set_tests_properties(LinkFlags-${name} PROPERTIES
656
      PASS_REGULAR_EXPRESSION "BADFLAG" DEPENDS LinkFlags-${depends})
657
  endmacro()
658
659
  ADD_LINK_FLAGS_TEST(lib prepare)
  ADD_LINK_FLAGS_TEST(dll lib)
660
661
  ADD_LINK_FLAGS_TEST(mod dll)
  ADD_LINK_FLAGS_TEST(exe mod)
662
663
  ADD_LINK_FLAGS_TEST(lib_config exe)
  ADD_LINK_FLAGS_TEST(dll_config lib_config)
664
665
666
667
668
669
670
671
672
673
  ADD_LINK_FLAGS_TEST(mod_config dll_config)
  ADD_LINK_FLAGS_TEST(exe_config mod_config)
  ADD_LINK_FLAGS_TEST(lib_flags exe_config)
  ADD_LINK_FLAGS_TEST(dll_flags lib_flags)
  ADD_LINK_FLAGS_TEST(mod_flags dll_flags)
  ADD_LINK_FLAGS_TEST(exe_flags mod_flags)
  ADD_LINK_FLAGS_TEST(lib_flags_config exe_flags)
  ADD_LINK_FLAGS_TEST(dll_flags_config lib_flags_config)
  ADD_LINK_FLAGS_TEST(mod_flags_config dll_flags_config)
  ADD_LINK_FLAGS_TEST(exe_flags_config mod_flags_config)
674

675
  # If we are running right now with a Unix Makefiles or Ninja based generator,
676
  # build the "Simple" test with the ExtraGenerators, if available
677
  # This doesn't test whether the generated project files work (unfortunately),
678
  # mainly it tests that cmake doesn't crash when generating these project files.
679
680
  if(${CMAKE_GENERATOR} MATCHES "Unix Makefiles" OR ${CMAKE_GENERATOR} MATCHES "Ninja")

681
    # check which generators we have
682
683
    execute_process(COMMAND ${CMAKE_CMAKE_COMMAND} --help
      OUTPUT_VARIABLE cmakeOutput ERROR_VARIABLE cmakeOutput)
684

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
    set(extraGenerators
      "CodeBlocks"
      "CodeLite"
      "Eclipse CDT4"
      "Kate"
      "Sublime Text 2")

    foreach(extraGenerator ${extraGenerators})
      if ("${cmakeOutput}" MATCHES "${extraGenerator} - ${CMAKE_GENERATOR}")
        set(extraGeneratorTestName "Simple_${extraGenerator}Generator")
        string(REPLACE " " "" extraGeneratorTestName ${extraGeneratorTestName})

        add_test(${extraGeneratorTestName} ${CMAKE_CTEST_COMMAND}
          --build-and-test
          "${CMake_SOURCE_DIR}/Tests/Simple"
          "${CMake_BINARY_DIR}/Tests/${extraGeneratorTestName}"
          --build-two-config
          --build-generator "${extraGenerator} - ${CMAKE_GENERATOR}"
          --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
          --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
          --build-project Simple
          --build-options ${build_options}
          --test-command Simple)
        list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${extraGeneratorTestName}")
      endif ()
    endforeach(extraGenerator)
711

712
  endif()
713

714
  # test for correct sub-project generation
715
716
  # not implemented in Xcode or Ninja
  if(NOT CMAKE_GENERATOR MATCHES "Xcode|Ninja")
717
718
    # run cmake and configure all of SubProject
    # but only build the independent executable car
719
    add_test(SubProject ${CMAKE_CTEST_COMMAND}
720
721
722
723
      --build-and-test
      "${CMake_SOURCE_DIR}/Tests/SubProject"
      "${CMake_BINARY_DIR}/Tests/SubProject"
      --build-project SubProject
724
      ${build_generator_args}
725
      --build-target car
726
      --build-options ${build_options}
727
728
      --test-command car
      )
729

730
731
732
733
734
    # For stage 2, do not run cmake again.
    # Then build the foo sub project which should build
    # the bar library which should be referenced because
    # foo links to the static library bar, but bar is not
    # directly in the foo sub project
735
    if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
736
      set(SubProject-Stage2_BUILD_MAKEPROGRAM
737
        --build-makeprogram ${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
738
739
        )
    endif()
740
    add_test(SubProject-Stage2  ${CMAKE_CTEST_COMMAND}
741
      --build-and-test
742
743
      "${CMake_SOURCE_DIR}/Tests/SubProject/foo"
      "${CMake_BINARY_DIR}/Tests/SubProject/foo"
744
      --build-generator ${CMAKE_GENERATOR}
745
      --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
746
      --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
747
      ${SubProject-Stage2_BUILD_MAKEPROGRAM}
748
      --build-nocmake
749
750
      --build-project foo
      --build-target foo
751
      --build-exe-dir "${CMake_BINARY_DIR}/Tests/SubProject/foo"
752
      --build-options ${build_options}
753
754
      --test-command foo
      )
755
756
    set_tests_properties ( SubProject-Stage2 PROPERTIES DEPENDS SubProject)
    list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SubProject")
757
  endif()
758

759
760
  # macro to add a test that will build a nightly release
  # of CMake for given platform using the release scripts
761
762
763
764
  macro(ADD_NIGHTLY_BUILD_TEST name script)
    set(_TEST_DIR "${CMake_BINARY_DIR}/Tests/${name}")
    file(MAKE_DIRECTORY "${_TEST_DIR}")
    file(WRITE "${_TEST_DIR}/nightly-cmake.sh"
765
      "cd ${_TEST_DIR}
766
${CMake_BINARY_DIR}/bin/cmake -DCMAKE_CREATE_VERSION=nightly -P ${CMake_SOURCE_DIR}/Utilities/Release/${script}
767
${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release/upload_release.cmake
768
    ")
769
770
771
    add_test(${name} /bin/sh ${_TEST_DIR}/nightly-cmake.sh)
    if(COMMAND SET_TESTS_PROPERTIES AND COMMAND GET_TEST_PROPERTY)
      set_tests_properties (${name} PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
772
773
    endif()
  endmacro()
774
  if(CMAKE_BUILD_NIGHTLY_RELEASES)
775
776
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWin32
      win32_release.cmake)
777
778
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWin64
      win64_release.cmake)
779
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyOSX
780
      osx_release.cmake)
781
782
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyLinux64
      linux64_release.cmake)
783
    set_property(TEST CMakeNightlyWin64 PROPERTY DEPENDS CMakeNightlyWin32)
784
  endif()
785

786
  # add tests with more complex invocations
787
  add_test(Framework ${CMAKE_CTEST_COMMAND}
788
789
790
791
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/Framework"
    "${CMake_BINARY_DIR}/Tests/Framework"
    --build-two-config
792
    ${build_generator_args}
793
    --build-project Framework
794
    --build-options ${build_options}
795
796
    "-DCMAKE_INSTALL_PREFIX:PATH=${CMake_BINARY_DIR}/Tests/Framework/Install"
    --test-command bar)
797
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Framework")
798

799
  add_test(TargetName ${CMAKE_CTEST_COMMAND}
800
801
802
803
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/TargetName"
    "${CMake_BINARY_DIR}/Tests/TargetName"
    --build-two-config
804
    ${build_generator_args}
805
    --build-project TargetName
806
    --build-options ${build_options}
807
    --test-command ${CMAKE_CMAKE_COMMAND} -E compare_files
808
809
    ${CMake_SOURCE_DIR}/Tests/TargetName/scripts/hello_world
    ${CMake_BINARY_DIR}/Tests/TargetName/scripts/hello_world)
810
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TargetName")
811

812
  add_test(LibName ${CMAKE_CTEST_COMMAND}
813
814
815
816
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/LibName"
    "${CMake_BINARY_DIR}/Tests/LibName"
    --build-two-config
817
    ${build_generator_args}
818
    --build-project LibName
819
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/LibName/lib"
820
    --build-options ${build_options}
821
822
    --test-command foobar
    )
823
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LibName")
824

825
  add_test(CustComDepend ${CMAKE_CTEST_COMMAND}
826
827
828
829
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustComDepend"
    "${CMake_BINARY_DIR}/Tests/CustComDepend"
    --build-two-config
830
    ${build_generator_args}
831
    --build-project CustComDepend
832
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustComDepend/bin"
833
    --build-options ${build_options}
834
835
    --test-command foo bar.c
    )
836
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustComDepend")
837

838
  add_test(ArgumentExpansion  ${CMAKE_CTEST_COMMAND}
Ben Boeckel's avatar
Ben Boeckel committed
839
840
841
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/ArgumentExpansion"
    "${CMake_BINARY_DIR}/Tests/ArgumentExpansion"
842
    ${build_generator_args}
Ben Boeckel's avatar
Ben Boeckel committed
843
844
    --build-project ArgumentExpansion
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/ArgumentExpansion/bin"
845
    --build-options ${build_options}
Ben Boeckel's avatar
Ben Boeckel committed
846
    )
847
  set_tests_properties(ArgumentExpansion PROPERTIES
848
    FAIL_REGULAR_EXPRESSION "Unexpected: ")
849
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ArgumentExpansion")
Ben Boeckel's avatar
Ben Boeckel committed
850

851
852
  add_test(GeneratorExpression
    ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
Brad King's avatar
Brad King committed
853
854
855
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/GeneratorExpression"
    "${CMake_BINARY_DIR}/Tests/GeneratorExpression"
856
    ${build_generator_args}
Brad King's avatar
Brad King committed
857
    --build-project GeneratorExpression
858
859
    --build-options ${build_options}
      -DCMAKE_BUILD_TYPE=\${CTEST_CONFIGURATION_TYPE}
860
    --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
Brad King's avatar
Brad King committed
861
862
863
    )
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/GeneratorExpression")

864
  add_test(CustomCommand  ${CMAKE_CTEST_COMMAND}
865
866
867
868
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustomCommand"
    "${CMake_BINARY_DIR}/Tests/CustomCommand"
    --build-two-config
869
    ${build_generator_args}
870
871
    --build-project CustomCommand
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustomCommand/bin"
872
    --build-options ${build_options}
873
874
    --test-command CustomCommand
    )
875
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustomCommand")
876

877
878
  ADD_TEST_MACRO(CustomCommandByproducts CustomCommandByproducts)

879
880
  ADD_TEST_MACRO(CommandLength CommandLength)

881
882
  ADD_TEST_MACRO(EmptyDepends ${CMAKE_CTEST_COMMAND})

883
  add_test(CustomCommandWorkingDirectory  ${CMAKE_CTEST_COMMAND}
884
885
886
887
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustomCommandWorkingDirectory"
    "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory"
    --build-two-config
888
    ${build_generator_args}
889
    --build-project TestWorkingDir
890
    --build-options ${build_options}
891
892
    --test-command working
    )
893
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory")
894

895
  add_test(OutOfSource ${CMAKE_CTEST_COMMAND}
896
897
898
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/OutOfSource"
    "${CMake_BINARY_DIR}/Tests/OutOfSource"
899
    ${build_generator_args}
900
901
    --build-project OutOfSource
    --build-two-config
902
    --build-options ${build_options}
903
904
    --test-command
    "${CMake_BINARY_DIR}/Tests/OutOfSource/SubDir/OutOfSourceSubdir/simple")
905
906
907
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/OutOfSource")
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/OutOfSourceDeep")
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/OutOfBinary")
908

909
  add_test(BuildDepends ${CMAKE_CTEST_COMMAND}
910
911
912
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/BuildDepends"
    "${CMake_BINARY_DIR}/Tests/BuildDepends"
913
    ${build_generator_args}
914
    --build-project BuildDepends
915
    --build-options ${build_options}
916
    )
917
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BuildDepends")
918

919
920
921
922
923
924
925
926
927
928
929
930
931
  set(MissingInstallInstallDir
    "${CMake_BINARY_DIR}/Tests/MissingInstall/InstallDirectory")
  add_test(MissingInstall ${CMAKE_CTEST_COMMAND}
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/MissingInstall"
    "${CMake_BINARY_DIR}/Tests/MissingInstall"
    ${build_generator_args}
    --build-project TestMissingInstall
    --build-two-config
    --build-options ${build_options}
    "-DCMAKE_INSTALL_PREFIX:PATH=${MissingInstallInstallDir}")
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/MissingInstall")

932
933
934
935
  # By default, run the CPackComponents test if the CTEST_TEST_CPACK
  # option is ON:
  #
  set(CTEST_RUN_CPackComponents ${CTEST_TEST_CPACK})
936
  set(CTEST_package_X11_TEST ${CTEST_TEST_CPACK})
937
  set(CTEST_RUN_CPackComponentsForAll ${CTEST_TEST_CPACK})
938
  set(CTEST_RUN_CPackComponentsPrefix ${CTEST_TEST_CPACK})
939

940
941
942
943
944
  find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis
    PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
    DOC "makensis program location"
    )

David Cole's avatar