CMakeLists.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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")
  9. # Skip generating the rpath pointing at the build tree to make sure
  10. # the executable is installed with the proper rpath in the install
  11. # tree.
  12. SET(CMAKE_SKIP_BUILD_RPATH 1)
  13. # Make sure the executable can run from the install tree.
  14. SET(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
  15. # Skip the dependency that causes a build when installing. This
  16. # avoids infinite loops when the post-build rule below installs.
  17. SET(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY 1)
  18. SET(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
  19. SET(EXTRA_INSTALL_FLAGS)
  20. MESSAGE("Extra install: ${EXTRA_INSTALL_FLAGS}")
  21. IF(STAGE2)
  22. SET(LIBPATHS
  23. ${CMAKE_INSTALL_PREFIX}/MyTest/lib/static
  24. ${CMAKE_INSTALL_PREFIX}/MyTest/lib
  25. )
  26. SET(t1NAMES test1 test1${CMAKE_DEBUG_POSTFIX} test1rel)
  27. SET(t2NAMES test2 test2${CMAKE_DEBUG_POSTFIX})
  28. SET(t4NAMES test4 test4${CMAKE_DEBUG_POSTFIX})
  29. # Make sure the install script ran.
  30. SET(CMAKE_INSTALL_SCRIPT_DID_RUN 0)
  31. INCLUDE(${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake OPTIONAL)
  32. IF(CMAKE_INSTALL_SCRIPT_DID_RUN)
  33. MESSAGE(STATUS "Stage 1 did run install script 2.")
  34. ELSE(CMAKE_INSTALL_SCRIPT_DID_RUN)
  35. MESSAGE(SEND_ERROR "Stage 1 did not run install script 2.")
  36. ENDIF(CMAKE_INSTALL_SCRIPT_DID_RUN)
  37. IF(CYGWIN OR MINGW)
  38. SET(LIBPATHS ${LIBPATHS} "${CMAKE_INSTALL_PREFIX}/MyTest/bin")
  39. ENDIF(CYGWIN OR MINGW)
  40. MESSAGE("Search for library in: ${LIBPATHS}")
  41. SET(TEST1_LIBRARY "TEST1_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
  42. SET(TEST2_LIBRARY "TEST2_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
  43. SET(TEST4_LIBRARY "TEST4_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
  44. FIND_LIBRARY(TEST1_LIBRARY
  45. NAMES ${t1NAMES}
  46. PATHS ${LIBPATHS}
  47. DOC "First library")
  48. FIND_LIBRARY(TEST2_LIBRARY
  49. NAMES ${t2NAMES}
  50. PATHS ${LIBPATHS}
  51. DOC "Second library")
  52. FIND_LIBRARY(TEST4_LIBRARY
  53. NAMES ${t4NAMES}
  54. PATHS ${LIBPATHS}
  55. DOC "Fourth library")
  56. INCLUDE_DIRECTORIES(${CMAKE_INSTALL_PREFIX}/MyTest/include)
  57. ADD_EXECUTABLE (SimpleInstExeS2 inst2.cxx foo.c foo.h)
  58. TARGET_LINK_LIBRARIES(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} ${TEST4_LIBRARY})
  59. SET(install_target SimpleInstExeS2)
  60. IF("${TEST1_LIBRARY}" MATCHES "static")
  61. MESSAGE(STATUS "test1 correctly found in lib/static")
  62. ELSE("${TEST1_LIBRARY}" MATCHES "static")
  63. MESSAGE(SEND_ERROR "test1 not found in lib/static!")
  64. ENDIF("${TEST1_LIBRARY}" MATCHES "static")
  65. # Check for failure of configuration-specific installation.
  66. IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
  67. MESSAGE(FATAL_ERROR "Debug-configuration file installed for Release!")
  68. ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
  69. IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
  70. MESSAGE(FATAL_ERROR "Release-configuration file installed for Debug!")
  71. ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
  72. # Check for failure of directory installation.
  73. IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
  74. MESSAGE(FATAL_ERROR "Directory installation did not install TSD.h")
  75. ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/TSD.h")
  76. IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
  77. MESSAGE(FATAL_ERROR "Directory installation installed CVS directory.")
  78. ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
  79. IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
  80. MESSAGE(FATAL_ERROR "Directory installation installed CVS directory.")
  81. ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
  82. IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
  83. MESSAGE(FATAL_ERROR "Directory installation installed CMakeLists.txt.")
  84. ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/CMakeLists.txt")
  85. # Check that scripts properly installed.
  86. IF(WIN32 AND NOT CYGWIN)
  87. SET(BAT .bat)
  88. ELSE(WIN32 AND NOT CYGWIN)
  89. SET(BAT)
  90. ENDIF(WIN32 AND NOT CYGWIN)
  91. FOREACH(loc share share/old1 share/old2 share/old3 share/alt)
  92. SET(CUR_SCRIPT "${CMAKE_INSTALL_PREFIX}/MyTest/${loc}/sample_script${BAT}")
  93. EXECUTE_PROCESS(
  94. COMMAND ${CUR_SCRIPT}
  95. RESULT_VARIABLE SAMPLE_SCRIPT_RESULT
  96. OUTPUT_VARIABLE SAMPLE_SCRIPT_OUTPUT
  97. )
  98. IF(NOT "${SAMPLE_SCRIPT_RESULT}" MATCHES "^0$")
  99. MESSAGE(FATAL_ERROR
  100. "Sample script [${CUR_SCRIPT}] failed: [${SAMPLE_SCRIPT_RESULT}]")
  101. ENDIF(NOT "${SAMPLE_SCRIPT_RESULT}" MATCHES "^0$")
  102. IF(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
  103. MESSAGE(FATAL_ERROR
  104. "Bad sample script [${CUR_SCRIPT}] output: [${SAMPLE_SCRIPT_OUTPUT}]")
  105. ENDIF(NOT "${SAMPLE_SCRIPT_OUTPUT}" MATCHES "Sample Script Output")
  106. ENDFOREACH(loc)
  107. # Check for failure of empty directory installation.
  108. IF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
  109. MESSAGE(FATAL_ERROR "Empty directory installation did not install.")
  110. ENDIF(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty")
  111. FILE(GLOB EMPTY_FILES "${CMAKE_INSTALL_PREFIX}/MyTest/share/empty/*")
  112. IF(EMPTY_FILES)
  113. MESSAGE(FATAL_ERROR "Empty directory installed [${EMPTY_FILES}].")
  114. ENDIF(EMPTY_FILES)
  115. # Make sure the test executable can run from the install tree.
  116. SET_TARGET_PROPERTIES(SimpleInstExeS2 PROPERTIES
  117. INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
  118. INSTALL_TARGETS(/MyTest/bin SimpleInstExeS2)
  119. # try to import the exported targets again
  120. SET(SimpleInstallS1_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
  121. FIND_PACKAGE(SimpleInstallS1 REQUIRED)
  122. GET_TARGET_PROPERTY(simpleInstallLocation S1_SimpleInstall LOCATION)
  123. IF(NOT simpleInstallLocation)
  124. MESSAGE(FATAL_ERROR "Target S1_SimpleInstall could not be imported, location: ${simpleInstallLocation}")
  125. ENDIF(NOT simpleInstallLocation)
  126. ELSE(STAGE2)
  127. # Wipe out the install directory to do a fresh test.
  128. FILE(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/MyTest)
  129. # this is stage 1, so create libraries and modules and install everything
  130. ADD_LIBRARY(test1 STATIC lib1.cxx)
  131. ADD_LIBRARY(test2 SHARED lib2.cxx)
  132. ADD_LIBRARY(test3 MODULE lib3.cxx)
  133. ADD_LIBRARY(test4 SHARED lib4.cxx)
  134. ADD_EXECUTABLE (SimpleInstall inst.cxx foo.c foo.h)
  135. TARGET_LINK_LIBRARIES(SimpleInstall test1 test2 test4)
  136. SET(install_target SimpleInstall)
  137. # Make sure the test executable can run from the install tree.
  138. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES
  139. INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
  140. # Test per-configuration output name.
  141. SET_TARGET_PROPERTIES(test1 PROPERTIES RELEASE_OUTPUT_NAME test1rel)
  142. SET_TARGET_PROPERTIES(test2 PROPERTIES PUBLIC_HEADER foo.h)
  143. IF(CMAKE_GENERATOR MATCHES "Makefiles")
  144. ADD_SUBDIRECTORY(TestSubDir)
  145. ADD_DEPENDENCIES(SimpleInstall TSD)
  146. ENDIF(CMAKE_GENERATOR MATCHES "Makefiles")
  147. ADD_DEPENDENCIES(SimpleInstall test3)
  148. ADD_DEPENDENCIES(test2 test3)
  149. ADD_DEPENDENCIES(test4 test2)
  150. INSTALL(TARGETS SimpleInstall test1 test2 test3 EXPORT SimpleInstallS1
  151. RUNTIME DESTINATION MyTest/bin COMPONENT Runtime # .exe, .dll
  152. LIBRARY DESTINATION MyTest/lib COMPONENT Runtime # .so, mod.dll
  153. ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
  154. PUBLIC_HEADER DESTINATION MyTest/include COMPONENT Development
  155. )
  156. INSTALL(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
  157. RUNTIME DESTINATION MyTest/bin
  158. LIBRARY DESTINATION MyTest/lib
  159. ARCHIVE DESTINATION MyTest/lib/static
  160. OPTIONAL # for coverage...target should always exist
  161. )
  162. INSTALL(FILES lib1.h DESTINATION MyTest/include/foo)
  163. INSTALL(FILES lib2.h
  164. DESTINATION MyTest/include/foo
  165. COMPONENT Development
  166. PERMISSIONS OWNER_READ OWNER_WRITE
  167. RENAME lib2renamed.h
  168. )
  169. # Test old-style install commands.
  170. INSTALL_FILES(/MyTest/include FILES lib3.h)
  171. INSTALL_FILES(/MyTest/include/old .h lib3)
  172. INSTALL_FILES(/MyTest/include/old "^lib2.h$")
  173. INSTALL_PROGRAMS(/MyTest/share/old1 FILES
  174. scripts/sample_script scripts/sample_script.bat)
  175. INSTALL_PROGRAMS(/MyTest/share/old2
  176. scripts/sample_script scripts/sample_script.bat)
  177. # "export" the targets collected in "SimpleInstallS1"
  178. INSTALL(EXPORT SimpleInstallS1 FILE SimpleInstallS1Config.cmake
  179. DESTINATION MyTest/lib
  180. PREFIX S1_ )
  181. EXPORT(TARGETS SimpleInstall test1 test2 test3
  182. FILE "${CMAKE_CURRENT_BINARY_DIR}/SimpleInstallS1Config.cmake"
  183. PREFIX S2_ )
  184. ADD_SUBDIRECTORY(scripts)
  185. # Test optional installation.
  186. INSTALL(FILES does_not_exist.h DESTINATION MyTest/include/foo OPTIONAL)
  187. # Test configuration-specific installation.
  188. INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
  189. DESTINATION MyTest/include/Release
  190. )
  191. INSTALL(FILES lib1.h RENAME lib1debug.h CONFIGURATIONS Debug
  192. DESTINATION MyTest/include/Debug
  193. )
  194. # Test directory installation.
  195. FILE(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
  196. FILE(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
  197. INSTALL(
  198. DIRECTORY TestSubDir scripts/ DESTINATION MyTest/share
  199. FILE_PERMISSIONS OWNER_READ OWNER_WRITE
  200. DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
  201. GROUP_READ GROUP_EXECUTE
  202. PATTERN "CVS" EXCLUDE
  203. REGEX "\\.txt$" EXCLUDE
  204. PATTERN "scripts/*" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
  205. )
  206. # Alternate directory installation for coverage.
  207. INSTALL(
  208. DIRECTORY scripts/ DESTINATION MyTest/share/alt
  209. COMPONENT Development
  210. USE_SOURCE_PERMISSIONS
  211. PATTERN "CVS" EXCLUDE
  212. REGEX "\\.txt$" EXCLUDE
  213. )
  214. # Test empty directory installation.
  215. INSTALL(DIRECTORY DESTINATION MyTest/share/empty)
  216. # Test user-specified install scripts, with and without COMPONENT.
  217. INSTALL(
  218. SCRIPT InstallScript1.cmake
  219. CODE "SET(INSTALL_CODE_DID_RUN 1)"
  220. SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
  221. )
  222. INSTALL(
  223. SCRIPT InstallScript3.cmake
  224. CODE "SET(INSTALL_CODE_WITH_COMPONENT_DID_RUN 1)"
  225. SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript4.cmake
  226. COMPONENT Development
  227. )
  228. SET_DIRECTORY_PROPERTIES(PROPERTIES
  229. ADDITIONAL_MAKE_CLEAN_FILES
  230. "${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake;${CMAKE_INSTALL_PREFIX}/InstallScript4Out.cmake")
  231. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstExe)
  232. # Disable VERSION test until it is implemented in the XCode generator.
  233. IF(NOT XCODE)
  234. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES VERSION 1.2)
  235. ENDIF(NOT XCODE)
  236. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES PRE_INSTALL_SCRIPT
  237. ${CMAKE_CURRENT_SOURCE_DIR}/PreInstall.cmake)
  238. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES POST_INSTALL_SCRIPT
  239. ${CMAKE_CURRENT_SOURCE_DIR}/PostInstall.cmake)
  240. SET_TARGET_PROPERTIES(test4 PROPERTIES VERSION 1.2 SOVERSION 3
  241. INSTALL_NAME_DIR @executable_path/../lib)
  242. ENDIF(STAGE2)
  243. IF(CMAKE_CONFIGURATION_TYPES)
  244. SET(SI_CONFIG -C ${CMAKE_CFG_INTDIR})
  245. ELSE(CMAKE_CONFIGURATION_TYPES)
  246. SET(SI_CONFIG)
  247. ENDIF(CMAKE_CONFIGURATION_TYPES)
  248. # Dummy test of CPack
  249. SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack")
  250. SET(CPACK_PACKAGE_VENDOR "Kitware")
  251. SET(CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/PackageScript.cmake")
  252. IF(WIN32 AND NOT UNIX)
  253. FIND_PROGRAM(NSIS_MAKENSIS NAMES makensis
  254. PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
  255. DOC "Where is makensis.exe located"
  256. )
  257. IF(NOT NSIS_MAKENSIS)
  258. SET(CPACK_GENERATOR TGZ)
  259. ENDIF(NOT NSIS_MAKENSIS)
  260. ENDIF(WIN32 AND NOT UNIX)
  261. IF(UNIX AND NOT APPLE)
  262. SET(CPACK_GENERATOR "TGZ;STGZ;TZ")
  263. # FIND_PROGRAM(found_compress
  264. # NAMES compress)
  265. # IF(found_compress)
  266. # FIND_PROGRAM(file_command NAMES file)
  267. # IF(NOT file_command)
  268. # set(file_command file)
  269. # ENDIF(NOT file_command)
  270. # EXECUTE_PROCESS(COMMAND ${file_command} ${found_compress}
  271. # OUTPUT_VARIABLE output)
  272. # set(SKIP_TZ FALSE)
  273. # if("${output}" MATCHES "script")
  274. # set(SKIP_TZ TRUE)
  275. # endif("${output}" MATCHES "script")
  276. # if("${output}" MATCHES "dummy.sh")
  277. # set(SKIP_TZ TRUE)
  278. # endif("${output}" MATCHES "dummy.sh")
  279. # if(NOT SKIP_TZ)
  280. # message("compress found and it was not a script")
  281. # message("output from file command: [${output}]")
  282. # SET(CPACK_GENERATOR "${CPACK_GENERATOR};TZ")
  283. # else(NOT SKIP_TZ)
  284. # message("compress found, but it was a script so dont use it")
  285. # message("output from file command: [${output}]")
  286. # endif(NOT SKIP_TZ)
  287. # ENDIF(found_compress)
  288. FIND_PROGRAM(found_bz2
  289. NAMES bzip2)
  290. IF(found_bz2)
  291. SET(CPACK_GENERATOR "${CPACK_GENERATOR};TBZ2")
  292. ENDIF(found_bz2)
  293. ENDIF(UNIX AND NOT APPLE)
  294. SET(CPACK_PACKAGE_EXECUTABLES "SimpleInstall" "Simple Install")
  295. SET(CMAKE_INSTALL_MFC_LIBRARIES 1)
  296. SET(CMAKE_INSTALL_DEBUG_LIBRARIES 1)
  297. INCLUDE(InstallRequiredSystemLibraries)
  298. INCLUDE(CPack)
  299. # Disable packaging test on Apple 10.3 and below. PackageMaker starts
  300. # DiskManagementTool as root and disowns it
  301. # (http://lists.apple.com/archives/installer-dev/2005/Jul/msg00005.html).
  302. # It is left holding open pipe handles and preventing ProcessUNIX from
  303. # detecting end-of-data even after its immediate child exits. Then
  304. # the test hangs until it times out and is killed. This is a
  305. # well-known bug in kwsys process execution that I would love to get
  306. # time to fix.
  307. SET(PACKAGE_TARGET --build-target package)
  308. IF(APPLE AND NOT CTEST_TEST_CPACK)
  309. EXECUTE_PROCESS(
  310. COMMAND sw_vers -productVersion
  311. OUTPUT_VARIABLE OSX_VERSION
  312. OUTPUT_STRIP_TRAILING_WHITESPACE
  313. )
  314. IF("${OSX_VERSION}" MATCHES "^10\\.[0123]")
  315. MESSAGE(STATUS "Disabling package test on OSX ${OSX_VERSION} < 10.4")
  316. SET(PACKAGE_TARGET)
  317. ENDIF("${OSX_VERSION}" MATCHES "^10\\.[0123]")
  318. ENDIF(APPLE AND NOT CTEST_TEST_CPACK)
  319. ADD_CUSTOM_COMMAND(
  320. TARGET ${install_target}
  321. POST_BUILD
  322. COMMAND ${CMAKE_CTEST_COMMAND}
  323. ARGS ${SI_CONFIG}
  324. --build-and-test
  325. ${CMAKE_SOURCE_DIR}
  326. ${CMAKE_BINARY_DIR}
  327. --build-generator ${CMAKE_GENERATOR}
  328. --build-project ${PROJECT_NAME}
  329. --build-makeprogram ${CMAKE_MAKE_PROGRAM}
  330. --build-noclean
  331. --build-target install
  332. ${PACKAGE_TARGET}
  333. COMMENT "Install Project"
  334. )