sheeldotme
sheeldotme

Reputation: 2503

How does one compile a 64 bit macOS application with NASM application using CMake?

Looking at the source setting CMAKE_ASM_NASM_OBJECT_FORMAT should be sufficient, however this does not seem to be the case.

I expected the following to create a valid build configuration for a macOS application using the macho64 file format.

project(hello_world ASM_NASM)
set(CMAKE_ASM_NASM_OBJECT_FORMAT macho64)
add_executable(hello_world source/main.asm)

However, when running make with VERBOSE=1

/usr/local/bin/nasm   -f macho -o CMakeFiles/main.dir/source/main.asm.o /hello-world/source/main.asm
/hello-world/source/main.asm:6: error: instruction not supported in 32-bit mode
/hello-world/source/main.asm:7: error: instruction not supported in 32-bit mode
/hello-world/source/main.asm:8: error: instruction not supported in 32-bit mode
/hello-world/source/main.asm:9: error: instruction not supported in 32-bit mode
/hello-world/source/main.asm:12: error: instruction not supported in 32-bit mode
/hello-world/source/main.asm:13: error: instruction not supported in 32-bit mode
make[2]: *** [CMakeFiles/main.dir/source/main.asm.o] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2

We can clearly see the 32 bit version of mach-o is passed to the format flag instead of the expected 64 bit version: macho64.

Versions

Upvotes: 0

Views: 889

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66089

The compiler is checked at the project() call.

You need to move setting the CMAKE_ASM_NASM_OBJECT_FORMAT variable before that call.

Upvotes: 1

Related Questions