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
For install results of building project, relevant syntax:
INSTALL( TARGETS exenames
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
BUNDLE DESTINATION .
)
For install exist files, relevant syntax:
INSTALL( FILES files DESTINATION directory )
We use an old project to show how to use them.

(1) install executable

CMakeLists.txt
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 )


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page