1 # Clang version information
3 # Make sure that CMake reconfigures when the version changes.
5 ${CMAKE_CURRENT_SOURCE_DIR}/VER
6 ${CMAKE_CURRENT_BINARY_DIR}/VER)
8 set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9 set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
11 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
12 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
13 "the makefiles distributed with LLVM. Please create a directory and run cmake "
14 "from there, passing the path to this source directory as the last argument. "
15 "This process created the file `CMakeCache.txt' and the directory "
16 "`CMakeFiles'. Please delete them.")
19 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
21 tablegenned_files_on_include_dir
22 "${CLANG_SOURCE_DIR}/include/clang/*.inc")
23 if( tablegenned_files_on_include_dir )
24 message(FATAL_ERROR "Apparently there is a previous in-source build, "
25 "probably as the result of running `configure' and `make' on "
26 "${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n"
27 "${tablegenned_files_on_include_dir}\nPlease clean the source directory.")
31 # Compute the Clang version from the contents of VER
32 file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VER CLANG_VERSION_DATA)
33 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
34 ${CLANG_VERSION_DATA})
35 message(STATUS "Clang version: ${CLANG_VERSION}")
37 # Add appropriate flags for GCC
38 if (CMAKE_COMPILER_IS_GNUCXX)
39 # FIXME: Turn off exceptions, RTTI:
40 # -fno-exceptions -fno-rtti
41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
45 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
48 macro(add_clang_library name)
51 file( GLOB_RECURSE headers *.h *.td *.def)
52 set(srcs ${srcs} ${headers})
53 string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
54 list( GET split_path -1 dir)
55 file( GLOB_RECURSE headers
56 ../../include/clang${dir}/*.h
57 ../../include/clang${dir}/*.td
58 ../../include/clang${dir}/*.def)
59 set(srcs ${srcs} ${headers})
60 endif(MSVC_IDE OR XCODE)
63 elseif (SHARED_LIBRARY)
68 add_library( ${name} ${libkind} ${srcs} )
69 if( LLVM_COMMON_DEPENDS )
70 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
71 endif( LLVM_COMMON_DEPENDS )
73 foreach(lib ${LLVM_USED_LIBS})
74 target_link_libraries( ${name} ${lib} )
76 endif( LLVM_USED_LIBS )
77 if( LLVM_LINK_COMPONENTS )
78 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
79 endif( LLVM_LINK_COMPONENTS )
80 get_system_libs(llvm_system_libs)
81 if( llvm_system_libs )
82 target_link_libraries(${name} ${llvm_system_libs})
83 endif( llvm_system_libs )
84 add_dependencies(${name} ClangDiagnosticCommon)
86 get_target_property(cflag ${name} COMPILE_FLAGS)
90 set(cflag "${cflag} /Za")
91 set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
93 install(TARGETS ${name}
94 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
95 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
96 endmacro(add_clang_library)
98 macro(add_clang_executable name)
101 file( GLOB_RECURSE headers *.h *.td *.def)
102 set(srcs ${srcs} ${headers})
104 add_llvm_executable( ${name} ${srcs} )
105 endmacro(add_clang_executable)
108 ${CMAKE_CURRENT_SOURCE_DIR}/include
109 ${CMAKE_CURRENT_BINARY_DIR}/include
112 install(DIRECTORY include/
118 PATTERN ".svn" EXCLUDE
121 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
124 PATTERN "CMakeFiles" EXCLUDE
128 add_definitions( -D_GNU_SOURCE )
130 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
131 if(CLANG_BUILD_EXAMPLES)
132 add_subdirectory(examples)
135 add_subdirectory(include)
136 add_subdirectory(lib)
137 add_subdirectory(tools)
140 add_subdirectory(test)