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 # 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")
56 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
59 macro(add_clang_library name)
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)
74 elseif (SHARED_LIBRARY)
79 add_library( ${name} ${libkind} ${srcs} )
80 if( LLVM_COMMON_DEPENDS )
81 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
82 endif( LLVM_COMMON_DEPENDS )
84 foreach(lib ${LLVM_USED_LIBS})
85 target_link_libraries( ${name} ${lib} )
87 endif( LLVM_USED_LIBS )
88 if( LLVM_LINK_COMPONENTS )
89 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
90 endif( LLVM_LINK_COMPONENTS )
92 target_link_libraries(${name} ${LLVM_COMMON_LIBS})
95 get_system_libs(llvm_system_libs)
96 if( llvm_system_libs )
97 target_link_libraries(${name} ${llvm_system_libs})
100 add_dependencies(${name} ClangDiagnosticCommon)
102 get_target_property(cflag ${name} COMPILE_FLAGS)
106 set(cflag "${cflag} /Za")
107 set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
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)
117 file( GLOB_RECURSE headers *.h *.td *.def)
118 set(srcs ${srcs} ${headers})
120 add_llvm_executable( ${name} ${srcs} )
121 endmacro(add_clang_executable)
124 ${CMAKE_CURRENT_SOURCE_DIR}/include
125 ${CMAKE_CURRENT_BINARY_DIR}/include
128 install(DIRECTORY include/
134 PATTERN ".svn" EXCLUDE
137 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
140 PATTERN "CMakeFiles" EXCLUDE
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)
151 add_subdirectory(include)
152 add_subdirectory(lib)
153 add_subdirectory(tools)
156 add_subdirectory(test)