- 1 year ago
CMake problem while assembling .asm files in CLion
When using CMake in CLion to assemble .asm
files, you need to configure your CMakeLists.txt file to properly handle the assembly files. Here's an example of how you can set up CMake to assemble .asm
files using NASM:
cmakecmake_minimum_required(VERSION 3.21)
project(AssemblyProject)
set(CMAKE_ASM_NASM_COMPILER "/path/to/nasm")
set(SOURCES
main.c
assembly.asm
)
add_executable(${PROJECT_NAME} ${SOURCES})
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
enable_language(ASM_NASM)
set_property(SOURCE assembly.asm PROPERTY LANGUAGE ASM_NASM)
set_property(SOURCE assembly.asm PROPERTY COMPILE_OPTIONS -fwin64)
else()
enable_language(ASM)
set_property(SOURCE assembly.asm PROPERTY LANGUAGE ASM)
endif()
Here's what this CMakeLists.txt file does:
Set the path to NASM: Modify the line
set(CMAKE_ASM_NASM_COMPILER "/path/to/nasm")
to point to the location of your NASM assembler. Replace/path/to/nasm
with the actual path.Define the source files: Update the
SOURCES
variable with the list of your source files, including the.c
and.asm
files.Add the executable: Use the
add_executable
command to create the executable target using the source files.Set the C standard: Use the
set_property
command to set the C standard for the target. In this example, it's set to C11, but you can adjust it as needed.Configure assembly file for Windows: If the system is Windows, enable NASM assembly language and set the appropriate properties for the
assembly.asm
file. In this example, it's set to assemble for Win64 (-fwin64
).Configure assembly file for non-Windows systems: For non-Windows systems, enable the default assembly language and set the properties for the
assembly.asm
file.
Make sure to replace /path/to/nasm
with the actual path to your NASM assembler.
With this setup, CLion should be able to assemble the .asm
file as part of the build process.