1 cmake_minimum_required (VERSION 3.10)
3 cmake_policy(SET CMP0129 NEW)
6 message("CTEST_FULL_OUTPUT ")
7 set(CMAKE_VERBOSE_MAKEFILE 1)
11 # (at least) the following toolchains can process assembler files directly
12 # and also generate assembler files from C:
13 if("${CMAKE_GENERATOR}" MATCHES "Makefile|Xcode|Ninja" AND
14 NOT CMAKE_OSX_ARCHITECTURES MATCHES ";")
15 if((CMAKE_C_COMPILER_ID MATCHES "^(GNU|LCC|Clang|AppleClang|HP|SunPro|XL|OrangeC)$") OR (CMAKE_C_COMPILER_ID MATCHES "Intel" AND UNIX)
16 AND NOT (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC"))
17 set(C_FLAGS "${CMAKE_C_FLAGS}")
18 separate_arguments(C_FLAGS)
19 if(CMAKE_OSX_SYSROOT AND CMAKE_C_SYSROOT_FLAG AND NOT ";${C_FLAGS};" MATCHES ";${CMAKE_C_SYSROOT_FLAG};")
20 list(APPEND C_FLAGS ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT})
22 if(CMAKE_OSX_ARCHITECTURES)
23 list(APPEND C_FLAGS -arch ${CMAKE_OSX_ARCHITECTURES})
24 elseif("${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Darwin;arm64")
25 list(APPEND C_FLAGS -arch arm64)
27 if(CMAKE_C_COMPILER_ID MATCHES "Clang")
28 # Just in case the user is passing -flto, we need to pass -fno-lto to
29 # clang when generating the assembly file, or else clang will generate
30 # LLVM IR instead of assembly.
31 list(APPEND C_FLAGS -fno-lto)
33 # Clang on OS X, and perhaps other compilers, do not support -g
34 # for both generating and assembling, so drop it from generating.
35 list(REMOVE_ITEM C_FLAGS -g)
39 COMMAND ${CMAKE_C_COMPILER} ${C_FLAGS}
40 "$<$<CONFIG:Debug>:${CMAKE_C_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL}>"
41 "$<$<NOT:$<CONFIG:Debug>>:${CMAKE_C_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL}>"
42 -S ${CMAKE_CURRENT_SOURCE_DIR}/main.c -o main.s
52 set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}")
53 enable_language(ASM OPTIONAL)
55 message(STATUS "No assembler enabled, using C")
59 add_executable(HelloAsm ${SRCS})