Prefix all attribute enumerators with attr_ for consistency.
[clang.git] / CMakeLists.txt
blob2cc5a8142c8837eb7618cc66f22c8036dc65181e
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   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")
51 endif ()
53 if (APPLE)
54   set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
55 endif ()
57 macro(add_clang_library name)
58   llvm_process_sources(srcs ${ARGN})
59   if(MSVC_IDE OR XCODE)
60     string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
61     list( GET split_path -1 dir)
62     file( GLOB_RECURSE headers
63       ../../include/clang${dir}/*.h
64       ../../include/clang${dir}/*.td
65       ../../include/clang${dir}/*.def)
66     set(srcs ${srcs} ${headers})
67   endif(MSVC_IDE OR XCODE)
68   if (MODULE)
69     set(libkind MODULE)
70   elseif (SHARED_LIBRARY)
71     set(libkind SHARED)
72   else()
73     set(libkind)
74   endif()
75   add_library( ${name} ${libkind} ${srcs} )
76   if( LLVM_COMMON_DEPENDS )
77     add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
78   endif( LLVM_COMMON_DEPENDS )
79   if( LLVM_USED_LIBS )
80     foreach(lib ${LLVM_USED_LIBS})
81       target_link_libraries( ${name} ${lib} )
82     endforeach(lib)
83   endif( LLVM_USED_LIBS )
84   if( LLVM_LINK_COMPONENTS )
85     llvm_config(${name} ${LLVM_LINK_COMPONENTS})
86   endif( LLVM_LINK_COMPONENTS )
87   if (LLVM_COMMON_LIBS)
88     target_link_libraries(${name} ${LLVM_COMMON_LIBS})
89   endif()
90   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()
96   add_dependencies(${name} ClangDiagnosticCommon)
97   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)
105   install(TARGETS ${name}
106     LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
107     ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
108 endmacro(add_clang_library)
110 macro(add_clang_executable name)
111   add_llvm_executable( ${name} ${ARGN} )
112 endmacro(add_clang_executable)
114 include_directories(
115   ${CMAKE_CURRENT_SOURCE_DIR}/include
116   ${CMAKE_CURRENT_BINARY_DIR}/include
117   )
119 install(DIRECTORY include/
120   DESTINATION include
121   FILES_MATCHING
122   PATTERN "*.def"
123   PATTERN "*.h"
124   PATTERN "*.td"
125   PATTERN ".svn" EXCLUDE
126   )
128 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
129   DESTINATION include
130   FILES_MATCHING
131   PATTERN "CMakeFiles" EXCLUDE
132   PATTERN "*.inc"
133   )
135 add_definitions( -D_GNU_SOURCE )
137 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
138 if(CLANG_BUILD_EXAMPLES)
139   add_subdirectory(examples)
140 endif ()
142 add_subdirectory(include)
143 add_subdirectory(lib)
144 add_subdirectory(tools)
145 add_subdirectory(runtime)
147 # TODO: docs.
148 add_subdirectory(test)