blob: 6154fdb66f1d21c29dabfb021adcfcd34e8f9a82 [file] [log] [blame]
Douglas Gregor7f7b7482009-08-23 05:28:29 +00001# Clang version information
Douglas Gregor34d9ffa2009-09-16 21:59:05 +00002
3# Make sure that CMake reconfigures when the version changes.
4configure_file(
5 ${CMAKE_CURRENT_SOURCE_DIR}/VER
6 ${CMAKE_CURRENT_BINARY_DIR}/VER)
7
Daniel Dunbar91ee77a2009-09-17 00:07:10 +00008set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
10
Chandler Carruth63e9c0d2010-04-17 20:12:02 +000011if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
12 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
13"the makefiles distributed with LLVM. Please create a directory and run cmake "
14"from there, passing the path to this source directory as the last argument. "
15"This process created the file `CMakeCache.txt' and the directory "
16"`CMakeFiles'. Please delete them.")
17endif()
18
19if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
20 file(GLOB_RECURSE
21 tablegenned_files_on_include_dir
22 "${CLANG_SOURCE_DIR}/include/clang/*.inc")
23 if( tablegenned_files_on_include_dir )
24 message(FATAL_ERROR "Apparently there is a previous in-source build, "
25"probably as the result of running `configure' and `make' on "
26"${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n"
27"${tablegenned_files_on_include_dir}\nPlease clean the source directory.")
28 endif()
29endif()
30
Douglas Gregor34d9ffa2009-09-16 21:59:05 +000031# Compute the Clang version from the contents of VER
32file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VER CLANG_VERSION_DATA)
33string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
34 ${CLANG_VERSION_DATA})
35message(STATUS "Clang version: ${CLANG_VERSION}")
Douglas Gregor7f7b7482009-08-23 05:28:29 +000036
Daniel Dunbara5107672010-06-25 17:33:46 +000037string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
38 ${CLANG_VERSION})
39string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
40 ${CLANG_VERSION})
41if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
42 set(CLANG_HAS_VERSION_PATCHLEVEL 1)
43 string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" CLANG_VERSION_PATCHLEVEL
44 ${CLANG_VERSION})
45else()
46 set(CLANG_HAS_VERSION_PATCHLEVEL 0)
47endif()
48
49# Configure the Version.inc file.
50configure_file(
51 ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
52 ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
53
Douglas Gregor9df3faf2009-09-18 14:47:57 +000054# Add appropriate flags for GCC
55if (CMAKE_COMPILER_IS_GNUCXX)
56 # FIXME: Turn off exceptions, RTTI:
57 # -fno-exceptions -fno-rtti
58 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
59endif ()
60
Douglas Gregoreb5dc492010-06-08 19:23:49 +000061if (APPLE)
62 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
63endif ()
64
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +000065macro(add_clang_library name)
Cedric Venetfe2f8082008-11-02 16:28:53 +000066 set(srcs ${ARGN})
Ted Kremenekbf5de3f2009-03-25 20:34:07 +000067 if(MSVC_IDE OR XCODE)
Douglas Gregorf5216f22009-06-17 18:31:02 +000068 file( GLOB_RECURSE headers *.h *.td *.def)
Cedric Venetfe2f8082008-11-02 16:28:53 +000069 set(srcs ${srcs} ${headers})
70 string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
71 list( GET split_path -1 dir)
Douglas Gregorf5216f22009-06-17 18:31:02 +000072 file( GLOB_RECURSE headers
73 ../../include/clang${dir}/*.h
74 ../../include/clang${dir}/*.td
75 ../../include/clang${dir}/*.def)
Cedric Venetfe2f8082008-11-02 16:28:53 +000076 set(srcs ${srcs} ${headers})
Ted Kremenekbf5de3f2009-03-25 20:34:07 +000077 endif(MSVC_IDE OR XCODE)
Douglas Gregoreb5dc492010-06-08 19:23:49 +000078 if (MODULE)
79 set(libkind MODULE)
80 elseif (SHARED_LIBRARY)
Douglas Gregorac47bc72009-09-25 06:35:15 +000081 set(libkind SHARED)
82 else()
83 set(libkind)
84 endif()
85 add_library( ${name} ${libkind} ${srcs} )
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +000086 if( LLVM_COMMON_DEPENDS )
87 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
88 endif( LLVM_COMMON_DEPENDS )
Douglas Gregorac47bc72009-09-25 06:35:15 +000089 if( LLVM_USED_LIBS )
90 foreach(lib ${LLVM_USED_LIBS})
91 target_link_libraries( ${name} ${lib} )
92 endforeach(lib)
93 endif( LLVM_USED_LIBS )
Benjamin Kramerbd785542009-10-11 12:22:00 +000094 if( LLVM_LINK_COMPONENTS )
95 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
96 endif( LLVM_LINK_COMPONENTS )
97 get_system_libs(llvm_system_libs)
98 if( llvm_system_libs )
99 target_link_libraries(${name} ${llvm_system_libs})
100 endif( llvm_system_libs )
Douglas Gregora393e9e2009-03-16 23:06:59 +0000101 add_dependencies(${name} ClangDiagnosticCommon)
Cedric Venet1c212a02008-12-13 11:00:04 +0000102 if(MSVC)
103 get_target_property(cflag ${name} COMPILE_FLAGS)
104 if(NOT cflag)
105 set(cflag "")
106 endif(NOT cflag)
107 set(cflag "${cflag} /Za")
108 set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
109 endif(MSVC)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000110 install(TARGETS ${name}
Oscar Fuentesbfb06ea2009-10-27 19:42:21 +0000111 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
Oscar Fuentes755f3df2009-06-12 02:54:12 +0000112 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000113endmacro(add_clang_library)
114
115macro(add_clang_executable name)
Cedric Venetfe2f8082008-11-02 16:28:53 +0000116 set(srcs ${ARGN})
117 if(MSVC_IDE)
Douglas Gregorf5216f22009-06-17 18:31:02 +0000118 file( GLOB_RECURSE headers *.h *.td *.def)
Cedric Venetfe2f8082008-11-02 16:28:53 +0000119 set(srcs ${srcs} ${headers})
120 endif(MSVC_IDE)
121 add_llvm_executable( ${name} ${srcs} )
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000122endmacro(add_clang_executable)
123
124include_directories(
125 ${CMAKE_CURRENT_SOURCE_DIR}/include
Douglas Gregora393e9e2009-03-16 23:06:59 +0000126 ${CMAKE_CURRENT_BINARY_DIR}/include
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000127 )
128
Oscar Fuentes82cac292009-10-27 19:59:34 +0000129install(DIRECTORY include/
130 DESTINATION include
131 FILES_MATCHING
132 PATTERN "*.def"
133 PATTERN "*.h"
134 PATTERN "*.td"
Chris Lattnerbc6ec752008-11-11 18:39:10 +0000135 PATTERN ".svn" EXCLUDE
136 )
137
Kovarththanan Rajaratnamec700a62010-04-01 14:24:41 +0000138install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
139 DESTINATION include
140 FILES_MATCHING
Chris Lattnerd7d5bb12010-04-25 04:59:35 +0000141 PATTERN "CMakeFiles" EXCLUDE
Kovarththanan Rajaratnamec700a62010-04-01 14:24:41 +0000142 PATTERN "*.inc"
143 )
144
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000145add_definitions( -D_GNU_SOURCE )
146
Daniel Dunbar45088e22009-11-17 09:32:51 +0000147option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
148if(CLANG_BUILD_EXAMPLES)
149 add_subdirectory(examples)
150endif ()
151
Douglas Gregora393e9e2009-03-16 23:06:59 +0000152add_subdirectory(include)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000153add_subdirectory(lib)
Daniel Dunbarcbcd98b2009-03-24 02:52:57 +0000154add_subdirectory(tools)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000155
156# TODO: docs.
Douglas Gregor291fbde2009-09-15 22:30:13 +0000157add_subdirectory(test)
158