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

20
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
21

22
# Fake a user home directory to avoid polluting the real one.
23 24 25 26 27
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.
28 29
# But provide original ENV{HOME} value in ENV{CTEST_REAL_HOME} for tests that
# need access to the real HOME directory.
30 31
set(ENV{CTEST_REAL_HOME} \"\$ENV{HOME}\")
set(ENV{HOME} \"${TEST_HOME}\")
32
")
33
endif()
34

35
# Choose a default configuration for CTest tests.
36 37 38 39
set(CTestTest_CONFIG Debug)
if(NOT CMAKE_CONFIGURATION_TYPES AND CMAKE_BUILD_TYPE)
  set(CTestTest_CONFIG ${CMAKE_BUILD_TYPE})
endif()
40

41
configure_file(${CMake_SOURCE_DIR}/Tests/EnforceConfig.cmake.in
42
               ${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake @ONLY)
43

44
# Testing
45
if(BUILD_TESTING)
46
  set(CMake_TEST_DEVENV "")
47 48 49
  if(CMAKE_VS_DEVENV_COMMAND)
    set(CMake_TEST_DEVENV "${CMAKE_VS_DEVENV_COMMAND}")
  elseif(CMAKE_GENERATOR MATCHES "Visual Studio [7-9] " AND
50 51 52 53
      NOT CMAKE_MAKE_PROGRAM MATCHES "[mM][sS][bB][uU][iI][lL][dD]\\.[eE][xX][eE]")
    set(CMake_TEST_DEVENV "${CMAKE_MAKE_PROGRAM}")
  endif()

54
  if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
55
    set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "")
56
  else()
57
    set(CMake_TEST_EXPLICIT_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
58
  endif()
59

60 61 62 63
  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()
64
  endif()
65

66
  set(MAKE_IS_GNU )
67 68
  if(CMAKE_MAKE_PROGRAM MATCHES make)
    execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} no_such_target --version
69 70 71 72 73 74 75 76 77 78
      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
79
      CMAKE_MAKE_PROGRAM MATCHES "nmake|gmake|wmake" OR
80
      CMAKE_GENERATOR MATCHES "Visual Studio|Xcode|Borland")
81 82 83 84 85
    set(MAKE_SUPPORTS_SPACES 1)
  else()
    set(MAKE_SUPPORTS_SPACES 0)
  endif()

86 87 88 89 90 91 92 93 94 95 96
  # 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()

97
  set(build_generator_args
98
    --build-generator ${CMAKE_GENERATOR}
99
    )
100 101 102 103 104
  if(CMAKE_GENERATOR_PLATFORM)
    list(APPEND build_generator_args
      --build-generator-platform ${CMAKE_GENERATOR_PLATFORM}
      )
  endif()
105
  if(CMAKE_GENERATOR_TOOLSET)
106
    list(APPEND build_generator_args
107
      --build-generator-toolset ${CMAKE_GENERATOR_TOOLSET}
108 109
      )
  endif()
110

111
  set(build_options)
112 113
  if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
    list(APPEND build_options -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
114
  endif()
115

116 117
  # Look for rpmbuild to use for tests.
  # The tool does not work with spaces in the path.
118
  if(NOT CMAKE_CURRENT_BINARY_DIR MATCHES " ")
119 120 121 122 123
    find_program(RPMBUILD_EXECUTABLE NAMES rpmbuild)
  else()
    set(RPMBUILD_EXECUTABLE "RPMBUILD_EXECUTABLE-NOTFOUND")
  endif()

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
  if(RPMBUILD_EXECUTABLE)
    set(CPACK_BINARY_RPM ON)
  else()
    set(CPACK_BINARY_RPM OFF)
  endif()

  # Look for rpmbuild to use for tests.
  # The tool does not work with spaces in the path.
  find_program(DPKG_EXECUTABLE NAMES dpkg)

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

140 141 142
  #---------------------------------------------------------------------------
  # Add tests below here.

143 144 145
  if(NOT CMake_TEST_EXTERNAL_CMAKE)
    add_subdirectory(CMakeLib)
  endif()
146 147
  add_subdirectory(CMakeOnly)
  add_subdirectory(RunCMake)
148

149
  add_subdirectory(FindPackageModeMakefileTest)
150

151
  # Collect a list of all test build directories.
152
  set(TEST_BUILD_DIRS)
153

154
  # Should the long tests be run?
155
  option(CMAKE_RUN_LONG_TESTS
156
    "Should the long tests be run (such as Bootstrap)." ON)
157
  mark_as_advanced(CMAKE_RUN_LONG_TESTS)
158

159 160
  if (CMAKE_RUN_LONG_TESTS)
    option(CTEST_TEST_CTEST
161
      "Should the tests that run a full sub ctest process be run?"
162
      OFF)
163
    mark_as_advanced(CTEST_TEST_CTEST)
164
  endif ()
165

166 167 168 169
  # Should tests that use CVS be run?
  #
  set(do_cvs_tests 0)

170 171
  if(EXISTS ${CMAKE_ROOT}/Modules/FindCVS.cmake)
    find_package(CVS QUIET)
172
  else()
173
    find_program(CVS_EXECUTABLE NAMES cvs)
174
  endif()
175

176 177
  if(CVS_EXECUTABLE)
    set(do_cvs_tests 1)
178
  endif()
179

180 181 182
  if(do_cvs_tests AND NOT UNIX)
    if("${CVS_EXECUTABLE}" MATCHES "cygwin")
      set(do_cvs_tests 0)
183 184
    endif()
  endif()
185

186 187 188 189 190 191 192 193 194 195 196
  # 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.
  #
197
  option(CTEST_TEST_CPACK
198 199
    "Should the tests that use '--build-target package' be run?"
    ON)
200 201
  mark_as_advanced(CTEST_TEST_CPACK)
  set(CTEST_TEST_OSX_ARCH 0)
202
  set(CMake_TEST_XCODE_VERSION 0)
203 204
  if(APPLE)
    execute_process(
205 206 207 208
      COMMAND sw_vers -productVersion
      OUTPUT_VARIABLE OSX_VERSION
      OUTPUT_STRIP_TRAILING_WHITESPACE
      )
209
    if(OSX_VERSION VERSION_LESS 10.4)
210 211 212
      message(STATUS "Forcing CTEST_TEST_CPACK=OFF on OSX < 10.4")
      message(STATUS "OSX_VERSION='${OSX_VERSION}'")
      set(CTEST_TEST_CPACK OFF)
213
    else()
214
      set(CTEST_TEST_OSX_ARCH 1)
215
    endif()
216 217 218 219 220 221 222 223 224 225 226
    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()
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
    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()
250
  endif()
251

252 253
  # Use 1500 or CTEST_TEST_TIMEOUT for long test timeout value,
  # whichever is greater.
254 255 256
  set(CMAKE_LONG_TEST_TIMEOUT 1500)
  if(CTEST_TEST_TIMEOUT)
    set(CMAKE_LONG_TEST_TIMEOUT ${CTEST_TEST_TIMEOUT})
257
  endif()
258 259
  if(CMAKE_LONG_TEST_TIMEOUT LESS 1500)
    set(CMAKE_LONG_TEST_TIMEOUT 1500)
260
  endif()
261

262 263 264
  add_test(NAME CMake.Copyright
    COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeCopyright.cmake)

265
  # add a bunch of standard build-and-test style tests
266 267
  ADD_TEST_MACRO(CommandLineTest CommandLineTest)
  ADD_TEST_MACRO(FindPackageTest FindPackageTest)
268
  ADD_TEST_MACRO(FindModulesExecuteAll FindModulesExecuteAll)
269 270 271 272
  ADD_TEST_MACRO(StringFileTest StringFileTest)
  ADD_TEST_MACRO(TryCompile TryCompile)
  ADD_TEST_MACRO(SystemInformation SystemInformation)
  ADD_TEST_MACRO(MathTest MathTest)
273 274 275
  ADD_TEST_MACRO(CompileFeatures CompileFeatures)
  ADD_TEST_MACRO(CMakeCommands.target_compile_features target_compile_features)

276
  if(CMake_TEST_RESOURCES)
277
    ADD_TEST_MACRO(VSResource VSResource)
278 279 280
    if (CMAKE_GENERATOR MATCHES "Ninja")
      add_test_macro(VSResourceNinjaForceRSP VSResourceNinjaForceRSP)
    endif ()
281
  endif()
282
  ADD_TEST_MACRO(MSManifest MSManifest)
283 284
  ADD_TEST_MACRO(Simple Simple)
  ADD_TEST_MACRO(PreOrder PreOrder)
285
  ADD_TEST_MACRO(MissingSourceFile MissingSourceFile)
286
  set_tests_properties(MissingSourceFile PROPERTIES
287
    PASS_REGULAR_EXPRESSION "CMake Error at CMakeLists.txt:3 \\(add_executable\\):[ \r\n]*Cannot find source file:[ \r\n]*DoesNotExist/MissingSourceFile.c")
288 289 290 291 292 293 294 295
  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()
296 297
    endif()
  endif()
298
  if(CMAKE_Fortran_COMPILER)
299
    ADD_TEST_MACRO(FortranOnly FortranOnly)
300
  endif()
301 302 303 304 305 306
  # 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.
307 308
  if(CMAKE_Fortran_COMPILER OR CMAKE_TEST_CMAKE_ADD_FORTRAN)
    set(CMAKE_SKIP_VSGNUFortran FALSE)
309 310
    # disable test for apple builds using ifort if they are building
    # more than one architecture, as ifort does not support that.
311 312 313 314 315 316 317 318
    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)
319
        AND (CMAKE_Fortran_COMPILER MATCHES ifort))
320 321 322 323
      message(STATUS "Skip VSGNUFortran for ifort and lsb compilers")
      set(CMAKE_SKIP_VSGNUFortran TRUE)
    endif()
    if(NOT CMAKE_SKIP_VSGNUFortran)
324
      ADD_TEST_MACRO(VSGNUFortran ${CMAKE_COMMAND} -P runtest.cmake)
325 326
    endif()
  endif()
327 328
  ADD_TEST_MACRO(COnly COnly)
  ADD_TEST_MACRO(CxxOnly CxxOnly)
329
  ADD_TEST_MACRO(CxxSubdirC CxxSubdirC)
330
  ADD_TEST_MACRO(IPO COnly/COnly)
331
  ADD_TEST_MACRO(OutDir runtime/OutDir)
332
  ADD_TEST_MACRO(ObjectLibrary UseCshared)
333 334
  ADD_TEST_MACRO(NewlineArgs NewlineArgs)
  ADD_TEST_MACRO(SetLang SetLang)
335
  ADD_TEST_MACRO(EmptyProperty EmptyProperty)
336
  ADD_TEST_MACRO(ExternalOBJ ExternalOBJ)
337 338 339
  if(NOT CMake_TEST_EXTERNAL_CMAKE)
    ADD_TEST_MACRO(LoadCommand LoadedCommand)
  endif()
340
  ADD_TEST_MACRO(LinkDirectory bin/LinkDirectory)
341
  ADD_TEST_MACRO(LinkLanguage LinkLanguage)
342 343
  ADD_TEST_MACRO(LinkLine LinkLine)
  ADD_TEST_MACRO(MacroTest miniMacroTest)
344
  ADD_TEST_MACRO(FunctionTest miniFunctionTest)
345
  ADD_TEST_MACRO(ReturnTest ReturnTest)
346
  ADD_TEST_MACRO(Properties Properties)
347
  ADD_TEST_MACRO(Assembler HelloAsm)
348
  ADD_TEST_MACRO(SourceGroups SourceGroups)
349
  ADD_TEST_MACRO(Preprocess Preprocess)
350
  set(ExportImport_BUILD_OPTIONS -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
351
  ADD_TEST_MACRO(ExportImport ExportImport)
Brad King's avatar
Brad King committed
352
  ADD_TEST_MACRO(Unset Unset)
353
  ADD_TEST_MACRO(PolicyScope PolicyScope)
354
  ADD_TEST_MACRO(EmptyLibrary EmptyLibrary)
355
  ADD_TEST_MACRO(CompileDefinitions CompileDefinitions)
356
  ADD_TEST_MACRO(CompileOptions CompileOptions)
357
  ADD_TEST_MACRO(CompatibleInterface CompatibleInterface)
358
  ADD_TEST_MACRO(AliasTarget AliasTarget)
359
  ADD_TEST_MACRO(StagingPrefix StagingPrefix)
360
  ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary)
361 362 363 364
  if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
    set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
    ADD_TEST_MACRO(ConfigSources ConfigSources)
  endif()
365
  ADD_TEST_MACRO(SourcesProperty SourcesProperty)
366
  ADD_TEST_MACRO(SourceFileProperty SourceFileProperty)
367
  if(CMAKE_CXX_COMPILER_ID STREQUAL GNU
368
      AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
369 370 371
    set(runCxxDialectTest 1)
  endif()
  if(CMAKE_CXX_COMPILER_ID STREQUAL Clang
372
        AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
373 374 375 376 377 378 379
    if(NOT APPLE OR POLICY CMP0025)
      set(runCxxDialectTest 1)
    endif()
  endif()
  if(runCxxDialectTest)
    ADD_TEST_MACRO(CxxDialect CxxDialect)
  endif()
380
  set_tests_properties(EmptyLibrary PROPERTIES
381
    PASS_REGULAR_EXPRESSION "CMake Error: CMake can not determine linker language for target: test")
382
  ADD_TEST_MACRO(CrossCompile CrossCompile)
383
  set_tests_properties(CrossCompile PROPERTIES
384
    PASS_REGULAR_EXPRESSION "TRY_RUN.. invoked in cross-compiling mode")
385
  if("${CMAKE_GENERATOR}" MATCHES "Make")
386
    ADD_TEST_MACRO(Policy0002 Policy0002)
387
  endif()
388
  if(CTEST_TEST_OSX_ARCH)
389
    ADD_TEST_MACRO(Architecture Architecture)
390
    set_tests_properties(Architecture PROPERTIES
391
      PASS_REGULAR_EXPRESSION "(file is not of required architecture|does not match cputype|not the architecture being linked)")
392
  endif()
393

394
  list(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX})
395

396
  if(NOT QT4_FOUND)
397
    find_package(Qt4 QUIET)
398
  endif()
399

400
  if(QT4_FOUND)
401 402 403 404
    # 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.
405 406 407
    include(CheckCXXSourceCompiles)
    set(_save_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
    set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
408

409 410
    set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES})
    set(CMAKE_REQUIRED_LIBRARIES ${QT_QTCORE_LIBRARIES})
411 412 413 414

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

415 416 417
    set(CMAKE_REQUIRED_INCLUDES "${_save_CMAKE_REQUIRED_INCLUDES}")
    set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}")
  endif()
418

419
  # run test for BundleUtilities on supported platforms/compilers
420
  if(MSVC OR
421
     MINGW OR
422 423
     CMAKE_SYSTEM_NAME MATCHES "Linux" OR
     CMAKE_SYSTEM_NAME MATCHES "Darwin")
424
  if(NOT "${CMAKE_GENERATOR}" STREQUAL "Watcom WMake")
425

426
    add_test(BundleUtilities ${CMAKE_CTEST_COMMAND}
427 428 429
      --build-and-test
      "${CMake_SOURCE_DIR}/Tests/BundleUtilities"
      "${CMake_BINARY_DIR}/Tests/BundleUtilities"
430
      ${build_generator_args}
431
      --build-project BundleUtilities
432
      --build-options ${build_options}
433
      )
434
    list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities")
435 436 437

    # run test for DeployQt4 on supported platforms/compilers (which depends on BundleUtilities)
    # this test also depends on the existence of the standard qtiff plugin
438
    if(QT4_WORKS AND QT_QTSQL_FOUND)
439
      add_test(Qt4Deploy ${CMAKE_CTEST_COMMAND}
440 441 442
        --build-and-test
        "${CMake_SOURCE_DIR}/Tests/Qt4Deploy"
        "${CMake_BINARY_DIR}/Tests/Qt4Deploy"
443
        ${build_generator_args}
444
        --build-project Qt4Deploy
445
        --build-options ${build_options}
446
        -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
447
        -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
448
        )
449
      list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Deploy")
450 451
    endif()

452 453
  endif()
  endif()
454

455 456 457 458
  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"
459
    "${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake" @ONLY)
460
  add_test(CMakeBuildTest ${CMAKE_CMAKE_COMMAND} -P
461
    "${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake")
462
  list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
463
  # now do it again for a project that has two project commands
464 465 466 467
  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"
468
    "${CMake_BINARY_DIR}/Tests/CMakeBuildDoubleProjectTest.cmake" @ONLY)
469
  add_test(CMakeDoubleProject ${CMAKE_CMAKE_COMMAND} -P
470
    "${CMake_BINARY_DIR}/Tests/CMakeBuildDoubleProjectTest.cmake")
471
  list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
472

Brad King's avatar
Brad King committed
473 474
  ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)

475 476 477 478
  add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/Module/ExternalData"
    "${CMake_BINARY_DIR}/Tests/Module/ExternalData"
479
    ${build_generator_args}
480
    --build-project ExternalDataTest
481
    --build-noclean
482
    --force-new-ctest-process
483 484
    --build-options ${build_options}
      -DMAKE_SUPPORTS_SPACES=${MAKE_SUPPORTS_SPACES}
485 486 487 488
    --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
    )
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Module/ExternalData")

489
  ADD_TEST_MACRO(Module.FindDependency FindDependency)
490

491 492
  ADD_TEST_MACRO(Module.WriteCompilerDetectionHeader WriteCompilerDetectionHeader)

493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
  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_SYSTEM_NAME MATCHES "IRIX64"
        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()

511 512 513 514 515 516 517 518 519 520
  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)
521
    add_test(Visibility ${CMAKE_CTEST_COMMAND}
522
      --build-and-test
523 524
      "${CMake_SOURCE_DIR}/Tests/Visibility"
      "${CMake_BINARY_DIR}/Tests/Visibility"
525
      ${build_generator_args}
526
      --build-project Visibility
527 528 529
      --build-options ${build_options}
    )
    list(APPEND TEST_BUILD_DIRS
530
      "${CMake_BINARY_DIR}/Tests/Visibility"
531 532 533
    )
  endif()

534
  add_test(LinkFlags-prepare
535 536 537 538
    ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/LinkFlags"
    "${CMake_BINARY_DIR}/Tests/LinkFlags"
539
    ${build_generator_args}
540 541
    --build-project LinkFlags
    --build-target LinkFlags
542 543
    --build-options ${build_options}
      -DTEST_CONFIG=\${CTEST_CONFIGURATION_TYPE}
544
    )
545
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LinkFlags")
546

547 548
  macro(ADD_LINK_FLAGS_TEST name depends)
    add_test(LinkFlags-${name}
549 550 551
      ${CMAKE_CMAKE_COMMAND} --build "${CMake_BINARY_DIR}/Tests/LinkFlags"
      --target LinkFlags_${name} --config \${CTEST_CONFIGURATION_TYPE}
      )
552
    set_tests_properties(LinkFlags-${name} PROPERTIES
553
      PASS_REGULAR_EXPRESSION "BADFLAG" DEPENDS LinkFlags-${depends})
554
  endmacro()
555 556
  ADD_LINK_FLAGS_TEST(lib prepare)
  ADD_LINK_FLAGS_TEST(dll lib)
557 558
  ADD_LINK_FLAGS_TEST(mod dll)
  ADD_LINK_FLAGS_TEST(exe mod)
559 560
  ADD_LINK_FLAGS_TEST(lib_config exe)
  ADD_LINK_FLAGS_TEST(dll_config lib_config)
561 562 563 564 565 566 567 568 569 570
  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)
571

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

578
    # check which generators we have
579 580
    execute_process(COMMAND ${CMAKE_CMAKE_COMMAND} --help
      OUTPUT_VARIABLE cmakeOutput ERROR_VARIABLE cmakeOutput)
581

582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    set(extraGenerators
      "CodeBlocks"
      "CodeLite"
      "Eclipse CDT4"
      "Kate"
      "KDevelop3"
      "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)
609

610
  endif()
611

612
  # test for correct sub-project generation
Brad King's avatar
Brad King committed
613 614
  # not implemented in VS 7.0, Xcode, or Ninja
  if(NOT CMAKE_GENERATOR MATCHES "Visual Studio 7$|Xcode|Ninja")
615 616
    # run cmake and configure all of SubProject
    # but only build the independent executable car
617
    add_test(SubProject ${CMAKE_CTEST_COMMAND}
618 619 620 621
      --build-and-test
      "${CMake_SOURCE_DIR}/Tests/SubProject"
      "${CMake_BINARY_DIR}/Tests/SubProject"
      --build-project SubProject
622
      ${build_generator_args}
623
      --build-target car
624
      --build-options ${build_options}
625 626
      --test-command car
      )
627

628 629 630 631 632
    # 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
633
    if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
634
      set(SubProject-Stage2_BUILD_MAKEPROGRAM
635
        --build-makeprogram ${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
636 637
        )
    endif()
638
    add_test(SubProject-Stage2  ${CMAKE_CTEST_COMMAND}
639
      --build-and-test
640 641
      "${CMake_SOURCE_DIR}/Tests/SubProject/foo"
      "${CMake_BINARY_DIR}/Tests/SubProject/foo"
642
      --build-generator ${CMAKE_GENERATOR}
643
      --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
644
      --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
645
      ${SubProject-Stage2_BUILD_MAKEPROGRAM}
646
      --build-nocmake
647 648
      --build-project foo
      --build-target foo
649
      --build-exe-dir "${CMake_BINARY_DIR}/Tests/SubProject/foo"
650
      --build-options ${build_options}
651 652
      --test-command foo
      )
653 654
    set_tests_properties ( SubProject-Stage2 PROPERTIES DEPENDS SubProject)
    list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SubProject")
655
  endif()
656

657 658
  # macro to add a test that will build a nightly release
  # of CMake for given platform using the release scripts
659 660 661 662
  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"
663
      "cd ${_TEST_DIR}
664
${CMake_BINARY_DIR}/bin/cmake -DCMAKE_CREATE_VERSION=nightly -P ${CMake_SOURCE_DIR}/Utilities/Release/${script}
665
${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release/upload_release.cmake
666
    ")
667 668 669
    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})
670 671
    endif()
  endmacro()
672
  if(CMAKE_BUILD_NIGHTLY_RELEASES)
673 674
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWin32
      win32_release.cmake)
675 676
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWin64
      win64_release.cmake)
677
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyOSX
678
      osx_release.cmake)
679 680
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyLinux64
      linux64_release.cmake)
681
    set_property(TEST CMakeNightlyWin64 PROPERTY DEPENDS CMakeNightlyWin32)
682
  endif()
683

684
  # add tests with more complex invocations
685
  add_test(Framework ${CMAKE_CTEST_COMMAND}
686 687 688 689
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/Framework"
    "${CMake_BINARY_DIR}/Tests/Framework"
    --build-two-config
690
    ${build_generator_args}
691
    --build-project Framework
692
    --build-options ${build_options}
693 694
    "-DCMAKE_INSTALL_PREFIX:PATH=${CMake_BINARY_DIR}/Tests/Framework/Install"
    --test-command bar)
695
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Framework")
696

697
  add_test(TargetName ${CMAKE_CTEST_COMMAND}
698 699 700 701
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/TargetName"
    "${CMake_BINARY_DIR}/Tests/TargetName"
    --build-two-config
702
    ${build_generator_args}
703
    --build-project TargetName
704
    --build-options ${build_options}
705
    --test-command ${CMAKE_CMAKE_COMMAND} -E compare_files
706 707
    ${CMake_SOURCE_DIR}/Tests/TargetName/scripts/hello_world
    ${CMake_BINARY_DIR}/Tests/TargetName/scripts/hello_world)
708
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TargetName")
709

710
  add_test(LibName ${CMAKE_CTEST_COMMAND}
711 712 713 714
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/LibName"
    "${CMake_BINARY_DIR}/Tests/LibName"
    --build-two-config
715
    ${build_generator_args}
716
    --build-project LibName
717
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/LibName/lib"
718
    --build-options ${build_options}
719 720
    --test-command foobar
    )
721
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LibName")
722

723
  add_test(CustComDepend ${CMAKE_CTEST_COMMAND}
724 725 726 727
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustComDepend"
    "${CMake_BINARY_DIR}/Tests/CustComDepend"
    --build-two-config
728
    ${build_generator_args}
729
    --build-project CustComDepend
730
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustComDepend/bin"
731
    --build-options ${build_options}
732 733
    --test-command foo bar.c
    )
734
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustComDepend")
735

736
  add_test(ArgumentExpansion  ${CMAKE_CTEST_COMMAND}
Ben Boeckel's avatar
Ben Boeckel committed
737 738 739
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/ArgumentExpansion"
    "${CMake_BINARY_DIR}/Tests/ArgumentExpansion"
740
    ${build_generator_args}
Ben Boeckel's avatar
Ben Boeckel committed
741 742
    --build-project ArgumentExpansion
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/ArgumentExpansion/bin"
743
    --build-options ${build_options}
Ben Boeckel's avatar
Ben Boeckel committed
744
    )
745
  set_tests_properties(ArgumentExpansion PROPERTIES
746
    FAIL_REGULAR_EXPRESSION "Unexpected: ")
747
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ArgumentExpansion")
Ben Boeckel's avatar
Ben Boeckel committed
748

749 750
  add_test(GeneratorExpression
    ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
751 752 753
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/GeneratorExpression"
    "${CMake_BINARY_DIR}/Tests/GeneratorExpression"
754
    ${build_generator_args}
755
    --build-project GeneratorExpression
756 757
    --build-options ${build_options}
      -DCMAKE_BUILD_TYPE=\${CTEST_CONFIGURATION_TYPE}
758
    --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
759 760 761
    )
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/GeneratorExpression")

762
  add_test(CustomCommand  ${CMAKE_CTEST_COMMAND}
763 764 765 766
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustomCommand"
    "${CMake_BINARY_DIR}/Tests/CustomCommand"
    --build-two-config
767
    ${build_generator_args}
768 769
    --build-project CustomCommand
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustomCommand/bin"
770
    --build-options ${build_options}
771 772
    --test-command CustomCommand
    )
773
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustomCommand")
774

775 776
  ADD_TEST_MACRO(CustomCommandByproducts CustomCommandByproducts)

777 778
  ADD_TEST_MACRO(EmptyDepends ${CMAKE_CTEST_COMMAND})

779
  add_test(CustomCommandWorkingDirectory  ${CMAKE_CTEST_COMMAND}
780 781 782 783
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustomCommandWorkingDirectory"
    "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory"
    --build-two-config
784
    ${build_generator_args}
785
    --build-project TestWorkingDir
786
    --build-options ${build_options}
787 788
    --test-command working
    )
789
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory")
790

791
   #add_test(SimpleExclude ${CMAKE_CTEST_COMMAND}
Ken Martin's avatar
Ken Martin committed
792 793 794
   #  --build-and-test
   #  "${CMake_SOURCE_DIR}/Tests/SimpleExclude"
   #  "${CMake_BINARY_DIR}/Tests/SimpleExclude"
795
   #  ${build_generator_args}
Ken Martin's avatar
Ken Martin committed
796 797
   #  --build-project SimpleExclude
   #  --build-two-config
798
   #  --build-options ${build_options}
Ken Martin's avatar
Ken Martin committed
799
   #  --test-command t4
800 801
   #--test-command "${CMAKE_COMMAND}"
   #"-DCONFIGURATION=\${CTEST_CONFIGURATION_TYPE}"
802
   #-P "${CMake_BINARY_DIR}/Tests/SimpleExclude/run.cmake"
Ken Martin's avatar
Ken Martin committed
803
   #)
804

805
#  add_test(SameName  ${CMAKE_CTEST_COMMAND}
806 807 808
#    --build-and-test
#    "${CMake_SOURCE_DIR}/Tests/SameName"
#    "${CMake_BINARY_DIR}/Tests/SameName"
809
#    ${build_generator_args}
810 811
#    --build-project SameName
#    --build-two-config
812
#    --build-options ${build_options}
813 814 815
#    --test-command
#    "${CMake_BINARY_DIR}/Tests/SameName/Exe1/mytest2")

816
  add_test(OutOfSource ${CMAKE_CTEST_COMMAND}
817 818 819
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/OutOfSource"
    "${CMake_BINARY_DIR}/Tests/OutOfSource"
820
    ${build_generator_args}
821 822
    --build-project OutOfSource
    --build-two-config
823
    --build-options ${build_options}
824 825
    --test-command
    "${CMake_BINARY_DIR}/Tests/OutOfSource/SubDir/OutOfSourceSubdir/simple")
826 827 828
  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")
829

830
  add_test(BuildDepends ${CMAKE_CTEST_COMMAND}
831 832 833
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/BuildDepends"
    "${CMake_BINARY_DIR}/Tests/BuildDepends"
834
    ${build_generator_args}
835
    --build-project BuildDepends
836
    --build-options ${build_options}
837
    )
838
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BuildDepends")
839

840
  set(SimpleInstallInstallDir
841
    "${CMake_BINARY_DIR}/Tests/SimpleInstall/InstallDirectory")
842
  add_test(SimpleInstall ${CMAKE_CTEST_COMMAND}
843 844 845
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/SimpleInstall"
    "${CMake_BINARY_DIR}/Tests/SimpleInstall"
846
    ${build_generator_args}
847 848
    --build-project TestSimpleInstall
    --build-two-config
849
    --build-options ${build_options}
850
    "-DCMAKE_INSTALL_PREFIX:PATH=${SimpleInstallInstallDir}"
851
    "-DCTEST_TEST_CPACK:BOOL=${CTEST_TEST_CPACK}"
852
    --test-command   ${SimpleInstallInstallDir}/MyTest/bin/SimpleInstExe)
853 854
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SimpleInstall")
  add_test(SimpleInstall-Stage2 ${CMAKE_CTEST_COMMAND}
855 856 857
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/SimpleInstallS2"
    "${CMake_BINARY_DIR}/Tests/SimpleInstallS2"
858
    ${build_generator_args}
859 860
    --build-project TestSimpleInstall
    --build-two-config
861
    --build-options ${build_options}
862 863
    "-DCMAKE_INSTALL_PREFIX:PATH=${SimpleInstallInstallDir}"
    "-DSTAGE2:BOOL=1"
864
    --test-command   ${SimpleInstallInstallDir}/MyTest/bin/SimpleInstExeS2)
865
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SimpleInstallS2")
866

867 868 869 870 871 872 873 874 875 876 877 878 879
  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")

880 881 882 883
  # By default, run the CPackComponents test if the CTEST_TEST_CPACK
  # option is ON:
  #
  set(CTEST_RUN_CPackComponents ${CTEST_TEST_CPACK})
884
  set(CTEST_package_X11_TEST ${CTEST_TEST_CPACK})
885
  set(CTEST_RUN_CPackComponentsForAll ${CTEST_TEST_CPACK})
886
  set(CTEST_RUN_CPackComponentsPrefix ${CTEST_TEST_CPACK})
887

888 889 890 891 892
  find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis
    PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
    DOC "makensis program location"
    )

893 894 895 896 897 898
  # But on Windows, only run the CPackComponents test if the NSIS
  # installer builder is available:
  #
  if(WIN32)
    if(NSIS_MAKENSIS_EXECUTABLE)
      set(CTEST_RUN_CPackComponents ON)
899
    else()
900
      set(CTEST_RUN_CPackComponents OFF)
901
      set(CTEST_package_X11_TEST OFF)
902 903
    endif()
  endif()
904

905 906 907 908 909 910 911 912 913 914 915
  # On Windows run the CPackWiXGenerator test
  # if the WiX Toolset seems to be available
  if(WIN32)
    file(TO_CMAKE_PATH "$ENV{WIX}" WIX_ROOT)

    find_program(WIX_LIGHT_EXECUTABLE light
      PATHS "${WIX_ROOT}/bin"
      DOC "WiX Toolset light.exe location")

    if(WIX_LIGHT_EXECUTABLE)
      add_test(CPackWiXGenerator ${CMAKE_CTEST_COMMAND}
916
        -C \${CTEST_CONFIGURATION_TYPE}
917 918 919
        --build-and-test
        "${CMake_SOURCE_DIR}/Tests/CPackWiXGenerator"
        "${CMake_BINARY_DIR}/Tests/CPackWiXGenerator"
920
        ${build_generator_args}
921
        --build-project CPackWiXGenerator
922
        --build-options ${build_options}
923 924
        --test-command ${CMAKE_CMAKE_COMMAND}
          "-DCPackWiXGenerator_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/CPackWiXGenerator"
925
          "-Dconfig=\${CTEST_CONFIGURATION_TYPE}"
926
          -P "${CMake_SOURCE_DIR}/Tests/CPackWiXGenerator/RunCPackVerifyResult.cmake")
927 928 929 930

      set_property(TEST CPackWiXGenerator PROPERTY
        ATTACHED_FILES_ON_FAIL
        "${CMake_BINARY_DIR}/Tests/CPackWiXGenerator/_CPack_Packages/win32/WIX/wix.log")
931 932 933
    endif()
  endif()

934
  if(CTEST_RUN_CPackComponents)
935
    set(CPackComponents_BUILD_OPTIONS)
936
    if(APPLE)
937
      set(CPackComponents_BUILD_OPTIONS -DCPACK_BINARY_DRAGNDROP:BOOL=ON)
938 939 940 941
      if(CMake_TEST_XCODE_VERSION VERSION_GREATER "4.6")
        set(CPackComponents_BUILD_OPTIONS ${CPackComponents_BUILD_OPTIONS}
          -DCPACK_BINARY_PRODUCTBUILD:BOOL=ON)
      endif()
942
    endif()