Skip to content
Snippets Groups Projects
Commit 78aea006 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Updating cmake build with improved scaffold install and FindClang module

parent 3a66b664
No related branches found
No related tags found
No related merge requests found
...@@ -49,12 +49,15 @@ endif() ...@@ -49,12 +49,15 @@ endif()
find_package(MPI REQUIRED) find_package(MPI REQUIRED)
find_package(Boost COMPONENTS system program_options REQUIRED) find_package(Boost COMPONENTS system program_options REQUIRED)
#find_package(ScaffoldClang REQUIRED)
message(STATUS "Found Boost Headers = ${Boost_INCLUDE_DIRS}") message(STATUS "Found Boost Headers = ${Boost_INCLUDE_DIRS}")
message(STATUS "Found Boost Libraries = ${Boost_LIBRARIES}") message(STATUS "Found Boost Libraries = ${Boost_LIBRARIES}")
message (STATUS "Found Scaffold/Clang Headers = ${ScaffoldClang_INCLUDE_DIRS}") if (NOT LLVM_ROOT)
# By default, users should install scaffold package from
# us, so it will be in this location
set (LLVM_ROOT /usr/local/scaffold/build/Release+Asserts)
endif()
find_package(Clang REQUIRED)
find_package(OpenMP) find_package(OpenMP)
if (OPENMP_FOUND) if (OPENMP_FOUND)
......
# Detect Clang libraries
#
# Defines the following variables:
# CLANG_FOUND - True if Clang was found
# CLANG_INCLUDE_DIRS - Where to find Clang includes
# CLANG_LIBRARY_DIRS - Where to find Clang libraries
#
# CLANG_LIBCLANG_LIB - Libclang C library
#
# CLANG_CLANGFRONTEND_LIB - Clang Frontend Library
# CLANG_CLANGDRIVER_LIB - Clang Driver Library
# ...
#
# Uses the same include and library paths detected by FindLLVM.cmake
#
# See http://clang.llvm.org/docs/InternalsManual.html for full list of libraries
#=============================================================================
# Copyright 2014-2015 Kevin Funk <kfunk@kde.org>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
if (${Clang_FIND_REQUIRED})
find_package(LLVM ${Clang_FIND_VERSION} REQUIRED)
else ()
find_package(LLVM ${Clang_FIND_VERSION})
endif ()
set(CLANG_FOUND FALSE)
if (LLVM_FOUND AND LLVM_LIBRARY_DIRS)
macro(FIND_AND_ADD_CLANG_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} HINTS ${LLVM_LIBRARY_DIRS})
if(CLANG_${_prettylibname_}_LIB)
set(CLANG_LIBS ${CLANG_LIBS} ${CLANG_${_prettylibname_}_LIB})
endif()
endmacro(FIND_AND_ADD_CLANG_LIB)
# note: On Windows there's 'libclang.dll' instead of 'clang.dll' -> search for 'libclang', too
find_library(CLANG_LIBCLANG_LIB NAMES clang libclang HINTS ${LLVM_LIBRARY_DIRS}) # LibClang: high-level C interface
FIND_AND_ADD_CLANG_LIB(clangFrontend)
FIND_AND_ADD_CLANG_LIB(clangDriver)
FIND_AND_ADD_CLANG_LIB(clangCodeGen)
FIND_AND_ADD_CLANG_LIB(clangSema)
FIND_AND_ADD_CLANG_LIB(clangChecker)
FIND_AND_ADD_CLANG_LIB(clangAnalysis)
FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend)
FIND_AND_ADD_CLANG_LIB(clangRewrite)
FIND_AND_ADD_CLANG_LIB(clangAST)
FIND_AND_ADD_CLANG_LIB(clangParse)
FIND_AND_ADD_CLANG_LIB(clangLex)
FIND_AND_ADD_CLANG_LIB(clangBasic)
FIND_AND_ADD_CLANG_LIB(clangARCMigrate)
FIND_AND_ADD_CLANG_LIB(clangEdit)
FIND_AND_ADD_CLANG_LIB(clangFrontendTool)
FIND_AND_ADD_CLANG_LIB(clangRewrite)
FIND_AND_ADD_CLANG_LIB(clangSerialization)
FIND_AND_ADD_CLANG_LIB(clangTooling)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCheckers)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCore)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerFrontend)
FIND_AND_ADD_CLANG_LIB(clangSema)
FIND_AND_ADD_CLANG_LIB(clangRewriteCore)
endif()
if(CLANG_LIBS)
set(CLANG_FOUND TRUE)
else()
message(STATUS "Could not find any Clang libraries in ${LLVM_LIBRARY_DIRS}")
endif()
if(CLANG_FOUND)
set(CLANG_LIBRARY_DIRS ${LLVM_LIBRARY_DIRS})
set(CLANG_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
# check whether llvm-config comes from an install prefix
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root
OUTPUT_VARIABLE _llvmSourceRoot
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(FIND "${LLVM_INCLUDE_DIRS}" "${_llvmSourceRoot}" _llvmIsInstalled)
if (NOT _llvmIsInstalled)
message(STATUS "Detected that llvm-config comes from a build-tree, adding more include directories for Clang")
list(APPEND CLANG_INCLUDE_DIRS
"${LLVM_INSTALL_PREFIX}/tools/clang/include" # build dir
"${_llvmSourceRoot}/tools/clang/include" # source dir
)
endif()
message(STATUS "Found Clang (LLVM version: ${LLVM_VERSION})")
message(STATUS " Include dirs: ${CLANG_INCLUDE_DIRS}")
message(STATUS " Clang libraries: ${CLANG_LIBS}")
message(STATUS " Libclang C library: ${CLANG_LIBCLANG_LIB}")
else()
if(Clang_FIND_REQUIRED)
message(FATAL_ERROR "Could NOT find Clang")
endif()
endif()
# - Find LLVM headers and libraries. # Find the native LLVM includes and libraries
# This module locates LLVM and adapts the llvm-config output for use with
# CMake.
# #
# A given list of COMPONENTS is passed to llvm-config. # Defines the following variables
# LLVM_INCLUDE_DIRS - where to find llvm include files
# LLVM_LIBRARY_DIRS - where to find llvm libs
# LLVM_CFLAGS - llvm compiler flags
# LLVM_LFLAGS - llvm linker flags
# LLVM_MODULE_LIBS - list of llvm libs for working with modules.
# LLVM_INSTALL_PREFIX - LLVM installation prefix
# LLVM_FOUND - True if llvm found.
# LLVM_VERSION - Version string ("llvm-config --version")
# #
# The following variables are defined: # This module reads hints about search locations from variables
# LLVM_FOUND - true if LLVM was found # LLVM_ROOT - Preferred LLVM installation prefix (containing bin/, lib/, ...)
# LLVM_CXXFLAGS - C++ compiler flags for files that include LLVM headers.
# LLVM_HOST_TARGET - Target triple used to configure LLVM.
# LLVM_INCLUDE_DIRS - Directory containing LLVM include files.
# LLVM_LDFLAGS - Linker flags to add when linking against LLVM
# (includes -LLLVM_LIBRARY_DIRS).
# LLVM_LIBRARIES - Full paths to the library files to link against.
# LLVM_LIBRARY_DIRS - Directory containing LLVM libraries.
# LLVM_ROOT_DIR - The root directory of the LLVM installation.
# llvm-config is searched for in ${LLVM_ROOT_DIR}/bin.
# LLVM_VERSION_MAJOR - Major version of LLVM.
# LLVM_VERSION_MINOR - Minor version of LLVM.
# LLVM_VERSION_STRING - Full LLVM version string (e.g. 2.9).
# #
# Note: The variable names were chosen in conformance with the offical CMake # Note: One may specify these as environment variables if they are not specified as
# guidelines, see ${CMAKE_ROOT}/Modules/readme.txt. # CMake variables or cache entries.
# Try suffixed versions to pick up the newest LLVM install available on Debian #=============================================================================
# derivatives. # Copyright 2014 Kevin Funk <kfunk@kde.org>
# We also want an user-specified LLVM_ROOT_DIR to take precedence over the #
# system default locations such as /usr/local/bin. Executing find_program() # Distributed under the OSI-approved BSD License (the "License");
# multiples times is the approach recommended in the docs. # see accompanying file Copyright.txt for details.
set(llvm_config_names llvm-config-5.0 llvm-config50 #
llvm-config-4.0 llvm-config40 # This software is distributed WITHOUT ANY WARRANTY; without even the
llvm-config-3.9 llvm-config39 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
llvm-config-3.8 llvm-config38 # See the License for more information.
llvm-config-3.7 llvm-config37 #=============================================================================
llvm-config-3.6 llvm-config36
llvm-config-3.5 llvm-config35
llvm-config)
find_program(LLVM_CONFIG
NAMES ${llvm_config_names}
PATHS ${LLVM_ROOT_DIR}/bin NO_DEFAULT_PATH
DOC "Path to llvm-config tool.")
find_program(LLVM_CONFIG NAMES ${llvm_config_names})
# Prints a warning/failure message depending on the required/quiet flags. Copied if (NOT LLVM_ROOT AND DEFINED ENV{LLVM_ROOT})
# from FindPackageHandleStandardArgs.cmake because it doesn't seem to be exposed. file(TO_CMAKE_PATH "$ENV{LLVM_ROOT}" LLVM_ROOT)
macro(_LLVM_FAIL _msg) endif()
if(LLVM_FIND_REQUIRED)
message(FATAL_ERROR "${_msg}") # if the user specified LLVM_ROOT, use that and fail otherwise
else() if (LLVM_ROOT)
if(NOT LLVM_FIND_QUIETLY) find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config HINTS ${LLVM_ROOT}/bin DOC "llvm-config executable" NO_DEFAULT_PATH)
message(STATUS "${_msg}") else()
# find llvm-config, prefer the one with a version suffix, e.g. llvm-config-3.5
# note: FreeBSD installs llvm-config as llvm-config35 and so on
# note: on some distributions, only 'llvm-config' is shipped, so let's always try to fallback on that
string(REPLACE "." "" LLVM_FIND_VERSION_CONCAT ${LLVM_FIND_VERSION})
find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config-${LLVM_FIND_VERSION} llvm-config${LLVM_FIND_VERSION_CONCAT} llvm-config DOC "llvm-config executable")
# other distributions don't ship llvm-config, but only some llvm-config-VERSION binary
# try to deduce installed LLVM version by looking up llvm-nm in PATH and *then* find llvm-config-VERSION via that
if (NOT LLVM_CONFIG_EXECUTABLE)
find_program(_llvmNmExecutable llvm-nm)
if (_llvmNmExecutable)
execute_process(COMMAND ${_llvmNmExecutable} --version OUTPUT_VARIABLE _out)
string(REGEX REPLACE ".*LLVM version ([^ \n]+).*" "\\1" _versionString "${_out}")
find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config-${_versionString} DOC "llvm-config executable")
endif() endif()
endif() endif()
endmacro() endif()
if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG) set(LLVM_FOUND FALSE)
if (WIN32)
# A bit of a sanity check:
if( NOT EXISTS ${LLVM_ROOT_DIR}/include/llvm )
message(FATAL_ERROR "LLVM_ROOT_DIR (${LLVM_ROOT_DIR}) is not a valid LLVM install")
endif()
# We incorporate the CMake features provided by LLVM:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT_DIR}/share/llvm/cmake;${LLVM_ROOT_DIR}/lib/cmake/llvm")
include(LLVMConfig)
# Set properties
set(LLVM_HOST_TARGET ${TARGET_TRIPLE})
set(LLVM_VERSION_STRING ${LLVM_PACKAGE_VERSION})
set(LLVM_CXXFLAGS ${LLVM_DEFINITIONS})
set(LLVM_LDFLAGS "")
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "all-targets" index)
list(APPEND LLVM_FIND_COMPONENTS ${LLVM_TARGETS_TO_BUILD})
# Work around LLVM bug 21016
list(FIND LLVM_TARGETS_TO_BUILD "X86" TARGET_X86)
if(TARGET_X86 GREATER -1)
list(APPEND LLVM_FIND_COMPONENTS x86utils)
endif()
# Similar to the work around above, but for AArch64
list(FIND LLVM_TARGETS_TO_BUILD "AArch64" TARGET_AArch64)
if(TARGET_AArch64 GREATER -1)
list(APPEND LLVM_FIND_COMPONENTS AArch64Utils)
endif()
# Similar to the work around above, but for AMDGPU
list(FIND LLVM_TARGETS_TO_BUILD "AMDGPU" TARGET_AMDGPU)
if(TARGET_AMDGPU GREATER -1)
list(APPEND LLVM_FIND_COMPONENTS AMDGPUUtils)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
# Versions below 3.7 do not support components debuginfo[dwarf|pdb]
# Only debuginfo is available
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfopdb" index)
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-8][\\.0-9A-Za-z]*")
# Versions below 3.9 do not support components debuginfocodeview, globalisel
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "globalisel" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[8-9][\\.0-9A-Za-z]*")
# Versions beginning with 3.8 do not support component ipa
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-9][\\.0-9A-Za-z]*")
# Versions below 4.0 do not support component debuginfomsf
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^[4-9]\\.[\\.0-9A-Za-z]*")
# Versions beginning with 4. do not support component ipa
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*") if (LLVM_CONFIG_EXECUTABLE)
llvm_map_components_to_libraries(tmplibs ${LLVM_FIND_COMPONENTS}) # verify that we've found the correct version of llvm-config
else() execute_process(COMMAND ${LLVM_CONFIG_EXECUTABLE} --version
llvm_map_components_to_libnames(tmplibs ${LLVM_FIND_COMPONENTS}) OUTPUT_VARIABLE LLVM_VERSION
endif() OUTPUT_STRIP_TRAILING_WHITESPACE)
if(MSVC)
set(LLVM_LDFLAGS "-LIBPATH:\"${LLVM_LIBRARY_DIRS}\"")
foreach(lib ${tmplibs})
list(APPEND LLVM_LIBRARIES "${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}")
endforeach()
else()
# Rely on the library search path being set correctly via -L on
# MinGW and others, as the library list returned by
# llvm_map_components_to_libraries also includes imagehlp and psapi.
set(LLVM_LDFLAGS "-L${LLVM_LIBRARY_DIRS}")
set(LLVM_LIBRARIES ${tmplibs})
endif()
# When using the CMake LLVM module, LLVM_DEFINITIONS is a list if (NOT LLVM_VERSION)
# instead of a string. Later, the list seperators would entirely set(_LLVM_ERROR_MESSAGE "Failed to parse version from llvm-config")
# disappear, replace them by spaces instead. A better fix would be elseif (LLVM_FIND_VERSION VERSION_GREATER LLVM_VERSION)
# to switch to add_definitions() instead of throwing strings around. set(_LLVM_ERROR_MESSAGE "LLVM version too old: ${LLVM_VERSION}")
string(REPLACE ";" " " LLVM_CXXFLAGS "${LLVM_CXXFLAGS}") else()
else() set(LLVM_FOUND TRUE)
if (NOT LLVM_FIND_QUIETLY) endif()
message(WARNING "Could not find llvm-config (LLVM >= ${LLVM_FIND_VERSION}). Try manually setting LLVM_CONFIG to the llvm-config executable of the installation to use.")
endif()
endif()
else() else()
macro(llvm_set var flag) set(_LLVM_ERROR_MESSAGE "Could NOT find 'llvm-config' executable")
if(LLVM_FIND_QUIETLY) endif()
set(_quiet_arg ERROR_QUIET)
endif()
set(result_code)
execute_process(
COMMAND ${LLVM_CONFIG} --${flag}
RESULT_VARIABLE result_code
OUTPUT_VARIABLE LLVM_${var}
OUTPUT_STRIP_TRAILING_WHITESPACE
${_quiet_arg}
)
if(result_code)
_LLVM_FAIL("Failed to execute llvm-config ('${LLVM_CONFIG}', result code: '${result_code})'")
else()
if(${ARGV2})
file(TO_CMAKE_PATH "${LLVM_${var}}" LLVM_${var})
endif()
endif()
endmacro()
macro(llvm_set_libs var flag)
if(LLVM_FIND_QUIETLY)
set(_quiet_arg ERROR_QUIET)
endif()
set(result_code)
execute_process(
COMMAND ${LLVM_CONFIG} --${flag} ${LLVM_FIND_COMPONENTS}
RESULT_VARIABLE result_code
OUTPUT_VARIABLE tmplibs
OUTPUT_STRIP_TRAILING_WHITESPACE
${_quiet_arg}
)
if(result_code)
_LLVM_FAIL("Failed to execute llvm-config ('${LLVM_CONFIG}', result code: '${result_code})'")
else()
file(TO_CMAKE_PATH "${tmplibs}" tmplibs)
string(REGEX MATCHALL "${pattern}[^ ]+" LLVM_${var} ${tmplibs})
endif()
endmacro()
llvm_set(VERSION_STRING version) if (LLVM_FOUND)
llvm_set(CXXFLAGS cxxflags) execute_process(
llvm_set(HOST_TARGET host-target) COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir
llvm_set(INCLUDE_DIRS includedir true) OUTPUT_VARIABLE LLVM_INCLUDE_DIRS
llvm_set(ROOT_DIR prefix true) OUTPUT_STRIP_TRAILING_WHITESPACE
llvm_set(ENABLE_ASSERTIONS assertion-mode) )
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*") execute_process(
# Versions below 3.7 do not support components debuginfo[dwarf|pdb] COMMAND ${LLVM_CONFIG_EXECUTABLE} --libdir
# Only debuginfo is available OUTPUT_VARIABLE LLVM_LIBRARY_DIRS
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index) OUTPUT_STRIP_TRAILING_WHITESPACE
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfopdb" index) )
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-8][\\.0-9A-Za-z]*")
# Versions below 3.9 do not support components debuginfocodeview, globalisel
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "globalisel" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[8-9][\\.0-9A-Za-z]*")
# Versions beginning with 3.8 do not support component ipa
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-9][\\.0-9A-Za-z]*")
# Versions below 4.0 do not support component debuginfomsf
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index)
endif()
if(${LLVM_VERSION_STRING} MATCHES "^[4-9]\\.[\\.0-9A-Za-z]*")
# Versions beginning with 4. do not support component ipa
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
endif()
llvm_set(LDFLAGS ldflags) execute_process(
if(NOT ${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*") COMMAND ${LLVM_CONFIG_EXECUTABLE} --cppflags
# In LLVM 3.5+, the system library dependencies (e.g. "-lz") are accessed OUTPUT_VARIABLE LLVM_CFLAGS
# using the separate "--system-libs" flag. OUTPUT_STRIP_TRAILING_WHITESPACE
llvm_set(SYSTEM_LIBS system-libs) )
string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}")
endif()
llvm_set(LIBRARY_DIRS libdir true)
llvm_set_libs(LIBRARIES libs)
# LLVM bug: llvm-config --libs tablegen returns -lLLVM-3.8.0
# but code for it is not in shared library
if("${LLVM_FIND_COMPONENTS}" MATCHES "tablegen")
if (NOT "${LLVM_LIBRARIES}" MATCHES "LLVMTableGen")
set(LLVM_LIBRARIES "${LLVM_LIBRARIES};-lLLVMTableGen")
endif()
endif()
llvm_set(TARGETS_TO_BUILD targets-built)
string(REGEX MATCHALL "${pattern}[^ ]+" LLVM_TARGETS_TO_BUILD ${LLVM_TARGETS_TO_BUILD})
endif()
# On CMake builds of LLVM, the output of llvm-config --cxxflags does not execute_process(
# include -fno-rtti, leading to linker errors. Be sure to add it. COMMAND ${LLVM_CONFIG_EXECUTABLE} --ldflags
if(CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) OUTPUT_VARIABLE LLVM_LFLAGS
if(NOT ${LLVM_CXXFLAGS} MATCHES "-fno-rtti") OUTPUT_STRIP_TRAILING_WHITESPACE
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fno-rtti") )
endif()
endif()
string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" ) execute_process(
string(REGEX REPLACE "[0-9]+\\.([0-9]+).*[A-Za-z]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" ) COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs core bitreader asmparser analysis
OUTPUT_VARIABLE LLVM_MODULE_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (${LLVM_VERSION_STRING} VERSION_LESS ${LLVM_FIND_VERSION}) execute_process(
message(FATAL_ERROR "Unsupported LLVM version found ${LLVM_VERSION_STRING}. At least version ${LLVM_FIND_VERSION} is required.") COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs
endif() OUTPUT_VARIABLE LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Use the default CMake facilities for handling QUIET/REQUIRED. execute_process(
include(FindPackageHandleStandardArgs) COMMAND ${LLVM_CONFIG_EXECUTABLE} --prefix
OUTPUT_VARIABLE LLVM_INSTALL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(${CMAKE_VERSION} VERSION_LESS "2.8.4") # potentially add include dir from binary dir for non-installed LLVM
# The VERSION_VAR argument is not supported on pre-2.8.4, work around this. execute_process(
set(VERSION_VAR dummy) COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root
OUTPUT_VARIABLE _llvmSourceRoot
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(FIND "${LLVM_INCLUDE_DIRS}" "${_llvmSourceRoot}" _llvmIsInstalled)
if (NOT _llvmIsInstalled)
list(APPEND LLVM_INCLUDE_DIRS "${LLVM_INSTALL_PREFIX}/include")
endif()
endif() endif()
find_package_handle_standard_args(LLVM if (LLVM_FIND_REQUIRED AND NOT LLVM_FOUND)
REQUIRED_VARS LLVM_ROOT_DIR LLVM_HOST_TARGET message(FATAL_ERROR "Could not find LLVM: ${_LLVM_ERROR_MESSAGE}")
VERSION_VAR LLVM_VERSION_STRING) elseif(_LLVM_ERROR_MESSAGE)
message(STATUS "Could not find LLVM: ${_LLVM_ERROR_MESSAGE}")
endif()
if (LLVM_FOUND)
string(REGEX REPLACE "-lLLVMScaffold" "${LLVM_ROOT}/lib/Scaffold.so" LLVM_LIBS ${LLVM_LIBS})
string(REGEX REPLACE "-lLLVMIntelJITEvents " "" LLVM_LIBS ${LLVM_LIBS})
string(REGEX REPLACE "-lLLVMOProfileJIT " "" LLVM_LIBS ${LLVM_LIBS})
message(STATUS "Found LLVM (version: ${LLVM_VERSION}): (using ${LLVM_CONFIG_EXECUTABLE})")
message(STATUS " Include dirs: ${LLVM_INCLUDE_DIRS}")
message(STATUS " LLVM libraries: ${LLVM_LIBS}")
endif()
...@@ -39,19 +39,18 @@ set(CMAKE_CXX_FLAGS "-D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FO ...@@ -39,19 +39,18 @@ set(CMAKE_CXX_FLAGS "-D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FO
set_source_files_properties(ScaffoldASTConsumer.cpp PROPERTIES COMPILE_FLAGS -fno-rtti) set_source_files_properties(ScaffoldASTConsumer.cpp PROPERTIES COMPILE_FLAGS -fno-rtti)
include_directories(${CLANG_INCLUDE_DIRS})
include_directories(${CLANG_INCLUDE_DIRS}/extra-tools)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate) include_directories(${CMAKE_SOURCE_DIR}/quantum/gate)
include_directories(/usr/local/scaffold/include)
include_directories(/usr/local/scaffold/build/include)
include_directories(/usr/local/scaffold/build/tools/clang/include)
add_library(${LIBRARY_NAME} SHARED ${SRC}) add_library(${LIBRARY_NAME} SHARED ${SRC})
install(FILES ${HEADERS} DESTINATION include) install(FILES ${HEADERS} DESTINATION include)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib) install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
link_directories("/usr/local/scaffold/build/Release+Asserts/lib") link_directories(${CLANG_LIBRARY_DIRS})
# Gather tests # Gather tests
file (GLOB test_files tests/*.cpp) file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "/usr/local/scaffold/include;/usr/local/scaffold/build/include;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_SOURCE_DIR}/quantum/gate/utils" "${LIBRARY_NAME};xacc-gateqir;clangTooling;clangFrontendTool;clangFrontend;clangDriver;clangSerialization;clangCodeGen;clangParse;clangSema;clangStaticAnalyzerFrontend;clangStaticAnalyzerCheckers;clangStaticAnalyzerCore;clangAnalysis;clangARCMigrate;clangEdit;clangAST;clangLex;clangBasic;LLVMAsmParser;LLVMInstrumentation;LLVMLinker;LLVMArchive;LLVMBitReader;LLVMDebugInfo;LLVMJIT;LLVMipo;LLVMVectorize;LLVMBitWriter;LLVMTableGen;LLVMHexagonCodeGen;LLVMHexagonDesc;LLVMHexagonInfo;LLVMHexagonAsmPrinter;LLVMPTXCodeGen;LLVMPTXDesc;LLVMPTXInfo;LLVMPTXAsmPrinter;LLVMMBlazeDisassembler;LLVMMBlazeAsmParser;LLVMMBlazeCodeGen;LLVMMBlazeDesc;LLVMMBlazeInfo;LLVMMBlazeAsmPrinter;LLVMCppBackendCodeGen;LLVMCppBackendInfo;LLVMMSP430CodeGen;LLVMMSP430Desc;LLVMMSP430Info;LLVMMSP430AsmPrinter;LLVMXCoreCodeGen;LLVMXCoreDesc;LLVMXCoreInfo;LLVMCellSPUCodeGen;LLVMCellSPUDesc;LLVMCellSPUInfo;LLVMMipsDisassembler;LLVMMipsAsmParser;LLVMMipsCodeGen;LLVMMipsDesc;LLVMMipsInfo;LLVMMipsAsmPrinter;LLVMARMDisassembler;LLVMARMAsmParser;LLVMARMCodeGen;LLVMARMDesc;LLVMARMInfo;LLVMARMAsmPrinter;LLVMPowerPCCodeGen;LLVMPowerPCDesc;LLVMPowerPCInfo;LLVMPowerPCAsmPrinter;LLVMSparcCodeGen;LLVMSparcDesc;LLVMSparcInfo;LLVMX86AsmParser;LLVMX86Disassembler;LLVMX86CodeGen;LLVMSelectionDAG;LLVMAsmPrinter;LLVMX86Desc;LLVMX86Info;LLVMX86AsmPrinter;LLVMX86Utils;gtest_main;gtest;LLVMMCDisassembler;LLVMMCParser;LLVMInterpreter;LLVMCodeGen;LLVMScalarOpts;LLVMInstCombine;LLVMTransformUtils;LLVMipa;LLVMAnalysis;LLVMMCJIT;LLVMRuntimeDyld;LLVMExecutionEngine;LLVMTarget;LLVMMC;LLVMObject;LLVMCore;LLVMSupport;dl;pthread") add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};xacc-gateqir;${CLANG_LIBS};${LLVM_LIBS};dl;pthread")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment