Fix null pointer dereference in StreamChecker::Fseek (reported in PR 8081) and simpli...
[clang.git] / CMakeLists.txt
blob1ba2a622d4e1c1ff929c3d62069de6f124f33425
1 # Clang version information
3 set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
4 set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
6 if( 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.")
12 endif()
14 if( 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()
24 endif()
26 # Compute the Clang version from the LLVM version.
27 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION 
28   ${PACKAGE_VERSION})
29 message(STATUS "Clang version: ${CLANG_VERSION}")
31 string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
32   ${CLANG_VERSION})
33 string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
34   ${CLANG_VERSION})
35 if (${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})
39 else()
40   set(CLANG_HAS_VERSION_PATCHLEVEL 0)
41 endif()
43 # Configure the Version.inc file.
44 configure_file(
45   ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
46   ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
48 # Add appropriate flags for GCC
49 if (CMAKE_COMPILER_IS_GNUCXX)
50   # FIXME: Turn off exceptions, RTTI:
51   # -fno-exceptions -fno-rtti
52   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
53 endif ()
55 if (APPLE)
56   set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
57 endif ()
59 macro(add_clang_library name)
60   set(srcs ${ARGN})
61   if(MSVC_IDE OR XCODE)
62     file( GLOB_RECURSE headers *.h *.td *.def)
63     set(srcs ${srcs} ${headers})
64     string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
65     list( GET split_path -1 dir)
66     file( GLOB_RECURSE headers 
67       ../../include/clang${dir}/*.h
68       ../../include/clang${dir}/*.td
69       ../../include/clang${dir}/*.def)
70     set(srcs ${srcs} ${headers})
71   endif(MSVC_IDE OR XCODE)
72   if (MODULE)
73     set(libkind MODULE)
74   elseif (SHARED_LIBRARY)
75     set(libkind SHARED)
76   else()
77     set(libkind)
78   endif()
79   add_library( ${name} ${libkind} ${srcs} )
80   if( LLVM_COMMON_DEPENDS )
81     add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
82   endif( LLVM_COMMON_DEPENDS )
83   if( LLVM_USED_LIBS )
84     foreach(lib ${LLVM_USED_LIBS})
85       target_link_libraries( ${name} ${lib} )
86     endforeach(lib)
87   endif( LLVM_USED_LIBS )
88   if( LLVM_LINK_COMPONENTS )
89     llvm_config(${name} ${LLVM_LINK_COMPONENTS})
90   endif( LLVM_LINK_COMPONENTS )
91   get_system_libs(llvm_system_libs)
92   if( llvm_system_libs )
93     target_link_libraries(${name} ${llvm_system_libs})
94   endif( llvm_system_libs )
95   add_dependencies(${name} ClangDiagnosticCommon)
96   if(MSVC)
97     get_target_property(cflag ${name} COMPILE_FLAGS)
98     if(NOT cflag)
99       set(cflag "")
100     endif(NOT cflag)
101     set(cflag "${cflag} /Za")
102     set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
103   endif(MSVC)
104   install(TARGETS ${name}
105     LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
106     ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
107 endmacro(add_clang_library)
109 macro(add_clang_executable name)
110   set(srcs ${ARGN})
111   if(MSVC_IDE)
112     file( GLOB_RECURSE headers *.h *.td *.def)
113     set(srcs ${srcs} ${headers})
114   endif(MSVC_IDE)
115   add_llvm_executable( ${name} ${srcs} )
116 endmacro(add_clang_executable)
118 include_directories(
119   ${CMAKE_CURRENT_SOURCE_DIR}/include
120   ${CMAKE_CURRENT_BINARY_DIR}/include
121   )
123 install(DIRECTORY include/
124   DESTINATION include
125   FILES_MATCHING
126   PATTERN "*.def"
127   PATTERN "*.h"
128   PATTERN "*.td"
129   PATTERN ".svn" EXCLUDE
130   )
132 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
133   DESTINATION include
134   FILES_MATCHING
135   PATTERN "CMakeFiles" EXCLUDE
136   PATTERN "*.inc"
137   )
139 add_definitions( -D_GNU_SOURCE )
141 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
142 if(CLANG_BUILD_EXAMPLES)
143   add_subdirectory(examples)
144 endif ()
146 add_subdirectory(include)
147 add_subdirectory(lib)
148 add_subdirectory(tools)
150 # TODO: docs.
151 add_subdirectory(test)