1 include(AddFileDependencies)
2 include(CMakeParseArguments)
4 function(llvm_replace_compiler_option var old new)
5 # Replaces a compiler option or switch `old' in `var' by `new'.
6 # If `old' is not in `var', appends `new' to `var'.
7 # Example: llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
8 # If the option already is on the variable, don't add it:
9 if( "${${var}}" MATCHES "(^| )${new}($| )" )
14 if( "${${var}}" MATCHES "(^| )${old}($| )" )
15 string( REGEX REPLACE "(^| )${old}($| )" " ${n} " ${var} "${${var}}" )
17 set( ${var} "${${var}} ${n}" )
19 set( ${var} "${${var}}" PARENT_SCOPE )
20 endfunction(llvm_replace_compiler_option)
22 macro(add_td_sources srcs)
25 source_group("TableGen descriptions" FILES ${tds})
26 set_source_files_properties(${tds} PROPERTIES HEADER_FILE_ONLY ON)
27 list(APPEND ${srcs} ${tds})
29 endmacro(add_td_sources)
32 macro(add_header_files srcs)
35 set_source_files_properties(${hds} PROPERTIES HEADER_FILE_ONLY ON)
36 list(APPEND ${srcs} ${hds})
38 endmacro(add_header_files)
41 function(llvm_process_sources OUT_VAR)
42 cmake_parse_arguments(ARG "" "" "ADDITIONAL_HEADERS" ${ARGN})
43 set(sources ${ARG_UNPARSED_ARGUMENTS})
44 llvm_check_source_file_list( ${sources} )
45 # Create file dependencies on the tablegenned files, if any. Seems
46 # that this is not strictly needed, as dependencies of the .cpp
47 # sources on the tablegenned .inc files are detected and handled,
49 foreach( s ${sources} )
50 set( f ${CMAKE_CURRENT_SOURCE_DIR}/${s} )
51 add_file_dependencies( ${f} ${TABLEGEN_OUTPUT} )
53 if( MSVC_IDE OR XCODE )
54 # This adds .td and .h files to the Visual Studio solution:
55 add_td_sources(sources)
56 add_header_files(sources)
57 set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
58 list(APPEND sources ${ARG_ADDITIONAL_HEADERS})
61 set( ${OUT_VAR} ${sources} PARENT_SCOPE )
62 endfunction(llvm_process_sources)
65 function(llvm_check_source_file_list)
67 file(GLOB globbed *.c *.cpp)
69 get_filename_component(fn ${g} NAME)
70 list(FIND LLVM_OPTIONAL_SOURCES ${fn} idx)
72 list(FIND listed ${fn} idx)
74 message(SEND_ERROR "Found unknown source file ${g}
75 Please update ${CMAKE_CURRENT_LIST_FILE}\n")
79 endfunction(llvm_check_source_file_list)