about summary refs log tree commit diff homepage
path: root/runtime/CMakeLists.txt
blob: ea8335de7b6531af1e1a1927336627bdecfdbf92 (plain) (blame)
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
#===------------------------------------------------------------------------===#
#
#                     The KLEE Symbolic Virtual Machine
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===------------------------------------------------------------------------===#
# Handle binaries
add_subdirectory(Runtest)

# Handle bitcode libraries
# Define the different configurations to be compiled and made available using a specific suffix

set(bc_architectures 32 64)

set(LIB_BC_SUFFIX "")

foreach (bc_architecture ${bc_architectures})
    foreach (bc_optimization ${available_klee_runtime_build_types})
        # Add configuration to the set of available configurations
        list(APPEND LIB_BC_SUFFIX "${bc_architecture}_${bc_optimization}")

        # Set specific flags for that configuration
        set(local_flags "")
        if (bc_architecture EQUAL "32")
            list(APPEND local_flags -m32)
        endif ()


        # Set specific compiler flags depending on the optimization
        if (bc_optimization STREQUAL "Release")
            list(APPEND local_flags -O2 -DNDebug)
        elseif (bc_optimization STREQUAL "Release+Debug")
            list(APPEND local_flags -O2 -g -DNDebug)
        elseif (bc_optimization STREQUAL "Release+Asserts")
            list(APPEND local_flags -O2 -g)
        elseif (bc_optimization STREQUAL "Release+Debug+Asserts")
            list(APPEND local_flags -O2 -g)
        elseif (bc_optimization STREQUAL "Debug")
            list(APPEND local_flags -g -DNDebug)
        elseif (bc_optimization STREQUAL "Debug+Asserts")
            list(APPEND local_flags -g)
        else()
            message(FATAL_ERROR
                    "Optimization (\"${bc_optimization}\") for runtime library unknown.")
        endif ()

        # Define suffix-specific optimizations
        set("LIB_BC_FLAGS_${bc_architecture}_${bc_optimization}" ${local_flags})
    endforeach ()
endforeach ()

message(STATUS "LIB_BC_SUFFIX: ${LIB_BC_SUFFIX}")
message(STATUS "KLEE_RUNTIME_DIRECTORY: ${KLEE_RUNTIME_DIRECTORY}")

# Add additional setups if needed, e.g.
# `list(APPEND LIB_BC_SUFFIX MY_SPECIAL_CONFIG)`

# Following define the specific flags: LIB_BC_FLAGS_*SUFFIX_FROM_ABOVE*
set(LIB_BC_FLAGS_64)
set(LIB_BC_FLAGS_32
        -m32
        )

# Common for all library configurations
# Since the runtime now contains fortified libc functions, it is
# important to compile it with -D_FORTIFY_SOURCE=0 to avoid infinite
# recursion
set(COMMON_CC_FLAGS
        "-I${CMAKE_SOURCE_DIR}/include"
        "-I${CMAKE_BINARY_DIR}/include"
        -g
        -D_DEBUG
        -D_FORTIFY_SOURCE=0
        -D_GNU_SOURCE
        -D__STDC_LIMIT_MACROS
        -D__STDC_CONSTANT_MACROS
        -Wall
        -Wwrite-strings
        )

if (${LLVM_VERSION_MAJOR} GREATER 4)
    list(APPEND COMMON_CC_FLAGS "-Xclang" "-disable-O0-optnone")
endif ()

foreach (_suffix ${LIB_BC_SUFFIX})
    list(APPEND "LIB_BC_FLAGS_${_suffix}" ${COMMON_CC_FLAGS})
endforeach ()

add_subdirectory(Freestanding)
add_subdirectory(Intrinsic)
add_subdirectory(klee-libc)
add_subdirectory(Fortify)

set(RUNTIME_LIBRARIES
        RuntimeFreestanding
        RuntimeIntrinsic
        RuntimeKLEELibc
        RuntimeFortify
        )

if (ENABLE_KLEE_EH_CXX)
    list(APPEND RUNTIME_LIBRARIES eh-cxx)
    add_subdirectory(klee-eh-cxx)
endif ()

if (ENABLE_POSIX_RUNTIME)
    list(APPEND RUNTIME_LIBRARIES RuntimePOSIX)
    add_subdirectory(POSIX)
endif ()

add_custom_target(BuildKLEERuntimes
        DEPENDS "${RUNTIME_LIBRARIES}"
        )

install(DIRECTORY "${KLEE_RUNTIME_DIRECTORY}/"
        DESTINATION "${KLEE_INSTALL_RUNTIME_DIR}"
        )