1 include(AddFileDependencies)
3 function(llvm_replace_compiler_option var old new)
4 # Replaces a compiler option or switch `old' in `var' by `new'.
5 # If `old' is not in `var', appends `new' to `var'.
6 # Example: llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
7 # If the option already is on the variable, don't add it:
8 if( "${${var}}" MATCHES "(^| )${new}($| )" )
13 if( "${${var}}" MATCHES "(^| )${old}($| )" )
14 string( REGEX REPLACE "(^| )${old}($| )" " ${n} " ${var} "${${var}}" )
16 set( ${var} "${${var}} ${n}" )
18 set( ${var} "${${var}}" PARENT_SCOPE )
19 endfunction(llvm_replace_compiler_option)
21 macro(add_td_sources srcs)
24 source_group("TableGen descriptions" FILES ${tds})
25 set_source_files_properties(${tds} PROPERTIES HEADER_FILE_ONLY ON)
26 list(APPEND ${srcs} ${tds})
28 endmacro(add_td_sources)
31 macro(add_header_files srcs)
34 set_source_files_properties(${hds} PROPERTIES HEADER_FILE_ONLY ON)
35 list(APPEND ${srcs} ${hds})
37 endmacro(add_header_files)
40 function(llvm_process_sources OUT_VAR)
41 cmake_parse_arguments(ARG "" "" "ADDITIONAL_HEADERS" ${ARGN})
42 set(sources ${ARG_UNPARSED_ARGUMENTS})
43 llvm_check_source_file_list( ${sources} )
44 # Create file dependencies on the tablegenned files, if any. Seems
45 # that this is not strictly needed, as dependencies of the .cpp
46 # sources on the tablegenned .inc files are detected and handled,
48 foreach( s ${sources} )
49 set( f ${CMAKE_CURRENT_SOURCE_DIR}/${s} )
50 add_file_dependencies( ${f} ${TABLEGEN_OUTPUT} )
52 if( MSVC_IDE OR XCODE )
53 # This adds .td and .h files to the Visual Studio solution:
54 add_td_sources(sources)
55 add_header_files(sources)
56 set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
57 list(APPEND sources ${ARG_ADDITIONAL_HEADERS})
60 # Set common compiler options:
61 if( NOT LLVM_REQUIRES_EH )
62 if( LLVM_COMPILER_IS_GCC_COMPATIBLE )
63 add_definitions( -fno-exceptions )
65 llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/EHsc" "/EHs-c-")
66 add_definitions( /D_HAS_EXCEPTIONS=0 )
69 if( NOT LLVM_REQUIRES_RTTI )
70 if( LLVM_COMPILER_IS_GCC_COMPATIBLE )
71 llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti")
73 llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-")
77 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE )
78 set( ${OUT_VAR} ${sources} PARENT_SCOPE )
79 endfunction(llvm_process_sources)
82 function(llvm_check_source_file_list)
84 file(GLOB globbed *.cpp)
86 get_filename_component(fn ${g} NAME)
87 list(FIND LLVM_OPTIONAL_SOURCES ${fn} idx)
89 list(FIND listed ${fn} idx)
91 message(SEND_ERROR "Found unknown source file ${g}
92 Please update ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt\n")
96 endfunction(llvm_check_source_file_list)