]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - CMakeLists.txt
Update clang to r103004.
[FreeBSD/FreeBSD.git] / CMakeLists.txt
1 # Clang version information
2
3 # Make sure that CMake reconfigures when the version changes.
4 configure_file(
5   ${CMAKE_CURRENT_SOURCE_DIR}/VER
6   ${CMAKE_CURRENT_BINARY_DIR}/VER)
7
8 set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9 set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
10
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.")
17 endif()
18
19 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
20   file(GLOB_RECURSE
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.")
28   endif()
29 endif()
30
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}")
36
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")
42 endif ()
43
44 macro(add_clang_library name)
45   set(srcs ${ARGN})
46   if(MSVC_IDE OR XCODE)
47     file( GLOB_RECURSE headers *.h *.td *.def)
48     set(srcs ${srcs} ${headers})
49     string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
50     list( GET split_path -1 dir)
51     file( GLOB_RECURSE headers 
52       ../../include/clang${dir}/*.h
53       ../../include/clang${dir}/*.td
54       ../../include/clang${dir}/*.def)
55     set(srcs ${srcs} ${headers})
56   endif(MSVC_IDE OR XCODE)
57   if (SHARED_LIBRARY)
58     set(libkind SHARED)
59   else()
60     set(libkind)
61   endif()
62   add_library( ${name} ${libkind} ${srcs} )
63   if( LLVM_COMMON_DEPENDS )
64     add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
65   endif( LLVM_COMMON_DEPENDS )
66   if( LLVM_USED_LIBS )
67     foreach(lib ${LLVM_USED_LIBS})
68       target_link_libraries( ${name} ${lib} )
69     endforeach(lib)
70   endif( LLVM_USED_LIBS )
71   if( LLVM_LINK_COMPONENTS )
72     llvm_config(${name} ${LLVM_LINK_COMPONENTS})
73   endif( LLVM_LINK_COMPONENTS )
74   get_system_libs(llvm_system_libs)
75   if( llvm_system_libs )
76     target_link_libraries(${name} ${llvm_system_libs})
77   endif( llvm_system_libs )
78   add_dependencies(${name} ClangDiagnosticCommon)
79   if(MSVC)
80     get_target_property(cflag ${name} COMPILE_FLAGS)
81     if(NOT cflag)
82       set(cflag "")
83     endif(NOT cflag)
84     set(cflag "${cflag} /Za")
85     set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
86   endif(MSVC)
87   install(TARGETS ${name}
88     LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
89     ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
90 endmacro(add_clang_library)
91
92 macro(add_clang_executable name)
93   set(srcs ${ARGN})
94   if(MSVC_IDE)
95     file( GLOB_RECURSE headers *.h *.td *.def)
96     set(srcs ${srcs} ${headers})
97   endif(MSVC_IDE)
98   add_llvm_executable( ${name} ${srcs} )
99 endmacro(add_clang_executable)
100
101 include_directories(
102   ${CMAKE_CURRENT_SOURCE_DIR}/include
103   ${CMAKE_CURRENT_BINARY_DIR}/include
104   )
105
106 install(DIRECTORY include/
107   DESTINATION include
108   FILES_MATCHING
109   PATTERN "*.def"
110   PATTERN "*.h"
111   PATTERN "*.td"
112   PATTERN ".svn" EXCLUDE
113   )
114
115 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
116   DESTINATION include
117   FILES_MATCHING
118   PATTERN "CMakeFiles" EXCLUDE
119   PATTERN "*.inc"
120   )
121
122 add_definitions( -D_GNU_SOURCE )
123
124 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
125 if(CLANG_BUILD_EXAMPLES)
126   add_subdirectory(examples)
127 endif ()
128
129 add_subdirectory(include)
130 add_subdirectory(lib)
131 add_subdirectory(tools)
132
133 # TODO: docs.
134 add_subdirectory(test)
135