Skip to content

Commit 7735281

Browse files
committed
blah
1 parent ce4fa84 commit 7735281

File tree

6 files changed

+458
-19
lines changed

6 files changed

+458
-19
lines changed

CMakeLists.txt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ project( ClamBCC
2424
DESCRIPTION "ClamAV Bytecode Compiler." )
2525

2626
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
27-
#include(Version)
27+
include(Version)
2828

2929
set(PACKAGE_NAME "${PROJECT_NAME}")
3030
set(PACKAGE_VERSION "${PROJECT_VERSION}")
3131
set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}${VERSION_SUFFIX}")
3232
set(PACKAGE_BUGREPORT "https://github.com/Cisco-Talos/clamav-bytecode-compiler/issues")
3333
set(PACKAGE_URL "https://www.clamav.net/")
34-
#HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH})
34+
HexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH})
3535

3636
# libtool library versioning rules: http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
3737
set(LIBCLAMBC_CURRENT 1)
@@ -40,7 +40,7 @@ set(LIBCLAMBC_AGE 0)
4040

4141
math(EXPR LIBCLAMBC_SOVERSION "${LIBCLAMBC_CURRENT} - ${LIBCLAMBC_AGE}")
4242
set(LIBCLAMBC_VERSION "${LIBCLAMBC_SOVERSION}.${LIBCLAMBC_AGE}.${LIBCLAMBC_REVISION}")
43-
#HexVersion(LIBCLAMBC_VERSION_NUM ${LIBCLAMBC_CURRENT} ${LIBCLAMBC_REVISION} ${LIBCLAMBC_AGE})
43+
HexVersion(LIBCLAMBC_VERSION_NUM ${LIBCLAMBC_CURRENT} ${LIBCLAMBC_REVISION} ${LIBCLAMBC_AGE})
4444

4545
# Git optionally used to add commit info into build to differentiate in bug reports.
4646
find_package(Git)
@@ -103,7 +103,7 @@ if(ENABLE_TESTS)
103103
set(Python3_TEST_PACKAGE "pytest;-v")
104104
endif()
105105

106-
#find_package(ClamAV REQUIRED)
106+
find_package(ClamAV REQUIRED)
107107
endif()
108108

109109
find_package(LLVM 16 REQUIRED)
@@ -187,15 +187,10 @@ configure_file(clambc-version.h.in clambc-version.h)
187187
# Build targets!
188188
#
189189

190-
include(AddLLVM)
191-
192190
# The bytecode compiler optimization passes
193191
# This is the core of the bytecode compiler
194192
add_subdirectory(libclambcc)
195193

196-
# Examples of plugins for the new and legacy pass managers.
197-
add_subdirectory(examples)
198-
199194
# The bytecode compiler application
200195
# This is really just a python script
201196
add_subdirectory(clambcc)
@@ -217,18 +212,17 @@ add_subdirectory(headers)
217212
# `pandoc -s file.tex -o file.md` mostly-works, but w/ the doxygen integration is insufficient.
218213
# add_subdirectory(docs)
219214

220-
#if(ENABLE_EXAMPLES)
221-
# # Example optimization passes; boilerplate to help compiler devs write new passes.
222-
# add_subdirectory( examples )
223-
#endif()
215+
if(ENABLE_EXAMPLES)
216+
# Example optimization passes; boilerplate to help compiler devs write new passes.
217+
add_subdirectory( examples )
218+
endif()
224219

225220
include(CTest)
226-
227221
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
228-
#if(ENABLE_TESTS)
229-
# # Tests to verify compiler works as intended and that signatures behave as intended.
230-
# add_subdirectory( test )
231-
#endif()
222+
if(ENABLE_TESTS)
223+
# Tests to verify compiler works as intended and that signatures behave as intended.
224+
add_subdirectory( test )
225+
endif()
232226

233227
if(WIN32)
234228
# Include the license(s) in the installation

cmake/FindClamAV.cmake

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#
2+
# Find the ClamAV programs and headers needed for the test suite.
3+
#
4+
# If found, will set:
5+
# ClamAV_FOUND, ClamAV_VERSION, and
6+
# - clamscan_EXECUTABLE
7+
# - clambc_EXECUTABLE
8+
# - sigtool_EXECUTABLE
9+
# - clambc_headers_DIRECTORY
10+
#
11+
# If you have a custom install location for ClamAV, you can provide a hint
12+
# by settings -DClamAV_HOME=<clamav install prefix>
13+
#
14+
15+
find_program(clamscan_EXECUTABLE
16+
NAMES clamscan clamscan.exe
17+
HINTS "${ClamAV_HOME}"
18+
PATH_SUFFIXES "bin"
19+
)
20+
if(NOT clamscan_EXECUTABLE AND NOT ClamAV_FIND_QUIETLY)
21+
message("Unable to find clamscan")
22+
endif()
23+
24+
find_program(clambc_EXECUTABLE
25+
NAMES clambc clambc.exe
26+
HINTS "${ClamAV_HOME}"
27+
PATH_SUFFIXES "bin"
28+
)
29+
if(NOT clambc_EXECUTABLE AND NOT ClamAV_FIND_QUIETLY)
30+
message("Unable to find clambc")
31+
endif()
32+
33+
find_program(sigtool_EXECUTABLE
34+
NAMES sigtool sigtool.exe
35+
HINTS "${ClamAV_HOME}"
36+
PATH_SUFFIXES "bin"
37+
)
38+
if(NOT sigtool_EXECUTABLE AND NOT ClamAV_FIND_QUIETLY)
39+
message("Unable to find sigtool")
40+
endif()
41+
42+
if(clamscan_EXECUTABLE AND clambc_EXECUTABLE AND sigtool_EXECUTABLE)
43+
execute_process(COMMAND "${clamscan_EXECUTABLE}" --version
44+
OUTPUT_VARIABLE ClamAV_VERSION_OUTPUT
45+
ERROR_VARIABLE ClamAV_VERSION_ERROR
46+
RESULT_VARIABLE ClamAV_VERSION_RESULT
47+
)
48+
if(NOT ${ClamAV_VERSION_RESULT} EQUAL 0)
49+
if(NOT ClamAV_FIND_QUIETLY)
50+
message(STATUS "ClamAV not found: Failed to determine version.")
51+
endif()
52+
unset(clamscan_EXECUTABLE)
53+
else()
54+
string(REGEX
55+
MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?(-devel)?"
56+
ClamAV_VERSION "${ClamAV_VERSION_OUTPUT}"
57+
)
58+
set(ClamAV_VERSION "${ClamAV_VERSION}")
59+
set(ClamAV_FOUND 1)
60+
61+
# Look for the clambc-headers. E.g.: <clamav prefix>/lib/clambc-headers/0.104.0
62+
#
63+
# In the future, the clamav-derived headers for compiling signatures will be
64+
# installed with clamav, and this path will be necessary to find them for running
65+
# the test suite.
66+
find_file(clambc_headers_DIRECTORY
67+
clambc-headers/${ClamAV_VERSION}
68+
HINTS "${ClamAV_HOME}"
69+
PATH_SUFFIXES "lib"
70+
)
71+
72+
if(NOT ClamAV_FIND_QUIETLY)
73+
message(STATUS "ClamAV found: ${ClamAV_VERSION}")
74+
message(STATUS " clamscan: ${clamscan_EXECUTABLE}")
75+
message(STATUS " clambc: ${clambc_EXECUTABLE}")
76+
message(STATUS " sigtool: ${sigtool_EXECUTABLE}")
77+
message(STATUS " bc headers: ${clambc_headers_DIRECTORY}")
78+
endif()
79+
80+
if(NOT clambc_headers_DIRECTORY)
81+
set(clambc_headers_DIRECTORY "")
82+
endif()
83+
endif()
84+
85+
mark_as_advanced(clamscan_EXECUTABLE clambc_EXECUTABLE sigtool_EXECUTABLE ClamAV_VERSION)
86+
else()
87+
if(ClamAV_FIND_REQUIRED)
88+
message(FATAL_ERROR "ClamAV not found.")
89+
else()
90+
if(NOT ClamAV_FIND_QUIETLY)
91+
message(STATUS "${_msg}")
92+
endif()
93+
endif()
94+
endif()

cmake/FindClang.cmake

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Detect Clang libraries
2+
#
3+
# Defines the following variables:
4+
# CLANG_FOUND - True if Clang was found
5+
# CLANG_INCLUDE_DIRS - Where to find Clang includes
6+
# CLANG_LIBRARY_DIRS - Where to find Clang libraries
7+
# CLANG_BUILTIN_DIR - Where to find Clang builtin includes
8+
#
9+
# CLANG_CLANG_LIB - Libclang C library
10+
#
11+
# CLANG_CLANGFRONTEND_LIB - Clang Frontend (C++) Library
12+
# CLANG_CLANGDRIVER_LIB - Clang Driver (C++) Library
13+
# ...
14+
#
15+
# CLANG_LIBS - All the Clang C++ libraries
16+
#
17+
# Uses the same include and library paths detected by FindLLVM.cmake
18+
#
19+
# See https://clang.llvm.org/docs/InternalsManual.html for full list of libraries
20+
21+
#=============================================================================
22+
# Copyright 2014-2015 Kevin Funk <[email protected]>
23+
#
24+
# Distributed under the OSI-approved BSD License (the "License");
25+
# see accompanying file Copyright.txt for details.
26+
#
27+
# This software is distributed WITHOUT ANY WARRANTY; without even the
28+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29+
# See the License for more information.
30+
31+
#=============================================================================
32+
33+
set(KNOWN_VERSIONS 16)
34+
35+
foreach(version ${KNOWN_VERSIONS})
36+
if(DEFINED Clang_FIND_VERSION AND Clang_FIND_VERSION VERSION_EQUAL version)
37+
find_package(LLVM ${version} PATHS ${LLVM_ROOT})
38+
else()
39+
find_package(LLVM PATHS ${LLVM_ROOT})
40+
endif()
41+
endforeach()
42+
43+
if (${Clang_FIND_REQUIRED})
44+
if(NOT DEFINED LLVM_FOUND)
45+
message(SEND_ERROR "Could not find LLVM (or Clang for that matter)")
46+
else()
47+
message("Found LLVM version ${LLVM_VERSION}")
48+
endif()
49+
endif()
50+
51+
set(CLANG_FOUND FALSE)
52+
53+
if(LLVM_FOUND AND LLVM_LIBRARY_DIRS)
54+
message("Searching for clang libraries...")
55+
macro(FIND_AND_ADD_CLANG_LIB _libname_)
56+
# message("Searching for ${LLVM_LIBRARY_DIRS}/lib${_libname_}-${Clang_FIND_VERSION}.so.1")
57+
string(TOUPPER ${_libname_} _prettylibname_)
58+
find_library(CLANG_${_prettylibname_}_LIB
59+
NAMES
60+
${_libname_}-${Clang_FIND_VERSION}.so.1 lib${_libname_}-${Clang_FIND_VERSION}.so.1
61+
${_libname_}-${Clang_FIND_VERSION} lib${_libname_}-${Clang_FIND_VERSION}
62+
${_libname_}.so.1 lib${_libname_}.so.1
63+
${_libname_} lib${_libname_}
64+
HINTS
65+
${LLVM_LIBRARY_DIRS} ${ARGN})
66+
if(CLANG_${_prettylibname_}_LIB)
67+
message("Found ${CLANG_${_prettylibname_}_LIB}")
68+
set(CLANG_LIBS ${CLANG_LIBS} ${CLANG_${_prettylibname_}_LIB})
69+
endif()
70+
endmacro(FIND_AND_ADD_CLANG_LIB)
71+
72+
FIND_AND_ADD_CLANG_LIB(clangFrontend)
73+
74+
# note: On Windows there's 'libclang.dll' instead of 'clang.dll' -> search for 'libclang', too
75+
FIND_AND_ADD_CLANG_LIB(clang NAMES clang libclang clang-${Clang_FIND_VERSION} libclang-${Clang_FIND_VERSION}) # LibClang: high-level C interface
76+
77+
FIND_AND_ADD_CLANG_LIB(clangDriver)
78+
FIND_AND_ADD_CLANG_LIB(clangCodeGen)
79+
FIND_AND_ADD_CLANG_LIB(clangSema)
80+
FIND_AND_ADD_CLANG_LIB(clangChecker)
81+
FIND_AND_ADD_CLANG_LIB(clangAnalysis)
82+
FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend)
83+
FIND_AND_ADD_CLANG_LIB(clangRewrite)
84+
FIND_AND_ADD_CLANG_LIB(clangAST)
85+
FIND_AND_ADD_CLANG_LIB(clangParse)
86+
FIND_AND_ADD_CLANG_LIB(clangLex)
87+
FIND_AND_ADD_CLANG_LIB(clangBasic)
88+
FIND_AND_ADD_CLANG_LIB(clangARCMigrate)
89+
FIND_AND_ADD_CLANG_LIB(clangEdit)
90+
FIND_AND_ADD_CLANG_LIB(clangFrontendTool)
91+
FIND_AND_ADD_CLANG_LIB(clangSerialization)
92+
FIND_AND_ADD_CLANG_LIB(clangTooling)
93+
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCheckers)
94+
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCore)
95+
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerFrontend)
96+
FIND_AND_ADD_CLANG_LIB(clangRewriteCore)
97+
endif()
98+
99+
if(CLANG_LIBS OR CLANG_CLANG_LIB)
100+
set(CLANG_FOUND TRUE)
101+
else()
102+
message(STATUS "Could not find any Clang libraries in ${LLVM_LIBRARY_DIRS}")
103+
endif()
104+
105+
if(CLANG_FOUND)
106+
set(CLANG_LIBRARY_DIRS ${LLVM_LIBRARY_DIRS})
107+
set(CLANG_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
108+
set(CLANG_VERSION ${LLVM_VERSION})
109+
110+
# svn version of clang has a svn suffix "8.0.0svn" but installs the header in "8.0.0", without the suffix
111+
string(REPLACE "svn" "" CLANG_VERSION_CLEAN "${CLANG_VERSION}")
112+
# dito for git
113+
string(REPLACE "git" "" CLANG_VERSION_CLEAN "${CLANG_VERSION}")
114+
115+
find_path(CLANG_BUILTIN_DIR
116+
# cpuid.h because it is defined in ClangSupport constructor as valid clang builtin dir indicator
117+
NAMES "cpuid.h"
118+
PATHS "${CLANG_LIBRARY_DIRS}"
119+
"${CLANG_INCLUDE_DIRS}"
120+
PATH_SUFFIXES "clang/${CLANG_VERSION}/include"
121+
"../../../clang/${CLANG_VERSION}/include"
122+
"clang/${CLANG_VERSION_CLEAN}/include"
123+
"../../../clang/${CLANG_VERSION_CLEAN}/include"
124+
NO_DEFAULT_PATH
125+
)
126+
127+
if (NOT CLANG_BUILTIN_DIR)
128+
message(FATAL_ERROR "Could not find Clang builtin directory")
129+
endif()
130+
get_filename_component(CLANG_BUILTIN_DIR ${CLANG_BUILTIN_DIR} ABSOLUTE)
131+
132+
# check whether llvm-config comes from an install prefix
133+
execute_process(
134+
COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root
135+
OUTPUT_VARIABLE _llvmSourceRoot
136+
OUTPUT_STRIP_TRAILING_WHITESPACE
137+
)
138+
string(FIND "${LLVM_INCLUDE_DIRS}" "${_llvmSourceRoot}" _llvmIsInstalled)
139+
if (NOT _llvmIsInstalled)
140+
message(STATUS "Detected that llvm-config comes from a build-tree, adding more include directories for Clang")
141+
list(APPEND CLANG_INCLUDE_DIRS
142+
"${LLVM_INSTALL_PREFIX}/tools/clang/include" # build dir
143+
)
144+
145+
# check whether the source is from llvm-project.git (currently recommended way to clone the LLVM projects)
146+
# contains all LLVM projects in the top-level directory
147+
get_filename_component(_llvmProjectClangIncludeDir ${_llvmSourceRoot}/../clang/include REALPATH)
148+
if (EXISTS ${_llvmProjectClangIncludeDir})
149+
message(STATUS " Note: llvm-project.git structure detected, using different include path pointing into source dir")
150+
list(APPEND CLANG_INCLUDE_DIRS "${_llvmProjectClangIncludeDir}") # source dir
151+
else()
152+
list(APPEND CLANG_INCLUDE_DIRS "${_llvmSourceRoot}/tools/clang/include") # source dir
153+
endif()
154+
endif()
155+
156+
# if the user specified LLVM_ROOT, use that and fail otherwise
157+
if (LLVM_ROOT)
158+
find_program(CLANG_EXECUTABLE NAMES clang HINTS ${LLVM_ROOT}/bin DOC "clang executable" NO_DEFAULT_PATH)
159+
elseif (NOT CLANG_EXECUTABLE)
160+
# find clang, prefer the one with a version suffix, e.g. clang-3.5
161+
# note: FreeBSD installs clang as clang35 and so on
162+
# note: on some distributions, only 'clang' is shipped, so let's always try to fallback on that
163+
string(REPLACE "." "" Clang_FIND_VERSION_CONCAT ${Clang_FIND_VERSION})
164+
find_program(CLANG_EXECUTABLE NAMES clang-${Clang_FIND_VERSION} clang${Clang_FIND_VERSION_CONCAT} clang DOC "clang executable")
165+
endif()
166+
167+
message(STATUS "Found Clang (LLVM version: ${CLANG_VERSION})")
168+
message(STATUS " Include dirs: ${CLANG_INCLUDE_DIRS}")
169+
message(STATUS " Clang libraries: ${CLANG_LIBS}")
170+
message(STATUS " Libclang C library: ${CLANG_CLANG_LIB}")
171+
message(STATUS " Builtin include dir: ${CLANG_BUILTIN_DIR}")
172+
message(STATUS " Clang executable: ${CLANG_EXECUTABLE}")
173+
else()
174+
if(Clang_FIND_REQUIRED)
175+
message(FATAL_ERROR "Could NOT find Clang")
176+
endif()
177+
endif()

0 commit comments

Comments
 (0)