1 include(AddLLVMDefinitions)
3 if( LLVM_ENABLE_ASSERTIONS )
4 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
6 add_definitions( -D_DEBUG )
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 )
14 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
15 add_definitions( -DNDEBUG )
27 set(LTDL_SHLIB_EXT ".dll")
29 # Maximum path length is 160 for non-unicode paths
36 set(LTDL_SHLIB_EXT ".dylib")
38 set(LTDL_SHLIB_EXT ".so")
41 # FIXME: Maximum path length is currently set to 'safe' fixed value
44 MESSAGE(SEND_ERROR "Unable to determine platform")
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.")
54 # On Windows all code is PIC. MinGW warns if -fPIC is used.
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.")
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 )
80 include(ChooseMSVCCRT)
82 # Add definitions that make MSVC much less annoying.
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
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'
108 -w14062 # Promote "enumerator in switch of enum is not handled" to level 1 warning.
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)
133 add_llvm_definitions( -D__STDC_LIMIT_MACROS )
134 add_llvm_definitions( -D__STDC_CONSTANT_MACROS )