Skip to content

Commit

Permalink
Pack extras in binary distribution
Browse files Browse the repository at this point in the history
Finally brought this back, without needing to actually install the extras. See CMakeLists.txt for the wonderful blog post by @jtanx that informed this workaround.
  • Loading branch information
ItEndsWithTens committed Jul 16, 2020
1 parent 45f6065 commit 2abae5e
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ if(NOT WIN32)
endif()

install(
FILES
README.txt
FILES README.txt
DESTINATION .
RENAME ${TURNSTILE_OUTPUT_NAME}.txt
)
Expand All @@ -337,4 +336,31 @@ set(CPACK_PACKAGE_VERSION_PATCH ${TURNSTILE_PATCH})

set(CPACK_PACKAGE_FILE_NAME TurnsTile-${TURNSTILE_VERSION}-${CMAKE_SYSTEM_NAME}-${TURNSTILE_ARCH}-${CMAKE_CXX_COMPILER_ID})

# These need to be defined before including CPack, otherwise they take on values
# intended for packaging source files. The vagaries of CPack, it would seem.
set(TURNSTILE_BINARY_PACKAGE_NAME ${CPACK_PACKAGE_FILE_NAME})
set(TURNSTILE_BINARY_PACKAGE_GENERATOR ${CPACK_GENERATOR})

include(CPack)

# Needs to be defined after including CPack, to get the right value of CPACK_SYSTEM_NAME.
set(TURNSTILE_CPACK_TEMP_DIR "${CMAKE_BINARY_DIR}/_CPack_Packages/${CPACK_SYSTEM_NAME}/${TURNSTILE_BINARY_PACKAGE_GENERATOR}/${TURNSTILE_BINARY_PACKAGE_NAME}")

# The content of the extras directory is potentially helpful and instructive for
# users, but doesn't really belong in the install location. Unfortunately, CPack
# will only package things specified by an 'install' command. Luckily the CODE
# signature of 'install' allows arbitrary CMake script like this, allowing the
# 'extras' files to stay out of the install destination while remaining in the
# binary distribution. Users then don't have to download anything else.
#
# This is a variation on Jeremy Tan's source package customization technique:
#
# https://jtanx.github.io/2019/08/22/cmake-dist-customisation/
#
install(
CODE "
file(
INSTALL ${CMAKE_SOURCE_DIR}/extras
DESTINATION ${TURNSTILE_CPACK_TEMP_DIR})
"
)

0 comments on commit 2abae5e

Please sign in to comment.