How to build a MASM Project?

Hi,  I try many times but fail to build a hello world masm project

could you help me to give me a simple example?

Thank you 

CmakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(MASMExample C ASM_MASM)

# 设置 MASM 和 LINK 的路径
set(MASM_PATH "C:/masm32/bin/ml.exe")
set(LINK_PATH "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x86/link.exe")
set(MASM_INCLUDE_DIR "C:/masm32/include")
# 添加你的汇编文件
set(SOURCE_FILES main.asm)

set(ENV{ASM_MASM} "C:/masm32/bin/ml.exe")
set(CMAKE_LINKER  "C:/masm32/bin/link.exe")
set(ENV{RC}       "C:/masm32/bin/rc.exe")

set(CMAKE_ASM_MASM_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> <CMAKE_ASM_MASM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> /OUT:<TARGET> <LINK_LIBRARIES>")
set(CMAKE_RC_COMPILE_OBJECT        "$ENV{RC} <DEFINES> <INCLUDES> <FLAGS> /r /Fo<OBJECT> <SOURCE>")

# 添加自定义命令以编译汇编文件
add_custom_command(
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main.obj
        COMMAND ${MASM_PATH} /c /Fo${CMAKE_CURRENT_BINARY_DIR}/main.obj /I"C:/masm32/include" ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILES}
        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILES}
)
set ( SOURCES
        main.asm)

# 创建一个伪目标,以确保生成的对象文件存在
add_custom_target(MASMCompile ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/main.obj)

# 添加可执行文件,确保依赖于生成的对象文件
add_executable(MASMExample ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/main.obj)

# 设置链接器为 Microsoft 的链接器
set_target_properties(MASMExample PROPERTIES LINKER_LANGUAGE C)
set(CMAKE_LINKER ${LINK_PATH})

# 依赖于编译步骤
add_dependencies(MASMExample MASMCompile)

 

main.asm

 

0

Please sign in to leave a comment.