CMakeLists.txt 109 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 COMMAND)
  string(REPLACE "." "/" dir "${NAME}")
  string(REGEX REPLACE "[^.]*\\." "" proj "${NAME}")
  add_test(${NAME} ${CMAKE_CTEST_COMMAND}
Ken Martin's avatar
Ken Martin committed
7
    --build-and-test
8 9
    "${CMake_SOURCE_DIR}/Tests/${dir}"
    "${CMake_BINARY_DIR}/Tests/${dir}"
Ken Martin's avatar
Ken Martin committed
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()
Ken Martin's avatar
Ken Martin committed
19

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

22
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
23

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

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

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

46
# Testing
47
if(BUILD_TESTING)
48
  set(CMake_TEST_DEVENV "")
49
  if(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")
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
  set(build_generator_args
87
    --build-generator ${CMAKE_GENERATOR}
88
    )
89
  if(CMAKE_GENERATOR_TOOLSET)
90
    list(APPEND build_generator_args
91
      --build-generator-toolset ${CMAKE_GENERATOR_TOOLSET}
92 93
      )
  endif()
94

95
  set(build_options)
96 97
  if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
    list(APPEND build_options -DCMAKE_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
98
  endif()
99

100 101 102
  if(NOT CMake_TEST_EXTERNAL_CMAKE)
    add_subdirectory(CMakeLib)
  endif()
103 104
  add_subdirectory(CMakeOnly)
  add_subdirectory(RunCMake)
105

106
  add_subdirectory(FindPackageModeMakefileTest)
107

108 109 110
  if(NOT CMake_TEST_EXTERNAL_CMAKE)
    add_subdirectory(CTestTestMemcheck)
  endif()
111

112
  # Collect a list of all test build directories.
113
  set(TEST_BUILD_DIRS)
114

115
  # Should the long tests be run?
116
  option(CMAKE_RUN_LONG_TESTS
117
    "Should the long tests be run (such as Bootstrap)." ON)
118
  mark_as_advanced(CMAKE_RUN_LONG_TESTS)
119

120 121
  if (CMAKE_RUN_LONG_TESTS)
    option(CTEST_TEST_CTEST
122
      "Should the tests that run a full sub ctest process be run?"
123
      OFF)
124
    mark_as_advanced(CTEST_TEST_CTEST)
125
  endif ()
126

127 128 129 130
  # Should tests that use CVS be run?
  #
  set(do_cvs_tests 0)

131 132
  if(EXISTS ${CMAKE_ROOT}/Modules/FindCVS.cmake)
    find_package(CVS QUIET)
133
  else()
134
    find_program(CVS_EXECUTABLE NAMES cvs)
135
  endif()
136

137 138
  if(CVS_EXECUTABLE)
    set(do_cvs_tests 1)
139
  endif()
140

141 142 143
  if(do_cvs_tests AND NOT UNIX)
    if("${CVS_EXECUTABLE}" MATCHES "cygwin")
      set(do_cvs_tests 0)
144 145
    endif()
  endif()
146

147 148 149 150 151 152 153 154 155 156 157
  # 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.
  #
158
  option(CTEST_TEST_CPACK
159 160
    "Should the tests that use '--build-target package' be run?"
    ON)
161 162 163 164
  mark_as_advanced(CTEST_TEST_CPACK)
  set(CTEST_TEST_OSX_ARCH 0)
  if(APPLE)
    execute_process(
165 166 167 168
      COMMAND sw_vers -productVersion
      OUTPUT_VARIABLE OSX_VERSION
      OUTPUT_STRIP_TRAILING_WHITESPACE
      )
169 170 171 172
    if(OSX_VERSION MATCHES "^10\\.[0123]" OR OSX_VERSION MATCHES "ProductVersion:\t10\\.[0123]")
      message(STATUS "Forcing CTEST_TEST_CPACK=OFF on OSX < 10.4")
      message(STATUS "OSX_VERSION='${OSX_VERSION}'")
      set(CTEST_TEST_CPACK OFF)
173
    else()
174
      set(CTEST_TEST_OSX_ARCH 1)
175 176
    endif()
  endif()
177

178 179
  # Use 1500 or CTEST_TEST_TIMEOUT for long test timeout value,
  # whichever is greater.
180 181 182
  set(CMAKE_LONG_TEST_TIMEOUT 1500)
  if(CTEST_TEST_TIMEOUT)
    set(CMAKE_LONG_TEST_TIMEOUT ${CTEST_TEST_TIMEOUT})
183
  endif()
184 185
  if(CMAKE_LONG_TEST_TIMEOUT LESS 1500)
    set(CMAKE_LONG_TEST_TIMEOUT 1500)
186
  endif()
187

188 189 190
  add_test(NAME CMake.Copyright
    COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeCopyright.cmake)

191
  # add a bunch of standard build-and-test style tests
Ken Martin's avatar
Ken Martin committed
192 193
  ADD_TEST_MACRO(CommandLineTest CommandLineTest)
  ADD_TEST_MACRO(FindPackageTest FindPackageTest)
Bill Hoffman's avatar
Bill Hoffman committed
194
  ADD_TEST_MACRO(FindModulesExecuteAll FindModulesExecuteAll)
Ken Martin's avatar
Ken Martin committed
195 196 197 198 199
  ADD_TEST_MACRO(StringFileTest StringFileTest)
  ADD_TEST_MACRO(TryCompile TryCompile)
  ADD_TEST_MACRO(TarTest TarTest)
  ADD_TEST_MACRO(SystemInformation SystemInformation)
  ADD_TEST_MACRO(MathTest MathTest)
200
  # assume no resources building to test
201
  set(TEST_RESOURCES FALSE)
202
  # for windows and cygwin assume we have resources
203 204 205
  if(WIN32 OR CYGWIN)
    set(TEST_RESOURCES TRUE)
  endif()
206
  # for borland and watcom there is no resource support
207 208
  if("${CMAKE_GENERATOR}" MATCHES "WMake" OR
      "${CMAKE_GENERATOR}" MATCHES "Borland")
209 210 211
    set(TEST_RESOURCES FALSE)
  endif()
  if(TEST_RESOURCES)
212
    ADD_TEST_MACRO(VSResource VSResource)
213
  endif()
Ken Martin's avatar
Ken Martin committed
214 215
  ADD_TEST_MACRO(Simple Simple)
  ADD_TEST_MACRO(PreOrder PreOrder)
216
  ADD_TEST_MACRO(MissingSourceFile MissingSourceFile)
217
  set_tests_properties(MissingSourceFile PROPERTIES
218
    PASS_REGULAR_EXPRESSION "CMake Error at CMakeLists.txt:3 \\(add_executable\\):[ \r\n]*Cannot find source file:[ \r\n]*DoesNotExist/MissingSourceFile.c")
219
  if(CMAKE_Fortran_COMPILER)
220
    ADD_TEST_MACRO(FortranOnly FortranOnly)
221
  endif()
222 223 224 225 226 227
  # 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.
228 229
  if(CMAKE_Fortran_COMPILER OR CMAKE_TEST_CMAKE_ADD_FORTRAN)
    set(CMAKE_SKIP_VSGNUFortran FALSE)
230 231
    # disable test for apple builds using ifort if they are building
    # more than one architecture, as ifort does not support that.
232 233 234 235 236 237 238 239
    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)
240
        AND (CMAKE_Fortran_COMPILER MATCHES ifort))
241 242 243 244
      message(STATUS "Skip VSGNUFortran for ifort and lsb compilers")
      set(CMAKE_SKIP_VSGNUFortran TRUE)
    endif()
    if(NOT CMAKE_SKIP_VSGNUFortran)
245
      ADD_TEST_MACRO(VSGNUFortran ${CMAKE_COMMAND} -P runtest.cmake)
246 247
    endif()
  endif()
Ken Martin's avatar
Ken Martin committed
248 249
  ADD_TEST_MACRO(COnly COnly)
  ADD_TEST_MACRO(CxxOnly CxxOnly)
250
  ADD_TEST_MACRO(IPO COnly/COnly)
251
  ADD_TEST_MACRO(OutDir runtime/OutDir)
Brad King's avatar
Brad King committed
252
  ADD_TEST_MACRO(ObjectLibrary UseCshared)
Ken Martin's avatar
Ken Martin committed
253 254
  ADD_TEST_MACRO(NewlineArgs NewlineArgs)
  ADD_TEST_MACRO(SetLang SetLang)
255
  ADD_TEST_MACRO(EmptyProperty EmptyProperty)
256
  ADD_TEST_MACRO(ExternalOBJ ExternalOBJ)
257 258 259
  if(NOT CMake_TEST_EXTERNAL_CMAKE)
    ADD_TEST_MACRO(LoadCommand LoadedCommand)
  endif()
260
  ADD_TEST_MACRO(LinkDirectory bin/LinkDirectory)
261
  ADD_TEST_MACRO(LinkLanguage LinkLanguage)
262 263
  ADD_TEST_MACRO(LinkLine LinkLine)
  ADD_TEST_MACRO(MacroTest miniMacroTest)
264
  ADD_TEST_MACRO(FunctionTest miniFunctionTest)
265
  ADD_TEST_MACRO(ReturnTest ReturnTest)
266
  ADD_TEST_MACRO(Properties Properties)
Alexander Neundorf's avatar
 
Alexander Neundorf committed
267
  ADD_TEST_MACRO(Assembler HelloAsm)
Alexander Neundorf's avatar
 
Alexander Neundorf committed
268
  ADD_TEST_MACRO(SourceGroups SourceGroups)
269
  ADD_TEST_MACRO(Preprocess Preprocess)
270
  set(ExportImport_BUILD_OPTIONS -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM})
271
  ADD_TEST_MACRO(ExportImport ExportImport)
Brad King's avatar
Brad King committed
272
  ADD_TEST_MACRO(Unset Unset)
273
  ADD_TEST_MACRO(PolicyScope PolicyScope)
274
  ADD_TEST_MACRO(EmptyLibrary EmptyLibrary)
275
  ADD_TEST_MACRO(CompileDefinitions CompileDefinitions)
276
  ADD_TEST_MACRO(CompileOptions CompileOptions)
277
  ADD_TEST_MACRO(CompatibleInterface CompatibleInterface)
278
  ADD_TEST_MACRO(AliasTarget AliasTarget)
279
  ADD_TEST_MACRO(StagingPrefix StagingPrefix)
280
  ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary)
281 282 283 284
  if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
    set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
    ADD_TEST_MACRO(ConfigSources ConfigSources)
  endif()
285
  ADD_TEST_MACRO(SourcesProperty SourcesProperty)
286
  set_tests_properties(EmptyLibrary PROPERTIES
287
    PASS_REGULAR_EXPRESSION "CMake Error: CMake can not determine linker language for target: test")
288
  ADD_TEST_MACRO(CrossCompile CrossCompile)
289
  set_tests_properties(CrossCompile PROPERTIES
290
    PASS_REGULAR_EXPRESSION "TRY_RUN.. invoked in cross-compiling mode")
291
  if("${CMAKE_GENERATOR}" MATCHES "Make")
292
    ADD_TEST_MACRO(Policy0002 Policy0002)
293
  endif()
294
  if(CTEST_TEST_OSX_ARCH)
295
    ADD_TEST_MACRO(Architecture Architecture)
296
    set_tests_properties(Architecture PROPERTIES
297
      PASS_REGULAR_EXPRESSION "(file is not of required architecture|does not match cputype|not the architecture being linked)")
298
  endif()
299

300
  list(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX})
301

302
  if(NOT QT4_FOUND)
303
    find_package(Qt4 QUIET)
304
  endif()
305

306
  if(QT4_FOUND)
307 308 309 310
    # 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.
311 312 313
    include(CheckCXXSourceCompiles)
    set(_save_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
    set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
314

315 316
    set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES})
    set(CMAKE_REQUIRED_LIBRARIES ${QT_QTCORE_LIBRARIES})
317 318 319 320

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

321 322 323
    set(CMAKE_REQUIRED_INCLUDES "${_save_CMAKE_REQUIRED_INCLUDES}")
    set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}")
  endif()
324

325
  # run test for BundleUtilities on supported platforms/compilers
326
  if(MSVC OR
327
     MINGW OR
328 329
     CMAKE_SYSTEM_NAME MATCHES "Linux" OR
     CMAKE_SYSTEM_NAME MATCHES "Darwin")
330
  if(NOT "${CMAKE_GENERATOR}" STREQUAL "Watcom WMake")
331

332
    add_test(BundleUtilities ${CMAKE_CTEST_COMMAND}
333 334 335
      --build-and-test
      "${CMake_SOURCE_DIR}/Tests/BundleUtilities"
      "${CMake_BINARY_DIR}/Tests/BundleUtilities"
336
      ${build_generator_args}
337
      --build-project BundleUtilities
338
      --build-options ${build_options}
339
      )
340
    list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities")
341 342 343

    # run test for DeployQt4 on supported platforms/compilers (which depends on BundleUtilities)
    # this test also depends on the existence of the standard qtiff plugin
344
    if(QT4_WORKS AND QT_QTSQL_FOUND)
345
      add_test(Qt4Deploy ${CMAKE_CTEST_COMMAND}
346 347 348
        --build-and-test
        "${CMake_SOURCE_DIR}/Tests/Qt4Deploy"
        "${CMake_BINARY_DIR}/Tests/Qt4Deploy"
349
        ${build_generator_args}
350
        --build-project Qt4Deploy
351
        --build-options ${build_options}
352
        -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
353
        -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
354
        )
355
      list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Deploy")
356 357
    endif()

358 359
  endif()
  endif()
360

361 362 363 364
  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"
365
    "${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake" @ONLY)
366
  add_test(CMakeBuildTest ${CMAKE_CMAKE_COMMAND} -P
367
    "${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake")
368
  list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
369
  # now do it again for a project that has two project commands
370 371 372 373
  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"
374
    "${CMake_BINARY_DIR}/Tests/CMakeBuildDoubleProjectTest.cmake" @ONLY)
375
  add_test(CMakeDoubleProject ${CMAKE_CMAKE_COMMAND} -P
376
    "${CMake_BINARY_DIR}/Tests/CMakeBuildDoubleProjectTest.cmake")
377
  list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
378

Brad King's avatar
Brad King committed
379 380
  ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)

381 382 383 384
  add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/Module/ExternalData"
    "${CMake_BINARY_DIR}/Tests/Module/ExternalData"
385
    ${build_generator_args}
386
    --build-project ExternalDataTest
387
    --build-noclean
388
    --force-new-ctest-process
389 390
    --build-options ${build_options}
      -DMAKE_SUPPORTS_SPACES=${MAKE_SUPPORTS_SPACES}
391 392 393 394
    --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
    )
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Module/ExternalData")

395
  ADD_TEST_MACRO(Module.GenerateExportHeader GenerateExportHeader)
396
  ADD_TEST_MACRO(Module.FindDependency FindDependency)
397

398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
  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()

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
  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)
    add_test(VisibilityInlinesHidden ${CMAKE_CTEST_COMMAND}
      --build-and-test
      "${CMake_SOURCE_DIR}/Tests/VisibilityInlinesHidden"
      "${CMake_BINARY_DIR}/Tests/VisibilityInlinesHidden"
      ${build_generator_args}
      --build-project VisibilityInlinesHidden
      --build-options ${build_options}
    )
    list(APPEND TEST_BUILD_DIRS
      "${CMake_BINARY_DIR}/Tests/VisibilityInlinesHidden"
    )
  endif()

439
  add_test(LinkFlags-prepare
440 441 442 443
    ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/LinkFlags"
    "${CMake_BINARY_DIR}/Tests/LinkFlags"
444
    ${build_generator_args}
445 446
    --build-project LinkFlags
    --build-target LinkFlags
447 448
    --build-options ${build_options}
      -DTEST_CONFIG=\${CTEST_CONFIGURATION_TYPE}
449
    )
450
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LinkFlags")
451

452 453
  macro(ADD_LINK_FLAGS_TEST name depends)
    add_test(LinkFlags-${name}
454 455 456
      ${CMAKE_CMAKE_COMMAND} --build "${CMake_BINARY_DIR}/Tests/LinkFlags"
      --target LinkFlags_${name} --config \${CTEST_CONFIGURATION_TYPE}
      )
457
    set_tests_properties(LinkFlags-${name} PROPERTIES
458
      PASS_REGULAR_EXPRESSION "BADFLAG" DEPENDS LinkFlags-${depends})
459
  endmacro()
460 461
  ADD_LINK_FLAGS_TEST(lib prepare)
  ADD_LINK_FLAGS_TEST(dll lib)
462 463
  ADD_LINK_FLAGS_TEST(mod dll)
  ADD_LINK_FLAGS_TEST(exe mod)
464 465
  ADD_LINK_FLAGS_TEST(lib_config exe)
  ADD_LINK_FLAGS_TEST(dll_config lib_config)
466 467 468 469 470 471 472 473 474 475
  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)
476

477 478
  # If we are running right now with a UnixMakefiles based generator,
  # build the "Simple" test with the ExtraGenerators, if available
479
  # This doesn't test whether the generated project files work (unfortunately),
480
  # mainly it tests that cmake doesn't crash when generating these project files.
481
  if(${CMAKE_GENERATOR} MATCHES "Unix Makefiles"  OR  ${CMAKE_GENERATOR} MATCHES "KDevelop")
482
    # check which generators we have
483 484
    execute_process(COMMAND ${CMAKE_CMAKE_COMMAND} --help
      OUTPUT_VARIABLE cmakeOutput ERROR_VARIABLE cmakeOutput)
485
    # check for the Eclipse generator
486 487
    if ("${cmakeOutput}" MATCHES Eclipse)
      add_test(Simple_EclipseGenerator ${CMAKE_CTEST_COMMAND}
488 489 490 491 492
         --build-and-test
         "${CMake_SOURCE_DIR}/Tests/Simple"
         "${CMake_BINARY_DIR}/Tests/Simple_EclipseGenerator"
         --build-two-config
         --build-generator "Eclipse CDT4 - Unix Makefiles"
493
         --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
494
         --build-project Simple
495
         --build-options ${build_options}
496
         --test-command Simple)
497
      list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Simple_EclipseGenerator")
498
    endif ()
499 500

    # check for the CodeBlocks generator
501 502
    if ("${cmakeOutput}" MATCHES CodeBlocks)
      add_test(Simple_CodeBlocksGenerator ${CMAKE_CTEST_COMMAND}
503 504 505 506 507
         --build-and-test
         "${CMake_SOURCE_DIR}/Tests/Simple"
         "${CMake_BINARY_DIR}/Tests/Simple_CodeBlocksGenerator"
         --build-two-config
         --build-generator "CodeBlocks - Unix Makefiles"
508
         --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
509
         --build-project Simple
510
         --build-options ${build_options}
511
         --test-command Simple)
512
      list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Simple_CodeBlocksGenerator")
513
    endif ()
514
    # check for the KDevelop3 generator
515 516
    if ("${cmakeOutput}" MATCHES KDevelop3)
      add_test(Simple_KDevelop3Generator ${CMAKE_CTEST_COMMAND}
517 518 519 520 521
         --build-and-test
         "${CMake_SOURCE_DIR}/Tests/Simple"
         "${CMake_BINARY_DIR}/Tests/Simple_KDevelop3Generator"
         --build-two-config
         --build-generator "KDevelop3 - Unix Makefiles"
522
         --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
523
         --build-project Simple
524
         --build-options ${build_options}
525
         --test-command Simple)
526
      list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Simple_KDevelop3Generator")
527
    endif ()
528

529
  endif()
530

531
  # test for correct sub-project generation
532
  # not implemented in VS 6, VS 7.0, Xcode, or Ninja
533
  if(NOT CMAKE_GENERATOR MATCHES "Visual Studio [67]$|Xcode|Ninja")
534 535
    # run cmake and configure all of SubProject
    # but only build the independent executable car
536
    add_test(SubProject ${CMAKE_CTEST_COMMAND}
537 538 539 540
      --build-and-test
      "${CMake_SOURCE_DIR}/Tests/SubProject"
      "${CMake_BINARY_DIR}/Tests/SubProject"
      --build-project SubProject
541
      ${build_generator_args}
542
      --build-target car
543
      --build-options ${build_options}
544 545
      --test-command car
      )
546

547 548 549 550 551
    # 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
552
    if(CMake_TEST_EXPLICIT_MAKE_PROGRAM)
553
      set(SubProject-Stage2_BUILD_MAKEPROGRAM
554
        --build-makeprogram ${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
555 556
        )
    endif()
557
    add_test(SubProject-Stage2  ${CMAKE_CTEST_COMMAND}
558
      --build-and-test
559 560
      "${CMake_SOURCE_DIR}/Tests/SubProject/foo"
      "${CMake_BINARY_DIR}/Tests/SubProject/foo"
561 562
      --build-generator ${CMAKE_GENERATOR}
      --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
563
      ${SubProject-Stage2_BUILD_MAKEPROGRAM}
564
      --build-nocmake
565 566
      --build-project foo
      --build-target foo
567
      --build-exe-dir "${CMake_BINARY_DIR}/Tests/SubProject/foo"
568
      --build-options ${build_options}
569 570
      --test-command foo
      )
571 572
    set_tests_properties ( SubProject-Stage2 PROPERTIES DEPENDS SubProject)
    list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SubProject")
573
  endif()
574

575 576
  # macro to add a test that will build a nightly release
  # of CMake for given platform using the release scripts
577 578 579 580
  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"
581
      "cd ${_TEST_DIR}
582
${CMake_BINARY_DIR}/bin/cmake -DCMAKE_CREATE_VERSION=nightly -P ${CMake_SOURCE_DIR}/Utilities/Release/${script}
583
${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release/upload_release.cmake
584
    ")
585 586 587
    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})
588 589
    endif()
  endmacro()
590
  if(CMAKE_BUILD_NIGHTLY_RELEASES)
591 592 593 594
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWindows
      dash2win64_release.cmake)
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyMac
      dashmacmini2_release.cmake)
595 596
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyMac64
      dashmacmini5_release.cmake)
597 598
    ADD_NIGHTLY_BUILD_TEST(CMakeNightlyLinux
      magrathea_release.cmake)
599
  endif()
600

601
  # add tests with more complex invocations
602
  add_test(Framework ${CMAKE_CTEST_COMMAND}
603 604 605 606
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/Framework"
    "${CMake_BINARY_DIR}/Tests/Framework"
    --build-two-config
607
    ${build_generator_args}
608
    --build-project Framework
609
    --build-options ${build_options}
610 611
    "-DCMAKE_INSTALL_PREFIX:PATH=${CMake_BINARY_DIR}/Tests/Framework/Install"
    --test-command bar)
612
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Framework")
613

614
  add_test(TargetName ${CMAKE_CTEST_COMMAND}
615 616 617 618
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/TargetName"
    "${CMake_BINARY_DIR}/Tests/TargetName"
    --build-two-config
619
    ${build_generator_args}
620
    --build-project TargetName
621
    --build-options ${build_options}
622
    --test-command ${CMAKE_CMAKE_COMMAND} -E compare_files
623 624
    ${CMake_SOURCE_DIR}/Tests/TargetName/scripts/hello_world
    ${CMake_BINARY_DIR}/Tests/TargetName/scripts/hello_world)
625
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TargetName")
626

627
  add_test(LibName ${CMAKE_CTEST_COMMAND}
628 629 630 631
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/LibName"
    "${CMake_BINARY_DIR}/Tests/LibName"
    --build-two-config
632
    ${build_generator_args}
633
    --build-project LibName
634
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/LibName/lib"
635
    --build-options ${build_options}
636 637
    --test-command foobar
    )
638
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LibName")
639

640
  add_test(CustComDepend ${CMAKE_CTEST_COMMAND}
641 642 643 644
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustComDepend"
    "${CMake_BINARY_DIR}/Tests/CustComDepend"
    --build-two-config
645
    ${build_generator_args}
646
    --build-project CustComDepend
647
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustComDepend/bin"
648
    --build-options ${build_options}
649 650
    --test-command foo bar.c
    )
651
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustComDepend")
652

653
  add_test(ArgumentExpansion  ${CMAKE_CTEST_COMMAND}
Ben Boeckel's avatar
Ben Boeckel committed
654 655 656
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/ArgumentExpansion"
    "${CMake_BINARY_DIR}/Tests/ArgumentExpansion"
657
    ${build_generator_args}
Ben Boeckel's avatar
Ben Boeckel committed
658 659
    --build-project ArgumentExpansion
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/ArgumentExpansion/bin"
660
    --build-options ${build_options}
Ben Boeckel's avatar
Ben Boeckel committed
661
    )
662
  set_tests_properties(ArgumentExpansion PROPERTIES
663
    FAIL_REGULAR_EXPRESSION "Unexpected: ")
664
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ArgumentExpansion")
Ben Boeckel's avatar
Ben Boeckel committed
665

Brad King's avatar
Brad King committed
666 667 668 669
  add_test(GeneratorExpression  ${CMAKE_CTEST_COMMAND}
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/GeneratorExpression"
    "${CMake_BINARY_DIR}/Tests/GeneratorExpression"
670
    ${build_generator_args}
Brad King's avatar
Brad King committed
671
    --build-project GeneratorExpression
672 673
    --build-options ${build_options}
      -DCMAKE_BUILD_TYPE=\${CTEST_CONFIGURATION_TYPE}
674
    --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
Brad King's avatar
Brad King committed
675 676 677
    )
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/GeneratorExpression")

678
  add_test(CustomCommand  ${CMAKE_CTEST_COMMAND}
679 680 681 682
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustomCommand"
    "${CMake_BINARY_DIR}/Tests/CustomCommand"
    --build-two-config
683
    ${build_generator_args}
684 685
    --build-project CustomCommand
    --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustomCommand/bin"
686
    --build-options ${build_options}
687 688
    --test-command CustomCommand
    )
689
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustomCommand")
690

691 692
  ADD_TEST_MACRO(EmptyDepends ${CMAKE_CTEST_COMMAND})

693
  add_test(CustomCommandWorkingDirectory  ${CMAKE_CTEST_COMMAND}
694 695 696 697
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/CustomCommandWorkingDirectory"
    "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory"
    --build-two-config
698
    ${build_generator_args}
699
    --build-project TestWorkingDir
700
    --build-options ${build_options}
701 702
    --test-command working
    )
703
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory")
704

705
   #add_test(SimpleExclude ${CMAKE_CTEST_COMMAND}
Ken Martin's avatar
Ken Martin committed
706 707 708
   #  --build-and-test
   #  "${CMake_SOURCE_DIR}/Tests/SimpleExclude"
   #  "${CMake_BINARY_DIR}/Tests/SimpleExclude"
709
   #  ${build_generator_args}
Ken Martin's avatar
Ken Martin committed
710 711
   #  --build-project SimpleExclude
   #  --build-two-config
712
   #  --build-options ${build_options}
Ken Martin's avatar
Ken Martin committed
713
   #  --test-command t4
714 715
   #--test-command "${CMAKE_COMMAND}"
   #"-DCONFIGURATION=\${CTEST_CONFIGURATION_TYPE}"
716
   #-P "${CMake_BINARY_DIR}/Tests/SimpleExclude/run.cmake"
Ken Martin's avatar
Ken Martin committed
717
   #)
718

719
#  add_test(SameName  ${CMAKE_CTEST_COMMAND}
720 721 722
#    --build-and-test
#    "${CMake_SOURCE_DIR}/Tests/SameName"
#    "${CMake_BINARY_DIR}/Tests/SameName"
723
#    ${build_generator_args}
724 725
#    --build-project SameName
#    --build-two-config
726
#    --build-options ${build_options}
727 728 729
#    --test-command
#    "${CMake_BINARY_DIR}/Tests/SameName/Exe1/mytest2")

730
  add_test(OutOfSource ${CMAKE_CTEST_COMMAND}
731 732 733
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/OutOfSource"
    "${CMake_BINARY_DIR}/Tests/OutOfSource"
734
    ${build_generator_args}
735 736
    --build-project OutOfSource
    --build-two-config
737
    --build-options ${build_options}
738 739
    --test-command
    "${CMake_BINARY_DIR}/Tests/OutOfSource/SubDir/OutOfSourceSubdir/simple")
740 741 742
  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")
743

744
  add_test(BuildDepends ${CMAKE_CTEST_COMMAND}
745 746 747
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/BuildDepends"
    "${CMake_BINARY_DIR}/Tests/BuildDepends"
748
    ${build_generator_args}
749
    --build-project BuildDepends
750
    --build-options ${build_options}
751
    )
752
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BuildDepends")
753

754
  set(SimpleInstallInstallDir
755
    "${CMake_BINARY_DIR}/Tests/SimpleInstall/InstallDirectory")
756
  add_test(SimpleInstall ${CMAKE_CTEST_COMMAND}
757 758 759
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/SimpleInstall"
    "${CMake_BINARY_DIR}/Tests/SimpleInstall"
760
    ${build_generator_args}
761 762
    --build-project TestSimpleInstall
    --build-two-config
763
    --build-options ${build_options}
764
    "-DCMAKE_INSTALL_PREFIX:PATH=${SimpleInstallInstallDir}"
765
    "-DCTEST_TEST_CPACK:BOOL=${CTEST_TEST_CPACK}"
766
    --test-command   ${SimpleInstallInstallDir}/MyTest/bin/SimpleInstExe)
767 768
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SimpleInstall")
  add_test(SimpleInstall-Stage2 ${CMAKE_CTEST_COMMAND}
769 770 771
    --build-and-test
    "${CMake_SOURCE_DIR}/Tests/SimpleInstallS2"
    "${CMake_BINARY_DIR}/Tests/SimpleInstallS2"
772
    ${build_generator_args}
773 774
    --build-project TestSimpleInstall
    --build-two-config
775
    --build-options ${build_options}
776 777
    "-DCMAKE_INSTALL_PREFIX:PATH=${SimpleInstallInstallDir}"
    "-DSTAGE2:BOOL=1"
778
    --test-command   ${SimpleInstallInstallDir}/MyTest/bin/SimpleInstExeS2)
779
  list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/SimpleInstallS2")
780

781 782 783 784 785 786 787 788 789 790 791 792