CMake/Assembler: Difference between revisions
Line 8: | Line 8: | ||
* ASM_MASM (since 2.6.3) | * ASM_MASM (since 2.6.3) | ||
We would be happy about patches which add support for nasm, yasm, tasm, etc. | |||
==Using the CMake Assembler Support== | ==Using the CMake Assembler Support== |
Revision as of 14:47, 11 January 2009
Introduction
Since version 2.6.0 CMake has basic support for using assembler source files in CMake projects. Assembler is different from other languages in that it actually is no single language, but there are many different assembler languages. CMake supports a generic "ASM" language and specialized "ASM_XXX" languages for assembler "dialects".
Currently supported:
- ASM-ATT (since 2.6.0)
- ASM_MASM (since 2.6.3)
We would be happy about patches which add support for nasm, yasm, tasm, etc.
Using the CMake Assembler Support
If you have a project which contains assembler files, you still probably don't want to use them in all cases, e.g. on all architectures. You have to add CMake code which tests for the respective architectures and enables the support for the associated assembler accordingly. You should also check whether the assembler has been found by testing MAKE_ASM-ATT_COMPILER_WORKS. This variable doesn't really show whether the assembler actually works, but only whether it has been found. There is no generic test whether an assembler works since each architecture would require its own assembler source file.
It is also possible to support multiple different assemblers in one project.
set(mySrcs foo.c bar.c) set(can_use_assembler FALSE) # test wether it is a x86 machine and as/gas is available if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i.86") enable_language(ASM-ATT) if(CMAKE_ASM-ATT_COMPILER_WORKS) set(can_use_assembler TRUE) set(mySrcs ${mySrcs} codec_i86.s) endif(CMAKE_ASM-ATT_COMPILER_WORKS) endif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i.86") # no assembler found if(not can_use_assembler) set(mySrcs ${mySrcs} codec_generic.c) endif(not can_use_assembler) add_executable(player ${mySrcs})
Supported Assembler Dialects
Generic ASM
This serves as base for the different assembler dialects.
- Supported assembler names: defaults to as, gas, may have toolchain specific prefix. This can be overriden by setting CMAKE_ASM_COMPILER before enabling the ASM language.
- Supported source files extensions: defaults to .s, .S, .asm. This can be overriden by setting CMAKE_ASM_SOURCE_FILE_EXTENSIONS before enabling the ASM language.
- The variables which define the commands for compiling and linking files, CMAKE_ASM_COMPILE_OBJECT, CMAKE_ASM_CREATE_(STATIC_LIBRARY|SHARED_LIBRARY|SHARED_MODULE), CMAKE_ASM_LINK_EXECUTABLE, default to gas behaviour. They can be overridden by setting them before enabling the ASM language.
- Involved files: CMakeASMInformation.cmake, CMakeDetermineASMCompiler.cmake, CMakeTestASMCompiler.cmake
ASM-ATT
This can be used for assembler files in AT&T assembler syntax. This includes the GNU assembler gas.
- Supported assembler names: as, gas, may have toolchain specific prefix
- Supported source files extensions: .s, .S, .asm
- Involved files: CMakeASM-ATTInformation.cmake, CMakeDetermineASM-ATTCompiler.cmake, CMakeTestASM-ATTCompiler.cmake
ASM_MASM
This is support for the Microsoft assembler.
- Supported assembler names: ml, ml64
- Supported source files extensions: .asm
- Involved files: CMakeASM_MASMInformation.cmake, CMakeDetermineASM_MASMCompiler.cmake, CMakeTestASM_MASMCompiler.cmake