I'm trying to create a package using CPack but struggling to find examples or documentation that helps me for my use case where I didn't build the code using a cmake project. I have a GO project that has produced a binary that I want installed on a system via either RPM on Linux or MSI on Windows.
My folder structure is like so:
HelloWorld
|
+---bin
| |
| +---l_run_me
| +---w_run_me.exe
|
+---src
| |
| +---hello_world.go
|
+---helper
| |
| +---pre_in.sh
| +---pre_un.sh
| +---post_in.sh
| +---post_un.sh
| +---wix_patch.xml
|
+---Copyright.txt
+---CPackConfig.cmake
The files chosen for the installer would depend on the OS I was building for. It all seemed quite trivial for Windows using the WiX generator. I was able to build an installer with the code listed below:
SET(CPACK_PACKAGE_NAME "HelloWorld")
SET(CPACK_PACKAGE_VENDOR "ABC Software")
SET(CPACK_PACKAGE_DESCRIPTION "A long package description should go here")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A summary description goes here")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/Copyright.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_HOST_SYSTEM_NAME})
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "HelloWorld")
SET(CPACK_INSTALLED_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/bin" "/")
if(WIN32)
SET(CPACK_GENERATOR WIX)
SET(CPACK_WIX_UPGRADE_GUID "b7cf4d8b-7479-481d-8d4a-b3db19545b43")
SET(CPACK_WIX_PRODUCT_GUID "b0e09ef0-80bc-4b20-b7e0-98bc75bd2670")
SET(CPACK_WIX_SIZEOF_VOID_P "4")
SET(CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_LIST_DIR}/patch.xml")
endif()
And running the resulting MSI installed the binary into C:\Program Files(x86)\HelloWorld
as I expected.
Now, for linux, I add a condition like:
if(WIN32)
....
elseif(UNIX)
SET(CPACK_GENERATOR RPM)
endif
expecting an RPM that would install the binary into /usr/local/HelloWorld
(as per ${CMAKE_INSTALL_PREFIX}
specifies) but instead I get the binary placed in /
.
What I want to happen is for the binary to install to /var/opt/HelloWorld/<files>
so I tried setting some more variables as per CPack documentation:
SET(CMAKE_INSTALL_PREFIX "/var/opt/${CPACK_PACKAGE_NAME}")
SET(CPACK_PACKAGING_INSTALL_PREFIX "/var/opt/${CPACK_PACKAGE_NAME}")
SET(CPACK_PACKAGE_DEFAULT_LOCATION "/var/opt/${CPACK_PACKAGE_NAME}")
but nothing worked as I expected. I noticed that the only place I had the path /
specified was when I set the ${CPACK_INSTALLED_DIRECTORIES}
. Now, this seems to be ignored on Windows but on Linux it does seem to matter.
The questions I can't seem to find answers for:
Is using
${CPACK_INSTALLED_DIRECTORIES}
the correct way to add items to an installer when no cmake project exist? I was slightly apprehensive about using it since my interpretation of the documentation seems to suggest this is used for supplementary items that are not part of the main installer.What are the correct CPack/CMake variables to set in order to choose a different install location? There seem to be a few to choose from and on Windows, the
${CPACK_PACKAGE_INSTALL_DIRECTORY}
seems to be honoured but on Linux it wasn't.