diff options
Diffstat (limited to 'Tests/CPackComponents')
-rw-r--r-- | Tests/CPackComponents/CMakeLists.txt | 128 | ||||
-rw-r--r-- | Tests/CPackComponents/Issue 7470.html | 9 | ||||
-rw-r--r-- | Tests/CPackComponents/VerifyResult.cmake | 48 | ||||
-rw-r--r-- | Tests/CPackComponents/mylib.cpp | 7 | ||||
-rw-r--r-- | Tests/CPackComponents/mylib.h | 1 | ||||
-rw-r--r-- | Tests/CPackComponents/mylibapp.cpp | 6 |
6 files changed, 199 insertions, 0 deletions
diff --git a/Tests/CPackComponents/CMakeLists.txt b/Tests/CPackComponents/CMakeLists.txt new file mode 100644 index 000000000..58f5bdffe --- /dev/null +++ b/Tests/CPackComponents/CMakeLists.txt @@ -0,0 +1,128 @@ +# 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 that allows +# users to select which pieces will be installed: the example +# application, the library binaries, and/or the header file. +cmake_minimum_required(VERSION 2.6) +project(CPackComponents) + +# Create the mylib library +add_library(mylib mylib.cpp) + +# Create the mylibapp application +add_executable(mylibapp mylibapp.cpp) +target_link_libraries(mylibapp mylib) + +# On Linux, enable using an absolute install path to verify that +# CMAKE_INSTALL_PREFIX and CPACK_SET_DESTDIR interact properly. +# +# But only use absolute paths if not targeting an NSIS installer +# as indicated by CPACK_BINARY_NSIS. (If we allow this, the test +# fails on Linux machines with makensis installed when we are not +# cross-compiling...) +# +if(UNIX AND NOT APPLE) + if(NOT CPACK_BINARY_NSIS) + set(mylib_install_to_absolute_path ON) + endif() +endif() + +if(mylib_install_to_absolute_path) + set(CMAKE_INSTALL_PREFIX "/opt/mylib") + set(CPACK_SET_DESTDIR ON) +endif() + +# 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) +install(FILES mylib.h + DESTINATION include + COMPONENT headers) +install(FILES "Issue 7470.html" + DESTINATION docs + COMPONENT documentation) + +if(mylib_install_to_absolute_path) + install(FILES mylib.cpp + DESTINATION /opt/mylib-source + COMPONENT source) +endif() + +# CPack boilerplate for this project +set(CPACK_PACKAGE_NAME "MyLib") +set(CPACK_PACKAGE_VENDOR "CMake.org") +set(CPACK_PACKAGE_CONTACT "somebody@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") + +# Settings used when building NSIS installers +set(CPACK_NSIS_MENU_LINKS + "ftp://ftpserver" "Test Ftp Link" + "ftps://ftpsserver" "Test Ftps Link" + "http://www.cmake.org" "CMake Web Site" + "https://github.com/" "Test Https Link" + "mailto:kitware@kitware.com" "Test MailTo Link" + "news://newsserver" "Test News Link" + ) + +# Suggested default root for end users of the installer: +set(CPACK_NSIS_INSTALL_ROOT "C:\\Program Files\\CMake Tests Install Root") + +# Include CPack to introduce the appropriate targets +include(CPack) + +# Installation types +cpack_add_install_type(Full + DISPLAY_NAME "Everything") +cpack_add_install_type(Developer) + +# Component groups +cpack_add_component_group(Runtime) +cpack_add_component_group(Development + EXPANDED + DESCRIPTION "All of the tools you'll ever need to develop software") + +# Components +cpack_add_component(applications + DISPLAY_NAME "MyLib Application" + DESCRIPTION "An extremely useful application that makes use of MyLib" + GROUP Runtime + INSTALL_TYPES Full) +cpack_add_component(documentation + DISPLAY_NAME "MyLib Documentation" + DESCRIPTION "The extensive suite of MyLib Application documentation files" + GROUP Runtime + INSTALL_TYPES Full) +cpack_add_component(libraries + DISPLAY_NAME "Libraries" + DESCRIPTION "Static libraries used to build programs with MyLib" + GROUP Development + INSTALL_TYPES Developer Full) +cpack_add_component(headers + DISPLAY_NAME "C++ Headers" + DESCRIPTION "C/C++ header files for use with MyLib" + GROUP Development + DEPENDS libraries + INSTALL_TYPES Developer Full) + +if(mylib_install_to_absolute_path) + cpack_add_component(source + DISPLAY_NAME "C++ Source Files" + DESCRIPTION "C/C++ source files to build MyLib" + GROUP Development + DEPENDS libraries + INSTALL_TYPES Developer Full) +endif() diff --git a/Tests/CPackComponents/Issue 7470.html b/Tests/CPackComponents/Issue 7470.html new file mode 100644 index 000000000..12df2c87d --- /dev/null +++ b/Tests/CPackComponents/Issue 7470.html @@ -0,0 +1,9 @@ +<html> +<body> +The install rule for this file demonstrates the problem described in<br/> +CMake issue #7470:<br/> +<br/> +<a href="http://public.kitware.com/Bug/view.php?id=7470"> +http://public.kitware.com/Bug/view.php?id=7470</a><br/> +</body> +</html> diff --git a/Tests/CPackComponents/VerifyResult.cmake b/Tests/CPackComponents/VerifyResult.cmake new file mode 100644 index 000000000..850ec0022 --- /dev/null +++ b/Tests/CPackComponents/VerifyResult.cmake @@ -0,0 +1,48 @@ +message(STATUS "=============================================================================") +message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") +message(STATUS "") + +if(NOT CPackComponents_BINARY_DIR) + message(FATAL_ERROR "CPackComponents_BINARY_DIR not set") +endif(NOT CPackComponents_BINARY_DIR) + +set(expected_file_mask "") + +if(WIN32) + # Only expect the *.exe installer if it looks like NSIS is + # installed on this machine: + # + find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis + PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS] + DOC "makensis.exe location" + ) + if(NSIS_MAKENSIS_EXECUTABLE) + set(expected_file_mask "${CPackComponents_BINARY_DIR}/MyLib-*.exe") + endif(NSIS_MAKENSIS_EXECUTABLE) +endif(WIN32) + +if(APPLE) + # Always expect the *.dmg installer - PackageMaker should always + # be installed on a development Mac: + # + set(expected_file_mask "${CPackComponents_BINARY_DIR}/MyLib-*.dmg") +endif(APPLE) + +if(expected_file_mask) + set(expected_count 1) + 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: CPackComponents 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) diff --git a/Tests/CPackComponents/mylib.cpp b/Tests/CPackComponents/mylib.cpp new file mode 100644 index 000000000..8ddac198c --- /dev/null +++ b/Tests/CPackComponents/mylib.cpp @@ -0,0 +1,7 @@ +#include "mylib.h" +#include "stdio.h" + +void mylib_function() +{ + printf("This is mylib"); +} diff --git a/Tests/CPackComponents/mylib.h b/Tests/CPackComponents/mylib.h new file mode 100644 index 000000000..5d0a822db --- /dev/null +++ b/Tests/CPackComponents/mylib.h @@ -0,0 +1 @@ +void mylib_function(); diff --git a/Tests/CPackComponents/mylibapp.cpp b/Tests/CPackComponents/mylibapp.cpp new file mode 100644 index 000000000..a438ac77f --- /dev/null +++ b/Tests/CPackComponents/mylibapp.cpp @@ -0,0 +1,6 @@ +#include "mylib.h" + +int main() +{ + mylib_function(); +} |