From cab7c288ad77cdada1415d5d484eaf8cb6fe6ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Baran?= Date: Mon, 29 Jan 2024 19:38:45 +0100 Subject: [PATCH] Add CPack to CMakeLists.txt for binary and source package generation (#4645) Add CPack to CMakeLists.txt. All default package exports are enabled for tiledb project so the superbuild's `package` command generates outputs based on the current platform (TGZ for Linux). Usage: - *Superbuild* - `make package` invokes `cpack` inside of the EP tiledb. - *Build* - `cpack` for default behaviour or `cpack -G ` for specific output - `make package` - `make package_source` Example output from Superbuild's `make package`: ``` TGZ CPack: Create package using TGZ CPack: Install projects CPack: - Run preinstall target for: TileDB CPack: - Install project: TileDB [] CPack: Create package CPack: - package: /mnt/c/Users/dbara/CLionProjects/TileDB/build_superbuild/tiledb/tiledb-linux-x86_64-2.20.0.tar.gz generated. CPack: - checksum file: /mnt/c/Users/dbara/CLionProjects/TileDB/build_superbuild/tiledb/tiledb-linux-x86_64-2.20.0.tar.gz.sha1 generated. ``` --- TYPE: FEATURE DESC: Add CPack to CMakeLists.txt --- cmake/TileDB-Superbuild.cmake | 7 +++++++ cmake/inputs/CustomCPackOptions.cmake.in | 18 ++++++++++++++++++ tiledb/CMakeLists.txt | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 cmake/inputs/CustomCPackOptions.cmake.in diff --git a/cmake/TileDB-Superbuild.cmake b/cmake/TileDB-Superbuild.cmake index 62e07f9b790..1a09e997439 100644 --- a/cmake/TileDB-Superbuild.cmake +++ b/cmake/TileDB-Superbuild.cmake @@ -191,3 +191,10 @@ if (TILEDB_TESTS) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tiledb ) endif() + +# make package (.tar.gz for Linux and MacOS, .zip for Windows) +add_custom_target(package + DEPENDS tiledb + COMMAND ${CMAKE_CPACK_COMMAND} --config CPackConfig.cmake -G "$,ZIP,TGZ>" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tiledb +) \ No newline at end of file diff --git a/cmake/inputs/CustomCPackOptions.cmake.in b/cmake/inputs/CustomCPackOptions.cmake.in new file mode 100644 index 00000000000..60f20100346 --- /dev/null +++ b/cmake/inputs/CustomCPackOptions.cmake.in @@ -0,0 +1,18 @@ +set(CPACK_SOURCE_IGNORE_FILES ".*\\.git;.*build.*") + +set(CPACK_PACKAGE_VENDOR "TileDB Inc.") +set(CPACK_PACKAGE_VERSION "@TILEDB_VERSION@") + +set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) + +# Append NOAVX2 if needed +if(NOT ${COMPILER_SUPPORTS_AVX2}) + set(NOAVX2 "-noavx2") +endif() + +# Set output name +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}${NOAVX2}-${CPACK_PACKAGE_VERSION}") +string(TOLOWER ${CPACK_PACKAGE_FILE_NAME} CPACK_PACKAGE_FILE_NAME ) + +# Enable HASH +set(CPACK_PACKAGE_CHECKSUM "SHA256") \ No newline at end of file diff --git a/tiledb/CMakeLists.txt b/tiledb/CMakeLists.txt index f4a11f7c052..06cf1186af6 100644 --- a/tiledb/CMakeLists.txt +++ b/tiledb/CMakeLists.txt @@ -1053,3 +1053,21 @@ configure_file( ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tiledb.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + +# Packaging configuration +configure_file ("${PROJECT_SOURCE_DIR}/cmake/inputs/CustomCPackOptions.cmake.in" + "${PROJECT_BINARY_DIR}/CustomCPackOptions.cmake" + @ONLY) +set (CPACK_PROJECT_CONFIG_FILE + "${PROJECT_BINARY_DIR}/CustomCPackOptions.cmake") + +# Not all options can be set in CustomCPackOptions.cmake +if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + set(CPACK_SOURCE_GENERATOR "ZIP") + set(CPACK_GENERATOR "ZIP") +else() + set(CPACK_SOURCE_GENERATOR "TGZ") + set(CPACK_GENERATOR "TGZ") +endif() + +include(CPack)