1 include(AddFileDependencies)
3 macro(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( "${${var}}" MATCHES "(^| )${old}($| )" )
8 string( REGEX REPLACE "(^| )${old}($| )" " ${new} " ${var} "${${var}}" )
10 set( ${var} "${${var}} ${new}" )
12 endmacro(llvm_replace_compiler_option)
14 macro(add_td_sources srcs)
17 source_group("TableGen descriptions" FILES ${tds})
18 set_source_files_properties(${tds} PROPERTIES HEADER_FILE_ONLY ON)
19 list(APPEND ${srcs} ${tds})
21 endmacro(add_td_sources)
24 macro(add_header_files srcs)
25 file(GLOB hds *.h *.def)
27 set_source_files_properties(${hds} PROPERTIES HEADER_FILE_ONLY ON)
28 list(APPEND ${srcs} ${hds})
30 endmacro(add_header_files)
33 function(llvm_process_sources OUT_VAR)
34 set( sources ${ARGN} )
35 llvm_check_source_file_list( ${sources} )
36 # Create file dependencies on the tablegenned files, if any. Seems
37 # that this is not strictly needed, as dependencies of the .cpp
38 # sources on the tablegenned .inc files are detected and handled,
40 foreach( s ${sources} )
41 set( f ${CMAKE_CURRENT_SOURCE_DIR}/${s} )
42 add_file_dependencies( ${f} ${TABLEGEN_OUTPUT} )
45 # This adds .td and .h files to the Visual Studio solution:
46 add_td_sources(sources)
47 add_header_files(sources)
50 # Set common compiler options:
51 if( NOT LLVM_REQUIRES_EH )
52 if( CMAKE_COMPILER_IS_GNUCXX )
53 add_definitions( -fno-exceptions )
55 string( REGEX REPLACE "[ ^]/EHsc ?" " /EHs-c- " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
56 add_definitions( /D_HAS_EXCEPTIONS=0 )
59 if( NOT LLVM_REQUIRES_RTTI )
60 if( CMAKE_COMPILER_IS_GNUCXX )
61 add_definitions( -fno-rtti )
63 string( REGEX REPLACE "[ ^]/GR ?" " /GR- " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
67 set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE )
68 set( ${OUT_VAR} ${sources} PARENT_SCOPE )
69 endfunction(llvm_process_sources)
72 function(llvm_check_source_file_list)
74 file(GLOB globbed *.cpp)
76 get_filename_component(fn ${g} NAME)
77 list(FIND listed ${fn} idx)
79 message(SEND_ERROR "Found unknown source file ${g}
80 Please update ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt\n")
83 endfunction(llvm_check_source_file_list)