For CMake's “install” command, what can the CO

2019-01-16 11:24发布

问题:

I don't know what the argument COMPONENT of the install() command means, and I don't understand the CMake documentation for this. What is it in more detail?

What would an example be?

回答1:

You can group installation targets into components, for example, "docs", "libs", "runtime", etc.

add_library(libone libone.c)
add_executable(one main1.c)
install(TARGETS libone one DESTINATION /somedir COMPONENT comp_one)

add_library(libtwo libtwo.c)
add_executable(two main2.c)
install(TARGETS libtwo two DESTINATION /somedir COMPONENT comp_two)

This makes it possible to run cmake -DCOMPONENT=comp_one -P {your_build_dir}/cmake_install.cmake to install only the libone library and the one executable. When you issue make install all components are installed.



回答2:

There are three ways you can use the install command in CMake:

  1. Install an executable

    INSTALL(TARGETS ExecutableTarget RUNTIME DESTINATION FOLDER_LOCATION)
    
  2. Install a static library

    INSTALL(TARGETS StaticLibraryTarget ARCHIVE DESTINATION FOLDER_LOCATION)
    
  3. Install dynamic library

    INSTALL(TARGETS SharedLibraryTarget LIBRARY DESTINATION FOLDER_LOCATION)
    


标签: cmake