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)
31 function(add_header_files_for_glob hdrs_out glob)
32 file(GLOB hds ${glob})
35 # Explicit existence check is necessary to filter dangling symlinks
36 # out. See https://bugs.gentoo.org/674662.
38 list(APPEND filtered ${file})
41 set(${hdrs_out} ${filtered} PARENT_SCOPE)
42 endfunction(add_header_files_for_glob)
44 function(find_all_header_files hdrs_out additional_headerdirs)
45 add_header_files_for_glob(hds *.h)
46 list(APPEND all_headers ${hds})
48 foreach(additional_dir ${additional_headerdirs})
49 add_header_files_for_glob(hds "${additional_dir}/*.h")
50 list(APPEND all_headers ${hds})
51 add_header_files_for_glob(hds "${additional_dir}/*.inc")
52 list(APPEND all_headers ${hds})
53 endforeach(additional_dir)
55 set( ${hdrs_out} ${all_headers} PARENT_SCOPE )
56 endfunction(find_all_header_files)
59 function(llvm_process_sources OUT_VAR)
60 cmake_parse_arguments(ARG "" "" "ADDITIONAL_HEADERS;ADDITIONAL_HEADER_DIRS" ${ARGN})
61 set(sources ${ARG_UNPARSED_ARGUMENTS})
62 llvm_check_source_file_list( ${sources} )
64 # This adds .td and .h files to the Visual Studio solution:
65 add_td_sources(sources)
66 find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")
68 set_source_files_properties(${hdrs} PROPERTIES HEADER_FILE_ONLY ON)
70 set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
71 list(APPEND sources ${ARG_ADDITIONAL_HEADERS} ${hdrs})
73 set( ${OUT_VAR} ${sources} PARENT_SCOPE )
74 endfunction(llvm_process_sources)
77 function(llvm_check_source_file_list)
78 cmake_parse_arguments(ARG "" "SOURCE_DIR" "" ${ARGN})
79 foreach(l ${ARG_UNPARSED_ARGUMENTS})
80 get_filename_component(fp ${l} REALPATH)
81 list(APPEND listed ${fp})
86 "${ARG_SOURCE_DIR}/*.c" "${ARG_SOURCE_DIR}/*.cpp")
88 file(GLOB globbed *.c *.cpp)
92 get_filename_component(fn ${g} NAME)
98 get_filename_component(gp ${g} REALPATH)
100 # Don't reject hidden files. Some editors create backups in the
101 # same directory as the file.
102 if (NOT "${fn}" MATCHES "^\\.")
103 list(FIND LLVM_OPTIONAL_SOURCES ${entry} idx)
105 list(FIND listed ${gp} idx)
108 set(fn_relative "${ARG_SOURCE_DIR}/${fn}")
110 set(fn_relative "${fn}")
112 message(SEND_ERROR "Found unknown source file ${fn_relative}
113 Please update ${CMAKE_CURRENT_LIST_FILE}\n")
118 endfunction(llvm_check_source_file_list)