]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - CMakeLists.txt
Update clang to r94309.
[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 # Compute the Clang version from the contents of VER
12 file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VER CLANG_VERSION_DATA)
13 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION 
14   ${CLANG_VERSION_DATA})
15 message(STATUS "Clang version: ${CLANG_VERSION}")
16
17 # Add appropriate flags for GCC
18 if (CMAKE_COMPILER_IS_GNUCXX)
19   # FIXME: Turn off exceptions, RTTI:
20   # -fno-exceptions -fno-rtti
21   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
22 endif ()
23
24 macro(add_clang_library name)
25   set(srcs ${ARGN})
26   if(MSVC_IDE OR XCODE)
27     file( GLOB_RECURSE headers *.h *.td *.def)
28     set(srcs ${srcs} ${headers})
29     string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
30     list( GET split_path -1 dir)
31     file( GLOB_RECURSE headers 
32       ../../include/clang${dir}/*.h
33       ../../include/clang${dir}/*.td
34       ../../include/clang${dir}/*.def)
35     set(srcs ${srcs} ${headers})
36   endif(MSVC_IDE OR XCODE)
37   if (SHARED_LIBRARY)
38     set(libkind SHARED)
39   else()
40     set(libkind)
41   endif()
42   add_library( ${name} ${libkind} ${srcs} )
43   if( LLVM_COMMON_DEPENDS )
44     add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
45   endif( LLVM_COMMON_DEPENDS )
46   if( LLVM_USED_LIBS )
47     foreach(lib ${LLVM_USED_LIBS})
48       target_link_libraries( ${name} ${lib} )
49     endforeach(lib)
50   endif( LLVM_USED_LIBS )
51   if( LLVM_LINK_COMPONENTS )
52     llvm_config(${name} ${LLVM_LINK_COMPONENTS})
53   endif( LLVM_LINK_COMPONENTS )
54   get_system_libs(llvm_system_libs)
55   if( llvm_system_libs )
56     target_link_libraries(${name} ${llvm_system_libs})
57   endif( llvm_system_libs )
58   add_dependencies(${name} ClangDiagnosticCommon)
59   if(MSVC)
60     get_target_property(cflag ${name} COMPILE_FLAGS)
61     if(NOT cflag)
62       set(cflag "")
63     endif(NOT cflag)
64     set(cflag "${cflag} /Za")
65     set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
66   endif(MSVC)
67   install(TARGETS ${name}
68     LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
69     ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
70 endmacro(add_clang_library)
71
72 macro(add_clang_executable name)
73   set(srcs ${ARGN})
74   if(MSVC_IDE)
75     file( GLOB_RECURSE headers *.h *.td *.def)
76     set(srcs ${srcs} ${headers})
77   endif(MSVC_IDE)
78   add_llvm_executable( ${name} ${srcs} )
79 endmacro(add_clang_executable)
80
81 include_directories(
82   ${CMAKE_CURRENT_SOURCE_DIR}/include
83   ${CMAKE_CURRENT_BINARY_DIR}/include
84   )
85
86 install(DIRECTORY include/
87   DESTINATION include
88   FILES_MATCHING
89   PATTERN "*.def"
90   PATTERN "*.h"
91   PATTERN "*.td"
92   PATTERN ".svn" EXCLUDE
93   )
94
95 add_definitions( -D_GNU_SOURCE )
96
97 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
98 if(CLANG_BUILD_EXAMPLES)
99   add_subdirectory(examples)
100 endif ()
101
102 add_subdirectory(include)
103 add_subdirectory(lib)
104 add_subdirectory(tools)
105
106 # TODO: docs.
107 add_subdirectory(test)
108