blob: e366275af9624be1cb2e7a28de50a8f7c8e44fbf [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
Douglas Gregor9df3faf2009-09-18 14:47:57 +000037# Add appropriate flags for GCC
38if (CMAKE_COMPILER_IS_GNUCXX)
39 # FIXME: Turn off exceptions, RTTI:
40 # -fno-exceptions -fno-rtti
41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
42endif ()
43
Douglas Gregoreb5dc492010-06-08 19:23:49 +000044if (APPLE)
45 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
46endif ()
47
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +000048macro(add_clang_library name)
Cedric Venetfe2f8082008-11-02 16:28:53 +000049 set(srcs ${ARGN})
Ted Kremenekbf5de3f2009-03-25 20:34:07 +000050 if(MSVC_IDE OR XCODE)
Douglas Gregorf5216f22009-06-17 18:31:02 +000051 file( GLOB_RECURSE headers *.h *.td *.def)
Cedric Venetfe2f8082008-11-02 16:28:53 +000052 set(srcs ${srcs} ${headers})
53 string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
54 list( GET split_path -1 dir)
Douglas Gregorf5216f22009-06-17 18:31:02 +000055 file( GLOB_RECURSE headers
56 ../../include/clang${dir}/*.h
57 ../../include/clang${dir}/*.td
58 ../../include/clang${dir}/*.def)
Cedric Venetfe2f8082008-11-02 16:28:53 +000059 set(srcs ${srcs} ${headers})
Ted Kremenekbf5de3f2009-03-25 20:34:07 +000060 endif(MSVC_IDE OR XCODE)
Douglas Gregoreb5dc492010-06-08 19:23:49 +000061 if (MODULE)
62 set(libkind MODULE)
63 elseif (SHARED_LIBRARY)
Douglas Gregorac47bc72009-09-25 06:35:15 +000064 set(libkind SHARED)
65 else()
66 set(libkind)
67 endif()
68 add_library( ${name} ${libkind} ${srcs} )
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +000069 if( LLVM_COMMON_DEPENDS )
70 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
71 endif( LLVM_COMMON_DEPENDS )
Douglas Gregorac47bc72009-09-25 06:35:15 +000072 if( LLVM_USED_LIBS )
73 foreach(lib ${LLVM_USED_LIBS})
74 target_link_libraries( ${name} ${lib} )
75 endforeach(lib)
76 endif( LLVM_USED_LIBS )
Benjamin Kramerbd785542009-10-11 12:22:00 +000077 if( LLVM_LINK_COMPONENTS )
78 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
79 endif( LLVM_LINK_COMPONENTS )
80 get_system_libs(llvm_system_libs)
81 if( llvm_system_libs )
82 target_link_libraries(${name} ${llvm_system_libs})
83 endif( llvm_system_libs )
Douglas Gregora393e9e2009-03-16 23:06:59 +000084 add_dependencies(${name} ClangDiagnosticCommon)
Cedric Venet1c212a02008-12-13 11:00:04 +000085 if(MSVC)
86 get_target_property(cflag ${name} COMPILE_FLAGS)
87 if(NOT cflag)
88 set(cflag "")
89 endif(NOT cflag)
90 set(cflag "${cflag} /Za")
91 set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
92 endif(MSVC)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +000093 install(TARGETS ${name}
Oscar Fuentesbfb06ea2009-10-27 19:42:21 +000094 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
Oscar Fuentes755f3df2009-06-12 02:54:12 +000095 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +000096endmacro(add_clang_library)
97
98macro(add_clang_executable name)
Cedric Venetfe2f8082008-11-02 16:28:53 +000099 set(srcs ${ARGN})
100 if(MSVC_IDE)
Douglas Gregorf5216f22009-06-17 18:31:02 +0000101 file( GLOB_RECURSE headers *.h *.td *.def)
Cedric Venetfe2f8082008-11-02 16:28:53 +0000102 set(srcs ${srcs} ${headers})
103 endif(MSVC_IDE)
104 add_llvm_executable( ${name} ${srcs} )
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000105endmacro(add_clang_executable)
106
107include_directories(
108 ${CMAKE_CURRENT_SOURCE_DIR}/include
Douglas Gregora393e9e2009-03-16 23:06:59 +0000109 ${CMAKE_CURRENT_BINARY_DIR}/include
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000110 )
111
Oscar Fuentes82cac292009-10-27 19:59:34 +0000112install(DIRECTORY include/
113 DESTINATION include
114 FILES_MATCHING
115 PATTERN "*.def"
116 PATTERN "*.h"
117 PATTERN "*.td"
Chris Lattnerbc6ec752008-11-11 18:39:10 +0000118 PATTERN ".svn" EXCLUDE
119 )
120
Kovarththanan Rajaratnamec700a62010-04-01 14:24:41 +0000121install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
122 DESTINATION include
123 FILES_MATCHING
Chris Lattnerd7d5bb12010-04-25 04:59:35 +0000124 PATTERN "CMakeFiles" EXCLUDE
Kovarththanan Rajaratnamec700a62010-04-01 14:24:41 +0000125 PATTERN "*.inc"
126 )
127
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000128add_definitions( -D_GNU_SOURCE )
129
Daniel Dunbar45088e22009-11-17 09:32:51 +0000130option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
131if(CLANG_BUILD_EXAMPLES)
132 add_subdirectory(examples)
133endif ()
134
Douglas Gregora393e9e2009-03-16 23:06:59 +0000135add_subdirectory(include)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000136add_subdirectory(lib)
Daniel Dunbarcbcd98b2009-03-24 02:52:57 +0000137add_subdirectory(tools)
Oscar Fuentesd2f4e5e2008-10-26 00:56:18 +0000138
139# TODO: docs.
Douglas Gregor291fbde2009-09-15 22:30:13 +0000140add_subdirectory(test)
141