2011-02-04 04:57:53 +08:00
|
|
|
# If we are not building as a part of LLVM, build Clang as an
|
|
|
|
# standalone project, using LLVM as an external library:
|
|
|
|
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
|
|
|
project(Clang)
|
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
|
|
set(CLANG_PATH_TO_LLVM_SOURCE "" CACHE PATH
|
|
|
|
"Path to LLVM source code. Not necessary if using an installed LLVM.")
|
|
|
|
set(CLANG_PATH_TO_LLVM_BUILD "" CACHE PATH
|
|
|
|
"Path to the directory where LLVM was built or installed.")
|
|
|
|
|
|
|
|
if( CLANG_PATH_TO_LLVM_SOURCE )
|
|
|
|
if( NOT EXISTS "${CLANG_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake" )
|
|
|
|
message(FATAL_ERROR "Please set CLANG_PATH_TO_LLVM_SOURCE to the root directory of LLVM source code.")
|
|
|
|
else()
|
|
|
|
get_filename_component(LLVM_MAIN_SRC_DIR ${CLANG_PATH_TO_LLVM_SOURCE}
|
|
|
|
ABSOLUTE)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if( NOT EXISTS "${CLANG_PATH_TO_LLVM_BUILD}/bin/tblgen${CMAKE_EXECUTABLE_SUFFIX}" )
|
|
|
|
message(FATAL_ERROR "Please set CLANG_PATH_TO_LLVM_BUILD to a directory containing a LLVM build.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CLANG_PATH_TO_LLVM_BUILD}/share/llvm/cmake")
|
|
|
|
|
|
|
|
get_filename_component(PATH_TO_LLVM_BUILD ${CLANG_PATH_TO_LLVM_BUILD}
|
|
|
|
ABSOLUTE)
|
|
|
|
|
|
|
|
include(AddLLVM)
|
|
|
|
include(TableGen)
|
|
|
|
include("${CLANG_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVM.cmake")
|
|
|
|
include(HandleLLVMOptions)
|
|
|
|
|
|
|
|
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
|
|
|
|
|
|
|
set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
|
|
|
|
set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR})
|
|
|
|
|
|
|
|
include_directories("${PATH_TO_LLVM_BUILD}/include" "${LLVM_MAIN_INCLUDE_DIR}")
|
|
|
|
if( NOT PATH_TO_LLVM_BUILD STREQUAL LLVM_MAIN_SRC_DIR )
|
|
|
|
include_directories("${LLVM_MAIN_INCLUDE_DIR}")
|
|
|
|
endif()
|
|
|
|
link_directories("${PATH_TO_LLVM_BUILD}/lib")
|
|
|
|
|
|
|
|
set(LLVM_TABLEGEN_EXE "${PATH_TO_LLVM_BUILD}/bin/tblgen")
|
|
|
|
|
|
|
|
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
|
|
|
|
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
|
|
|
|
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
|
|
|
|
|
|
|
|
add_definitions( -D__STDC_LIMIT_MACROS )
|
|
|
|
add_definitions( -D__STDC_CONSTANT_MACROS )
|
|
|
|
endif()
|
2009-09-17 05:59:05 +08:00
|
|
|
|
2009-09-17 08:07:10 +08:00
|
|
|
set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2010-04-18 04:12:02 +08:00
|
|
|
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
|
|
|
|
message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
|
|
|
|
"the makefiles distributed with LLVM. Please create a directory and run cmake "
|
|
|
|
"from there, passing the path to this source directory as the last argument. "
|
|
|
|
"This process created the file `CMakeCache.txt' and the directory "
|
|
|
|
"`CMakeFiles'. Please delete them.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
|
|
|
|
file(GLOB_RECURSE
|
|
|
|
tablegenned_files_on_include_dir
|
|
|
|
"${CLANG_SOURCE_DIR}/include/clang/*.inc")
|
|
|
|
if( tablegenned_files_on_include_dir )
|
|
|
|
message(FATAL_ERROR "Apparently there is a previous in-source build, "
|
|
|
|
"probably as the result of running `configure' and `make' on "
|
|
|
|
"${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n"
|
|
|
|
"${tablegenned_files_on_include_dir}\nPlease clean the source directory.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2010-06-26 07:34:47 +08:00
|
|
|
# Compute the Clang version from the LLVM version.
|
2010-09-11 05:13:16 +08:00
|
|
|
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
|
2010-06-26 07:34:47 +08:00
|
|
|
${PACKAGE_VERSION})
|
2009-09-17 05:59:05 +08:00
|
|
|
message(STATUS "Clang version: ${CLANG_VERSION}")
|
2009-08-23 13:28:29 +08:00
|
|
|
|
2010-06-26 01:33:46 +08:00
|
|
|
string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
|
|
|
|
${CLANG_VERSION})
|
|
|
|
string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
|
|
|
|
${CLANG_VERSION})
|
|
|
|
if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
|
|
|
|
set(CLANG_HAS_VERSION_PATCHLEVEL 1)
|
|
|
|
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" CLANG_VERSION_PATCHLEVEL
|
|
|
|
${CLANG_VERSION})
|
|
|
|
else()
|
|
|
|
set(CLANG_HAS_VERSION_PATCHLEVEL 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Configure the Version.inc file.
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
|
|
|
|
|
2009-09-18 22:47:57 +08:00
|
|
|
# Add appropriate flags for GCC
|
|
|
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
2010-10-15 08:16:22 +08:00
|
|
|
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")
|
2009-09-18 22:47:57 +08:00
|
|
|
endif ()
|
|
|
|
|
2010-06-09 03:23:49 +08:00
|
|
|
if (APPLE)
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
|
|
|
|
endif ()
|
|
|
|
|
2008-10-26 08:56:18 +08:00
|
|
|
macro(add_clang_library name)
|
2011-01-04 01:00:02 +08:00
|
|
|
llvm_process_sources(srcs ${ARGN})
|
2009-03-26 04:34:07 +08:00
|
|
|
if(MSVC_IDE OR XCODE)
|
2008-11-03 00:28:53 +08:00
|
|
|
string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
list( GET split_path -1 dir)
|
2010-09-11 05:13:16 +08:00
|
|
|
file( GLOB_RECURSE headers
|
2009-06-18 02:31:02 +08:00
|
|
|
../../include/clang${dir}/*.h
|
|
|
|
../../include/clang${dir}/*.td
|
|
|
|
../../include/clang${dir}/*.def)
|
2008-11-03 00:28:53 +08:00
|
|
|
set(srcs ${srcs} ${headers})
|
2009-03-26 04:34:07 +08:00
|
|
|
endif(MSVC_IDE OR XCODE)
|
2010-06-09 03:23:49 +08:00
|
|
|
if (MODULE)
|
|
|
|
set(libkind MODULE)
|
|
|
|
elseif (SHARED_LIBRARY)
|
2009-09-25 14:35:15 +08:00
|
|
|
set(libkind SHARED)
|
|
|
|
else()
|
|
|
|
set(libkind)
|
|
|
|
endif()
|
|
|
|
add_library( ${name} ${libkind} ${srcs} )
|
2008-10-26 08:56:18 +08:00
|
|
|
if( LLVM_COMMON_DEPENDS )
|
|
|
|
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
|
|
|
|
endif( LLVM_COMMON_DEPENDS )
|
2009-09-25 14:35:15 +08:00
|
|
|
if( LLVM_USED_LIBS )
|
|
|
|
foreach(lib ${LLVM_USED_LIBS})
|
|
|
|
target_link_libraries( ${name} ${lib} )
|
|
|
|
endforeach(lib)
|
|
|
|
endif( LLVM_USED_LIBS )
|
2009-10-11 20:22:00 +08:00
|
|
|
if( LLVM_LINK_COMPONENTS )
|
|
|
|
llvm_config(${name} ${LLVM_LINK_COMPONENTS})
|
|
|
|
endif( LLVM_LINK_COMPONENTS )
|
2010-09-11 05:13:16 +08:00
|
|
|
if (LLVM_COMMON_LIBS)
|
|
|
|
target_link_libraries(${name} ${LLVM_COMMON_LIBS})
|
|
|
|
endif()
|
2010-09-11 10:13:48 +08:00
|
|
|
if( NOT MINGW )
|
|
|
|
get_system_libs(llvm_system_libs)
|
|
|
|
if( llvm_system_libs )
|
|
|
|
target_link_libraries(${name} ${llvm_system_libs})
|
|
|
|
endif()
|
|
|
|
endif()
|
2009-03-17 07:06:59 +08:00
|
|
|
add_dependencies(${name} ClangDiagnosticCommon)
|
2008-12-13 19:00:04 +08:00
|
|
|
if(MSVC)
|
|
|
|
get_target_property(cflag ${name} COMPILE_FLAGS)
|
|
|
|
if(NOT cflag)
|
|
|
|
set(cflag "")
|
|
|
|
endif(NOT cflag)
|
|
|
|
set(cflag "${cflag} /Za")
|
|
|
|
set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
|
|
|
|
endif(MSVC)
|
2008-10-26 08:56:18 +08:00
|
|
|
install(TARGETS ${name}
|
2009-10-28 03:42:21 +08:00
|
|
|
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
2009-06-12 10:54:12 +08:00
|
|
|
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
|
2008-10-26 08:56:18 +08:00
|
|
|
endmacro(add_clang_library)
|
|
|
|
|
|
|
|
macro(add_clang_executable name)
|
2011-01-04 01:00:02 +08:00
|
|
|
add_llvm_executable( ${name} ${ARGN} )
|
2008-10-26 08:56:18 +08:00
|
|
|
endmacro(add_clang_executable)
|
|
|
|
|
|
|
|
include_directories(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
2009-03-17 07:06:59 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
2008-10-26 08:56:18 +08:00
|
|
|
)
|
|
|
|
|
2009-10-28 03:59:34 +08:00
|
|
|
install(DIRECTORY include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.def"
|
|
|
|
PATTERN "*.h"
|
|
|
|
PATTERN "*.td"
|
2008-11-12 02:39:10 +08:00
|
|
|
PATTERN ".svn" EXCLUDE
|
|
|
|
)
|
|
|
|
|
2010-04-01 22:24:41 +08:00
|
|
|
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
2010-04-25 12:59:35 +08:00
|
|
|
PATTERN "CMakeFiles" EXCLUDE
|
2010-04-01 22:24:41 +08:00
|
|
|
PATTERN "*.inc"
|
|
|
|
)
|
|
|
|
|
2008-10-26 08:56:18 +08:00
|
|
|
add_definitions( -D_GNU_SOURCE )
|
|
|
|
|
2009-11-17 17:32:51 +08:00
|
|
|
option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
|
|
|
|
if(CLANG_BUILD_EXAMPLES)
|
|
|
|
add_subdirectory(examples)
|
|
|
|
endif ()
|
|
|
|
|
2009-03-17 07:06:59 +08:00
|
|
|
add_subdirectory(include)
|
2008-10-26 08:56:18 +08:00
|
|
|
add_subdirectory(lib)
|
2009-03-24 10:52:57 +08:00
|
|
|
add_subdirectory(tools)
|
2010-12-16 11:28:42 +08:00
|
|
|
add_subdirectory(runtime)
|
2008-10-26 08:56:18 +08:00
|
|
|
|
|
|
|
# TODO: docs.
|
2009-09-16 06:30:13 +08:00
|
|
|
add_subdirectory(test)
|