llvm.org GIT mirror llvm / d538e24
Changes for building Clang and others using LLVM as an external library. Installs tblgen (required by Clang). Translates handling of user settings and platform-dependant options to its own file, where it can included by another project. Installs the .cmake files required by projects like Clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124816 91177308-0d34-0410-b5e6-96231b3b80d8 Oscar Fuentes 8 years ago
7 changed file(s) with 187 addition(s) and 158 deletion(s). Raw diff Collapse all Expand all
132132
133133 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
134134
135 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
136 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
137 else()
138 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
139 endif()
140
141 if( LLVM_ENABLE_ASSERTIONS )
142 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
143 if( NOT MSVC )
144 add_definitions( -D_DEBUG )
145 endif()
146 # On Release builds cmake automatically defines NDEBUG, so we
147 # explicitly undefine it:
148 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
149 add_definitions( -UNDEBUG )
150 endif()
151 else()
152 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
153 add_definitions( -DNDEBUG )
154 endif()
155 endif()
156
157135 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
158136 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
159137 endif()
179157
180158 include(AddLLVMDefinitions)
181159
182 if(WIN32)
183 if(CYGWIN)
184 set(LLVM_ON_WIN32 0)
185 set(LLVM_ON_UNIX 1)
186 else(CYGWIN)
187 set(LLVM_ON_WIN32 1)
188 set(LLVM_ON_UNIX 0)
189 endif(CYGWIN)
190 set(LTDL_SHLIB_EXT ".dll")
191 set(EXEEXT ".exe")
192 # Maximum path length is 160 for non-unicode paths
193 set(MAXPATHLEN 160)
194 else(WIN32)
195 if(UNIX)
196 set(LLVM_ON_WIN32 0)
197 set(LLVM_ON_UNIX 1)
198 if(APPLE)
199 set(LTDL_SHLIB_EXT ".dylib")
200 else(APPLE)
201 set(LTDL_SHLIB_EXT ".so")
202 endif(APPLE)
203 set(EXEEXT "")
204 # FIXME: Maximum path length is currently set to 'safe' fixed value
205 set(MAXPATHLEN 2024)
206 else(UNIX)
207 MESSAGE(SEND_ERROR "Unable to determine platform")
208 endif(UNIX)
209 endif(WIN32)
210
211160 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
212161
213 if( LLVM_ENABLE_PIC )
214 if( XCODE )
215 # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
216 # know how to disable this, so just force ENABLE_PIC off for now.
217 message(WARNING "-fPIC not supported with Xcode.")
218 elseif( WIN32 )
219 # On Windows all code is PIC. MinGW warns if -fPIC is used.
220 else()
221 include(CheckCXXCompilerFlag)
222 check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)
223 if( SUPPORTS_FPIC_FLAG )
224 message(STATUS "Building with -fPIC")
225 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
226 set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
227 else( SUPPORTS_FPIC_FLAG )
228 message(WARNING "-fPIC not supported.")
229 endif()
230 endif()
231 endif()
232
233162 include(config-ix)
163
164 include(HandleLLVMOptions)
165
166 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
167 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
168 else()
169 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
170 endif()
171
172 configure_file(
173 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
174 ${LLVM_BINARY_DIR}/include/llvm/Config/config.h)
175
176 configure_file(
177 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
178 ${LLVM_BINARY_DIR}/include/llvm/Config/llvm-config.h)
179
180 configure_file(
181 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
182 ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h)
234183
235184 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
236185 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
237186 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
238
239 # set(CMAKE_VERBOSE_MAKEFILE true)
240
241 add_llvm_definitions( -D__STDC_LIMIT_MACROS )
242 add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
243187
244188 # MSVC has a gazillion warnings with this.
245189 if( MSVC )
250194
251195 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
252196 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
253
254 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
255 # TODO: support other platforms and toolchains.
256 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
257 if( LLVM_BUILD_32_BITS )
258 message(STATUS "Building 32 bits executables and libraries.")
259 add_llvm_definitions( -m32 )
260 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
261 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
262 endif( LLVM_BUILD_32_BITS )
263 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
264
265 if( MSVC )
266 include(ChooseMSVCCRT)
267
268 # Add definitions that make MSVC much less annoying.
269 add_llvm_definitions(
270 # For some reason MS wants to deprecate a bunch of standard functions...
271 -D_CRT_SECURE_NO_DEPRECATE
272 -D_CRT_SECURE_NO_WARNINGS
273 -D_CRT_NONSTDC_NO_DEPRECATE
274 -D_CRT_NONSTDC_NO_WARNINGS
275 -D_SCL_SECURE_NO_DEPRECATE
276 -D_SCL_SECURE_NO_WARNINGS
277
278 -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
279 -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
280 -wd4224 # Suppress 'nonstandard extension used : formal parameter 'identifier' was previously defined as a type'
281 -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
282 -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
283 -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
284 -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
285 -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
286 -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
287 -wd4355 # Suppress ''this' : used in base member initializer list'
288 -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
289 -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
290 -wd4715 # Suppress ''function' : not all control paths return a value'
291 -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
292 -wd4065 # Suppress 'switch statement contains 'default' but no 'case' labels'
293
294 -w14062 # Promote "enumerator in switch of enum is not handled" to level 1 warning.
295 )
296
297 # Enable warnings
298 if (LLVM_ENABLE_WARNINGS)
299 add_llvm_definitions( /W4 /Wall )
300 if (LLVM_ENABLE_PEDANTIC)
301 # No MSVC equivalent available
302 endif (LLVM_ENABLE_PEDANTIC)
303 endif (LLVM_ENABLE_WARNINGS)
304 if (LLVM_ENABLE_WERROR)
305 add_llvm_definitions( /WX )
306 endif (LLVM_ENABLE_WERROR)
307 elseif( CMAKE_COMPILER_IS_GNUCXX )
308 if (LLVM_ENABLE_WARNINGS)
309 add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings )
310 if (LLVM_ENABLE_PEDANTIC)
311 add_llvm_definitions( -pedantic -Wno-long-long )
312 endif (LLVM_ENABLE_PEDANTIC)
313 endif (LLVM_ENABLE_WARNINGS)
314 if (LLVM_ENABLE_WERROR)
315 add_llvm_definitions( -Werror )
316 endif (LLVM_ENABLE_WERROR)
317 endif( MSVC )
318197
319198 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
320199
356356 endif()
357357
358358 set(LLVM_PREFIX ${CMAKE_INSTALL_PREFIX})
359
360 configure_file(
361 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
362 ${LLVM_BINARY_DIR}/include/llvm/Config/config.h
363 )
364
365 configure_file(
366 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
367 ${LLVM_BINARY_DIR}/include/llvm/Config/llvm-config.h
368 )
369
370 configure_file(
371 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
372 ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h
373 )
374
99 LLVMConfig.cmake
1010 LLVMLibDeps.cmake
1111 DESTINATION share/llvm/cmake)
12
13 install(DIRECTORY .
14 DESTINATION share/llvm/cmake
15 PATTERN *.cmake
16 PATTERN LLVM.cmake EXCLUDE
17 PATTERN LLVMConfig.cmake EXCLUDE
18 PATTERN LLVMLibDeps.cmake EXCLUDE
19 PATTERN FindBison.cmake EXCLUDE
20 PATTERN GetTargetTriple.cmake EXCLUDE
21 PATTERN VersionFromVCS.cmake EXCLUDE
22 PATTERN CheckAtomic.cmake EXCLUDE)
23
24 install(FILES
25 ${llvm_cmake_builddir}/LLVM.cmake
26 LLVMConfig.cmake
27 LLVMLibDeps.cmake
28 DESTINATION share/llvm/cmake)
0 include(AddLLVMDefinitions)
1
2 if( LLVM_ENABLE_ASSERTIONS )
3 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
4 if( NOT MSVC )
5 add_definitions( -D_DEBUG )
6 endif()
7 # On Release builds cmake automatically defines NDEBUG, so we
8 # explicitly undefine it:
9 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
10 add_definitions( -UNDEBUG )
11 endif()
12 else()
13 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
14 add_definitions( -DNDEBUG )
15 endif()
16 endif()
17
18 if(WIN32)
19 if(CYGWIN)
20 set(LLVM_ON_WIN32 0)
21 set(LLVM_ON_UNIX 1)
22 else(CYGWIN)
23 set(LLVM_ON_WIN32 1)
24 set(LLVM_ON_UNIX 0)
25 endif(CYGWIN)
26 set(LTDL_SHLIB_EXT ".dll")
27 set(EXEEXT ".exe")
28 # Maximum path length is 160 for non-unicode paths
29 set(MAXPATHLEN 160)
30 else(WIN32)
31 if(UNIX)
32 set(LLVM_ON_WIN32 0)
33 set(LLVM_ON_UNIX 1)
34 if(APPLE)
35 set(LTDL_SHLIB_EXT ".dylib")
36 else(APPLE)
37 set(LTDL_SHLIB_EXT ".so")
38 endif(APPLE)
39 set(EXEEXT "")
40 # FIXME: Maximum path length is currently set to 'safe' fixed value
41 set(MAXPATHLEN 2024)
42 else(UNIX)
43 MESSAGE(SEND_ERROR "Unable to determine platform")
44 endif(UNIX)
45 endif(WIN32)
46
47 if( LLVM_ENABLE_PIC )
48 if( XCODE )
49 # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
50 # know how to disable this, so just force ENABLE_PIC off for now.
51 message(WARNING "-fPIC not supported with Xcode.")
52 elseif( WIN32 )
53 # On Windows all code is PIC. MinGW warns if -fPIC is used.
54 else()
55 include(CheckCXXCompilerFlag)
56 check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)
57 if( SUPPORTS_FPIC_FLAG )
58 message(STATUS "Building with -fPIC")
59 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
60 set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
61 else( SUPPORTS_FPIC_FLAG )
62 message(WARNING "-fPIC not supported.")
63 endif()
64 endif()
65 endif()
66
67 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
68 # TODO: support other platforms and toolchains.
69 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
70 if( LLVM_BUILD_32_BITS )
71 message(STATUS "Building 32 bits executables and libraries.")
72 add_llvm_definitions( -m32 )
73 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
74 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
75 endif( LLVM_BUILD_32_BITS )
76 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
77
78 if( MSVC )
79 include(ChooseMSVCCRT)
80
81 # Add definitions that make MSVC much less annoying.
82 add_llvm_definitions(
83 # For some reason MS wants to deprecate a bunch of standard functions...
84 -D_CRT_SECURE_NO_DEPRECATE
85 -D_CRT_SECURE_NO_WARNINGS
86 -D_CRT_NONSTDC_NO_DEPRECATE
87 -D_CRT_NONSTDC_NO_WARNINGS
88 -D_SCL_SECURE_NO_DEPRECATE
89 -D_SCL_SECURE_NO_WARNINGS
90
91 -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
92 -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
93 -wd4224 # Suppress 'nonstandard extension used : formal parameter 'identifier' was previously defined as a type'
94 -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
95 -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
96 -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
97 -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
98 -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
99 -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
100 -wd4355 # Suppress ''this' : used in base member initializer list'
101 -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
102 -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
103 -wd4715 # Suppress ''function' : not all control paths return a value'
104 -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
105 -wd4065 # Suppress 'switch statement contains 'default' but no 'case' labels'
106
107 -w14062 # Promote "enumerator in switch of enum is not handled" to level 1 warning.
108 )
109
110 # Enable warnings
111 if (LLVM_ENABLE_WARNINGS)
112 add_llvm_definitions( /W4 /Wall )
113 if (LLVM_ENABLE_PEDANTIC)
114 # No MSVC equivalent available
115 endif (LLVM_ENABLE_PEDANTIC)
116 endif (LLVM_ENABLE_WARNINGS)
117 if (LLVM_ENABLE_WERROR)
118 add_llvm_definitions( /WX )
119 endif (LLVM_ENABLE_WERROR)
120 elseif( CMAKE_COMPILER_IS_GNUCXX )
121 if (LLVM_ENABLE_WARNINGS)
122 add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings )
123 if (LLVM_ENABLE_PEDANTIC)
124 add_llvm_definitions( -pedantic -Wno-long-long )
125 endif (LLVM_ENABLE_PEDANTIC)
126 endif (LLVM_ENABLE_WARNINGS)
127 if (LLVM_ENABLE_WERROR)
128 add_llvm_definitions( -Werror )
129 endif (LLVM_ENABLE_WERROR)
130 endif( MSVC )
131
132 add_llvm_definitions( -D__STDC_LIMIT_MACROS )
133 add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
134
0 # This file provides information and services to the final user.
1
2 set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@)
13
24 set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@)
35
1517
1618 set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@)
1719
20 set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
21
22 set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS)
23
24 set(HAVE_LIBDL @HAVE_LIBDL@)
25 set(HAVE_LIBPTHREAD @HAVE_LIBPTHREAD)
26
1827 # We try to include using the current setting of CMAKE_MODULE_PATH,
1928 # which suppossedly was filled by the user with the directory where
2029 # this file was installed:
2020 # The file in LLVM_TARGET_DEFINITIONS may be not in the current
2121 # directory and local_tds may not contain it, so we must
2222 # explicitly list it here:
23 DEPENDS tblgen ${local_tds} ${global_tds} ${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
23 DEPENDS ${LLVM_TABLEGEN_EXE} ${local_tds} ${global_tds}
24 ${LLVM_TARGET_DEFINITIONS_ABSOLUTE}
2425 COMMENT "Building ${ofn}..."
2526 )
2627 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
0 set(LLVM_REQUIRES_EH 1)
11 set(LLVM_REQUIRES_RTTI 1)
2
3 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
24
35 add_executable(tblgen
46 ARMDecoderEmitter.cpp
4749 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD AND NOT BEOS )
4850 target_link_libraries(tblgen pthread)
4951 endif()
52
53 install(TARGETS tblgen RUNTIME DESTINATION bin)