CMakeLists.txt 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. PROJECT (TestSimpleInstall)
  2. SET(CMAKE_VERBOSE_MAKEFILE 1)
  3. #SET(EXECUTABLE_OUTPUT_PATH "${TestSimpleInstall_BINARY_DIR}/This is exec path")
  4. SET(EXECUTABLE_OUTPUT_PATH "${TestSimpleInstall_BINARY_DIR}/ExecPath")
  5. SET(LIBRARY_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}")
  6. # Skip generating the rpath pointing at the build tree to make sure
  7. # the executable is installed with the proper rpath in the install
  8. # tree.
  9. SET(CMAKE_SKIP_BUILD_RPATH 1)
  10. # Make sure the executable can run from the install tree.
  11. SET(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
  12. # Skip the dependency that causes a build when installing. This
  13. # avoids infinite loops when the post-build rule below installs.
  14. SET(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY 1)
  15. SET(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
  16. SET(EXTRA_INSTALL_FLAGS)
  17. MESSAGE("Extra install: ${EXTRA_INSTALL_FLAGS}")
  18. IF(STAGE2)
  19. SET(LIBPATHS
  20. ${CMAKE_INSTALL_PREFIX}/MyTest/lib/static
  21. ${CMAKE_INSTALL_PREFIX}/MyTest/lib
  22. )
  23. SET(t1NAMES test1 test1${CMAKE_DEBUG_POSTFIX} test1rel)
  24. SET(t2NAMES test2 test2${CMAKE_DEBUG_POSTFIX})
  25. SET(t4NAMES test4 test4${CMAKE_DEBUG_POSTFIX})
  26. # Make sure the install script ran.
  27. SET(CMAKE_INSTALL_SCRIPT_DID_RUN 0)
  28. INCLUDE(${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake OPTIONAL)
  29. IF(CMAKE_INSTALL_SCRIPT_DID_RUN)
  30. MESSAGE(STATUS "Stage 1 did run install script 2.")
  31. ELSE(CMAKE_INSTALL_SCRIPT_DID_RUN)
  32. MESSAGE(SEND_ERROR "Stage 1 did not run install script 2.")
  33. ENDIF(CMAKE_INSTALL_SCRIPT_DID_RUN)
  34. IF(CYGWIN OR MINGW)
  35. SET(LIBPATHS ${LIBPATHS} "${CMAKE_INSTALL_PREFIX}/MyTest/bin")
  36. ENDIF(CYGWIN OR MINGW)
  37. MESSAGE("Search for library in: ${LIBPATHS}")
  38. SET(TEST1_LIBRARY "TEST1_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
  39. SET(TEST2_LIBRARY "TEST2_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
  40. SET(TEST4_LIBRARY "TEST4_LIBRARY-NOTFOUND" CACHE FILEPATH "Force find." FORCE)
  41. FIND_LIBRARY(TEST1_LIBRARY
  42. NAMES ${t1NAMES}
  43. PATHS ${LIBPATHS}
  44. DOC "First library")
  45. FIND_LIBRARY(TEST2_LIBRARY
  46. NAMES ${t2NAMES}
  47. PATHS ${LIBPATHS}
  48. DOC "Second library")
  49. FIND_LIBRARY(TEST4_LIBRARY
  50. NAMES ${t4NAMES}
  51. PATHS ${LIBPATHS}
  52. DOC "Fourth library")
  53. INCLUDE_DIRECTORIES(${CMAKE_INSTALL_PREFIX}/MyTest/include)
  54. ADD_EXECUTABLE (SimpleInstallS2 inst2.cxx foo.c foo.h)
  55. TARGET_LINK_LIBRARIES(SimpleInstallS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} ${TEST4_LIBRARY})
  56. SET(install_target SimpleInstallS2)
  57. IF("${TEST1_LIBRARY}" MATCHES "static")
  58. MESSAGE(STATUS "test1 correctly found in lib/static")
  59. ELSE("${TEST1_LIBRARY}" MATCHES "static")
  60. MESSAGE(SEND_ERROR "test1 not found in lib/static!")
  61. ENDIF("${TEST1_LIBRARY}" MATCHES "static")
  62. # Check for failure of configuration-specific installation.
  63. IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
  64. MESSAGE(FATAL_ERROR "Debug-configuration file installed for Release!")
  65. ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Release/lib1debug.h")
  66. IF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
  67. MESSAGE(FATAL_ERROR "Release-configuration file installed for Debug!")
  68. ENDIF(EXISTS "${CMAKE_INSTALL_PREFIX}/MyTest/include/Debug/lib1release.h")
  69. # Make sure the test executable can run from the install tree.
  70. SET_TARGET_PROPERTIES(SimpleInstallS2 PROPERTIES
  71. INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
  72. INSTALL_TARGETS(/MyTest/bin SimpleInstallS2)
  73. ELSE(STAGE2)
  74. # this is stage 1, so create libraries and modules and install everything
  75. ADD_LIBRARY(test1 STATIC lib1.cxx)
  76. ADD_LIBRARY(test2 SHARED lib2.cxx)
  77. ADD_LIBRARY(test3 MODULE lib3.cxx)
  78. ADD_LIBRARY(test4 SHARED lib4.cxx)
  79. ADD_EXECUTABLE (SimpleInstall inst.cxx foo.c foo.h)
  80. TARGET_LINK_LIBRARIES(SimpleInstall test1 test2 test4)
  81. SET(install_target SimpleInstall)
  82. # Make sure the test executable can run from the install tree.
  83. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES
  84. INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
  85. # Test per-configuration output name.
  86. SET_TARGET_PROPERTIES(test1 PROPERTIES RELEASE_OUTPUT_NAME test1rel)
  87. IF(CMAKE_GENERATOR MATCHES "Makefiles")
  88. ADD_SUBDIRECTORY(TestSubDir)
  89. ADD_DEPENDENCIES(SimpleInstall TSD)
  90. ENDIF(CMAKE_GENERATOR MATCHES "Makefiles")
  91. ADD_DEPENDENCIES(SimpleInstall test3)
  92. ADD_DEPENDENCIES(test2 test3)
  93. ADD_DEPENDENCIES(test4 test2)
  94. INSTALL(TARGETS SimpleInstall test1 test2 test3
  95. RUNTIME DESTINATION MyTest/bin COMPONENT Runtime # .exe, .dll
  96. LIBRARY DESTINATION MyTest/lib COMPONENT Runtime # .so, mod.dll
  97. ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
  98. )
  99. INSTALL(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
  100. RUNTIME DESTINATION MyTest/bin
  101. LIBRARY DESTINATION MyTest/lib
  102. ARCHIVE DESTINATION MyTest/lib/static
  103. )
  104. INSTALL(FILES lib1.h DESTINATION MyTest/include/foo)
  105. INSTALL(FILES lib2.h
  106. DESTINATION MyTest/include/foo
  107. PERMISSIONS OWNER_READ OWNER_WRITE
  108. RENAME lib2renamed.h
  109. )
  110. INSTALL_FILES(/MyTest/include FILES lib3.h)
  111. # Test configuration-specific installation.
  112. INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
  113. DESTINATION MyTest/include/Release
  114. )
  115. INSTALL(FILES lib1.h RENAME lib1debug.h CONFIGURATIONS Debug
  116. DESTINATION MyTest/include/Debug
  117. )
  118. # Test user-specified install scripts.
  119. INSTALL(
  120. SCRIPT InstallScript1.cmake
  121. CODE "SET(INSTALL_CODE_DID_RUN 1)"
  122. SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
  123. )
  124. SET_DIRECTORY_PROPERTIES(PROPERTIES
  125. ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake)
  126. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstallExe)
  127. # Disable VERSION test until it is implemented in the XCode generator.
  128. #SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES VERSION 1.2)
  129. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES PRE_INSTALL_SCRIPT
  130. ${CMAKE_CURRENT_SOURCE_DIR}/PreInstall.cmake)
  131. SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES POST_INSTALL_SCRIPT
  132. ${CMAKE_CURRENT_SOURCE_DIR}/PostInstall.cmake)
  133. SET_TARGET_PROPERTIES(test4 PROPERTIES VERSION 1.2 SOVERSION 3)
  134. ENDIF(STAGE2)
  135. IF(CMAKE_CONFIGURATION_TYPES)
  136. SET(SI_CONFIG -C ${CMAKE_CFG_INTDIR})
  137. ELSE(CMAKE_CONFIGURATION_TYPES)
  138. SET(SI_CONFIG)
  139. ENDIF(CMAKE_CONFIGURATION_TYPES)
  140. # Dummy test of CPack
  141. SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack")
  142. SET(CPACK_PACKAGE_VENDOR "Kitware")
  143. IF(WIN32 AND NOT UNIX)
  144. FIND_PROGRAM(NSIS_MAKENSIS NAMES makensis
  145. PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
  146. DOC "Where is makensis.exe located"
  147. )
  148. IF(NOT NSIS_MAKENSIS)
  149. SET(CPACK_GENERATOR TGZ)
  150. ENDIF(NOT NSIS_MAKENSIS)
  151. ENDIF(WIN32 AND NOT UNIX)
  152. IF(UNIX AND NOT APPLE)
  153. SET(CPACK_GENERATOR "TGZ;STGZ")
  154. FIND_PROGRAM(found_compress
  155. NAMES compress)
  156. IF(found_compress)
  157. FIND_PROGRAM(file_command NAMES file)
  158. IF(NOT file_command)
  159. set(file_command file)
  160. ENDIF(NOT file_command)
  161. EXECUTE_PROCESS(COMMAND ${file_command} ${found_compress}
  162. OUTPUT_VARIABLE output)
  163. if(NOT "${output}" MATCHES "script")
  164. message("compress found and it was not a script")
  165. message("output from file command: [${output}]")
  166. SET(CPACK_GENERATOR "${CPACK_GENERATOR};TZ")
  167. else(NOT "${output}" MATCHES "script")
  168. message("compress found, but it was a script so dont use it")
  169. message("output from file command: [${output}]")
  170. endif(NOT "${output}" MATCHES "script")
  171. ENDIF(found_compress)
  172. FIND_PROGRAM(found_bz2
  173. NAMES bzip2)
  174. IF(found_bz2)
  175. SET(CPACK_GENERATOR "${CPACK_GENERATOR};TBZ2")
  176. ENDIF(found_bz2)
  177. ENDIF(UNIX AND NOT APPLE)
  178. SET(CPACK_PACKAGE_EXECUTABLES "SimpleInstall" "Simple Install")
  179. SET(CMAKE_INSTALL_MFC_LIBRARIES 1)
  180. INCLUDE(InstallRequiredSystemLibraries)
  181. INCLUDE(CPack)
  182. IF(APPLE AND NOT CTEST_TEST_CPACK)
  183. # Issue with packaging on the mac, so disable it for now
  184. ADD_CUSTOM_COMMAND(
  185. TARGET ${install_target}
  186. POST_BUILD
  187. COMMAND ${CMAKE_CTEST_COMMAND}
  188. ARGS ${SI_CONFIG}
  189. --build-and-test
  190. ${CMAKE_SOURCE_DIR}
  191. ${CMAKE_BINARY_DIR}
  192. --build-generator ${CMAKE_GENERATOR}
  193. --build-project ${PROJECT_NAME}
  194. --build-makeprogram ${CMAKE_MAKE_PROGRAM}
  195. --build-noclean
  196. --build-target install
  197. COMMENT "Install Project"
  198. )
  199. ELSE(APPLE AND NOT CTEST_TEST_CPACK)
  200. ADD_CUSTOM_COMMAND(
  201. TARGET ${install_target}
  202. POST_BUILD
  203. COMMAND ${CMAKE_CTEST_COMMAND}
  204. ARGS ${SI_CONFIG}
  205. --build-and-test
  206. ${CMAKE_SOURCE_DIR}
  207. ${CMAKE_BINARY_DIR}
  208. --build-generator ${CMAKE_GENERATOR}
  209. --build-project ${PROJECT_NAME}
  210. --build-makeprogram ${CMAKE_MAKE_PROGRAM}
  211. --build-noclean
  212. --build-target install
  213. --build-target package
  214. COMMENT "Install Project"
  215. )
  216. ENDIF(APPLE AND NOT CTEST_TEST_CPACK)