CPack new tests for component install

This commit is contained in:
Eric NOULARD 2010-12-02 22:56:26 +01:00 committed by Bill Hoffman
parent b5d7f2c57c
commit 88b7f4252c
7 changed files with 214 additions and 0 deletions

View File

@ -486,6 +486,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
#
set(CTEST_RUN_CPackComponents ${CTEST_TEST_CPACK})
set(CTEST_package_X11_TEST ${CTEST_TEST_CPACK})
set(CTEST_RUN_CPackComponentsForAll ${CTEST_TEST_CPACK})
find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis
PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]
@ -534,6 +535,32 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackComponents")
ENDIF(CTEST_RUN_CPackComponents)
IF(CTEST_RUN_CPackComponentsForAll)
set(CPackComponentsForAll_EXTRA_OPTIONS)
set(CPackRun_CPackGen "-DCPackGen=ZIP")
set(CPackRun_CPackCommand "-DCPackCommand=${CMAKE_CPACK_COMMAND}")
ADD_TEST(CPackComponentsForAll-ZIP-NoComponent ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/CPackComponentsForAll"
"${CMake_BINARY_DIR}/Tests/CPackComponentsForAll/buildZIP-NoComponent"
--build-generator ${CMAKE_TEST_GENERATOR}
--build-project CPackComponentsForAll
--build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
--build-options
-DCPACK_BINARY_ZIP:BOOL=ON
${CPackComponentsForAll_EXTRA_OPTIONS}
--graphviz=CPackComponentsForAll.dot
--test-command ${CMAKE_CMAKE_COMMAND}
"-DCPackComponentsForAll_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/CPackComponentsForAll/buildZIP-NoComponent"
"${CPackRun_CPackCommand}"
"${CPackRun_CPackGen}"
-P "${CMake_SOURCE_DIR}/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake")
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackComponentsForAll")
ENDIF(CTEST_RUN_CPackComponentsForAll)
# By default, turn this test off (because it takes a long time...)
#
if(NOT DEFINED CTEST_RUN_CPackTestAllGenerators)

View File

@ -0,0 +1,120 @@
# CPack Example: User-selectable Installation Components
#
# In this example, we have a simple library (mylib) with an example
# application (mylibapp). We create a binary installer (a CPack Generator)
# which supports CPack components.
#
# Depending on the CPack generator and on some CPACK_xxx var values
# the generator may produce a single (NSIS, PackageMaker)
# or several package files (Archive Generators, RPM, DEB)
cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
project(CPackComponentsForAll)
# Create the mylib library
add_library(mylib mylib.cpp)
# Create the mylibapp application
add_executable(mylibapp mylibapp.cpp)
target_link_libraries(mylibapp mylib)
# Duplicate of mylibapp application
# which won't be put in any component (?mistake?)
add_executable(mylibapp2 mylibapp.cpp)
target_link_libraries(mylibapp2 mylib)
# Create installation targets. Note that we put each kind of file
# into a different component via COMPONENT. These components will
# be used to create the installation components.
install(TARGETS mylib
ARCHIVE
DESTINATION lib
COMPONENT libraries)
install(TARGETS mylibapp
RUNTIME
DESTINATION bin
COMPONENT applications)
# This application does not belong to any component
# thus (as of cmake 2.8.2) it will be left "uninstalled"
# by a component-aware installer unless a
# CPACK_MONOLITHIC_INSTALL=1 is set (at cmake time).
install(TARGETS mylibapp2
RUNTIME
DESTINATION bin)
install(FILES mylib.h
DESTINATION include
COMPONENT headers)
# CPack boilerplate for this project
set(CPACK_PACKAGE_NAME "MyLib")
set(CPACK_PACKAGE_CONTACT "None")
set(CPACK_PACKAGE_VENDOR "CMake.org")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
set(CPACK_PACKAGE_VERSION "1.0.2")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "2")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
# Tell CPack all of the components to install. The "ALL"
# refers to the fact that this is the set of components that
# will be included when CPack is instructed to put everything
# into the binary installer (the default behavior).
set(CPACK_COMPONENTS_ALL applications libraries headers Unspecified)
# Set the displayed names for each of the components to install.
# These will be displayed in the list of components inside the installer.
set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
# Provide descriptions for each of the components to install.
# When the user hovers the mouse over the name of a component,
# the description will be shown in the "Description" box in the
# installer. If no descriptions are provided, the "Description"
# box will be removed.
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")
# Put the components into two different groups: "Runtime" and "Development"
set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
set(CPACK_COMPONENT_HEADERS_GROUP "Development")
# Expand the "Development" group by default, since we have so few components.
# Also, provide this group with a description.
set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)
set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
"All of the tools you'll ever need to develop software")
# It doesn't make sense to install the headers without the libraries
# (because you could never use the headers!), so make the headers component
# depend on the libraries component.
set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
# Create two installation types with pre-selected components.
# The "Developer" installation has just the library and headers,
# while the "Full" installation has everything.
set(CPACK_ALL_INSTALL_TYPES Full Developer)
set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")
set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)
set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)
# We may use the CPack specific config file in order
# to tailor CPack behavio on a CPack generator specific way
# (Behavior would be different for RPM or TGZ or DEB ...)
if (USE_CPACK_PROJECT_CONFIG)
# Setup project specific CPack-time CPack Config file.
configure_file(${MyLib_SOURCE_DIR}/MyLibCPackConfig.cmake.in
${MyLib_BINARY_DIR}/MyLibCPackConfig.cmake
@ONLY)
set(CPACK_PROJECT_CONFIG_FILE ${MyLib_BINARY_DIR}/MyLibCPackConfig.cmake)
endif (USE_CPACK_PROJECT_CONFIG)
# Include CPack to introduce the appropriate targets
include(CPack)

View File

@ -0,0 +1,7 @@
if(CPACK_GENERATOR MATCHES "ZIP")
# set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
endif(CPACK_GENERATOR MATCHES "ZIP")
if(CPACK_GENERATOR MATCHES "TGZ")
set(CPACK_MONOLITHIC_INSTALL 1)
endif(CPACK_GENERATOR MATCHES "TGZ")

View File

@ -0,0 +1,46 @@
message(STATUS "=============================================================================")
message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
message(STATUS "")
if(NOT CPackComponentsForAll_BINARY_DIR)
message(FATAL_ERROR "CPackComponentsForAll_BINARY_DIR not set")
endif(NOT CPackComponentsForAll_BINARY_DIR)
if(NOT CPackGen)
message(FATAL_ERROR "CPackGen not set")
endif(NOT CPackGen)
if(NOT CPackCommand)
message(FATAL_ERROR "CPackCommand not set")
endif(NOT CPackCommand)
set(expected_file_mask "")
execute_process(COMMAND ${CPackCommand} -G ${CPackGen}
RESULT_VARIABLE result
OUTPUT_VARIABLE stdout
ERROR_VARIABLE stderr
WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
if(CPackGen MATCHES "ZIP")
set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
set(expected_count 2)
endif(CPackGen MATCHES "ZIP")
if(expected_file_mask)
file(GLOB expected_file "${expected_file_mask}")
message(STATUS "expected_count='${expected_count}'")
message(STATUS "expected_file='${expected_file}'")
message(STATUS "expected_file_mask='${expected_file_mask}'")
if(NOT expected_file)
message(FATAL_ERROR "error: expected_file does not exist: CPackComponentsForAll test fails.")
endif(NOT expected_file)
list(LENGTH expected_file actual_count)
message(STATUS "actual_count='${actual_count}'")
if(NOT actual_count EQUAL expected_count)
message(FATAL_ERROR "error: expected_count does not match actual_count: CPackComponents test fails.")
endif(NOT actual_count EQUAL expected_count)
endif(expected_file_mask)

View File

@ -0,0 +1,7 @@
#include "mylib.h"
#include "stdio.h"
void mylib_function()
{
printf("This is mylib");
}

View File

@ -0,0 +1 @@
void mylib_function();

View File

@ -0,0 +1,6 @@
#include "mylib.h"
int main()
{
mylib_function();
}