1 cmake_minimum_required (VERSION 2.6)
2 PROJECT (TestSimpleInstall)
3 SET(CMAKE_VERBOSE_MAKEFILE 1)
4 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY
5 "${TestSimpleInstall_BINARY_DIR}/bin")
6 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
7 "${TestSimpleInstall_BINARY_DIR}/lib/static")
8 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY
9 "${TestSimpleInstall_BINARY_DIR}/lib")
11 # Skip generating the rpath pointing at the build tree to make sure
12 # the executable is installed with the proper rpath in the install
14 SET(CMAKE_SKIP_BUILD_RPATH 1)
16 # Make sure the executable can run from the install tree.
17 SET(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
19 # Skip the dependency that causes a build when installing. This
20 # avoids infinite loops when the post-build rule below installs.
21 SET(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY 1)
22 SET(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY 1)
24 SET(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
26 SET(EXTRA_INSTALL_FLAGS)
27 MESSAGE("Extra install: ${EXTRA_INSTALL_FLAGS}")
31 ${CMAKE_INSTALL_PREFIX}/MyTest/lib/static
32 ${CMAKE_INSTALL_PREFIX}/MyTest/lib
34 SET(t1NAMES test1 test1${CMAKE_DEBUG_POSTFIX} test1rel)
35 SET(t2NAMES test2 test2${CMAKE_DEBUG_POSTFIX})
36 SET(t4NAMES test4 test4${CMAKE_DEBUG_POSTFIX})
38 # Make sure the install script ran.
39 SET(CMAKE_INSTALL_SCRIPT_DID_RUN 0)
40 INCLUDE(${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake OPTIONAL)
41 IF(CMAKE_INSTALL_SCRIPT_DID_RUN)
42 MESSAGE(STATUS "Stage 1 did run install script 2.")
43 ELSE(CMAKE_INSTALL_SCRIPT_DID_RUN)
44 MESSAGE(SEND_ERROR "Stage 1 did not run install script 2.")
45 ENDIF(CMAKE_INSTALL_SCRIPT_DID_RUN)
48 SET(LIBPATHS ${LIBPATHS} "${CMAKE_INSTALL_PREFIX}/MyTest/bin")
49 ENDIF(CYGWIN OR MINGW)
50 MESSAGE("Search for library in: ${LIBPATHS}")
52 SET(TEST1_LIBRARY "TEST1_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
53 SET(TEST2_LIBRARY "TEST2_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
54 SET(TEST4_LIBRARY "TEST4_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
56 FIND_LIBRARY(TEST1_LIBRARY
60 FIND_LIBRARY(TEST2_LIBRARY
64 FIND_LIBRARY(TEST4_LIBRARY
69 INCLUDE_DIRECTORIES(${CMAKE_INSTALL_PREFIX}/MyTest/include)
70 ADD_EXECUTABLE (SimpleInstExeS2 inst2.cxx foo.c foo.h)
71 TARGET_LINK_LIBRARIES(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} ${TEST4_LIBRARY})
72 SET(install_target SimpleInstExeS2)
74 IF("${TEST1_LIBRARY}" MATCHES "static")
75 MESSAGE(STATUS "test1 correctly found in lib/static")
76 ELSE("${TEST1_LIBRARY}" MATCHES "static")
77 MESSAGE(SEND_ERROR "test1 not found in lib/static!")
78 ENDIF("${TEST1_LIBRARY}" MATCHES "static")
80 # Check for failure of configuration-specific installation.
81 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
82 MESSAGE(FATAL_ERROR "Debug-configuration file installed for Release!")
83 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
84 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
85 MESSAGE(FATAL_ERROR "Release-configuration file installed for Debug!")
86 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
88 # Check for failure of directory installation.
89 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
90 MESSAGE(FATAL_ERROR "Directory installation did not install TSD.h")
91 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
92 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
93 MESSAGE(FATAL_ERROR "Directory installation installed CVS directory.")
94 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
95 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
96 MESSAGE(FATAL_ERROR "Directory installation installed CVS directory.")
97 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
98 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
99 MESSAGE(FATAL_ERROR "Directory installation installed CMakeLists.txt.")
100 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
101 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.h")
102 MESSAGE(FATAL_ERROR "Directory installation did not install alternate TSD.h")
103 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.h")
104 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.cxx")
105 MESSAGE(FATAL_ERROR "Directory installation installed alternate TSD.cxx")
106 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.cxx")
108 # Check that scripts properly installed.
109 IF(WIN32 AND NOT CYGWIN)
111 ELSE(WIN32 AND NOT CYGWIN)
113 ENDIF(WIN32 AND NOT CYGWIN)
114 FOREACH(loc share share/old1 share/old2 share/old3 share/alt)
115 SET(CUR_SCRIPT "${CMAKE_INSTALL_PREFIX}/MyTest/${loc}/sample_script${BAT}")
117 COMMAND ${CUR_SCRIPT}
118 RESULT_VARIABLE SAMPLE_SCRIPT_RESULT
119 OUTPUT_VARIABLE SAMPLE_SCRIPT_OUTPUT
121 IF(NOT "${SAMPLE_SCRIPT_RESULT}" MATCHES "^0$")
123 "Sample script [${CUR_SCRIPT}] failed: [${SAMPLE_SCRIPT_RESULT}]")
124 ENDIF(NOT "${SAMPLE_SCRIPT_RESULT}" MATCHES "^0$")
125 IF(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
127 "Bad sample script [${CUR_SCRIPT}] output: [${SAMPLE_SCRIPT_OUTPUT}]")
128 ENDIF(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
131 # Check for failure of empty directory installation.
132 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
133 MESSAGE(FATAL_ERROR "Empty directory installation did not install.")
134 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
135 FILE(GLOB EMPTY_FILES "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty/*")
137 MESSAGE(FATAL_ERROR "Empty directory installed [${EMPTY_FILES}].")
140 # Make sure the test executable can run from the install tree.
141 SET_TARGET_PROPERTIES(SimpleInstExeS2 PROPERTIES
142 INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
144 INSTALL_TARGETS(/MyTest/bin SimpleInstExeS2)
146 # try to import the exported targets again
147 SET(SimpleInstallS1_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
148 FIND_PACKAGE(SimpleInstallS1 REQUIRED)
149 GET_TARGET_PROPERTY(simpleInstallImported S1_SimpleInstall IMPORTED)
150 IF(NOT simpleInstallImported)
151 MESSAGE(FATAL_ERROR "Target S1_SimpleInstall could not be imported")
152 ENDIF(NOT simpleInstallImported)
155 # Wipe out the install directory to do a fresh test.
156 FILE(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/MyTest)
158 # this is stage 1, so create libraries and modules and install everything
159 ADD_LIBRARY(test1 STATIC lib1.cxx)
160 ADD_LIBRARY(test2 SHARED lib2.cxx)
161 ADD_LIBRARY(test3 MODULE lib3.cxx)
162 ADD_LIBRARY(test4 SHARED lib4.cxx)
164 ADD_EXECUTABLE (SimpleInstall inst.cxx foo.c foo.h)
165 TARGET_LINK_LIBRARIES(SimpleInstall test1 test2 test4)
166 SET(install_target SimpleInstall)
168 # Make sure the test executable can run from the install tree.
169 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES
170 INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
172 # Test per-configuration output name.
173 SET_TARGET_PROPERTIES(test1 PROPERTIES RELEASE_OUTPUT_NAME test1rel)
174 SET_TARGET_PROPERTIES(test2 PROPERTIES PUBLIC_HEADER foo.h)
176 IF(CMAKE_GENERATOR MATCHES "Makefiles")
177 ADD_SUBDIRECTORY(TestSubDir)
178 ADD_DEPENDENCIES(SimpleInstall TSD)
179 ENDIF(CMAKE_GENERATOR MATCHES "Makefiles")
181 ADD_DEPENDENCIES(SimpleInstall test3)
182 ADD_DEPENDENCIES(test2 test3)
183 ADD_DEPENDENCIES(test4 test2)
185 INSTALL(TARGETS SimpleInstall test1 test2 test3 EXPORT SimpleInstallS1
186 RUNTIME DESTINATION MyTest/bin COMPONENT Runtime # .exe, .dll
187 LIBRARY DESTINATION MyTest/lib COMPONENT Runtime # .so, mod.dll
188 ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
189 PUBLIC_HEADER DESTINATION MyTest/include COMPONENT Development
192 INSTALL(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
193 RUNTIME DESTINATION MyTest/bin
194 LIBRARY DESTINATION MyTest/lib
195 ARCHIVE DESTINATION MyTest/lib/static
196 OPTIONAL # for coverage...target should always exist
198 INSTALL(FILES lib1.h DESTINATION MyTest/include/foo)
200 DESTINATION MyTest/include/foo
201 COMPONENT Development
202 PERMISSIONS OWNER_READ OWNER_WRITE
206 # Test old-style install commands.
207 INSTALL_FILES(/MyTest/include FILES lib3.h)
208 INSTALL_FILES(/MyTest/include/old .h lib3)
209 INSTALL_FILES(/MyTest/include/old "^lib2.h$")
210 INSTALL_PROGRAMS(/MyTest/share/old1 FILES
211 scripts/sample_script scripts/sample_script.bat)
212 INSTALL_PROGRAMS(/MyTest/share/old2
213 scripts/sample_script scripts/sample_script.bat)
215 # "export" the targets collected in "SimpleInstallS1"
216 INSTALL(EXPORT SimpleInstallS1 FILE SimpleInstallS1Config.cmake
217 DESTINATION MyTest/lib
220 EXPORT(TARGETS SimpleInstall test1 test2 test3
221 FILE "${CMAKE_CURRENT_BINARY_DIR}/SimpleInstallS1Config.cmake"
224 ADD_SUBDIRECTORY(scripts)
226 # Test optional installation.
227 INSTALL(FILES does_not_exist.h DESTINATION MyTest/include/foo OPTIONAL)
229 # Test configuration-specific installation.
230 INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
231 DESTINATION MyTest/include/Release
233 INSTALL(FILES lib1.h RENAME lib1debug.h CONFIGURATIONS Debug
234 DESTINATION MyTest/include/Debug
237 # Test directory installation.
238 FILE(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
239 FILE(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
241 DIRECTORY TestSubDir scripts/ DESTINATION MyTest/share
242 FILE_PERMISSIONS OWNER_READ OWNER_WRITE
243 DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
244 GROUP_READ GROUP_EXECUTE
245 PATTERN "CVS" EXCLUDE
246 REGEX "\\.txt$" EXCLUDE
247 PATTERN "scripts/*" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
250 # Alternate directory installation for coverage.
252 DIRECTORY scripts/ DESTINATION MyTest/share/alt
253 COMPONENT Development
254 USE_SOURCE_PERMISSIONS
255 PATTERN "CVS" EXCLUDE
256 REGEX "\\.txt$" EXCLUDE
259 DIRECTORY TestSubDir DESTINATION MyTest/share/alt
260 FILE_PERMISSIONS OWNER_READ OWNER_WRITE
261 DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
262 GROUP_READ GROUP_EXECUTE
263 FILES_MATCHING PATTERN "*.h"
266 # Test empty directory installation.
267 INSTALL(DIRECTORY DESTINATION MyTest/share/empty)
269 # Test user-specified install scripts, with and without COMPONENT.
271 SCRIPT InstallScript1.cmake
272 CODE "SET(INSTALL_CODE_DID_RUN 1)"
273 SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
276 SCRIPT InstallScript3.cmake
277 CODE "SET(INSTALL_CODE_WITH_COMPONENT_DID_RUN 1)"
278 SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript4.cmake
279 COMPONENT Development
281 SET_DIRECTORY_PROPERTIES(PROPERTIES
282 ADDITIONAL_MAKE_CLEAN_FILES
283 "${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake;${CMAKE_INSTALL_PREFIX}/InstallScript4Out.cmake")
285 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstExe)
286 # Disable VERSION test until it is implemented in the XCode generator.
288 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES VERSION 1.2)
290 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES PRE_INSTALL_SCRIPT
291 ${CMAKE_CURRENT_SOURCE_DIR}/PreInstall.cmake)
292 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES POST_INSTALL_SCRIPT
293 ${CMAKE_CURRENT_SOURCE_DIR}/PostInstall.cmake)
294 SET_TARGET_PROPERTIES(test4 PROPERTIES VERSION 1.2 SOVERSION 3
295 INSTALL_NAME_DIR @executable_path/../lib)
298 IF(CMAKE_CONFIGURATION_TYPES)
299 SET(SI_CONFIG -C ${CMAKE_CFG_INTDIR})
300 ELSE(CMAKE_CONFIGURATION_TYPES)
302 ENDIF(CMAKE_CONFIGURATION_TYPES)
304 # Dummy test of CPack
305 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack")
306 SET(CPACK_PACKAGE_VENDOR "Kitware")
307 SET(CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/PackageScript.cmake")
309 IF(WIN32 AND NOT UNIX)
310 FIND_PROGRAM(NSIS_MAKENSIS NAMES makensis
311 PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
312 DOC "Where is makensis.exe located"
314 IF(NOT NSIS_MAKENSIS)
315 SET(CPACK_GENERATOR TGZ)
316 ENDIF(NOT NSIS_MAKENSIS)
317 ENDIF(WIN32 AND NOT UNIX)
318 IF(UNIX AND NOT APPLE)
319 SET(CPACK_GENERATOR "TGZ;STGZ;TZ")
320 # FIND_PROGRAM(found_compress
323 # FIND_PROGRAM(file_command NAMES file)
324 # IF(NOT file_command)
325 # set(file_command file)
326 # ENDIF(NOT file_command)
327 # EXECUTE_PROCESS(COMMAND ${file_command} ${found_compress}
328 # OUTPUT_VARIABLE output)
330 # if("${output}" MATCHES "script")
332 # endif("${output}" MATCHES "script")
333 # if("${output}" MATCHES "dummy.sh")
335 # endif("${output}" MATCHES "dummy.sh")
337 # message("compress found and it was not a script")
338 # message("output from file command: [${output}]")
339 # SET(CPACK_GENERATOR "${CPACK_GENERATOR};TZ")
341 # message("compress found, but it was a script so dont use it")
342 # message("output from file command: [${output}]")
344 # ENDIF(found_compress)
345 FIND_PROGRAM(found_bz2
348 SET(CPACK_GENERATOR "${CPACK_GENERATOR};TBZ2")
350 ENDIF(UNIX AND NOT APPLE)
352 SET(CPACK_PACKAGE_EXECUTABLES "SimpleInstall" "Simple Install")
353 SET(CMAKE_INSTALL_MFC_LIBRARIES 1)
354 SET(CMAKE_INSTALL_DEBUG_LIBRARIES 1)
355 INCLUDE(InstallRequiredSystemLibraries)
358 # Disable packaging test on Apple 10.3 and below. PackageMaker starts
359 # DiskManagementTool as root and disowns it
360 # (http://lists.apple.com/archives/installer-dev/2005/Jul/msg00005.html).
361 # It is left holding open pipe handles and preventing ProcessUNIX from
362 # detecting end-of-data even after its immediate child exits. Then
363 # the test hangs until it times out and is killed. This is a
364 # well-known bug in kwsys process execution that I would love to get
366 SET(PACKAGE_TARGET --build-target package)
367 IF(APPLE AND NOT CTEST_TEST_CPACK)
369 COMMAND sw_vers -productVersion
370 OUTPUT_VARIABLE OSX_VERSION
371 OUTPUT_STRIP_TRAILING_WHITESPACE
373 IF("${OSX_VERSION}" MATCHES "^10\\.[0123]" OR "${OSX_VERSION}" MATCHES "ProductVersion:\t10\\.[0123]")
374 MESSAGE(STATUS "Disabling package test on OSX < 10.4")
375 MESSAGE(STATUS "OSX_VERSION='${OSX_VERSION}'")
377 ENDIF("${OSX_VERSION}" MATCHES "^10\\.[0123]" OR "${OSX_VERSION}" MATCHES "ProductVersion:\t10\\.[0123]")
378 ENDIF(APPLE AND NOT CTEST_TEST_CPACK)
381 TARGET ${install_target}
383 COMMAND ${CMAKE_CTEST_COMMAND}
388 --build-generator ${CMAKE_GENERATOR}
389 --build-project ${PROJECT_NAME}
390 --build-makeprogram ${CMAKE_MAKE_PROGRAM}
392 --build-target install
394 COMMENT "Install Project"