Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 1 | include(LLVMParseArguments) |
| 2 | |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 3 | # Compile a source into an object file with COMPILER_RT_TEST_COMPILER using |
Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 4 | # a provided compile flags and dependenices. |
| 5 | # clang_compile(<object> <source> |
| 6 | # CFLAGS <list of compile flags> |
| 7 | # DEPS <list of dependencies>) |
| 8 | macro(clang_compile object_file source) |
| 9 | parse_arguments(SOURCE "CFLAGS;DEPS" "" ${ARGN}) |
| 10 | get_filename_component(source_rpath ${source} REALPATH) |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 11 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 12 | list(APPEND SOURCE_DEPS clang) |
| 13 | endif() |
Alexey Samsonov | 1847401 | 2014-03-24 09:42:12 +0000 | [diff] [blame^] | 14 | 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() |
| 20 | # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options |
| 21 | # which are not supported by Clang. |
| 22 | list(APPEND global_flags -Wno-unknown-warning-option) |
| 23 | set(compile_flags ${global_flags} ${SOURCE_CFLAGS}) |
Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 24 | add_custom_command( |
| 25 | OUTPUT ${object_file} |
Alexey Samsonov | 1847401 | 2014-03-24 09:42:12 +0000 | [diff] [blame^] | 26 | COMMAND ${COMPILER_RT_TEST_COMPILER} ${compile_flags} -c -o "${object_file}" |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 27 | ${source_rpath} |
Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 28 | MAIN_DEPENDENCY ${source} |
Alexey Samsonov | 150d62a | 2014-02-19 13:01:03 +0000 | [diff] [blame] | 29 | DEPENDS ${SOURCE_DEPS}) |
Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 30 | endmacro() |