Oscar Fuentes | 1bbdd46 | 2008-11-14 22:06:14 +0000 | [diff] [blame] | 1 | include(AddFileDependencies) |
| 2 | |
Oscar Fuentes | 927d8ae | 2011-01-11 12:31:34 +0000 | [diff] [blame] | 3 | function(llvm_replace_compiler_option var old new) |
Oscar Fuentes | 53bf3ee | 2011-01-07 20:31:03 +0000 | [diff] [blame] | 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") |
Oscar Fuentes | 927d8ae | 2011-01-11 12:31:34 +0000 | [diff] [blame] | 7 | # If the option already is on the variable, don't add it: |
| 8 | if( "${${var}}" MATCHES "(^| )${new}($| )" ) |
| 9 | set(n "") |
Oscar Fuentes | 53bf3ee | 2011-01-07 20:31:03 +0000 | [diff] [blame] | 10 | else() |
Oscar Fuentes | 927d8ae | 2011-01-11 12:31:34 +0000 | [diff] [blame] | 11 | set(n "${new}") |
Oscar Fuentes | 53bf3ee | 2011-01-07 20:31:03 +0000 | [diff] [blame] | 12 | endif() |
Oscar Fuentes | 927d8ae | 2011-01-11 12:31:34 +0000 | [diff] [blame] | 13 | if( "${${var}}" MATCHES "(^| )${old}($| )" ) |
| 14 | string( REGEX REPLACE "(^| )${old}($| )" " ${n} " ${var} "${${var}}" ) |
| 15 | else() |
| 16 | set( ${var} "${${var}} ${n}" ) |
| 17 | endif() |
| 18 | set( ${var} "${${var}}" PARENT_SCOPE ) |
| 19 | endfunction(llvm_replace_compiler_option) |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 20 | |
| 21 | macro(add_td_sources srcs) |
| 22 | file(GLOB tds *.td) |
| 23 | if( tds ) |
| 24 | source_group("TableGen descriptions" FILES ${tds}) |
| 25 | set_source_files_properties(${tds} PROPERTIES HEADER_FILE_ONLY ON) |
| 26 | list(APPEND ${srcs} ${tds}) |
| 27 | endif() |
| 28 | endmacro(add_td_sources) |
| 29 | |
| 30 | |
| 31 | macro(add_header_files srcs) |
NAKAMURA Takumi | b253451 | 2012-06-24 03:50:58 +0000 | [diff] [blame] | 32 | file(GLOB hds *.h) |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 33 | if( hds ) |
| 34 | set_source_files_properties(${hds} PROPERTIES HEADER_FILE_ONLY ON) |
| 35 | list(APPEND ${srcs} ${hds}) |
| 36 | endif() |
| 37 | endmacro(add_header_files) |
| 38 | |
| 39 | |
| 40 | function(llvm_process_sources OUT_VAR) |
Oscar Fuentes | 1bbdd46 | 2008-11-14 22:06:14 +0000 | [diff] [blame] | 41 | set( sources ${ARGN} ) |
Oscar Fuentes | d442ab8 | 2009-11-02 19:11:03 +0000 | [diff] [blame] | 42 | llvm_check_source_file_list( ${sources} ) |
Oscar Fuentes | 1bbdd46 | 2008-11-14 22:06:14 +0000 | [diff] [blame] | 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, |
| 46 | # but just in case... |
| 47 | foreach( s ${sources} ) |
| 48 | set( f ${CMAKE_CURRENT_SOURCE_DIR}/${s} ) |
| 49 | add_file_dependencies( ${f} ${TABLEGEN_OUTPUT} ) |
| 50 | endforeach(s) |
Jordan Rose | e8e6b6b | 2012-10-23 21:36:55 +0000 | [diff] [blame] | 51 | if( MSVC_IDE OR XCODE ) |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 52 | # This adds .td and .h files to the Visual Studio solution: |
NAKAMURA Takumi | b253451 | 2012-06-24 03:50:58 +0000 | [diff] [blame] | 53 | # FIXME: Shall we handle *.def here? |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 54 | add_td_sources(sources) |
| 55 | add_header_files(sources) |
| 56 | endif() |
Oscar Fuentes | f0c55a9 | 2010-10-17 02:26:16 +0000 | [diff] [blame] | 57 | |
| 58 | # Set common compiler options: |
| 59 | if( NOT LLVM_REQUIRES_EH ) |
Oscar Fuentes | 104e992 | 2011-05-11 13:53:08 +0000 | [diff] [blame] | 60 | if( LLVM_COMPILER_IS_GCC_COMPATIBLE ) |
Oscar Fuentes | f0c55a9 | 2010-10-17 02:26:16 +0000 | [diff] [blame] | 61 | add_definitions( -fno-exceptions ) |
Francois Pichet | b361452 | 2010-12-04 14:30:22 +0000 | [diff] [blame] | 62 | elseif( MSVC ) |
Oscar Fuentes | 927d8ae | 2011-01-11 12:31:34 +0000 | [diff] [blame] | 63 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/EHsc" "/EHs-c-") |
Francois Pichet | b361452 | 2010-12-04 14:30:22 +0000 | [diff] [blame] | 64 | add_definitions( /D_HAS_EXCEPTIONS=0 ) |
Oscar Fuentes | f0c55a9 | 2010-10-17 02:26:16 +0000 | [diff] [blame] | 65 | endif() |
| 66 | endif() |
| 67 | if( NOT LLVM_REQUIRES_RTTI ) |
Oscar Fuentes | 104e992 | 2011-05-11 13:53:08 +0000 | [diff] [blame] | 68 | if( LLVM_COMPILER_IS_GCC_COMPATIBLE ) |
Oscar Fuentes | 927d8ae | 2011-01-11 12:31:34 +0000 | [diff] [blame] | 69 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti") |
Francois Pichet | a785a6b | 2010-12-04 09:42:30 +0000 | [diff] [blame] | 70 | elseif( MSVC ) |
Oscar Fuentes | 927d8ae | 2011-01-11 12:31:34 +0000 | [diff] [blame] | 71 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-") |
Oscar Fuentes | f0c55a9 | 2010-10-17 02:26:16 +0000 | [diff] [blame] | 72 | endif() |
| 73 | endif() |
| 74 | |
Oscar Fuentes | 449d4e1 | 2011-01-02 12:30:18 +0000 | [diff] [blame] | 75 | set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE ) |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 76 | set( ${OUT_VAR} ${sources} PARENT_SCOPE ) |
Oscar Fuentes | 1bbdd46 | 2008-11-14 22:06:14 +0000 | [diff] [blame] | 77 | endfunction(llvm_process_sources) |
Oscar Fuentes | d442ab8 | 2009-11-02 19:11:03 +0000 | [diff] [blame] | 78 | |
| 79 | |
| 80 | function(llvm_check_source_file_list) |
| 81 | set(listed ${ARGN}) |
| 82 | file(GLOB globbed *.cpp) |
| 83 | foreach(g ${globbed}) |
| 84 | get_filename_component(fn ${g} NAME) |
Chandler Carruth | 7c888ee | 2012-06-21 09:51:26 +0000 | [diff] [blame] | 85 | list(FIND LLVM_OPTIONAL_SOURCES ${fn} idx) |
Oscar Fuentes | d442ab8 | 2009-11-02 19:11:03 +0000 | [diff] [blame] | 86 | if( idx LESS 0 ) |
Chandler Carruth | 7c888ee | 2012-06-21 09:51:26 +0000 | [diff] [blame] | 87 | list(FIND listed ${fn} idx) |
| 88 | if( idx LESS 0 ) |
| 89 | message(SEND_ERROR "Found unknown source file ${g} |
Oscar Fuentes | d442ab8 | 2009-11-02 19:11:03 +0000 | [diff] [blame] | 90 | Please update ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt\n") |
Chandler Carruth | 7c888ee | 2012-06-21 09:51:26 +0000 | [diff] [blame] | 91 | endif() |
Oscar Fuentes | d442ab8 | 2009-11-02 19:11:03 +0000 | [diff] [blame] | 92 | endif() |
| 93 | endforeach() |
| 94 | endfunction(llvm_check_source_file_list) |