BuildArch must only be added to a spec file for a "noarch" package
or rpmbuild will fail.
For all others, the --target argument sets the package architecture
In the process of Fixing rpm architecture, we make it mandatory,
adding a default value of native architecture (the same as if no
--target argument is present)
Update the documentation at the top of the file to mandatory.
---
 Modules/CPackRPM.cmake | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/Modules/CPackRPM.cmake b/Modules/CPackRPM.cmake
index 7516393..5135893 100644
--- a/Modules/CPackRPM.cmake
+++ b/Modules/CPackRPM.cmake
@@ -54,8 +54,8 @@
 #
 #  The RPM package architecture.
 #
-#  * Mandatory : NO
-#  * Default   : -
+#  * Mandatory : YES
+#  * Default   : Native architecture output by "uname -m"
 #
 #  This may be set to "noarch" if you know you are building a noarch package.
 #
@@ -619,12 +619,21 @@ endif()
 # RPM "Version" from RPM "Release"
 string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION})
 
-# CPACK_RPM_PACKAGE_ARCHITECTURE (optional)
-if(CPACK_RPM_PACKAGE_ARCHITECTURE)
-  set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}")
+# CPACK_RPM_PACKAGE_ARCHITECTURE (mandatory)
+if (NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
+  execute_process(COMMAND uname "-m"
+                  OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
+                  OUTPUT_STRIP_TRAILING_WHITESPACE)
+else()
   if(CPACK_RPM_PACKAGE_DEBUG)
     message("CPackRPM:Debug: using user-specified build arch = 
${CPACK_RPM_PACKAGE_ARCHITECTURE}")
   endif()
+endif()
+if (NOT CPACK_RPM_PACKAGE_ARCHITECTURE_)
+  set(CPACK_RPM_PACKAGE_ARCHITECTURE_ ${CPACK_RPM_PACKAGE_ARCHITECTURE})
+endif()
+if(${CPACK_RPM_PACKAGE_ARCHITECTURE_} STREQUAL "noarch")
+  set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE_}")
 else()
   set(TMP_RPM_BUILDARCH "")
 endif()
@@ -934,7 +943,7 @@ file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES)
 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS)
 file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS)
 
-#set(CPACK_RPM_FILE_NAME 
"${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm")
+#set(CPACK_RPM_FILE_NAME 
"${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE_}.rpm")
 set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
 # it seems rpmbuild can't handle spaces in the path
 # neither escaping (as below) nor putting quotes around the path seem to help
@@ -1282,6 +1291,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}"
+            --target "${CPACK_RPM_PACKAGE_ARCHITECTURE_}"
             "${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.2.2

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to