2011-02-03 23:57:53 +03: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}" )
|
2011-07-15 03:42:32 +04:00
|
|
|
# Looking for bin/Debug/tblgen is a complete hack. How can we get
|
|
|
|
# around this?
|
|
|
|
if( NOT EXISTS "${CLANG_PATH_TO_LLVM_BUILD}/bin/Debug/tblgen${CMAKE_EXECUTABLE_SUFFIX}" )
|
|
|
|
message(FATAL_ERROR "Please set CLANG_PATH_TO_LLVM_BUILD to a directory containing a LLVM build.")
|
|
|
|
endif()
|
2011-02-03 23:57:53 +03:00
|
|
|
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)
|
2011-04-10 20:17:31 +04:00
|
|
|
include("${CLANG_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake")
|
2011-02-03 23:57:53 +03:00
|
|
|
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})
|
|
|
|
|
2011-02-14 23:14:11 +03:00
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
2011-02-03 23:57:53 +03:00
|
|
|
include_directories("${PATH_TO_LLVM_BUILD}/include" "${LLVM_MAIN_INCLUDE_DIR}")
|
|
|
|
link_directories("${PATH_TO_LLVM_BUILD}/lib")
|
|
|
|
|
2011-07-15 03:42:32 +04:00
|
|
|
if( EXISTS "${CLANG_PATH_TO_LLVM_BUILD}/bin/tblgen${CMAKE_EXECUTABLE_SUFFIX}" )
|
|
|
|
set(LLVM_TABLEGEN_EXE "${PATH_TO_LLVM_BUILD}/bin/tblgen")
|
|
|
|
else()
|
|
|
|
# FIXME: This is an utter hack.
|
|
|
|
set(LLVM_TABLEGEN_EXE "${PATH_TO_LLVM_BUILD}/bin/Debug/tblgen")
|
|
|
|
endif()
|
2011-02-03 23:57:53 +03:00
|
|
|
|
|
|
|
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 )
|
|
|
|
|
2011-02-15 10:54:28 +03:00
|
|
|
set( CLANG_BUILT_STANDALONE 1 )
|
2011-02-03 23:57:53 +03:00
|
|
|
endif()
|
2009-09-17 01:59:05 +04:00
|
|
|
|
2011-02-04 01:48:20 +03:00
|
|
|
set(CLANG_RESOURCE_DIR "" CACHE STRING
|
|
|
|
"Relative directory from the Clang binary to its resource files.")
|
|
|
|
|
|
|
|
set(C_INCLUDE_DIRS "" CACHE STRING
|
|
|
|
"Colon separated list of directories clang will search for headers.")
|
|
|
|
|
2011-05-20 19:57:59 +04:00
|
|
|
set(CLANG_VENDOR "" CACHE STRING
|
|
|
|
"Vendor-specific text for showing with version information.")
|
|
|
|
|
|
|
|
if( CLANG_VENDOR )
|
|
|
|
add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " )
|
|
|
|
endif()
|
|
|
|
|
2009-09-17 04:07:10 +04:00
|
|
|
set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2010-04-18 00:12:02 +04: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 03:34:47 +04:00
|
|
|
# Compute the Clang version from the LLVM version.
|
2010-09-11 01:13:16 +04:00
|
|
|
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
|
2010-06-26 03:34:47 +04:00
|
|
|
${PACKAGE_VERSION})
|
2009-09-17 01:59:05 +04:00
|
|
|
message(STATUS "Clang version: ${CLANG_VERSION}")
|
2009-08-23 09:28:29 +04:00
|
|
|
|
2010-06-25 21:33:46 +04: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 18:47:57 +04:00
|
|
|
# Add appropriate flags for GCC
|
2011-05-11 17:53:30 +04:00
|
|
|
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
|
2010-10-15 04:16:22 +04: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 18:47:57 +04:00
|
|
|
endif ()
|
|
|
|
|
2010-06-08 23:23:49 +04:00
|
|
|
if (APPLE)
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
|
|
|
|
endif ()
|
|
|
|
|
2011-02-04 01:48:20 +03:00
|
|
|
configure_file(
|
|
|
|
${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
|
|
|
|
${CLANG_BINARY_DIR}/include/clang/Config/config.h)
|
|
|
|
|
2011-02-21 01:06:32 +03:00
|
|
|
include(LLVMParseArguments)
|
|
|
|
|
|
|
|
function(clang_tablegen)
|
|
|
|
# Syntax:
|
|
|
|
# clang_tablegen output-file [tablegen-arg ...] SOURCE source-file
|
|
|
|
# [[TARGET cmake-target-name] [DEPENDS extra-dependency ...]]
|
|
|
|
#
|
|
|
|
# Generates a custom command for invoking tblgen as
|
|
|
|
#
|
|
|
|
# tblgen source-file -o=output-file tablegen-arg ...
|
|
|
|
#
|
|
|
|
# and, if cmake-target-name is provided, creates a custom target for
|
|
|
|
# executing the custom command depending on output-file. It is
|
|
|
|
# possible to list more files to depend after DEPENDS.
|
|
|
|
|
|
|
|
parse_arguments( CTG "SOURCE;TARGET;DEPENDS" "" ${ARGN} )
|
|
|
|
|
|
|
|
if( NOT CTG_SOURCE )
|
|
|
|
message(FATAL_ERROR "SOURCE source-file required by clang_tablegen")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set( LLVM_TARGET_DEFINITIONS ${CTG_SOURCE} )
|
|
|
|
tablegen( ${CTG_DEFAULT_ARGS} )
|
|
|
|
|
|
|
|
list( GET CTG_DEFAULT_ARGS 0 output_file )
|
|
|
|
if( CTG_TARGET )
|
|
|
|
add_custom_target( ${CTG_TARGET} DEPENDS ${output_file} ${CTG_DEPENDS} )
|
2011-02-21 01:06:44 +03:00
|
|
|
set_target_properties( ${CTG_TARGET} PROPERTIES FOLDER "Clang tablegenning")
|
2011-02-21 01:06:32 +03:00
|
|
|
endif()
|
|
|
|
endfunction(clang_tablegen)
|
|
|
|
|
2008-10-26 03:56:18 +03:00
|
|
|
macro(add_clang_library name)
|
2011-01-03 20:00:02 +03:00
|
|
|
llvm_process_sources(srcs ${ARGN})
|
2009-03-25 23:34:07 +03:00
|
|
|
if(MSVC_IDE OR XCODE)
|
2008-11-02 19:28:53 +03:00
|
|
|
string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
list( GET split_path -1 dir)
|
2010-09-11 01:13:16 +04:00
|
|
|
file( GLOB_RECURSE headers
|
2011-02-10 04:03:09 +03:00
|
|
|
../../../include/clang/StaticAnalyzer${dir}/*.h
|
|
|
|
../../../include/clang/StaticAnalyzer${dir}/*.td
|
|
|
|
../../../include/clang/StaticAnalyzer${dir}/*.def
|
2009-06-17 22:31:02 +04:00
|
|
|
../../include/clang${dir}/*.h
|
|
|
|
../../include/clang${dir}/*.td
|
|
|
|
../../include/clang${dir}/*.def)
|
2008-11-02 19:28:53 +03:00
|
|
|
set(srcs ${srcs} ${headers})
|
2009-03-25 23:34:07 +03:00
|
|
|
endif(MSVC_IDE OR XCODE)
|
2010-06-08 23:23:49 +04:00
|
|
|
if (MODULE)
|
|
|
|
set(libkind MODULE)
|
|
|
|
elseif (SHARED_LIBRARY)
|
2009-09-25 10:35:15 +04:00
|
|
|
set(libkind SHARED)
|
|
|
|
else()
|
|
|
|
set(libkind)
|
|
|
|
endif()
|
|
|
|
add_library( ${name} ${libkind} ${srcs} )
|
2008-10-26 03:56:18 +03:00
|
|
|
if( LLVM_COMMON_DEPENDS )
|
|
|
|
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
|
|
|
|
endif( LLVM_COMMON_DEPENDS )
|
2011-03-30 00:51:00 +04:00
|
|
|
|
|
|
|
target_link_libraries( ${name} ${LLVM_USED_LIBS} )
|
|
|
|
llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
|
|
|
|
target_link_libraries( ${name} ${LLVM_COMMON_LIBS} )
|
|
|
|
link_system_libs( ${name} )
|
|
|
|
|
2009-03-17 02:06:59 +03:00
|
|
|
add_dependencies(${name} ClangDiagnosticCommon)
|
2008-12-13 14:00:04 +03: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 03:56:18 +03:00
|
|
|
install(TARGETS ${name}
|
2009-10-27 22:42:21 +03:00
|
|
|
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
2009-06-12 06:54:12 +04:00
|
|
|
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
|
2011-02-21 01:06:44 +03:00
|
|
|
set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
|
2008-10-26 03:56:18 +03:00
|
|
|
endmacro(add_clang_library)
|
|
|
|
|
|
|
|
macro(add_clang_executable name)
|
2011-01-03 20:00:02 +03:00
|
|
|
add_llvm_executable( ${name} ${ARGN} )
|
2011-02-21 01:06:44 +03:00
|
|
|
set_target_properties(${name} PROPERTIES FOLDER "Clang executables")
|
2008-10-26 03:56:18 +03:00
|
|
|
endmacro(add_clang_executable)
|
|
|
|
|
2011-03-17 22:03:04 +03:00
|
|
|
include_directories(BEFORE
|
2009-03-17 02:06:59 +03:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
2011-03-17 22:03:04 +03:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
2008-10-26 03:56:18 +03:00
|
|
|
)
|
|
|
|
|
2009-10-27 22:59:34 +03:00
|
|
|
install(DIRECTORY include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.def"
|
|
|
|
PATTERN "*.h"
|
2008-11-11 21:39:10 +03:00
|
|
|
PATTERN ".svn" EXCLUDE
|
|
|
|
)
|
|
|
|
|
2010-04-01 18:24:41 +04:00
|
|
|
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
2010-04-25 08:59:35 +04:00
|
|
|
PATTERN "CMakeFiles" EXCLUDE
|
2010-04-01 18:24:41 +04:00
|
|
|
PATTERN "*.inc"
|
|
|
|
)
|
|
|
|
|
2011-02-04 01:48:20 +03:00
|
|
|
add_definitions( -D_GNU_SOURCE -DHAVE_CLANG_CONFIG_H )
|
2008-10-26 03:56:18 +03:00
|
|
|
|
2011-02-25 22:24:02 +03:00
|
|
|
# Clang version information
|
|
|
|
set(CLANG_EXECUTABLE_VERSION
|
|
|
|
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
|
|
|
|
"Version number that will be placed into the clang executable, in the form XX.YY")
|
|
|
|
set(LIBCLANG_LIBRARY_VERSION
|
|
|
|
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
|
|
|
|
"Version number that will be placed into the libclang library , in the form XX.YY")
|
|
|
|
mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
|
|
|
|
|
|
|
|
|
2009-11-17 12:32:51 +03:00
|
|
|
option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF)
|
|
|
|
if(CLANG_BUILD_EXAMPLES)
|
|
|
|
add_subdirectory(examples)
|
|
|
|
endif ()
|
|
|
|
|
2009-03-17 02:06:59 +03:00
|
|
|
add_subdirectory(include)
|
2008-10-26 03:56:18 +03:00
|
|
|
add_subdirectory(lib)
|
2009-03-24 05:52:57 +03:00
|
|
|
add_subdirectory(tools)
|
2010-12-16 06:28:42 +03:00
|
|
|
add_subdirectory(runtime)
|
2008-10-26 03:56:18 +03:00
|
|
|
|
|
|
|
# TODO: docs.
|
2011-02-25 03:32:30 +03:00
|
|
|
add_subdirectory(test)
|
2011-02-15 10:54:28 +03:00
|
|
|
|
2011-02-25 03:32:30 +03:00
|
|
|
if( LLVM_INCLUDE_TESTS )
|
2011-02-25 03:12:04 +03:00
|
|
|
if( NOT CLANG_BUILT_STANDALONE )
|
|
|
|
add_subdirectory(unittests)
|
|
|
|
endif()
|
2011-02-15 10:54:28 +03:00
|
|
|
endif()
|
2011-02-16 06:07:15 +03:00
|
|
|
|
|
|
|
# Workaround for MSVS10 to avoid the Dialog Hell
|
|
|
|
# FIXME: This could be removed with future version of CMake.
|
|
|
|
if( CLANG_BUILT_STANDALONE AND MSVC_VERSION EQUAL 1600 )
|
|
|
|
set(CLANG_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/Clang.sln")
|
|
|
|
if( EXISTS "${CLANG_SLN_FILENAME}" )
|
|
|
|
file(APPEND "${CLANG_SLN_FILENAME}" "\n# This should be regenerated!\n")
|
|
|
|
endif()
|
|
|
|
endif()
|