问题
For the example CMakeLists.txt attached to CMake wiki. I also added below what is the actual make command to create just the component based TGZ. I am confused and not seeing any help in the documents.
CMakeLists.txt
cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
project(MyLib)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix prepended on to install directories." FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CPACK_PACKAGE_NAME "MyLib")
set(CPACK_PACKAGE_VENDOR "CMake.org")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
add_library(mylib mylib.cpp)
add_executable(mylibapp mylibapp.cpp)
target_link_libraries(mylibapp mylib)
install(TARGETS mylib
ARCHIVE
DESTINATION lib
COMPONENT libraries)
install(TARGETS mylibapp
RUNTIME
DESTINATION bin
COMPONENT applications)
install(FILES mylib.h
DESTINATION include
COMPONENT headers)
set(CPACK_COMPONENTS_ALL applications libraries headers)
set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
"An extremely useful application that makes use of MyLib")
set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
"Static libraries used to build programs with MyLib")
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
"C/C++ header files for use with MyLib")
set(CPACK_GENERATOR "TGZ")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_SET_DESTDIR ON)
set(CPACK_PACKAGE_CONTACT "jhf")
# This must always be last!
include(CPack)
I have a similar CMakeLists.txt and when I do make package
, I end up getting all my binaries and libraries in the TGZ. What should the make package command be if I need just a TGZ with application component from the above CMakeLists.txt?
回答1:
It is simple. Just set the CMAKE variable CPACK_COMPONENTS_ALL to the list of components you want to appear in the installation:
SET(CPACK_COMPONENTS_ALL applications) #only pack "applications" component
回答2:
Take a look at CPackComponent.
I have exactly the same question with you.
I'm a beginner to cmake, and today I've try a whole day on this, just now I noticed a cmake module named CPackComponent which begins appeared in cmake 2.8.5 standard modules.
For now, I haven't made sure whether it is the reason yet. But the variables in the documents listed by you can be found in this module.
cmake 2.8.5 is the earliest version contained CPackComponent in its standard modules.
Have a check at http://www.cmake.org/cmake/help/v2.8.5/cmake.html#module:CPackComponent
And cmake 2.8.8 is the earliest version listed the variables you want. e.g. CPACK_COMPONENTS_ALL
Over here http://www.cmake.org/cmake/help/v2.8.8/cmake.html#module:CPackComponent
I'm sorry I'm a newbie too, could not help you any more.
来源:https://stackoverflow.com/questions/16663955/cpack-component-level-install