gpt4 book ai didi

CMake如何设置nasm文件扩展名

转载 作者:行者123 更新时间:2023-11-30 16:14:49 24 4
gpt4 key购买 nike

我正在尝试使用 CMake 编译 nasm 源文件并且对后缀有一些误解。默认CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS有值(value)nasm;asm所以我想要 *.S被识别为ASM_NASM文件由 CMake 。设置

set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS "${CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS};S")

似乎不起作用。这是完整的CMakeLists.txt :

cmake_minimum_required(VERSION 3.10)

project(casm)
enable_language(ASM_NASM)
set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS "${CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS};S")
set(CMAKE_ASM_NASM_COMPILE_OPTIONS "${CMAKE_ASM_NASM_COMPILE_OPTIONS} -f elf64 -g")
add_executable(min main.c min.S)

打印以下错误:

CMake Error: CMake can not determine linker language for target: min
CMake Error: Cannot determine link language for target "min".

虽然只是重命名 min.Smin.asm并将添加可执行文件替换为

add_executable(min main.c min.asm)

工作得很好:

Scanning dependencies of target min
[ 33%] Building C object CMakeFiles/min.dir/main.c.o
[ 66%] Building ASM_NASM object CMakeFiles/min.dir/min.asm.o
[100%] Linking C executable min
[100%] Built target min

我也尝试过 set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS "")没有任何效果,那么用户对该属性的设置是否会被忽略?

最佳答案

我遇到了同样的问题,即“.s”扩展名。这工作正常:

set_source_files_properties(min.S PROPERTIES LANGUAGE ASM_NASM)

更一般:

file(GLOB_RECURSE src_asm "<path>/*.S" "<path>/*.s")
foreach(X IN ITEMS ${src_asm})
set_source_files_properties(${X} PROPERTIES LANGUAGE ASM_NASM)
endforeach()
target_sources(target PRIVATE ${src_c} ${src_asm})

关于CMake如何设置nasm文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57374317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com