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)
32 file(GLOB hds *.h *.def)
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 set( sources ${ARGN} )
42 llvm_check_source_file_list( ${sources} )
43 # Create file dependencies on the tablegenned files, if any. Seems
44 # that this is not strictly needed, as dependencies of the .cpp
45 # sources on the tablegenned .inc files are detected and handled,
47 foreach( s ${sources} )
48 set( f ${CMAKE_CURRENT_SOURCE_DIR}/${s} )
49 add_file_dependencies( ${f} ${TABLEGEN_OUTPUT} )
52 # This adds .td and .h files to the Visual Studio solution:
53 add_td_sources(sources)
54 add_header_files(sources)
57 # Set common compiler options:
58 if( NOT LLVM_REQUIRES_EH )
59 if( CMAKE_COMPILER_IS_GNUCXX )
60 add_definitions( -fno-exceptions )
62 llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/EHsc" "/EHs-c-")
63 add_definitions( /D_HAS_EXCEPTIONS=0 )
66 if( NOT LLVM_REQUIRES_RTTI )
67 if( CMAKE_COMPILER_IS_GNUCXX )
68 llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti")
70 llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-")
74 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE )
75 set( ${OUT_VAR} ${sources} PARENT_SCOPE )
76 endfunction(llvm_process_sources)
79 function(llvm_check_source_file_list)
81 file(GLOB globbed *.cpp)
83 get_filename_component(fn ${g} NAME)
84 list(FIND listed ${fn} idx)
86 message(SEND_ERROR "Found unknown source file ${g}
87 Please update ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt\n")
90 endfunction(llvm_check_source_file_list)