[cmake-developers] [PATCH] CPackRPM: Fix cross-building rpms

Joshua Clayton stillcompiling at gmail.com
Tue Feb 3 17:04:01 EST 2015


Add the --target argument to rpmbuild
Do not add a BuildArch variable to the spec file for arch specific packages
BuildArch causes rpm building to fail except for "noarch" packages
---
 Modules/CPackRPM.cmake | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Modules/CPackRPM.cmake b/Modules/CPackRPM.cmake
index 43e3fe0..b9d7381 100644
--- a/Modules/CPackRPM.cmake
+++ b/Modules/CPackRPM.cmake
@@ -615,7 +615,14 @@ endif()
 string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
 
 # CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
-if(CPACK_RPM_PACKAGE_ARCHITECTURE)
+if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
+  execute_process(COMMAND uname "-m"
+  WORKING_DIRECTORY "${WDIR}"
+  OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE)
+endif()
+set(TMP_CPACK_RPM_TARGET "--target" "${CPACK_RPM_PACKAGE_ARCHITECTURE}")
+
+if (CPACK_RPM_PACKAGE_ARCHITECTURE STREQUAL "noarch")
   set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
   if(CPACK_RPM_PACKAGE_DEBUG)
     message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
@@ -1277,6 +1284,7 @@ if(RPMBUILD_EXECUTABLE)
     COMMAND "${RPMBUILD_EXECUTABLE}" -bb
             --define "_topdir ${CPACK_RPM_DIRECTORY}"
             --buildroot "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
+            ${TMP_CPACK_RPM_TARGET}
             "${CPACK_RPM_BINARY_SPECFILE}"
     WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}"
     RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT
-- 
2.1.0



More information about the cmake-developers mailing list