Oscar Fuentes | d538e24 | 2011-02-03 20:57:36 +0000 | [diff] [blame^] | 1 | include(AddLLVMDefinitions) |
| 2 | |
| 3 | if( LLVM_ENABLE_ASSERTIONS ) |
| 4 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
| 5 | if( NOT MSVC ) |
| 6 | add_definitions( -D_DEBUG ) |
| 7 | endif() |
| 8 | # On Release builds cmake automatically defines NDEBUG, so we |
| 9 | # explicitly undefine it: |
| 10 | if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" ) |
| 11 | add_definitions( -UNDEBUG ) |
| 12 | endif() |
| 13 | else() |
| 14 | if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" ) |
| 15 | add_definitions( -DNDEBUG ) |
| 16 | endif() |
| 17 | endif() |
| 18 | |
| 19 | if(WIN32) |
| 20 | if(CYGWIN) |
| 21 | set(LLVM_ON_WIN32 0) |
| 22 | set(LLVM_ON_UNIX 1) |
| 23 | else(CYGWIN) |
| 24 | set(LLVM_ON_WIN32 1) |
| 25 | set(LLVM_ON_UNIX 0) |
| 26 | endif(CYGWIN) |
| 27 | set(LTDL_SHLIB_EXT ".dll") |
| 28 | set(EXEEXT ".exe") |
| 29 | # Maximum path length is 160 for non-unicode paths |
| 30 | set(MAXPATHLEN 160) |
| 31 | else(WIN32) |
| 32 | if(UNIX) |
| 33 | set(LLVM_ON_WIN32 0) |
| 34 | set(LLVM_ON_UNIX 1) |
| 35 | if(APPLE) |
| 36 | set(LTDL_SHLIB_EXT ".dylib") |
| 37 | else(APPLE) |
| 38 | set(LTDL_SHLIB_EXT ".so") |
| 39 | endif(APPLE) |
| 40 | set(EXEEXT "") |
| 41 | # FIXME: Maximum path length is currently set to 'safe' fixed value |
| 42 | set(MAXPATHLEN 2024) |
| 43 | else(UNIX) |
| 44 | MESSAGE(SEND_ERROR "Unable to determine platform") |
| 45 | endif(UNIX) |
| 46 | endif(WIN32) |
| 47 | |
| 48 | if( LLVM_ENABLE_PIC ) |
| 49 | if( XCODE ) |
| 50 | # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't |
| 51 | # know how to disable this, so just force ENABLE_PIC off for now. |
| 52 | message(WARNING "-fPIC not supported with Xcode.") |
| 53 | elseif( WIN32 ) |
| 54 | # On Windows all code is PIC. MinGW warns if -fPIC is used. |
| 55 | else() |
| 56 | include(CheckCXXCompilerFlag) |
| 57 | check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG) |
| 58 | if( SUPPORTS_FPIC_FLAG ) |
| 59 | message(STATUS "Building with -fPIC") |
| 60 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") |
| 61 | set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") |
| 62 | else( SUPPORTS_FPIC_FLAG ) |
| 63 | message(WARNING "-fPIC not supported.") |
| 64 | endif() |
| 65 | endif() |
| 66 | endif() |
| 67 | |
| 68 | if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 69 | # TODO: support other platforms and toolchains. |
| 70 | option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF) |
| 71 | if( LLVM_BUILD_32_BITS ) |
| 72 | message(STATUS "Building 32 bits executables and libraries.") |
| 73 | add_llvm_definitions( -m32 ) |
| 74 | list(APPEND CMAKE_EXE_LINKER_FLAGS -m32) |
| 75 | list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32) |
| 76 | endif( LLVM_BUILD_32_BITS ) |
| 77 | endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 78 | |
| 79 | if( MSVC ) |
| 80 | include(ChooseMSVCCRT) |
| 81 | |
| 82 | # Add definitions that make MSVC much less annoying. |
| 83 | add_llvm_definitions( |
| 84 | # For some reason MS wants to deprecate a bunch of standard functions... |
| 85 | -D_CRT_SECURE_NO_DEPRECATE |
| 86 | -D_CRT_SECURE_NO_WARNINGS |
| 87 | -D_CRT_NONSTDC_NO_DEPRECATE |
| 88 | -D_CRT_NONSTDC_NO_WARNINGS |
| 89 | -D_SCL_SECURE_NO_DEPRECATE |
| 90 | -D_SCL_SECURE_NO_WARNINGS |
| 91 | |
| 92 | -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned' |
| 93 | -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored' |
| 94 | -wd4224 # Suppress 'nonstandard extension used : formal parameter 'identifier' was previously defined as a type' |
| 95 | -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data' |
| 96 | -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data' |
| 97 | -wd4275 # Suppress 'An exported class was derived from a class that was not exported.' |
| 98 | -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception' |
| 99 | -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized' |
| 100 | -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized' |
| 101 | -wd4355 # Suppress ''this' : used in base member initializer list' |
| 102 | -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated' |
| 103 | -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible' |
| 104 | -wd4715 # Suppress ''function' : not all control paths return a value' |
| 105 | -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)' |
| 106 | -wd4065 # Suppress 'switch statement contains 'default' but no 'case' labels' |
| 107 | |
| 108 | -w14062 # Promote "enumerator in switch of enum is not handled" to level 1 warning. |
| 109 | ) |
| 110 | |
| 111 | # Enable warnings |
| 112 | if (LLVM_ENABLE_WARNINGS) |
| 113 | add_llvm_definitions( /W4 /Wall ) |
| 114 | if (LLVM_ENABLE_PEDANTIC) |
| 115 | # No MSVC equivalent available |
| 116 | endif (LLVM_ENABLE_PEDANTIC) |
| 117 | endif (LLVM_ENABLE_WARNINGS) |
| 118 | if (LLVM_ENABLE_WERROR) |
| 119 | add_llvm_definitions( /WX ) |
| 120 | endif (LLVM_ENABLE_WERROR) |
| 121 | elseif( CMAKE_COMPILER_IS_GNUCXX ) |
| 122 | if (LLVM_ENABLE_WARNINGS) |
| 123 | add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings ) |
| 124 | if (LLVM_ENABLE_PEDANTIC) |
| 125 | add_llvm_definitions( -pedantic -Wno-long-long ) |
| 126 | endif (LLVM_ENABLE_PEDANTIC) |
| 127 | endif (LLVM_ENABLE_WARNINGS) |
| 128 | if (LLVM_ENABLE_WERROR) |
| 129 | add_llvm_definitions( -Werror ) |
| 130 | endif (LLVM_ENABLE_WERROR) |
| 131 | endif( MSVC ) |
| 132 | |
| 133 | add_llvm_definitions( -D__STDC_LIMIT_MACROS ) |
| 134 | add_llvm_definitions( -D__STDC_CONSTANT_MACROS ) |
| 135 | |