CMakeLists.txt 1.41 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
cmake_minimum_required (VERSION 2.6)
2
project(Assembler C)
3 4
message("CTEST_FULL_OUTPUT ")
set(CMAKE_VERBOSE_MAKEFILE 1)
5 6 7

set(SRCS)

8
# (at least) the following toolchains can process assembler files directly
9
# and also generate assembler files from C:
10
if("${CMAKE_GENERATOR}" MATCHES "Makefile|Xcode|Ninja" AND
11
    NOT CMAKE_OSX_ARCHITECTURES)
12 13
  if((CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang|HP|SunPro|XL)$") OR (CMAKE_C_COMPILER_ID STREQUAL "Intel"  AND  UNIX)
     AND NOT (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC"))
14 15
    set(C_FLAGS "${CMAKE_C_FLAGS}")
    separate_arguments(C_FLAGS)
16 17 18
    if(CMAKE_OSX_SYSROOT AND CMAKE_C_SYSROOT_FLAG AND NOT ";${C_FLAGS};" MATCHES ";${CMAKE_C_SYSROOT_FLAG};")
      list(APPEND C_FLAGS ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT})
    endif()
19 20 21
    # Clang on OS X, and perhaps other compilers, do not support -g
    # for both generating and assembling, so drop it from generating.
    list(REMOVE_ITEM C_FLAGS -g)
22 23 24 25 26 27 28
    set(SRCS main.s)
    add_custom_command(
      OUTPUT main.s
      COMMAND ${CMAKE_C_COMPILER} ${C_FLAGS} -S ${CMAKE_CURRENT_SOURCE_DIR}/main.c -o main.s
      DEPENDS main.c
      VERBATIM
      )
29 30
  endif()
endif()
31

32 33

if(SRCS)
34
  set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}")
35
  enable_language(ASM OPTIONAL)
36
else()
37 38
  message(STATUS "No assembler enabled, using C")
  set(SRCS main.c)
39
endif()
40 41

add_executable(HelloAsm ${SRCS})