Douglas Gregor | 7f7b748 | 2009-08-23 05:28:29 +0000 | [diff] [blame] | 1 | # Clang version information |
Douglas Gregor | 34d9ffa | 2009-09-16 21:59:05 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 91ee77a | 2009-09-17 00:07:10 +0000 | [diff] [blame] | 8 | set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 9 | set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 10 | |
Chandler Carruth | 63e9c0d | 2010-04-17 20:12:02 +0000 | [diff] [blame] | 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 | |
Douglas Gregor | 34d9ffa | 2009-09-16 21:59:05 +0000 | [diff] [blame] | 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}") |
Douglas Gregor | 7f7b748 | 2009-08-23 05:28:29 +0000 | [diff] [blame] | 36 | |
Douglas Gregor | 9df3faf | 2009-09-18 14:47:57 +0000 | [diff] [blame] | 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 | |
Douglas Gregor | eb5dc49 | 2010-06-08 19:23:49 +0000 | [diff] [blame] | 44 | if (APPLE) |
| 45 | set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") |
| 46 | endif () |
| 47 | |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 48 | macro(add_clang_library name) |
Cedric Venet | fe2f808 | 2008-11-02 16:28:53 +0000 | [diff] [blame] | 49 | set(srcs ${ARGN}) |
Ted Kremenek | bf5de3f | 2009-03-25 20:34:07 +0000 | [diff] [blame] | 50 | if(MSVC_IDE OR XCODE) |
Douglas Gregor | f5216f2 | 2009-06-17 18:31:02 +0000 | [diff] [blame] | 51 | file( GLOB_RECURSE headers *.h *.td *.def) |
Cedric Venet | fe2f808 | 2008-11-02 16:28:53 +0000 | [diff] [blame] | 52 | set(srcs ${srcs} ${headers}) |
| 53 | string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR}) |
| 54 | list( GET split_path -1 dir) |
Douglas Gregor | f5216f2 | 2009-06-17 18:31:02 +0000 | [diff] [blame] | 55 | file( GLOB_RECURSE headers |
| 56 | ../../include/clang${dir}/*.h |
| 57 | ../../include/clang${dir}/*.td |
| 58 | ../../include/clang${dir}/*.def) |
Cedric Venet | fe2f808 | 2008-11-02 16:28:53 +0000 | [diff] [blame] | 59 | set(srcs ${srcs} ${headers}) |
Ted Kremenek | bf5de3f | 2009-03-25 20:34:07 +0000 | [diff] [blame] | 60 | endif(MSVC_IDE OR XCODE) |
Douglas Gregor | eb5dc49 | 2010-06-08 19:23:49 +0000 | [diff] [blame] | 61 | if (MODULE) |
| 62 | set(libkind MODULE) |
| 63 | elseif (SHARED_LIBRARY) |
Douglas Gregor | ac47bc7 | 2009-09-25 06:35:15 +0000 | [diff] [blame] | 64 | set(libkind SHARED) |
| 65 | else() |
| 66 | set(libkind) |
| 67 | endif() |
| 68 | add_library( ${name} ${libkind} ${srcs} ) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 69 | if( LLVM_COMMON_DEPENDS ) |
| 70 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 71 | endif( LLVM_COMMON_DEPENDS ) |
Douglas Gregor | ac47bc7 | 2009-09-25 06:35:15 +0000 | [diff] [blame] | 72 | if( LLVM_USED_LIBS ) |
| 73 | foreach(lib ${LLVM_USED_LIBS}) |
| 74 | target_link_libraries( ${name} ${lib} ) |
| 75 | endforeach(lib) |
| 76 | endif( LLVM_USED_LIBS ) |
Benjamin Kramer | bd78554 | 2009-10-11 12:22:00 +0000 | [diff] [blame] | 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 ) |
Douglas Gregor | a393e9e | 2009-03-16 23:06:59 +0000 | [diff] [blame] | 84 | add_dependencies(${name} ClangDiagnosticCommon) |
Cedric Venet | 1c212a0 | 2008-12-13 11:00:04 +0000 | [diff] [blame] | 85 | if(MSVC) |
| 86 | get_target_property(cflag ${name} COMPILE_FLAGS) |
| 87 | if(NOT cflag) |
| 88 | set(cflag "") |
| 89 | endif(NOT cflag) |
| 90 | set(cflag "${cflag} /Za") |
| 91 | set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag}) |
| 92 | endif(MSVC) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 93 | install(TARGETS ${name} |
Oscar Fuentes | bfb06ea | 2009-10-27 19:42:21 +0000 | [diff] [blame] | 94 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
Oscar Fuentes | 755f3df | 2009-06-12 02:54:12 +0000 | [diff] [blame] | 95 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 96 | endmacro(add_clang_library) |
| 97 | |
| 98 | macro(add_clang_executable name) |
Cedric Venet | fe2f808 | 2008-11-02 16:28:53 +0000 | [diff] [blame] | 99 | set(srcs ${ARGN}) |
| 100 | if(MSVC_IDE) |
Douglas Gregor | f5216f2 | 2009-06-17 18:31:02 +0000 | [diff] [blame] | 101 | file( GLOB_RECURSE headers *.h *.td *.def) |
Cedric Venet | fe2f808 | 2008-11-02 16:28:53 +0000 | [diff] [blame] | 102 | set(srcs ${srcs} ${headers}) |
| 103 | endif(MSVC_IDE) |
| 104 | add_llvm_executable( ${name} ${srcs} ) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 105 | endmacro(add_clang_executable) |
| 106 | |
| 107 | include_directories( |
| 108 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
Douglas Gregor | a393e9e | 2009-03-16 23:06:59 +0000 | [diff] [blame] | 109 | ${CMAKE_CURRENT_BINARY_DIR}/include |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 110 | ) |
| 111 | |
Oscar Fuentes | 82cac29 | 2009-10-27 19:59:34 +0000 | [diff] [blame] | 112 | install(DIRECTORY include/ |
| 113 | DESTINATION include |
| 114 | FILES_MATCHING |
| 115 | PATTERN "*.def" |
| 116 | PATTERN "*.h" |
| 117 | PATTERN "*.td" |
Chris Lattner | bc6ec75 | 2008-11-11 18:39:10 +0000 | [diff] [blame] | 118 | PATTERN ".svn" EXCLUDE |
| 119 | ) |
| 120 | |
Kovarththanan Rajaratnam | ec700a6 | 2010-04-01 14:24:41 +0000 | [diff] [blame] | 121 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ |
| 122 | DESTINATION include |
| 123 | FILES_MATCHING |
Chris Lattner | d7d5bb1 | 2010-04-25 04:59:35 +0000 | [diff] [blame] | 124 | PATTERN "CMakeFiles" EXCLUDE |
Kovarththanan Rajaratnam | ec700a6 | 2010-04-01 14:24:41 +0000 | [diff] [blame] | 125 | PATTERN "*.inc" |
| 126 | ) |
| 127 | |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 128 | add_definitions( -D_GNU_SOURCE ) |
| 129 | |
Daniel Dunbar | 45088e2 | 2009-11-17 09:32:51 +0000 | [diff] [blame] | 130 | option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF) |
| 131 | if(CLANG_BUILD_EXAMPLES) |
| 132 | add_subdirectory(examples) |
| 133 | endif () |
| 134 | |
Douglas Gregor | a393e9e | 2009-03-16 23:06:59 +0000 | [diff] [blame] | 135 | add_subdirectory(include) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 136 | add_subdirectory(lib) |
Daniel Dunbar | cbcd98b | 2009-03-24 02:52:57 +0000 | [diff] [blame] | 137 | add_subdirectory(tools) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 138 | |
| 139 | # TODO: docs. |
Douglas Gregor | 291fbde | 2009-09-15 22:30:13 +0000 | [diff] [blame] | 140 | add_subdirectory(test) |
| 141 | |