CPack script not recognizing CMAKE_BINARY_DIR

For my CPack configuration, I have a step where I do -
set(CPACK_INSTALL_SCRIPTS ${CMAKE_SOURCE_DIR}/cmake/CPackfoo.cmake)

Inside CPackfoo.cmake , I am using a command - execute_process(COMMAND textutil -convert html README.md -output "${CMAKE_BINARY_DIR}/README.html")
But it seems like ${CMAKE_BINARY_DIR} is not recognized here and textutil tries to write README.html to / . Is there an obvious way to fix this that I am missing?

I think that sounds right. Not all CMake variables are transported over to CPack time. Apparently CMAKE_BINARY_DIR is one of them. You could configure_file(@ONLY) the script and use @CMAKE_BINARY_DIR@ to have it be replaced at a time when it is known.