For Unix system, we always use the command make install to put executables or existing files in the right directory. Cmake uses different variables to identify targets which will be installed.
Target | Variable |
---|---|
executables | RUNTIME |
dynamic link libraries | LIBRARY |
static link libraries | ARCHIVE |
macosx_bundle | BUNDLE |
INSTALL( TARGETS exenames
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
BUNDLE DESTINATION .
)
INSTALL( FILES files DESTINATION directory )
(1) install executable
set( CMAKE_INSTALL_PREFIX "/usr/local" ) ... add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${UI_HEADERS} ${QRC_Srcs} ) ... install( TARGETS CMakeTest RUNTIME DESTINATION bin ) # /usr/local/bin BUNDLE
(2) install application
set( CMAKE_INSTALL_PREFIX "/Applications" ) ... add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${HEADERS} ${SOURCES} ${UI_HEADERS} ${QRC_Srcs} ) ... install( TARGETS CMakeTest BUNDLE DESTINATION . ) # /usr/local/bin
(3) install files
set( CMAKE_INSTALL_PREFIX "/usr/local" ) ... set( importFiles Untitled.png mainwindow.ui ) install( FILES ${importFiles} DESTINATION share )