Keep track in chained PCH of implicit members that were added after the definition...
[clang.git] / CMakeLists.txt
blob7f6e811414ec110aaab187bc4f460f4819f2df1b
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 -Wcast-qual -fno-strict-aliasing -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   if (LLVM_COMMON_LIBS)
92     target_link_libraries(${name} ${LLVM_COMMON_LIBS})
93   endif()
94   if( NOT MINGW )
95     get_system_libs(llvm_system_libs)
96     if( llvm_system_libs )
97       target_link_libraries(${name} ${llvm_system_libs})
98     endif()
99   endif()
100   add_dependencies(${name} ClangDiagnosticCommon)
101   if(MSVC)
102     get_target_property(cflag ${name} COMPILE_FLAGS)
103     if(NOT cflag)
104       set(cflag "")
105     endif(NOT cflag)
106     set(cflag "${cflag} /Za")
107     set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
108   endif(MSVC)
109   install(TARGETS ${name}
110     LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
111     ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
112 endmacro(add_clang_library)
114 macro(add_clang_executable name)
115   set(srcs ${ARGN})
116   if(MSVC_IDE)
117     file( GLOB_RECURSE headers *.h *.td *.def)
118     set(srcs ${srcs} ${headers})
119   endif(MSVC_IDE)
120   add_llvm_executable( ${name} ${srcs} )
121 endmacro(add_clang_executable)
123 include_directories(
124   ${CMAKE_CURRENT_SOURCE_DIR}/include
125   ${CMAKE_CURRENT_BINARY_DIR}/include
126   )
128 install(DIRECTORY include/
129   DESTINATION include
130   FILES_MATCHING
131   PATTERN "*.def"
132   PATTERN "*.h"
133   PATTERN "*.td"
134   PATTERN ".svn" EXCLUDE
135   )
137 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
138   DESTINATION include
139   FILES_MATCHING
140   PATTERN "CMakeFiles" EXCLUDE
141   PATTERN "*.inc"
142   )
144 add_definitions( -D_GNU_SOURCE )
146 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
147 if(CLANG_BUILD_EXAMPLES)
148   add_subdirectory(examples)
149 endif ()
151 add_subdirectory(include)
152 add_subdirectory(lib)
153 add_subdirectory(tools)
155 # TODO: docs.
156 add_subdirectory(test)