blob: 2d1dd22e3dca88ca5d725c8ad6e2ccadcf4c7588 [file] [log] [blame]
Alexey Samsonovca7fcf22012-12-19 12:33:39 +00001include(LLVMParseArguments)
2
Alexey Samsonov150d62a2014-02-19 13:01:03 +00003# Compile a source into an object file with COMPILER_RT_TEST_COMPILER using
Alexey Samsonovca7fcf22012-12-19 12:33:39 +00004# a provided compile flags and dependenices.
5# clang_compile(<object> <source>
6# CFLAGS <list of compile flags>
7# DEPS <list of dependencies>)
8macro(clang_compile object_file source)
9 parse_arguments(SOURCE "CFLAGS;DEPS" "" ${ARGN})
10 get_filename_component(source_rpath ${source} REALPATH)
Alexey Samsonov150d62a2014-02-19 13:01:03 +000011 if(NOT COMPILER_RT_STANDALONE_BUILD)
12 list(APPEND SOURCE_DEPS clang)
13 endif()
Alexey Samsonov18474012014-03-24 09:42:12 +000014 string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
15 if(is_cxx)
16 string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
17 else()
18 string(REPLACE " " ";" global_flags "${CMAKE_C_FLAGS}")
19 endif()
Timur Iskhodzhanov82ee0432014-05-28 08:38:13 +000020 # On Windows, CMAKE_*_FLAGS are built for MSVC but we use the GCC clang.exe
21 # which doesn't support flags starting with "/smth". Replace those with
22 # "-smth" equivalents.
23 if(MSVC)
24 string(REGEX REPLACE "^/" "-" global_flags "${global_flags}")
25 string(REPLACE ";/" ";-" global_flags "${global_flags}")
26 endif()
Alexey Samsonov18474012014-03-24 09:42:12 +000027 # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options
28 # which are not supported by Clang.
29 list(APPEND global_flags -Wno-unknown-warning-option)
30 set(compile_flags ${global_flags} ${SOURCE_CFLAGS})
Alexey Samsonovca7fcf22012-12-19 12:33:39 +000031 add_custom_command(
32 OUTPUT ${object_file}
Timur Iskhodzhanovb0279d72014-05-12 08:55:20 +000033 COMMAND ${COMPILER_RT_TEST_COMPILER} ${compile_flags} -c
Timur Iskhodzhanov82ee0432014-05-28 08:38:13 +000034 -o "${object_file}"
Alexey Samsonov150d62a2014-02-19 13:01:03 +000035 ${source_rpath}
Alexey Samsonovca7fcf22012-12-19 12:33:39 +000036 MAIN_DEPENDENCY ${source}
Alexey Samsonov150d62a2014-02-19 13:01:03 +000037 DEPENDS ${SOURCE_DEPS})
Alexey Samsonovca7fcf22012-12-19 12:33:39 +000038endmacro()