-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
458 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# | ||
# Find the ClamAV programs and headers needed for the test suite. | ||
# | ||
# If found, will set: | ||
# ClamAV_FOUND, ClamAV_VERSION, and | ||
# - clamscan_EXECUTABLE | ||
# - clambc_EXECUTABLE | ||
# - sigtool_EXECUTABLE | ||
# - clambc_headers_DIRECTORY | ||
# | ||
# If you have a custom install location for ClamAV, you can provide a hint | ||
# by settings -DClamAV_HOME=<clamav install prefix> | ||
# | ||
|
||
find_program(clamscan_EXECUTABLE | ||
NAMES clamscan clamscan.exe | ||
HINTS "${ClamAV_HOME}" | ||
PATH_SUFFIXES "bin" | ||
) | ||
if(NOT clamscan_EXECUTABLE AND NOT ClamAV_FIND_QUIETLY) | ||
message("Unable to find clamscan") | ||
endif() | ||
|
||
find_program(clambc_EXECUTABLE | ||
NAMES clambc clambc.exe | ||
HINTS "${ClamAV_HOME}" | ||
PATH_SUFFIXES "bin" | ||
) | ||
if(NOT clambc_EXECUTABLE AND NOT ClamAV_FIND_QUIETLY) | ||
message("Unable to find clambc") | ||
endif() | ||
|
||
find_program(sigtool_EXECUTABLE | ||
NAMES sigtool sigtool.exe | ||
HINTS "${ClamAV_HOME}" | ||
PATH_SUFFIXES "bin" | ||
) | ||
if(NOT sigtool_EXECUTABLE AND NOT ClamAV_FIND_QUIETLY) | ||
message("Unable to find sigtool") | ||
endif() | ||
|
||
if(clamscan_EXECUTABLE AND clambc_EXECUTABLE AND sigtool_EXECUTABLE) | ||
execute_process(COMMAND "${clamscan_EXECUTABLE}" --version | ||
OUTPUT_VARIABLE ClamAV_VERSION_OUTPUT | ||
ERROR_VARIABLE ClamAV_VERSION_ERROR | ||
RESULT_VARIABLE ClamAV_VERSION_RESULT | ||
) | ||
if(NOT ${ClamAV_VERSION_RESULT} EQUAL 0) | ||
if(NOT ClamAV_FIND_QUIETLY) | ||
message(STATUS "ClamAV not found: Failed to determine version.") | ||
endif() | ||
unset(clamscan_EXECUTABLE) | ||
else() | ||
string(REGEX | ||
MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?(-devel)?" | ||
ClamAV_VERSION "${ClamAV_VERSION_OUTPUT}" | ||
) | ||
set(ClamAV_VERSION "${ClamAV_VERSION}") | ||
set(ClamAV_FOUND 1) | ||
|
||
# Look for the clambc-headers. E.g.: <clamav prefix>/lib/clambc-headers/0.104.0 | ||
# | ||
# In the future, the clamav-derived headers for compiling signatures will be | ||
# installed with clamav, and this path will be necessary to find them for running | ||
# the test suite. | ||
find_file(clambc_headers_DIRECTORY | ||
clambc-headers/${ClamAV_VERSION} | ||
HINTS "${ClamAV_HOME}" | ||
PATH_SUFFIXES "lib" | ||
) | ||
|
||
if(NOT ClamAV_FIND_QUIETLY) | ||
message(STATUS "ClamAV found: ${ClamAV_VERSION}") | ||
message(STATUS " clamscan: ${clamscan_EXECUTABLE}") | ||
message(STATUS " clambc: ${clambc_EXECUTABLE}") | ||
message(STATUS " sigtool: ${sigtool_EXECUTABLE}") | ||
message(STATUS " bc headers: ${clambc_headers_DIRECTORY}") | ||
endif() | ||
|
||
if(NOT clambc_headers_DIRECTORY) | ||
set(clambc_headers_DIRECTORY "") | ||
endif() | ||
endif() | ||
|
||
mark_as_advanced(clamscan_EXECUTABLE clambc_EXECUTABLE sigtool_EXECUTABLE ClamAV_VERSION) | ||
else() | ||
if(ClamAV_FIND_REQUIRED) | ||
message(FATAL_ERROR "ClamAV not found.") | ||
else() | ||
if(NOT ClamAV_FIND_QUIETLY) | ||
message(STATUS "${_msg}") | ||
endif() | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
# 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_BUILTIN_DIR - Where to find Clang builtin includes | ||
# | ||
# CLANG_CLANG_LIB - Libclang C library | ||
# | ||
# CLANG_CLANGFRONTEND_LIB - Clang Frontend (C++) Library | ||
# CLANG_CLANGDRIVER_LIB - Clang Driver (C++) Library | ||
# ... | ||
# | ||
# CLANG_LIBS - All the Clang C++ libraries | ||
# | ||
# Uses the same include and library paths detected by FindLLVM.cmake | ||
# | ||
# See https://clang.llvm.org/docs/InternalsManual.html for full list of libraries | ||
|
||
#============================================================================= | ||
# Copyright 2014-2015 Kevin Funk <[email protected]> | ||
# | ||
# 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. | ||
|
||
#============================================================================= | ||
|
||
set(KNOWN_VERSIONS 16) | ||
|
||
foreach(version ${KNOWN_VERSIONS}) | ||
if(DEFINED Clang_FIND_VERSION AND Clang_FIND_VERSION VERSION_EQUAL version) | ||
find_package(LLVM ${version} PATHS ${LLVM_ROOT}) | ||
else() | ||
find_package(LLVM PATHS ${LLVM_ROOT}) | ||
endif() | ||
endforeach() | ||
|
||
if (${Clang_FIND_REQUIRED}) | ||
if(NOT DEFINED LLVM_FOUND) | ||
message(SEND_ERROR "Could not find LLVM (or Clang for that matter)") | ||
else() | ||
message("Found LLVM version ${LLVM_VERSION}") | ||
endif() | ||
endif() | ||
|
||
set(CLANG_FOUND FALSE) | ||
|
||
if(LLVM_FOUND AND LLVM_LIBRARY_DIRS) | ||
message("Searching for clang libraries...") | ||
macro(FIND_AND_ADD_CLANG_LIB _libname_) | ||
# message("Searching for ${LLVM_LIBRARY_DIRS}/lib${_libname_}-${Clang_FIND_VERSION}.so.1") | ||
string(TOUPPER ${_libname_} _prettylibname_) | ||
find_library(CLANG_${_prettylibname_}_LIB | ||
NAMES | ||
${_libname_}-${Clang_FIND_VERSION}.so.1 lib${_libname_}-${Clang_FIND_VERSION}.so.1 | ||
${_libname_}-${Clang_FIND_VERSION} lib${_libname_}-${Clang_FIND_VERSION} | ||
${_libname_}.so.1 lib${_libname_}.so.1 | ||
${_libname_} lib${_libname_} | ||
HINTS | ||
${LLVM_LIBRARY_DIRS} ${ARGN}) | ||
if(CLANG_${_prettylibname_}_LIB) | ||
message("Found ${CLANG_${_prettylibname_}_LIB}") | ||
set(CLANG_LIBS ${CLANG_LIBS} ${CLANG_${_prettylibname_}_LIB}) | ||
endif() | ||
endmacro(FIND_AND_ADD_CLANG_LIB) | ||
|
||
FIND_AND_ADD_CLANG_LIB(clangFrontend) | ||
|
||
# note: On Windows there's 'libclang.dll' instead of 'clang.dll' -> search for 'libclang', too | ||
FIND_AND_ADD_CLANG_LIB(clang NAMES clang libclang clang-${Clang_FIND_VERSION} libclang-${Clang_FIND_VERSION}) # LibClang: high-level C interface | ||
|
||
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(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(clangRewriteCore) | ||
endif() | ||
|
||
if(CLANG_LIBS OR CLANG_CLANG_LIB) | ||
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}) | ||
set(CLANG_VERSION ${LLVM_VERSION}) | ||
|
||
# svn version of clang has a svn suffix "8.0.0svn" but installs the header in "8.0.0", without the suffix | ||
string(REPLACE "svn" "" CLANG_VERSION_CLEAN "${CLANG_VERSION}") | ||
# dito for git | ||
string(REPLACE "git" "" CLANG_VERSION_CLEAN "${CLANG_VERSION}") | ||
|
||
find_path(CLANG_BUILTIN_DIR | ||
# cpuid.h because it is defined in ClangSupport constructor as valid clang builtin dir indicator | ||
NAMES "cpuid.h" | ||
PATHS "${CLANG_LIBRARY_DIRS}" | ||
"${CLANG_INCLUDE_DIRS}" | ||
PATH_SUFFIXES "clang/${CLANG_VERSION}/include" | ||
"../../../clang/${CLANG_VERSION}/include" | ||
"clang/${CLANG_VERSION_CLEAN}/include" | ||
"../../../clang/${CLANG_VERSION_CLEAN}/include" | ||
NO_DEFAULT_PATH | ||
) | ||
|
||
if (NOT CLANG_BUILTIN_DIR) | ||
message(FATAL_ERROR "Could not find Clang builtin directory") | ||
endif() | ||
get_filename_component(CLANG_BUILTIN_DIR ${CLANG_BUILTIN_DIR} ABSOLUTE) | ||
|
||
# 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 | ||
) | ||
|
||
# check whether the source is from llvm-project.git (currently recommended way to clone the LLVM projects) | ||
# contains all LLVM projects in the top-level directory | ||
get_filename_component(_llvmProjectClangIncludeDir ${_llvmSourceRoot}/../clang/include REALPATH) | ||
if (EXISTS ${_llvmProjectClangIncludeDir}) | ||
message(STATUS " Note: llvm-project.git structure detected, using different include path pointing into source dir") | ||
list(APPEND CLANG_INCLUDE_DIRS "${_llvmProjectClangIncludeDir}") # source dir | ||
else() | ||
list(APPEND CLANG_INCLUDE_DIRS "${_llvmSourceRoot}/tools/clang/include") # source dir | ||
endif() | ||
endif() | ||
|
||
# if the user specified LLVM_ROOT, use that and fail otherwise | ||
if (LLVM_ROOT) | ||
find_program(CLANG_EXECUTABLE NAMES clang HINTS ${LLVM_ROOT}/bin DOC "clang executable" NO_DEFAULT_PATH) | ||
elseif (NOT CLANG_EXECUTABLE) | ||
# find clang, prefer the one with a version suffix, e.g. clang-3.5 | ||
# note: FreeBSD installs clang as clang35 and so on | ||
# note: on some distributions, only 'clang' is shipped, so let's always try to fallback on that | ||
string(REPLACE "." "" Clang_FIND_VERSION_CONCAT ${Clang_FIND_VERSION}) | ||
find_program(CLANG_EXECUTABLE NAMES clang-${Clang_FIND_VERSION} clang${Clang_FIND_VERSION_CONCAT} clang DOC "clang executable") | ||
endif() | ||
|
||
message(STATUS "Found Clang (LLVM version: ${CLANG_VERSION})") | ||
message(STATUS " Include dirs: ${CLANG_INCLUDE_DIRS}") | ||
message(STATUS " Clang libraries: ${CLANG_LIBS}") | ||
message(STATUS " Libclang C library: ${CLANG_CLANG_LIB}") | ||
message(STATUS " Builtin include dir: ${CLANG_BUILTIN_DIR}") | ||
message(STATUS " Clang executable: ${CLANG_EXECUTABLE}") | ||
else() | ||
if(Clang_FIND_REQUIRED) | ||
message(FATAL_ERROR "Could NOT find Clang") | ||
endif() | ||
endif() |
Oops, something went wrong.