CMakeLists.txt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. cmake_minimum_required(VERSION 3.9)
  2. project(Qt4Deploy)
  3. set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/install)
  4. find_package(Qt4 REQUIRED QtMain QtCore QtSql)
  5. include(${QT_USE_FILE})
  6. add_executable(testdeploy MACOSX_BUNDLE testdeploy.cpp)
  7. target_link_libraries(testdeploy ${QT_LIBRARIES})
  8. set_target_properties(testdeploy PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}")
  9. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  10. if(_isMultiConfig AND QT_QTCORE_LIBRARY_RELEASE AND QT_QTCORE_LIBRARY_DEBUG)
  11. # note: installing debug Qt libraries from a Qt installation configured with
  12. # -debug-and-release not yet supported (very low priority).
  13. install(CODE "
  14. if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Dd][Ee][Bb][Uu][Gg])$\")
  15. return()
  16. endif()
  17. ")
  18. endif()
  19. # install the Qt4 app with qsqlite plugin
  20. install(CODE "file(REMOVE_RECURSE \"${CMAKE_INSTALL_PREFIX}\")")
  21. install(TARGETS testdeploy DESTINATION .)
  22. include(../../Modules/DeployQt4.cmake)
  23. if(APPLE)
  24. install_qt4_executable(testdeploy.app "qsqlite")
  25. elseif(WIN32)
  26. install_qt4_executable(testdeploy.exe "qsqlite")
  27. else()
  28. install_qt4_executable(testdeploy "qsqlite")
  29. endif()
  30. # test depends on standard qsqlite plugin
  31. if(QT_QSQLITE_PLUGIN_DEBUG OR QT_QSQLITE_PLUGIN_RELEASE)
  32. # test the deployed Qt application
  33. if(APPLE)
  34. install(CODE "
  35. message(STATUS \"executing: ${CMAKE_INSTALL_PREFIX}/testdeploy.app/Contents/MacOS/testdeploy\")
  36. execute_process(COMMAND \"${CMAKE_INSTALL_PREFIX}/testdeploy.app/Contents/MacOS/testdeploy\"
  37. RESULT_VARIABLE result)
  38. if(NOT result STREQUAL \"0\")
  39. message(FATAL_ERROR \"error running testdeploy app\")
  40. endif()
  41. ")
  42. else()
  43. install(CODE "
  44. message(STATUS \"executing: ${CMAKE_INSTALL_PREFIX}/testdeploy\")
  45. execute_process(COMMAND \"${CMAKE_INSTALL_PREFIX}/testdeploy\"
  46. RESULT_VARIABLE result)
  47. if(NOT result STREQUAL \"0\")
  48. message(FATAL_ERROR \"error running testdeploy app\")
  49. endif()
  50. ")
  51. endif()
  52. # custom target to install and test the installation at build time
  53. if(_isMultiConfig)
  54. set(install_config "-DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_CFG_INTDIR}")
  55. endif()
  56. add_custom_target(testdeploy_test ALL
  57. COMMAND ${CMAKE_COMMAND} ${install_config} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
  58. COMMENT "${CMAKE_COMMAND} ${install_config} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake"
  59. DEPENDS testdeploy)
  60. endif()