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.")
14 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
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.")
26 # Compute the Clang version from the LLVM version.
27 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
29 message(STATUS "Clang version: ${CLANG_VERSION}")
31 string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
33 string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
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
40 set(CLANG_HAS_VERSION_PATCHLEVEL 0)
43 # Configure the Version.inc 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")
54 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
57 macro(add_clang_library name)
58 llvm_process_sources(srcs ${ARGN})
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)
70 elseif (SHARED_LIBRARY)
75 add_library( ${name} ${libkind} ${srcs} )
76 if( LLVM_COMMON_DEPENDS )
77 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
78 endif( LLVM_COMMON_DEPENDS )
80 foreach(lib ${LLVM_USED_LIBS})
81 target_link_libraries( ${name} ${lib} )
83 endif( LLVM_USED_LIBS )
84 if( LLVM_LINK_COMPONENTS )
85 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
86 endif( LLVM_LINK_COMPONENTS )
88 target_link_libraries(${name} ${LLVM_COMMON_LIBS})
91 get_system_libs(llvm_system_libs)
92 if( llvm_system_libs )
93 target_link_libraries(${name} ${llvm_system_libs})
96 add_dependencies(${name} ClangDiagnosticCommon)
98 get_target_property(cflag ${name} COMPILE_FLAGS)
102 set(cflag "${cflag} /Za")
103 set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
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)
115 ${CMAKE_CURRENT_SOURCE_DIR}/include
116 ${CMAKE_CURRENT_BINARY_DIR}/include
119 install(DIRECTORY include/
125 PATTERN ".svn" EXCLUDE
128 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
131 PATTERN "CMakeFiles" EXCLUDE
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)
142 add_subdirectory(include)
143 add_subdirectory(lib)
144 add_subdirectory(tools)
145 add_subdirectory(runtime)
148 add_subdirectory(test)