Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
94 lines (81 loc) · 3.56 KB
/
Copy pathCMakeLists.txt
File metadata and controls
94 lines (81 loc) · 3.56 KB
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
cmake_minimum_required(VERSION 3.20)
project(Map2Check VERSION 9.0.0 LANGUAGES C CXX)
option(BUILD_DOC "Build documentation" OFF)
option(SKIP_AFL_PLUS_PLUS "Don't use AFL++" OFF)
option(SKIP_KLEE "Don't use KLEE" OFF)
option(REGRESSION "Prepare Regression Tests" OFF)
option(ENABLE_TEST "Build all tests" OFF)
option(MAP2CHECK_ENABLE_SANITIZERS "Enable AddressSanitizer + UndefinedBehaviorSanitizer for testing" OFF)
option(MAP2CHECK_DYNAMIC_LINK "Link dynamically (required when KLEE/Z3 are only available as shared libraries)" OFF)
option(ENABLE_CLAM "Enable --add-invariants via Clam (requires Clam dev16 installed, see docs/reports/2026-08-16-crabllvm-review.md)" OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/release"
CACHE PATH "Install prefix (default: <repo>/release)" FORCE)
endif()
# --- Sanitizer configuration (Phase 1.5 — OpenSSF Best Practices) ---
if(MAP2CHECK_ENABLE_SANITIZERS)
message(STATUS "Sanitizers enabled: ASan + UBSan (dynamic linking)")
add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer -g)
add_link_options(-fsanitize=address,undefined)
# Ensure all targets (including OBJECT libraries) are compiled with -fPIC,
# required for LLVM pass shared libraries (.so)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# ASan requires dynamic linking — skip static config
set(Map2Check_MODE "SHARED")
else()
# --- Static linking configuration ---
set(Map2Check_MODE "STATIC")
# Prefer static archives, but fall back to shared objects: Ubuntu's
# libz3-dev package only ships libz3.so (no libz3.a), so a ".a"-only
# suffix list makes find_library() fail to locate Z3 even when installed.
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so")
set(CMAKE_EXE_LINKER_FLAGS "-Bstatic -static-libgcc -static-libstdc++")
endif()
# --- Abstract-interpretation invariants (Clam, formerly crab-llvm) ---
# Off by default, and deliberately so: an unsound invariant does not raise an
# error, it produces a wrong TRUE. Under KLEE klee_assume() prunes a reachable
# state; under AFL++ nondet_assume() longjmps past the input and the execution
# disappears. Promoting this to a default needs the differential evidence
# described in docs/reports/2026-08-16-crabllvm-review.md.
#
# Clam is a subprocess tool, not a linked library, so this only records intent.
# The binary still checks at run time that the driver is actually installed --
# neither condition implies the other.
if(ENABLE_CLAM)
add_compile_definitions(MAP2CHECK_ENABLE_CLAM)
message(STATUS "Clam invariants: ENABLED (--add-invariants available)")
else()
message(STATUS "Clam invariants: disabled (-DENABLE_CLAM=ON to enable)")
endif()
# --- Core dependencies ---
include(cmake/FindClang.cmake)
include(cmake/FindBoost.cmake)
if(NOT SKIP_AFL_PLUS_PLUS)
include(cmake/FindAFLPlusPlus.cmake)
endif()
if(NOT SKIP_KLEE)
include(cmake/FindZ3.cmake)
include(cmake/FindMiniSat.cmake)
include(cmake/FindSTP.cmake)
include(cmake/FindKleeUCLibC.cmake)
include(cmake/FindKlee.cmake)
endif()
if(REGRESSION)
include(cmake/DownloadRegression.cmake)
endif()
include_directories(${PROJECT_SOURCE_DIR})
if(ENABLE_TEST)
# include(CTest) em vez de enable_testing(): gera DartConfiguration.tcl,
# necessário para `ctest -T memcheck` (job Valgrind no CI).
include(CTest)
include(cmake/FindGTest.cmake)
message(STATUS "Adding tests")
add_subdirectory(tests)
endif()
add_subdirectory(modules)
if(BUILD_DOC)
include(cmake/GenerateDocs.cmake)
endif()