blob: 2cc5a8142c8837eb7618cc66f22c8036dc65181e [file] [log] [blame]
Douglas Gregor7f7b7482009-08-23 05:28:29 +00001# Clang version information
Douglas Gregor34d9ffa2009-09-16 21:59:05 +00002
Daniel Dunbar91ee77a2009-09-17 00:07:10 +00003set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
4set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
5
Chandler Carruth63e9c0d2010-04-17 20:12:02 +00006if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
7 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
8"the makefiles distributed with LLVM. Please create a directory and run cmake "
9"from there, passing the path to this source directory as the last argument. "
10"This process created the file `CMakeCache.txt' and the directory "
11"`CMakeFiles'. Please delete them.")
12endif()
13
14if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
15 file(GLOB_RECURSE
16 tablegenned_files_on_include_dir
17 "${CLANG_SOURCE_DIR}/include/clang/*.inc")
18 if( tablegenned_files_on_include_dir )
19 message(FATAL_ERROR "Apparently there is a previous in-source build, "
20"probably as the result of running `configure' and `make' on "
21"${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n"
22"${tablegenned_files_on_include_dir}\nPlease clean the source directory.")
23 endif()
24endif()
25
Daniel Dunbarc4b8e922010-06-25 23:34:47 +000026# Compute the Clang version from the LLVM version.
Michael J. Spencer5a7f3492010-09-10 21:13:16 +000027string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
Daniel Dunbarc4b8e922010-06-25 23:34:47 +000028 ${PACKAGE_VERSION})
Douglas Gregor34d9ffa2009-09-16 21:59:05 +000029message(STATUS "Clang version: ${CLANG_VERSION}")
Douglas Gregor7f7b7482009-08-23 05:28:29 +000030
Daniel Dunbara5107672010-06-25 17:33:46 +000031string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
32 ${CLANG_VERSION})
33string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
34 ${CLANG_VERSION})
35if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
36 set(CLANG_HAS_VERSION_PATCHLEVEL 1)
37 string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" CLANG_VERSION_PATCHLEVEL
38 ${CLANG_VERSION})
39else()
40 set(CLANG_HAS_VERSION_PATCHLEVEL 0)
41endif()
42
43# Configure the Version.inc file.
44configure_file(
45 ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
46 ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
47
Douglas Gregor9df3faf2009-09-18 14:47:57 +000048# Add appropriate flags for GCC
49if (CMAKE_COMPILER_IS_GNUCXX)
Oscar Fuentes827c5732010-10-15 00:16:22 +000050 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
Douglas Gregor9df3faf2009-09-18 14:47:57 +000051endif ()
52
Douglas Gregoreb5dc492010-06-08 19:23:49 +000053if (APPLE)
54 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
55endif ()
56
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +000057macro(add_clang_library name)
Oscar Fuentes99174012011-01-03 17:00:02 +000058 llvm_process_sources(srcs ${ARGN})
Ted Kremenekbf5de3f2009-03-25 20:34:07 +000059 if(MSVC_IDE OR XCODE)
Cedric Venetfe2f8082008-11-02 16:28:53 +000060 string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
61 list( GET split_path -1 dir)
Michael J. Spencer5a7f3492010-09-10 21:13:16 +000062 file( GLOB_RECURSE headers
Douglas Gregorf5216f22009-06-17 18:31:02 +000063 ../../include/clang${dir}/*.h
64 ../../include/clang${dir}/*.td
65 ../../include/clang${dir}/*.def)
Cedric Venetfe2f8082008-11-02 16:28:53 +000066 set(srcs ${srcs} ${headers})
Ted Kremenekbf5de3f2009-03-25 20:34:07 +000067 endif(MSVC_IDE OR XCODE)
Douglas Gregoreb5dc492010-06-08 19:23:49 +000068 if (MODULE)
69 set(libkind MODULE)
70 elseif (SHARED_LIBRARY)
Douglas Gregorac47bc72009-09-25 06:35:15 +000071 set(libkind SHARED)
72 else()
73 set(libkind)
74 endif()
75 add_library( ${name} ${libkind} ${srcs} )
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +000076 if( LLVM_COMMON_DEPENDS )
77 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
78 endif( LLVM_COMMON_DEPENDS )
Douglas Gregorac47bc72009-09-25 06:35:15 +000079 if( LLVM_USED_LIBS )
80 foreach(lib ${LLVM_USED_LIBS})
81 target_link_libraries( ${name} ${lib} )
82 endforeach(lib)
83 endif( LLVM_USED_LIBS )
Benjamin Kramerbd785542009-10-11 12:22:00 +000084 if( LLVM_LINK_COMPONENTS )
85 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
86 endif( LLVM_LINK_COMPONENTS )
Michael J. Spencer5a7f3492010-09-10 21:13:16 +000087 if (LLVM_COMMON_LIBS)
88 target_link_libraries(${name} ${LLVM_COMMON_LIBS})
89 endif()
Michael J. Spencer28709c12010-09-11 02:13:48 +000090 if( NOT MINGW )
91 get_system_libs(llvm_system_libs)
92 if( llvm_system_libs )
93 target_link_libraries(${name} ${llvm_system_libs})
94 endif()
95 endif()
Douglas Gregora393e9e2009-03-16 23:06:59 +000096 add_dependencies(${name} ClangDiagnosticCommon)
Cedric Venet1c212a02008-12-13 11:00:04 +000097 if(MSVC)
98 get_target_property(cflag ${name} COMPILE_FLAGS)
99 if(NOT cflag)
100 set(cflag "")
101 endif(NOT cflag)
102 set(cflag "${cflag} /Za")
103 set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
104 endif(MSVC)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000105 install(TARGETS ${name}
Oscar Fuentesbfb06ea2009-10-27 19:42:21 +0000106 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
Oscar Fuentes755f3df2009-06-12 02:54:12 +0000107 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000108endmacro(add_clang_library)
109
110macro(add_clang_executable name)
Oscar Fuentes99174012011-01-03 17:00:02 +0000111 add_llvm_executable( ${name} ${ARGN} )
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000112endmacro(add_clang_executable)
113
114include_directories(
115 ${CMAKE_CURRENT_SOURCE_DIR}/include
Douglas Gregora393e9e2009-03-16 23:06:59 +0000116 ${CMAKE_CURRENT_BINARY_DIR}/include
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000117 )
118
Oscar Fuentes82cac292009-10-27 19:59:34 +0000119install(DIRECTORY include/
120 DESTINATION include
121 FILES_MATCHING
122 PATTERN "*.def"
123 PATTERN "*.h"
124 PATTERN "*.td"
Chris Lattnerbc6ec752008-11-11 18:39:10 +0000125 PATTERN ".svn" EXCLUDE
126 )
127
Kovarththanan Rajaratnamec700a62010-04-01 14:24:41 +0000128install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
129 DESTINATION include
130 FILES_MATCHING
Chris Lattnerd7d5bb12010-04-25 04:59:35 +0000131 PATTERN "CMakeFiles" EXCLUDE
Kovarththanan Rajaratnamec700a62010-04-01 14:24:41 +0000132 PATTERN "*.inc"
133 )
134
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000135add_definitions( -D_GNU_SOURCE )
136
Daniel Dunbar45088e22009-11-17 09:32:51 +0000137option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
138if(CLANG_BUILD_EXAMPLES)
139 add_subdirectory(examples)
140endif ()
141
Douglas Gregora393e9e2009-03-16 23:06:59 +0000142add_subdirectory(include)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000143add_subdirectory(lib)
Daniel Dunbarcbcd98b2009-03-24 02:52:57 +0000144add_subdirectory(tools)
Michael J. Spencer48263ba2010-12-16 03:28:42 +0000145add_subdirectory(runtime)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000146
147# TODO: docs.
Douglas Gregor291fbde2009-09-15 22:30:13 +0000148add_subdirectory(test)