1 PROJECT (TestSimpleInstall)
2 SET(CMAKE_VERBOSE_MAKEFILE 1)
3 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY
4 "${TestSimpleInstall_BINARY_DIR}/bin")
5 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
6 "${TestSimpleInstall_BINARY_DIR}/lib/static")
7 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY
8 "${TestSimpleInstall_BINARY_DIR}/lib")
10 # Skip generating the rpath pointing at the build tree to make sure
11 # the executable is installed with the proper rpath in the install
13 SET(CMAKE_SKIP_BUILD_RPATH 1)
15 # Make sure the executable can run from the install tree.
16 SET(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
18 # Skip the dependency that causes a build when installing. This
19 # avoids infinite loops when the post-build rule below installs.
20 SET(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY 1)
21 SET(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY 1)
23 SET(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
25 SET(EXTRA_INSTALL_FLAGS)
26 MESSAGE("Extra install: ${EXTRA_INSTALL_FLAGS}")
30 ${CMAKE_INSTALL_PREFIX}/MyTest/lib/static
31 ${CMAKE_INSTALL_PREFIX}/MyTest/lib
33 SET(t1NAMES test1 test1${CMAKE_DEBUG_POSTFIX} test1rel)
34 SET(t2NAMES test2 test2${CMAKE_DEBUG_POSTFIX})
35 SET(t4NAMES test4 test4${CMAKE_DEBUG_POSTFIX})
37 # Make sure the install script ran.
38 SET(CMAKE_INSTALL_SCRIPT_DID_RUN 0)
39 INCLUDE(${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake OPTIONAL)
40 IF(CMAKE_INSTALL_SCRIPT_DID_RUN)
41 MESSAGE(STATUS "Stage 1 did run install script 2.")
42 ELSE(CMAKE_INSTALL_SCRIPT_DID_RUN)
43 MESSAGE(SEND_ERROR "Stage 1 did not run install script 2.")
44 ENDIF(CMAKE_INSTALL_SCRIPT_DID_RUN)
47 SET(LIBPATHS ${LIBPATHS} "${CMAKE_INSTALL_PREFIX}/MyTest/bin")
48 ENDIF(CYGWIN OR MINGW)
49 MESSAGE("Search for library in: ${LIBPATHS}")
51 SET(TEST1_LIBRARY "TEST1_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
52 SET(TEST2_LIBRARY "TEST2_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
53 SET(TEST4_LIBRARY "TEST4_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
55 FIND_LIBRARY(TEST1_LIBRARY
59 FIND_LIBRARY(TEST2_LIBRARY
63 FIND_LIBRARY(TEST4_LIBRARY
68 INCLUDE_DIRECTORIES(${CMAKE_INSTALL_PREFIX}/MyTest/include)
69 ADD_EXECUTABLE (SimpleInstExeS2 inst2.cxx foo.c foo.h)
70 TARGET_LINK_LIBRARIES(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} ${TEST4_LIBRARY})
71 SET(install_target SimpleInstExeS2)
73 IF("${TEST1_LIBRARY}" MATCHES "static")
74 MESSAGE(STATUS "test1 correctly found in lib/static")
75 ELSE("${TEST1_LIBRARY}" MATCHES "static")
76 MESSAGE(SEND_ERROR "test1 not found in lib/static!")
77 ENDIF("${TEST1_LIBRARY}" MATCHES "static")
79 # Check for failure of configuration-specific installation.
80 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
81 MESSAGE(FATAL_ERROR "Debug-configuration file installed for Release!")
82 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
83 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
84 MESSAGE(FATAL_ERROR "Release-configuration file installed for Debug!")
85 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
87 # Check for failure of directory installation.
88 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
89 MESSAGE(FATAL_ERROR "Directory installation did not install TSD.h")
90 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
91 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
92 MESSAGE(FATAL_ERROR "Directory installation installed CVS directory.")
93 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
94 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
95 MESSAGE(FATAL_ERROR "Directory installation installed CVS directory.")
96 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
97 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
98 MESSAGE(FATAL_ERROR "Directory installation installed CMakeLists.txt.")
99 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
100 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.h")
101 MESSAGE(FATAL_ERROR "Directory installation did not install alternate TSD.h")
102 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.h")
103 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.cxx")
104 MESSAGE(FATAL_ERROR "Directory installation installed alternate TSD.cxx")
105 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.cxx")
107 # Check that scripts properly installed.
108 IF(WIN32 AND NOT CYGWIN)
110 ELSE(WIN32 AND NOT CYGWIN)
112 ENDIF(WIN32 AND NOT CYGWIN)
113 FOREACH(loc share share/old1 share/old2 share/old3 share/alt)
114 SET(CUR_SCRIPT "${CMAKE_INSTALL_PREFIX}/MyTest/${loc}/sample_script${BAT}")
116 COMMAND ${CUR_SCRIPT}
117 RESULT_VARIABLE SAMPLE_SCRIPT_RESULT
118 OUTPUT_VARIABLE SAMPLE_SCRIPT_OUTPUT
120 IF(NOT "${SAMPLE_SCRIPT_RESULT}" MATCHES "^0$")
122 "Sample script [${CUR_SCRIPT}] failed: [${SAMPLE_SCRIPT_RESULT}]")
123 ENDIF(NOT "${SAMPLE_SCRIPT_RESULT}" MATCHES "^0$")
124 IF(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
126 "Bad sample script [${CUR_SCRIPT}] output: [${SAMPLE_SCRIPT_OUTPUT}]")
127 ENDIF(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
130 # Check for failure of empty directory installation.
131 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
132 MESSAGE(FATAL_ERROR "Empty directory installation did not install.")
133 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
134 FILE(GLOB EMPTY_FILES "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty/*")
136 MESSAGE(FATAL_ERROR "Empty directory installed [${EMPTY_FILES}].")
139 # Make sure the test executable can run from the install tree.
140 SET_TARGET_PROPERTIES(SimpleInstExeS2 PROPERTIES
141 INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
143 INSTALL_TARGETS(/MyTest/bin SimpleInstExeS2)
145 # try to import the exported targets again
146 SET(SimpleInstallS1_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
147 FIND_PACKAGE(SimpleInstallS1 REQUIRED)
148 GET_TARGET_PROPERTY(simpleInstallImported S1_SimpleInstall IMPORTED)
149 IF(NOT simpleInstallImported)
150 MESSAGE(FATAL_ERROR "Target S1_SimpleInstall could not be imported")
151 ENDIF(NOT simpleInstallImported)
154 # Wipe out the install directory to do a fresh test.
155 FILE(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/MyTest)
157 # this is stage 1, so create libraries and modules and install everything
158 ADD_LIBRARY(test1 STATIC lib1.cxx)
159 ADD_LIBRARY(test2 SHARED lib2.cxx)
160 ADD_LIBRARY(test3 MODULE lib3.cxx)
161 ADD_LIBRARY(test4 SHARED lib4.cxx)
163 ADD_EXECUTABLE (SimpleInstall inst.cxx foo.c foo.h)
164 TARGET_LINK_LIBRARIES(SimpleInstall test1 test2 test4)
165 SET(install_target SimpleInstall)
167 # Make sure the test executable can run from the install tree.
168 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES
169 INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
171 # Test per-configuration output name.
172 SET_TARGET_PROPERTIES(test1 PROPERTIES RELEASE_OUTPUT_NAME test1rel)
173 SET_TARGET_PROPERTIES(test2 PROPERTIES PUBLIC_HEADER foo.h)
175 IF(CMAKE_GENERATOR MATCHES "Makefiles")
176 ADD_SUBDIRECTORY(TestSubDir)
177 ADD_DEPENDENCIES(SimpleInstall TSD)
178 ENDIF(CMAKE_GENERATOR MATCHES "Makefiles")
180 ADD_DEPENDENCIES(SimpleInstall test3)
181 ADD_DEPENDENCIES(test2 test3)
182 ADD_DEPENDENCIES(test4 test2)
184 INSTALL(TARGETS SimpleInstall test1 test2 test3 EXPORT SimpleInstallS1
185 RUNTIME DESTINATION MyTest/bin COMPONENT Runtime # .exe, .dll
186 LIBRARY DESTINATION MyTest/lib COMPONENT Runtime # .so, mod.dll
187 ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
188 PUBLIC_HEADER DESTINATION MyTest/include COMPONENT Development
191 INSTALL(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
192 RUNTIME DESTINATION MyTest/bin
193 LIBRARY DESTINATION MyTest/lib
194 ARCHIVE DESTINATION MyTest/lib/static
195 OPTIONAL # for coverage...target should always exist
197 INSTALL(FILES lib1.h DESTINATION MyTest/include/foo)
199 DESTINATION MyTest/include/foo
200 COMPONENT Development
201 PERMISSIONS OWNER_READ OWNER_WRITE
205 # Test old-style install commands.
206 INSTALL_FILES(/MyTest/include FILES lib3.h)
207 INSTALL_FILES(/MyTest/include/old .h lib3)
208 INSTALL_FILES(/MyTest/include/old "^lib2.h$")
209 INSTALL_PROGRAMS(/MyTest/share/old1 FILES
210 scripts/sample_script scripts/sample_script.bat)
211 INSTALL_PROGRAMS(/MyTest/share/old2
212 scripts/sample_script scripts/sample_script.bat)
214 # "export" the targets collected in "SimpleInstallS1"
215 INSTALL(EXPORT SimpleInstallS1 FILE SimpleInstallS1Config.cmake
216 DESTINATION MyTest/lib
219 EXPORT(TARGETS SimpleInstall test1 test2 test3
220 FILE "${CMAKE_CURRENT_BINARY_DIR}/SimpleInstallS1Config.cmake"
223 ADD_SUBDIRECTORY(scripts)
225 # Test optional installation.
226 INSTALL(FILES does_not_exist.h DESTINATION MyTest/include/foo OPTIONAL)
228 # Test configuration-specific installation.
229 INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
230 DESTINATION MyTest/include/Release
232 INSTALL(FILES lib1.h RENAME lib1debug.h CONFIGURATIONS Debug
233 DESTINATION MyTest/include/Debug
236 # Test directory installation.
237 FILE(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
238 FILE(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
240 DIRECTORY TestSubDir scripts/ DESTINATION MyTest/share
241 FILE_PERMISSIONS OWNER_READ OWNER_WRITE
242 DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
243 GROUP_READ GROUP_EXECUTE
244 PATTERN "CVS" EXCLUDE
245 REGEX "\\.txt$" EXCLUDE
246 PATTERN "scripts/*" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
249 # Alternate directory installation for coverage.
251 DIRECTORY scripts/ DESTINATION MyTest/share/alt
252 COMPONENT Development
253 USE_SOURCE_PERMISSIONS
254 PATTERN "CVS" EXCLUDE
255 REGEX "\\.txt$" EXCLUDE
258 DIRECTORY TestSubDir DESTINATION MyTest/share/alt
259 FILE_PERMISSIONS OWNER_READ OWNER_WRITE
260 DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
261 GROUP_READ GROUP_EXECUTE
262 FILES_MATCHING PATTERN "*.h"
265 # Test empty directory installation.
266 INSTALL(DIRECTORY DESTINATION MyTest/share/empty)
268 # Test user-specified install scripts, with and without COMPONENT.
270 SCRIPT InstallScript1.cmake
271 CODE "SET(INSTALL_CODE_DID_RUN 1)"
272 SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
275 SCRIPT InstallScript3.cmake
276 CODE "SET(INSTALL_CODE_WITH_COMPONENT_DID_RUN 1)"
277 SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript4.cmake
278 COMPONENT Development
280 SET_DIRECTORY_PROPERTIES(PROPERTIES
281 ADDITIONAL_MAKE_CLEAN_FILES
282 "${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake;${CMAKE_INSTALL_PREFIX}/InstallScript4Out.cmake")
284 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstExe)
285 # Disable VERSION test until it is implemented in the XCode generator.
287 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES VERSION 1.2)
289 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES PRE_INSTALL_SCRIPT
290 ${CMAKE_CURRENT_SOURCE_DIR}/PreInstall.cmake)
291 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES POST_INSTALL_SCRIPT
292 ${CMAKE_CURRENT_SOURCE_DIR}/PostInstall.cmake)
293 SET_TARGET_PROPERTIES(test4 PROPERTIES VERSION 1.2 SOVERSION 3
294 INSTALL_NAME_DIR @executable_path/../lib)
297 IF(CMAKE_CONFIGURATION_TYPES)
298 SET(SI_CONFIG -C ${CMAKE_CFG_INTDIR})
299 ELSE(CMAKE_CONFIGURATION_TYPES)
301 ENDIF(CMAKE_CONFIGURATION_TYPES)
303 # Dummy test of CPack
304 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack")
305 SET(CPACK_PACKAGE_VENDOR "Kitware")
306 SET(CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/PackageScript.cmake")
308 IF(WIN32 AND NOT UNIX)
309 FIND_PROGRAM(NSIS_MAKENSIS NAMES makensis
310 PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
311 DOC "Where is makensis.exe located"
313 IF(NOT NSIS_MAKENSIS)
314 SET(CPACK_GENERATOR TGZ)
315 ENDIF(NOT NSIS_MAKENSIS)
316 ENDIF(WIN32 AND NOT UNIX)
317 IF(UNIX AND NOT APPLE)
318 SET(CPACK_GENERATOR "TGZ;STGZ;TZ")
319 # FIND_PROGRAM(found_compress
322 # FIND_PROGRAM(file_command NAMES file)
323 # IF(NOT file_command)
324 # set(file_command file)
325 # ENDIF(NOT file_command)
326 # EXECUTE_PROCESS(COMMAND ${file_command} ${found_compress}
327 # OUTPUT_VARIABLE output)
329 # if("${output}" MATCHES "script")
331 # endif("${output}" MATCHES "script")
332 # if("${output}" MATCHES "dummy.sh")
334 # endif("${output}" MATCHES "dummy.sh")
336 # message("compress found and it was not a script")
337 # message("output from file command: [${output}]")
338 # SET(CPACK_GENERATOR "${CPACK_GENERATOR};TZ")
340 # message("compress found, but it was a script so dont use it")
341 # message("output from file command: [${output}]")
343 # ENDIF(found_compress)
344 FIND_PROGRAM(found_bz2
347 SET(CPACK_GENERATOR "${CPACK_GENERATOR};TBZ2")
349 ENDIF(UNIX AND NOT APPLE)
351 SET(CPACK_PACKAGE_EXECUTABLES "SimpleInstall" "Simple Install")
352 SET(CMAKE_INSTALL_MFC_LIBRARIES 1)
353 SET(CMAKE_INSTALL_DEBUG_LIBRARIES 1)
354 INCLUDE(InstallRequiredSystemLibraries)
357 # Disable packaging test on Apple 10.3 and below. PackageMaker starts
358 # DiskManagementTool as root and disowns it
359 # (http://lists.apple.com/archives/installer-dev/2005/Jul/msg00005.html).
360 # It is left holding open pipe handles and preventing ProcessUNIX from
361 # detecting end-of-data even after its immediate child exits. Then
362 # the test hangs until it times out and is killed. This is a
363 # well-known bug in kwsys process execution that I would love to get
365 SET(PACKAGE_TARGET --build-target package)
366 IF(APPLE AND NOT CTEST_TEST_CPACK)
368 COMMAND sw_vers -productVersion
369 OUTPUT_VARIABLE OSX_VERSION
370 OUTPUT_STRIP_TRAILING_WHITESPACE
372 IF("${OSX_VERSION}" MATCHES "^10\\.[0123]" OR "${OSX_VERSION}" MATCHES "ProductVersion:\t10\\.[0123]")
373 MESSAGE(STATUS "Disabling package test on OSX < 10.4")
374 MESSAGE(STATUS "OSX_VERSION='${OSX_VERSION}'")
376 ENDIF("${OSX_VERSION}" MATCHES "^10\\.[0123]" OR "${OSX_VERSION}" MATCHES "ProductVersion:\t10\\.[0123]")
377 ENDIF(APPLE AND NOT CTEST_TEST_CPACK)
380 TARGET ${install_target}
382 COMMAND ${CMAKE_CTEST_COMMAND}
387 --build-generator ${CMAKE_GENERATOR}
388 --build-project ${PROJECT_NAME}
389 --build-makeprogram ${CMAKE_MAKE_PROGRAM}
391 --build-target install
393 COMMENT "Install Project"