-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
129 lines (111 loc) · 4.43 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
cmake_minimum_required(VERSION 3.1.0)
# FIXME: Unfortunately, C is (at least temporarily) required due to a bug
# in LLVM 14. See https://github.com/llvm/llvm-project/issues/53950.
project(sbt-instrumentation LANGUAGES C CXX)
# --------------------------------------------------
# Build type
# --------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type not set. Setting default.")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "RelWithDebInfo"
"MinSizeRel" "Release")
# --------------------------------------------------
# Compilation flags
# --------------------------------------------------
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -fno-rtti")
# --------------------------------------------------
# LLVM
# --------------------------------------------------
find_package(LLVM REQUIRED CONFIG)
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
include(AddLLVM)
if(${LLVM_PACKAGE_VERSION} VERSION_LESS "3.9.1")
message(FATAL_ERROR "Need LLVM in version at least 3.9.1")
endif()
# TODO: Move this to the section above when we switch to C++14
# LLVM 10 and newer require at least C++14 standard
if(${LLVM_PACKAGE_VERSION} VERSION_GREATER "9.0")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
# otherwise we need C++11 standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
add_definitions(${LLVM_DEFINITIONS})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "LLVM definitions: ${LLVM_DEFINITIONS}")
message(STATUS "LLVM include dir: ${LLVM_INCLUDE_DIRS}")
message(STATUS "LLVM libraries dir: ${LLVM_LIBRARY_DIRS}")
option(LLVM_LINK_DYLIB "Link with LLVM dynamically" ON)
if(LLVM_LINK_DYLIB)
message(STATUS "LLVM linking: dynamic")
set(LLVM_LIBS LLVM)
else()
message(STATUS "LLVM linking: static")
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(LLVM_LIBS bitwriter core irreader
linker support)
endif()
# --------------------------------------------------
# DG
# --------------------------------------------------
add_definitions(-DHAVE_LLVM)
if(DG_PATH)
include_directories(${DG_PATH}/include/)
else()
include_directories(${CMAKE_SOURCE_DIR}/dg/include)
set(DG_PATH ${CMAKE_SOURCE_DIR}/dg)
endif()
# Those libraries we'll use, since we want to use the LLVM points-to analysis
find_library(libdganalysis dganalysis PATHS ${DG_PATH}/lib/)
find_library(libdgllvmpta dgllvmpta PATHS ${DG_PATH}/lib/)
find_library(libdgpta dgpta PATHS ${DG_PATH}/lib/)
if(libdganalysis AND libdgllvmpta AND libdgpta)
message(STATUS "DG libraries found: ${libdganalysis}, ${libdgllvmpta}, ${libdgpta}")
set(DG_LIBS ${libdganalysis} ${libdgllvmpta} ${libdgpta})
else()
message(FATAL_ERROR "DG not found! Try specifying -DDG_PATH=<path>.")
endif()
# ------------------------------------------------
# jsoncpp
# ------------------------------------------------
find_package(jsoncpp 1.9.2 QUIET CONFIG)
if(jsoncpp_FOUND)
message(STATUS "Found jsoncpp (found version \"${jsoncpp_VERSION}\")")
set(JSON_LIBS jsoncpp_lib)
else()
# Test if older jsoncpp is available
find_package(jsoncpp QUIET CONFIG)
if(jsoncpp_FOUND)
message(STATUS "System version is older than 1.9.2")
endif()
message(STATUS "Using bootsrapped jsoncpp library")
set(JSON_FILES jsoncpp.cpp)
endif()
# --------------------------------------------------
# Global includes
# --------------------------------------------------
include_directories(include)
include_directories(analyses)
# --------------------------------------------------
# Set correct install directories
# --------------------------------------------------
include(GNUInstallDirs)
message(STATUS "CMAKE_INSTALL_BINDIR: \"${CMAKE_INSTALL_BINDIR}\"")
# --------------------------------------------------
# Subdirectories
# --------------------------------------------------
add_subdirectory(analyses)
add_subdirectory(instrumentations)
add_subdirectory(src)
add_subdirectory(tests)