[x265] [PATCH] cmake: Build ARM/AArch64/RISC-V assembly without custom commands

Martin Storsjö martin at martin.st
Wed Nov 5 13:35:38 UTC 2025


This simplifies the build, allows the build systems to
natively track dependencies for rebuilding the .S files. It
also makes sure that other implicit command line parameters
are passed to the build of the assembly files, like making
sure CMAKE_OSX_DEPLOYMENT_TARGET has an effect, avoiding
link time warnings.

The use of custom commands for building assembly was done
for specific reasons; with MSVC and Xcode project, nasm sources
built natively as a source in cmake won't get compiled.

Therefore, there's a condition, for "if(MSVC_IDE OR XCODE)"
that triggers using custom commands for the nasm sources (for
x86).

There was no such similar condition for the ARM/AArch64 assembly
though. And there really isn't a need for it either. MSVC can't
build the GNU style .S assembly as-is anyway, and Xcode can handle
.S files just fine, without needing the nasm workaround.

Building the project as an Xcode project does have other problems
though; the previous form of using custom commands fails with
modern Xcode versions, due to "the custom command generating
ssd-neon-dotprod.S.o is attached to multiple targets [...] This
is not allowed by the Xcode new build system". Treating the files
as native source files avoids this issue, but to fully fix building
in that configuration, one would have to avoid conflicts between
source files e.g. "dct.S" and "dct.cpp" both producing an output
named "dct.o".
---
 source/CMakeLists.txt        | 92 +-----------------------------------
 source/common/CMakeLists.txt | 42 +++++++++++++++-
 2 files changed, 42 insertions(+), 92 deletions(-)

diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index 9f93b6ec2..02a03cb22 100755
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -865,97 +865,7 @@ if((MSVC_IDE OR XCODE OR GCC) AND ENABLE_ASSEMBLY)
         set(SUFFIX o)
     endif()
 
-    if(ARM OR CROSS_COMPILE_ARM)
-    # compile ARM arch asm files here
-        enable_language(ASM)
-        if(APPLE)
-            set(ARM_ARGS ${ARM_ARGS} -arch ${CMAKE_OSX_ARCHITECTURES})
-        endif()
-        foreach(ASM ${ARM_ASMS})
-			set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/arm/${ASM})
-            list(APPEND ASM_SRCS ${ASM_SRC})
-            list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
-            add_custom_command(
-                OUTPUT ${ASM}.${SUFFIX}
-                COMMAND ${CMAKE_CXX_COMPILER}
-                ARGS ${ARM_ARGS} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
-                DEPENDS ${ASM_SRC})
-        endforeach()
-	elseif(ARM64 OR CROSS_COMPILE_ARM64)
-    # compile ARM64 arch asm files here
-        enable_language(ASM)
-        foreach(ASM ${ARM_ASMS})
-            set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/aarch64/${ASM})
-            list(APPEND ASM_SRCS ${ASM_SRC})
-            list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
-            add_custom_command(
-                OUTPUT ${ASM}.${SUFFIX}
-                COMMAND ${CMAKE_CXX_COMPILER}
-                ARGS ${ARM_ARGS} ${ASM_FLAGS} ${AARCH64_NEON_FLAG} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
-                DEPENDS ${ASM_SRC})
-        endforeach()
-        if(CPU_HAS_NEON_DOTPROD)
-            foreach(ASM ${ARM_ASMS_NEON_DOTPROD})
-                set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/aarch64/${ASM})
-                list(APPEND ASM_SRCS ${ASM_SRC})
-                list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
-                add_custom_command(
-                    OUTPUT ${ASM}.${SUFFIX}
-                    COMMAND ${CMAKE_CXX_COMPILER}
-                    ARGS ${ARM_ARGS} ${ASM_FLAGS} ${AARCH64_NEON_DOTPROD_FLAG} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
-                    DEPENDS ${ASM_SRC})
-            endforeach()
-        endif()
-        if(CPU_HAS_SVE)
-            foreach(ASM ${ARM_ASMS_SVE})
-                set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/aarch64/${ASM})
-                list(APPEND ASM_SRCS ${ASM_SRC})
-                list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
-                add_custom_command(
-                    OUTPUT ${ASM}.${SUFFIX}
-                    COMMAND ${CMAKE_CXX_COMPILER}
-                    ARGS ${ARM_ARGS} ${ASM_FLAGS} ${AARCH64_SVE_FLAG} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
-                    DEPENDS ${ASM_SRC})
-            endforeach()
-        endif()
-        if(CPU_HAS_SVE2)
-            foreach(ASM ${ARM_ASMS_SVE2})
-                set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/aarch64/${ASM})
-                list(APPEND ASM_SRCS ${ASM_SRC})
-                list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
-                add_custom_command(
-                    OUTPUT ${ASM}.${SUFFIX}
-                    COMMAND ${CMAKE_CXX_COMPILER}
-                    ARGS ${ARM_ARGS} ${ASM_FLAGS} ${AARCH64_SVE2_FLAG} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
-                    DEPENDS ${ASM_SRC})
-            endforeach()
-        endif()
-        if(CPU_HAS_SVE2_BITPERM)
-            foreach(ASM ${ARM_ASMS_SVE2_BITPERM})
-                set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/aarch64/${ASM})
-                list(APPEND ASM_SRCS ${ASM_SRC})
-                list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
-                add_custom_command(
-                    OUTPUT ${ASM}.${SUFFIX}
-                    COMMAND ${CMAKE_CXX_COMPILER}
-                    ARGS ${ARM_ARGS} ${ASM_FLAGS} ${AARCH64_SVE2_BITPERM_FLAG} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
-                    DEPENDS ${ASM_SRC})
-            endforeach()
-        endif()
-    elseif(RISCV64 OR CROSS_COMPILE_RISCV64)
-    # compile RISCV64 arch asm files here
-        enable_language(ASM)
-        foreach(ASM ${RISCV64_ASMS})
-            set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/riscv64/${ASM})
-            list(APPEND ASM_SRCS ${ASM_SRC})
-            list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
-            add_custom_command(
-                OUTPUT ${ASM}.${SUFFIX}
-                COMMAND ${CMAKE_CXX_COMPILER}
-                ARGS ${RISCV64_ARGS} ${ASM_FLAGS} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
-                DEPENDS ${ASM_SRC})
-        endforeach()
-    elseif(X86)
+    if(X86)
     # compile X86 arch asm files here
         foreach(ASM ${MSVC_ASMS})
             set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/x86/${ASM})
diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt
index 017cd5db5..9a5fe3365 100644
--- a/source/common/CMakeLists.txt
+++ b/source/common/CMakeLists.txt
@@ -90,8 +90,10 @@ if(ENABLE_ASSEMBLY AND (ARM OR CROSS_COMPILE_ARM))
     set(A_SRCS asm.S cpu-a.S mc-a.S sad-a.S pixel-util.S ssd-a.S blockcopy8.S ipfilter8.S dct-a.S)
     set(VEC_PRIMITIVES)
 
+    enable_language(ASM)
+
     set(ARM_ASMS "${A_SRCS}" CACHE INTERNAL "ARM Assembly Sources")
-    foreach(SRC ${C_SRCS})
+    foreach(SRC ${C_SRCS} ${A_SRCS})
         set(ASM_PRIMITIVES ${ASM_PRIMITIVES} arm/${SRC})
     endforeach()
     source_group(Assembly FILES ${ASM_PRIMITIVES})
@@ -128,12 +130,22 @@ if(ENABLE_ASSEMBLY AND (ARM64 OR CROSS_COMPILE_ARM64))
         set(ASM_PRIMITIVES ${ASM_PRIMITIVES} aarch64/${SRC})
         set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${AARCH64_NEON_FLAG})
     endforeach()
+    string(REPLACE ";" " " ASM_NEON_FLAGS "${ASM_FLAGS};${AARCH64_NEON_FLAG}")
+    foreach(SRC ${A_SRCS})
+        set(ASM_PRIMITIVES ${ASM_PRIMITIVES} aarch64/${SRC})
+        set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${ASM_NEON_FLAGS})
+    endforeach()
 
     if(CPU_HAS_NEON_DOTPROD)
         foreach(SRC ${C_SRCS_NEON_DOTPROD})
             set(ASM_PRIMITIVES ${ASM_PRIMITIVES} aarch64/${SRC})
             set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${AARCH64_NEON_DOTPROD_FLAG})
         endforeach()
+        string(REPLACE ";" " " ASM_NEON_DOTPROD_FLAGS "${ASM_FLAGS};${AARCH64_NEON_DOTPROD_FLAG}")
+        foreach(SRC ${A_SRCS_NEON_DOTPROD})
+            set(ASM_PRIMITIVES ${ASM_PRIMITIVES} aarch64/${SRC})
+            set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${ASM_NEON_DOTPROD_FLAGS})
+        endforeach()
     endif()
 
     if(CPU_HAS_NEON_I8MM)
@@ -149,6 +161,13 @@ if(ENABLE_ASSEMBLY AND (ARM64 OR CROSS_COMPILE_ARM64))
             set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${AARCH64_SVE_FLAG})
         endforeach()
     endif()
+    if(CPU_HAS_SVE)
+        string(REPLACE ";" " " ASM_SVE_FLAGS "${ASM_FLAGS};${AARCH64_SVE_FLAG}")
+        foreach(SRC ${A_SRCS_SVE})
+            set(ASM_PRIMITIVES ${ASM_PRIMITIVES} aarch64/${SRC})
+            set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${ASM_SVE_FLAGS})
+        endforeach()
+    endif()
 
     if(CPU_HAS_SVE2 AND HAVE_SVE_BRIDGE)
         foreach(SRC ${C_SRCS_SVE2})
@@ -156,6 +175,21 @@ if(ENABLE_ASSEMBLY AND (ARM64 OR CROSS_COMPILE_ARM64))
             set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${AARCH64_SVE2_FLAG})
         endforeach()
     endif()
+    if(CPU_HAS_SVE2)
+        string(REPLACE ";" " " ASM_SVE2_FLAGS "${ASM_FLAGS};${AARCH64_SVE2_FLAG}")
+        foreach(SRC ${A_SRCS_SVE2})
+            set(ASM_PRIMITIVES ${ASM_PRIMITIVES} aarch64/${SRC})
+            set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${ASM_SVE2_FLAGS})
+        endforeach()
+    endif()
+
+    if(CPU_HAS_SVE2_BITPERM)
+        string(REPLACE ";" " " ASM_SVE2_BITPERM_FLAGS "${ASM_FLAGS};${AARCH64_SVE2_BITPERM_FLAG}")
+        foreach(SRC ${A_SRCS_SVE2_BITPERM})
+            set(ASM_PRIMITIVES ${ASM_PRIMITIVES} aarch64/${SRC})
+            set_source_files_properties(aarch64/${SRC} PROPERTIES COMPILE_FLAGS ${ASM_SVE2_BITPERM_FLAGS})
+        endforeach()
+    endif()
 
     source_group(Assembly FILES ${ASM_PRIMITIVES})
 
@@ -189,6 +223,12 @@ if(ENABLE_ASSEMBLY AND (RISCV64 OR CROSS_COMPILE_RISCV64))
     set(VEC_PRIMITIVES)
 
     if(CPU_HAS_RVV)
+        string(REPLACE ";" " " ASM_RISCV_FLAGS "${ASM_FLAGS}")
+        foreach(SRC ${A_SRCS})
+            set(ASM_PRIMITIVES ${ASM_PRIMITIVES} riscv64/${SRC})
+            set_source_files_properties(riscv64/${SRC} PROPERTIES COMPILE_FLAGS ${ASM_RISCV_FLAGS})
+        endforeach()
+
         set(RISCV64_ASMS "${A_SRCS}" CACHE INTERNAL "RISCV64 Assembly Sources")
     endif()
 
-- 
2.50.1 (Apple Git-155)



More information about the x265-devel mailing list