CMakeLists.txt 6.81 KB
Newer Older
1
2
3
4
5
6
# VTK examples now require CMake 2.0 or higher.
CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
  MESSAGE(FATAL_ERROR "VTKExamples requires CMake 2.0 or higher.")
ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
7

8
# Choose behavior based on whether we are building inside the VTK tree.
9
IF(VTK_BINARY_DIR)
10
11
12
  # We are building in the VTK tree.  Add tests for some examples.
  # Test the build system examples.
  IF(BUILD_TESTING)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    # If multiple configuration types are available we must add the test
    # in a way that will use the configuration given for testing.  When
    # CTest 2.1 and higher is used to drive the tests it evaluates the
    # ADD_TEST commands stored in the test files using standard cmake
    # language evaluation.  The variable CTEST_CONFIGURATION_TYPE expands
    # to the configuration specified for testing (Debug, Release, etc.).
    # This variable must be stored in the test string and evaluated at
    # testing time, so the dollar must be stored in a way that will not be
    # evaluated immediately.  In CMake 2.1 and higher this can be done
    # with an escaped dollar but we must support older CMake versions
    # syntactically.  Since we do not know what tool will be used to drive
    # the tests (Dart, CTest <= 2.0, CTest > 2.0, etc.) we have to have a
    # special cache option "VTK_TEST_WITH_CTEST" to enable this feature.
    # Dashboard maintainers will have to set this option to properly run
    # these tests.

    # Default to single-configuration behavior.
    SET(VTK_EXAMPLE_TEST_CONFIG_TYPE)
    SET(VTK_EXAMPLE_TEST_RUN_DIR "${EXECUTABLE_OUTPUT_PATH}")

    # Enable multi-configuration behavior if support is available.
    IF(CMAKE_CONFIGURATION_TYPES AND VTK_TEST_WITH_CTEST)
      SET(DOLLAR "$")
      IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.0)
        SET(VTK_EXAMPLE_TEST_CONFIG_TYPE -C "${DOLLAR}{CTEST_CONFIGURATION_TYPE}")
        SET(VTK_EXAMPLE_TEST_RUN_DIR "${EXECUTABLE_OUTPUT_PATH}/${DOLLAR}{CTEST_CONFIGURATION_TYPE}")
      ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.0)
    ENDIF(CMAKE_CONFIGURATION_TYPES AND VTK_TEST_WITH_CTEST)

    # Add a test to build the vtkLocal example.
43
    ADD_TEST(Example-vtkLocal ${CMAKE_CTEST_COMMAND}
44
      ${VTK_EXAMPLE_TEST_CONFIG_TYPE}
45
46
47
48
49
50
51
      --build-and-test
      ${VTK_SOURCE_DIR}/Examples/Build/vtkLocal
      ${VTK_BINARY_DIR}/Examples/Build/vtkLocal
      --build-two-config
      --build-generator ${CMAKE_GENERATOR}
      --build-makeprogram ${MAKEPROGRAM}
      --build-project VTKLOCAL
52
      --build-run-dir ${VTK_EXAMPLE_TEST_RUN_DIR}
53
      --build-options -DVTK_DIR:PATH=${VTK_BINARY_DIR}
54
      --test-command "${VTK_BINARY_DIR}/Examples/Build/vtkLocal/bin/vtkLocalTest"
55
      )
56
57

    # Add a test to build the vtkMy example.
58
    ADD_TEST(Example-vtkMy ${CMAKE_CTEST_COMMAND}
59
      ${VTK_EXAMPLE_TEST_CONFIG_TYPE}
60
61
62
63
64
65
      --build-and-test
      ${VTK_SOURCE_DIR}/Examples/Build/vtkMy
      ${VTK_BINARY_DIR}/Examples/Build/vtkMy
      --build-two-config
      --build-generator ${CMAKE_GENERATOR}
      --build-makeprogram ${MAKEPROGRAM}
66
      --build-project VTKMY
67
      --build-run-dir ${VTK_EXAMPLE_TEST_RUN_DIR}
68
      --build-options -DVTK_DIR:PATH=${VTK_BINARY_DIR}
69
      --test-command "${VTK_BINARY_DIR}/Examples/Build/vtkMy/bin/vtkmyEx1"
70
      )
71
72
73
74
75
  ENDIF(BUILD_TESTING)

  # Build the examples as a separate project using a custom target.
  # Make sure it uses the same build configuration as VTK.
  IF(CMAKE_CONFIGURATION_TYPES)
76
    SET(VTKExamples_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  ELSE(CMAKE_CONFIGURATION_TYPES)
    SET(VTKExamples_CONFIG_TYPE)
  ENDIF(CMAKE_CONFIGURATION_TYPES)
  ADD_CUSTOM_COMMAND(
    OUTPUT ${VTK_BINARY_DIR}/VTKExamples
    COMMAND ${CMAKE_CTEST_COMMAND}
    ARGS ${VTKExamples_CONFIG_TYPE}
         --build-and-test
         ${VTK_SOURCE_DIR}/Examples
         ${VTK_BINARY_DIR}/Examples/All
         --build-noclean
         --build-two-config
         --build-project VTKExamples
         --build-generator ${CMAKE_GENERATOR}
         --build-makeprogram ${MAKEPROGRAM}
         --build-options -DVTK_DIR:PATH=${VTK_BINARY_DIR}
93
                         -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
94
                         -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
95
96
97
98
                         -DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
                         -DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
                         -DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
                         -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
99
                         -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
100
                         -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
101
102
103
104
105
106
107
                         -DCMAKE_CXX_FLAGS_DEBUG:STRING=${CMAKE_CXX_FLAGS_DEBUG}
                         -DCMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE}
                         -DCMAKE_CXX_FLAGS_MINSIZEREL:STRING=${CMAKE_CXX_FLAGS_MINSIZEREL}
                         -DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
                         -DEXECUTABLE_OUTPUT_PATH:PATH=${EXECUTABLE_OUTPUT_PATH}
                         -DLIBRARY_OUTPUT_PATH:PATH=${LIBRARY_OUTPUT_PATH}
         )
108
  ADD_CUSTOM_TARGET(VTKExamplesTarget ALL DEPENDS ${VTK_BINARY_DIR}/VTKExamples)
109
110

  # Make sure the target builds after the rest of VTK.
111
  ADD_DEPENDENCIES(VTKExamplesTarget
112
113
114
115
116
117
118
119
    vtkCommon
    vtkFiltering
    vtkImaging
    vtkGraphics
    vtkGenericFiltering
    vtkIO
    )
  IF(VTK_USE_RENDERING)
120
    ADD_DEPENDENCIES(VTKExamplesTarget vtkRendering)
121
    ADD_DEPENDENCIES(VTKExamplesTarget vtkVolumeRendering)
122
    ADD_DEPENDENCIES(VTKExamplesTarget vtkHybrid)
123
124
    ADD_DEPENDENCIES(VTKExamplesTarget vtkWidgets)
  ENDIF(VTK_USE_RENDERING)
125
  IF(VTK_USE_PARALLEL)
126
    ADD_DEPENDENCIES(VTKExamplesTarget vtkParallel)
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  ENDIF(VTK_USE_PARALLEL)

ELSE(VTK_BINARY_DIR)
  # We are building outside the VTK tree.  Build the examples directly.
  PROJECT(VTKExamples)

  # Find and load the VTK configuration.
  FIND_PACKAGE(VTK)
  IF(NOT VTK_DIR)
    MESSAGE(FATAL_ERROR "Please set VTK_DIR.")
  ENDIF(NOT VTK_DIR)
  INCLUDE(${VTK_USE_FILE})

  # Most examples require rendering support.
  IF(VTK_USE_RENDERING)
    SUBDIRS(
143
144
      AMR/Cxx
      MultiBlock/Cxx
145
146
147
148
149
150
151
152
153
      DataManipulation/Cxx
      Medical/Cxx
      Modelling/Cxx
      Rendering/Cxx
      Tutorial/Step1/Cxx
      Tutorial/Step2/Cxx
      Tutorial/Step3/Cxx
      Tutorial/Step4/Cxx
      Tutorial/Step5/Cxx
154
      Tutorial/Step6/Cxx
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
      )

    IF(VTK_USE_PARALLEL)
      SUBDIRS(ParallelProcessing)
    ENDIF(VTK_USE_PARALLEL)

    IF(VTK_USE_QVTK)
      SUBDIRS(GUI/Qt)
    ENDIF(VTK_USE_QVTK)

    IF(VTK_USE_MFC)
      SUBDIRS(GUI/Win32/vtkMFC)
    ENDIF(VTK_USE_MFC)
  ENDIF(VTK_USE_RENDERING)
ENDIF(VTK_BINARY_DIR)