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 | |
Daniel Dunbar | 91ee77a | 2009-09-17 00:07:10 +0000 | [diff] [blame] | 3 | set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 4 | set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 5 | |
Chandler Carruth | 63e9c0d | 2010-04-17 20:12:02 +0000 | [diff] [blame] | 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.") |
| 12 | endif() |
| 13 | |
| 14 | if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) |
| 15 | file(GLOB_RECURSE |
| 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.") |
| 23 | endif() |
| 24 | endif() |
| 25 | |
Daniel Dunbar | c4b8e92 | 2010-06-25 23:34:47 +0000 | [diff] [blame] | 26 | # Compute the Clang version from the LLVM version. |
Michael J. Spencer | 5a7f349 | 2010-09-10 21:13:16 +0000 | [diff] [blame] | 27 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION |
Daniel Dunbar | c4b8e92 | 2010-06-25 23:34:47 +0000 | [diff] [blame] | 28 | ${PACKAGE_VERSION}) |
Douglas Gregor | 34d9ffa | 2009-09-16 21:59:05 +0000 | [diff] [blame] | 29 | message(STATUS "Clang version: ${CLANG_VERSION}") |
Douglas Gregor | 7f7b748 | 2009-08-23 05:28:29 +0000 | [diff] [blame] | 30 | |
Daniel Dunbar | a510767 | 2010-06-25 17:33:46 +0000 | [diff] [blame] | 31 | string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR |
| 32 | ${CLANG_VERSION}) |
| 33 | string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR |
| 34 | ${CLANG_VERSION}) |
| 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 |
| 38 | ${CLANG_VERSION}) |
| 39 | else() |
| 40 | set(CLANG_HAS_VERSION_PATCHLEVEL 0) |
| 41 | endif() |
| 42 | |
| 43 | # Configure the Version.inc file. |
| 44 | configure_file( |
| 45 | ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in |
| 46 | ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc) |
| 47 | |
Douglas Gregor | 9df3faf | 2009-09-18 14:47:57 +0000 | [diff] [blame] | 48 | # Add appropriate flags for GCC |
| 49 | if (CMAKE_COMPILER_IS_GNUCXX) |
Oscar Fuentes | 827c573 | 2010-10-15 00:16:22 +0000 | [diff] [blame] | 50 | 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") |
Douglas Gregor | 9df3faf | 2009-09-18 14:47:57 +0000 | [diff] [blame] | 51 | endif () |
| 52 | |
Douglas Gregor | eb5dc49 | 2010-06-08 19:23:49 +0000 | [diff] [blame] | 53 | if (APPLE) |
| 54 | set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") |
| 55 | endif () |
| 56 | |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 57 | macro(add_clang_library name) |
Oscar Fuentes | 9917401 | 2011-01-03 17:00:02 +0000 | [diff] [blame^] | 58 | llvm_process_sources(srcs ${ARGN}) |
Ted Kremenek | bf5de3f | 2009-03-25 20:34:07 +0000 | [diff] [blame] | 59 | if(MSVC_IDE OR XCODE) |
Cedric Venet | fe2f808 | 2008-11-02 16:28:53 +0000 | [diff] [blame] | 60 | string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR}) |
| 61 | list( GET split_path -1 dir) |
Michael J. Spencer | 5a7f349 | 2010-09-10 21:13:16 +0000 | [diff] [blame] | 62 | file( GLOB_RECURSE headers |
Douglas Gregor | f5216f2 | 2009-06-17 18:31:02 +0000 | [diff] [blame] | 63 | ../../include/clang${dir}/*.h |
| 64 | ../../include/clang${dir}/*.td |
| 65 | ../../include/clang${dir}/*.def) |
Cedric Venet | fe2f808 | 2008-11-02 16:28:53 +0000 | [diff] [blame] | 66 | set(srcs ${srcs} ${headers}) |
Ted Kremenek | bf5de3f | 2009-03-25 20:34:07 +0000 | [diff] [blame] | 67 | endif(MSVC_IDE OR XCODE) |
Douglas Gregor | eb5dc49 | 2010-06-08 19:23:49 +0000 | [diff] [blame] | 68 | if (MODULE) |
| 69 | set(libkind MODULE) |
| 70 | elseif (SHARED_LIBRARY) |
Douglas Gregor | ac47bc7 | 2009-09-25 06:35:15 +0000 | [diff] [blame] | 71 | set(libkind SHARED) |
| 72 | else() |
| 73 | set(libkind) |
| 74 | endif() |
| 75 | add_library( ${name} ${libkind} ${srcs} ) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 76 | if( LLVM_COMMON_DEPENDS ) |
| 77 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 78 | endif( LLVM_COMMON_DEPENDS ) |
Douglas Gregor | ac47bc7 | 2009-09-25 06:35:15 +0000 | [diff] [blame] | 79 | if( LLVM_USED_LIBS ) |
| 80 | foreach(lib ${LLVM_USED_LIBS}) |
| 81 | target_link_libraries( ${name} ${lib} ) |
| 82 | endforeach(lib) |
| 83 | endif( LLVM_USED_LIBS ) |
Benjamin Kramer | bd78554 | 2009-10-11 12:22:00 +0000 | [diff] [blame] | 84 | if( LLVM_LINK_COMPONENTS ) |
| 85 | llvm_config(${name} ${LLVM_LINK_COMPONENTS}) |
| 86 | endif( LLVM_LINK_COMPONENTS ) |
Michael J. Spencer | 5a7f349 | 2010-09-10 21:13:16 +0000 | [diff] [blame] | 87 | if (LLVM_COMMON_LIBS) |
| 88 | target_link_libraries(${name} ${LLVM_COMMON_LIBS}) |
| 89 | endif() |
Michael J. Spencer | 28709c1 | 2010-09-11 02:13:48 +0000 | [diff] [blame] | 90 | if( NOT MINGW ) |
| 91 | get_system_libs(llvm_system_libs) |
| 92 | if( llvm_system_libs ) |
| 93 | target_link_libraries(${name} ${llvm_system_libs}) |
| 94 | endif() |
| 95 | endif() |
Douglas Gregor | a393e9e | 2009-03-16 23:06:59 +0000 | [diff] [blame] | 96 | add_dependencies(${name} ClangDiagnosticCommon) |
Cedric Venet | 1c212a0 | 2008-12-13 11:00:04 +0000 | [diff] [blame] | 97 | if(MSVC) |
| 98 | get_target_property(cflag ${name} COMPILE_FLAGS) |
| 99 | if(NOT cflag) |
| 100 | set(cflag "") |
| 101 | endif(NOT cflag) |
| 102 | set(cflag "${cflag} /Za") |
| 103 | set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag}) |
| 104 | endif(MSVC) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 105 | install(TARGETS ${name} |
Oscar Fuentes | bfb06ea | 2009-10-27 19:42:21 +0000 | [diff] [blame] | 106 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
Oscar Fuentes | 755f3df | 2009-06-12 02:54:12 +0000 | [diff] [blame] | 107 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 108 | endmacro(add_clang_library) |
| 109 | |
| 110 | macro(add_clang_executable name) |
Oscar Fuentes | 9917401 | 2011-01-03 17:00:02 +0000 | [diff] [blame^] | 111 | add_llvm_executable( ${name} ${ARGN} ) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 112 | endmacro(add_clang_executable) |
| 113 | |
| 114 | include_directories( |
| 115 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
Douglas Gregor | a393e9e | 2009-03-16 23:06:59 +0000 | [diff] [blame] | 116 | ${CMAKE_CURRENT_BINARY_DIR}/include |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 117 | ) |
| 118 | |
Oscar Fuentes | 82cac29 | 2009-10-27 19:59:34 +0000 | [diff] [blame] | 119 | install(DIRECTORY include/ |
| 120 | DESTINATION include |
| 121 | FILES_MATCHING |
| 122 | PATTERN "*.def" |
| 123 | PATTERN "*.h" |
| 124 | PATTERN "*.td" |
Chris Lattner | bc6ec75 | 2008-11-11 18:39:10 +0000 | [diff] [blame] | 125 | PATTERN ".svn" EXCLUDE |
| 126 | ) |
| 127 | |
Kovarththanan Rajaratnam | ec700a6 | 2010-04-01 14:24:41 +0000 | [diff] [blame] | 128 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ |
| 129 | DESTINATION include |
| 130 | FILES_MATCHING |
Chris Lattner | d7d5bb1 | 2010-04-25 04:59:35 +0000 | [diff] [blame] | 131 | PATTERN "CMakeFiles" EXCLUDE |
Kovarththanan Rajaratnam | ec700a6 | 2010-04-01 14:24:41 +0000 | [diff] [blame] | 132 | PATTERN "*.inc" |
| 133 | ) |
| 134 | |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 135 | add_definitions( -D_GNU_SOURCE ) |
| 136 | |
Daniel Dunbar | 45088e2 | 2009-11-17 09:32:51 +0000 | [diff] [blame] | 137 | option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF) |
| 138 | if(CLANG_BUILD_EXAMPLES) |
| 139 | add_subdirectory(examples) |
| 140 | endif () |
| 141 | |
Douglas Gregor | a393e9e | 2009-03-16 23:06:59 +0000 | [diff] [blame] | 142 | add_subdirectory(include) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 143 | add_subdirectory(lib) |
Daniel Dunbar | cbcd98b | 2009-03-24 02:52:57 +0000 | [diff] [blame] | 144 | add_subdirectory(tools) |
Michael J. Spencer | 48263ba | 2010-12-16 03:28:42 +0000 | [diff] [blame] | 145 | add_subdirectory(runtime) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 146 | |
| 147 | # TODO: docs. |
Douglas Gregor | 291fbde | 2009-09-15 22:30:13 +0000 | [diff] [blame] | 148 | add_subdirectory(test) |