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 # Test importing a library found on disk.
70 ADD_LIBRARY(lib_test4 UNKNOWN IMPORTED)
71 SET_PROPERTY(TARGET lib_test4 PROPERTY IMPORTED_LOCATION ${TEST4_LIBRARY})
73 INCLUDE_DIRECTORIES(${CMAKE_INSTALL_PREFIX}/MyTest/include)
74 ADD_EXECUTABLE (SimpleInstExeS2 inst2.cxx foo.c foo.h)
75 TARGET_LINK_LIBRARIES(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} lib_test4)
76 SET(install_target SimpleInstExeS2)
78 IF("${TEST1_LIBRARY}" MATCHES "static")
79 MESSAGE(STATUS "test1 correctly found in lib/static")
80 ELSE("${TEST1_LIBRARY}" MATCHES "static")
81 MESSAGE(SEND_ERROR "test1 not found in lib/static!")
82 ENDIF("${TEST1_LIBRARY}" MATCHES "static")
84 # Check for failure of configuration-specific installation.
85 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
86 MESSAGE(FATAL_ERROR "Debug-configuration file installed for Release!")
87 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
88 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
89 MESSAGE(FATAL_ERROR "Release-configuration file installed for Debug!")
90 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
92 # Check for failure of directory installation.
93 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
94 MESSAGE(FATAL_ERROR "Directory installation did not install TSD.h")
95 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
96 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
97 MESSAGE(FATAL_ERROR "Directory installation installed CVS directory.")
98 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
99 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
100 MESSAGE(FATAL_ERROR "Directory installation installed CVS directory.")
101 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
102 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
103 MESSAGE(FATAL_ERROR "Directory installation installed CMakeLists.txt.")
104 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
105 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.h")
106 MESSAGE(FATAL_ERROR "Directory installation did not install alternate TSD.h")
107 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.h")
108 IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.cxx")
109 MESSAGE(FATAL_ERROR "Directory installation installed alternate TSD.cxx")
110 ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/alt/TestSubDir/TSD.cxx")
112 # Check that scripts properly installed.
113 IF(WIN32 AND NOT CYGWIN)
115 ELSE(WIN32 AND NOT CYGWIN)
117 ENDIF(WIN32 AND NOT CYGWIN)
118 FOREACH(loc share share/old1 share/old2 share/old3 share/alt)
119 SET(CUR_SCRIPT "${CMAKE_INSTALL_PREFIX}/MyTest/${loc}/sample_script${BAT}")
121 COMMAND ${CUR_SCRIPT}
122 RESULT_VARIABLE SAMPLE_SCRIPT_RESULT
123 OUTPUT_VARIABLE SAMPLE_SCRIPT_OUTPUT
125 IF(NOT "${SAMPLE_SCRIPT_RESULT}" MATCHES "^0$")
127 "Sample script [${CUR_SCRIPT}] failed: [${SAMPLE_SCRIPT_RESULT}]")
128 ENDIF(NOT "${SAMPLE_SCRIPT_RESULT}" MATCHES "^0$")
129 IF(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
131 "Bad sample script [${CUR_SCRIPT}] output: [${SAMPLE_SCRIPT_OUTPUT}]")
132 ENDIF(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
135 # Check for failure of empty directory installation.
136 IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
137 MESSAGE(FATAL_ERROR "Empty directory installation did not install.")
138 ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
139 FILE(GLOB EMPTY_FILES "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty/*")
141 MESSAGE(FATAL_ERROR "Empty directory installed [${EMPTY_FILES}].")
144 # Make sure the test executable can run from the install tree.
145 SET_TARGET_PROPERTIES(SimpleInstExeS2 PROPERTIES
146 INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
148 INSTALL_TARGETS(/MyTest/bin SimpleInstExeS2)
150 # try to import the exported targets again
151 SET(SimpleInstallS1_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
152 FIND_PACKAGE(SimpleInstallS1 REQUIRED)
153 GET_TARGET_PROPERTY(simpleInstallImported S1_SimpleInstall IMPORTED)
154 IF(NOT simpleInstallImported)
155 MESSAGE(FATAL_ERROR "Target S1_SimpleInstall could not be imported")
156 ENDIF(NOT simpleInstallImported)
159 # Wipe out the install directory to do a fresh test.
160 FILE(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/MyTest)
162 # this is stage 1, so create libraries and modules and install everything
163 ADD_LIBRARY(test1 STATIC lib1.cxx)
164 ADD_LIBRARY(test2 SHARED lib2.cxx)
165 ADD_LIBRARY(test3 MODULE lib3.cxx)
166 ADD_LIBRARY(test4 SHARED lib4.cxx)
168 ADD_EXECUTABLE (SimpleInstall inst.cxx foo.c foo.h)
169 TARGET_LINK_LIBRARIES(SimpleInstall test1 test2 test4)
170 SET(install_target SimpleInstall)
172 # Make sure the test executable can run from the install tree.
173 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES
174 INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
176 # Test per-configuration output name.
177 SET_TARGET_PROPERTIES(test1 PROPERTIES RELEASE_OUTPUT_NAME test1rel)
178 SET_TARGET_PROPERTIES(test2 PROPERTIES PUBLIC_HEADER foo.h)
180 IF(CMAKE_GENERATOR MATCHES "Makefiles")
181 ADD_SUBDIRECTORY(TestSubDir)
182 ADD_DEPENDENCIES(SimpleInstall TSD)
183 ENDIF(CMAKE_GENERATOR MATCHES "Makefiles")
185 ADD_DEPENDENCIES(SimpleInstall test3)
186 ADD_DEPENDENCIES(test2 test3)
187 ADD_DEPENDENCIES(test4 test2)
189 INSTALL(TARGETS SimpleInstall test1 test2 test3 EXPORT SimpleInstallS1
190 RUNTIME DESTINATION MyTest/bin COMPONENT Runtime # .exe, .dll
191 LIBRARY DESTINATION MyTest/lib COMPONENT Runtime # .so, mod.dll
192 ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
193 PUBLIC_HEADER DESTINATION MyTest/include COMPONENT Development
196 INSTALL(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
197 RUNTIME DESTINATION MyTest/bin
198 LIBRARY DESTINATION MyTest/lib
199 ARCHIVE DESTINATION MyTest/lib/static
200 OPTIONAL # for coverage...target should always exist
202 INSTALL(FILES lib1.h DESTINATION MyTest/include/foo)
204 DESTINATION MyTest/include/foo
205 COMPONENT Development
206 PERMISSIONS OWNER_READ OWNER_WRITE
210 # Test old-style install commands.
211 INSTALL_FILES(/MyTest/include FILES lib3.h)
212 INSTALL_FILES(/MyTest/include/old .h lib3)
213 INSTALL_FILES(/MyTest/include/old "^lib2.h$")
214 INSTALL_PROGRAMS(/MyTest/share/old1 FILES
215 scripts/sample_script scripts/sample_script.bat)
216 INSTALL_PROGRAMS(/MyTest/share/old2
217 scripts/sample_script scripts/sample_script.bat)
219 # "export" the targets collected in "SimpleInstallS1"
220 INSTALL(EXPORT SimpleInstallS1 FILE SimpleInstallS1Config.cmake
221 DESTINATION MyTest/lib
224 EXPORT(TARGETS SimpleInstall test1 test2 test3
225 FILE "${CMAKE_CURRENT_BINARY_DIR}/SimpleInstallS1Config.cmake"
228 ADD_SUBDIRECTORY(scripts)
230 # Test optional installation.
231 INSTALL(FILES does_not_exist.h DESTINATION MyTest/include/foo OPTIONAL)
233 # Test configuration-specific installation.
234 INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
235 DESTINATION MyTest/include/Release
237 INSTALL(FILES lib1.h RENAME lib1debug.h CONFIGURATIONS Debug
238 DESTINATION MyTest/include/Debug
241 # Test directory installation.
242 FILE(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
243 FILE(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
245 DIRECTORY TestSubDir scripts/ DESTINATION MyTest/share
246 FILE_PERMISSIONS OWNER_READ OWNER_WRITE
247 DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
248 GROUP_READ GROUP_EXECUTE
249 PATTERN "CVS" EXCLUDE
250 REGEX "\\.txt$" EXCLUDE
251 PATTERN "scripts/*" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
254 # Alternate directory installation for coverage.
256 DIRECTORY scripts/ DESTINATION MyTest/share/alt
257 COMPONENT Development
258 USE_SOURCE_PERMISSIONS
259 PATTERN "CVS" EXCLUDE
260 REGEX "\\.txt$" EXCLUDE
263 DIRECTORY TestSubDir DESTINATION MyTest/share/alt
264 FILE_PERMISSIONS OWNER_READ OWNER_WRITE
265 DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
266 GROUP_READ GROUP_EXECUTE
267 FILES_MATCHING PATTERN "*.h"
270 # Test empty directory installation.
271 INSTALL(DIRECTORY DESTINATION MyTest/share/empty)
273 # Test optional directory installation.
274 INSTALL(DIRECTORY does-not-exist DESTINATION MyTest/share OPTIONAL)
276 # Test user-specified install scripts, with and without COMPONENT.
278 SCRIPT InstallScript1.cmake
279 CODE "SET(INSTALL_CODE_DID_RUN 1)"
280 SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
283 SCRIPT InstallScript3.cmake
284 CODE "SET(INSTALL_CODE_WITH_COMPONENT_DID_RUN 1)"
285 SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript4.cmake
286 COMPONENT Development
288 SET_DIRECTORY_PROPERTIES(PROPERTIES
289 ADDITIONAL_MAKE_CLEAN_FILES
290 "${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake;${CMAKE_INSTALL_PREFIX}/InstallScript4Out.cmake")
292 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstExe)
293 # Disable VERSION test until it is implemented in the XCode generator.
295 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES VERSION 1.2)
297 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES PRE_INSTALL_SCRIPT
298 ${CMAKE_CURRENT_SOURCE_DIR}/PreInstall.cmake)
299 SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES POST_INSTALL_SCRIPT
300 ${CMAKE_CURRENT_SOURCE_DIR}/PostInstall.cmake)
301 SET_TARGET_PROPERTIES(test4 PROPERTIES VERSION 1.2 SOVERSION 3
302 INSTALL_NAME_DIR @executable_path/../lib)
305 IF(CMAKE_CONFIGURATION_TYPES)
306 SET(SI_CONFIG -C ${CMAKE_CFG_INTDIR})
307 ELSE(CMAKE_CONFIGURATION_TYPES)
309 ENDIF(CMAKE_CONFIGURATION_TYPES)
311 # Dummy test of CPack
312 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack")
313 SET(CPACK_PACKAGE_VENDOR "Kitware")
314 SET(CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/PackageScript.cmake")
316 IF(WIN32 AND NOT UNIX)
317 FIND_PROGRAM(NSIS_MAKENSIS NAMES makensis
318 PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
319 DOC "Where is makensis.exe located"
321 IF(NOT NSIS_MAKENSIS)
322 SET(CPACK_GENERATOR TGZ)
323 ENDIF(NOT NSIS_MAKENSIS)
324 ENDIF(WIN32 AND NOT UNIX)
325 IF(UNIX AND NOT APPLE)
326 SET(CPACK_GENERATOR "TGZ;STGZ;TZ")
327 # FIND_PROGRAM(found_compress
330 # FIND_PROGRAM(file_command NAMES file)
331 # IF(NOT file_command)
332 # set(file_command file)
333 # ENDIF(NOT file_command)
334 # EXECUTE_PROCESS(COMMAND ${file_command} ${found_compress}
335 # OUTPUT_VARIABLE output)
337 # if("${output}" MATCHES "script")
339 # endif("${output}" MATCHES "script")
340 # if("${output}" MATCHES "dummy.sh")
342 # endif("${output}" MATCHES "dummy.sh")
344 # message("compress found and it was not a script")
345 # message("output from file command: [${output}]")
346 # SET(CPACK_GENERATOR "${CPACK_GENERATOR};TZ")
348 # message("compress found, but it was a script so dont use it")
349 # message("output from file command: [${output}]")
351 # ENDIF(found_compress)
352 FIND_PROGRAM(found_bz2
355 SET(CPACK_GENERATOR "${CPACK_GENERATOR};TBZ2")
357 ENDIF(UNIX AND NOT APPLE)
359 SET(CPACK_PACKAGE_EXECUTABLES "SimpleInstall" "Simple Install")
360 SET(CMAKE_INSTALL_MFC_LIBRARIES 1)
361 SET(CMAKE_INSTALL_DEBUG_LIBRARIES 1)
362 INCLUDE(InstallRequiredSystemLibraries)
366 SET(PACKAGE_TARGET --build-target package)
367 ELSE(CTEST_TEST_CPACK)
369 ENDIF(CTEST_TEST_CPACK)
372 TARGET ${install_target}
374 COMMAND ${CMAKE_CTEST_COMMAND}
379 --build-generator ${CMAKE_GENERATOR}
380 --build-project ${PROJECT_NAME}
381 --build-makeprogram ${CMAKE_MAKE_PROGRAM}
383 --build-target install
385 COMMENT "Install Project"