And these are some steps inside CPackfoo.cmake.in -
....
if (APPLE)
....
execute_process(COMMAND textutil -convert html README.md -output "@CMAKE_BINARY_DIR@/README.html")
set(CPACK_PACKAGE_DESCRIPTION_FILE "@CMAKE_BINARY_DIR@/README.html") # Trying to overwrite the variable
set(CPACK_RESOURCE_FILE_README "@CMAKE_BINARY_DIR@/README.html") # Trying to overwrite the variable
....
endif()
....
But when packaging for APPLE, the README.html file is not present either in the packaged tarball or the .pkg file.
I think the variables set in CPackfoo.cmake are not carried over to the original CPack configuration file.
How could I fix this?
Try using absolute paths for any files you reference, a relative path is fairly ambiguous when tools that use those paths could be running in different directories other than the source directory. This may require you to wire through variables like CMAKE_BINARY_DIR as mentioned by @ben.boeckel in another forum discussion thread.
Pretty sure the if(APPLE) expression will always evaluate to false inside the CPackfoo.cmake file. The APPLE variable is defined at configure time, but I don’t think it is defined when cpack is running.
I think the APPLE check works, because this - execute_process(COMMAND textutil -convert html README.md -output "@CMAKE_BINARY_DIR@/README.html") is correctly executed and I am able to see a README.html in ${CMAKE_BINARY_DIR}.
What package generator are you using? Note that the docs for CPACK_RESOURCE_FILE_README mention that not all CPack generators support it.
I suggest that you add some message(...) commands around the commands in CPackfoo.cmake.in to print out values you are expecting to be set. Run cpack with the -V option for more verbose output. This should confirm that things are set and executed how and when you expected.