about summary refs log tree commit diff homepage
path: root/tools
diff options
context:
space:
mode:
authorDan Liew <daniel.liew@imperial.ac.uk>2016-11-01 22:47:30 +0000
committerDan Liew <delcypher@gmail.com>2016-11-07 22:16:29 +0000
commit7e75b491d389c15d48a5cfc455ba9442d7c108ed (patch)
tree09502118849cb0fc85723d09ceed88ce2ff50fab /tools
parent48abc42627315f3435e60ee3d95c1749c667519f (diff)
downloadklee-7e75b491d389c15d48a5cfc455ba9442d7c108ed.tar.gz
Implement a CMake based build system for KLEE.
This is based off intial work by @jirislaby in #481. However it
has been substantially modified.

Notably it includes a separate build sytem to build the runtimes which
is inspired by the old build system. The reason for doing this is
because CMake is not well suited for building the runtime:

* CMake is configured to use the host compiler, not the bitcode
  compiler. These are not the same thing.

* Building the runtime using `add_custom_command()` is flawed
  because we can't automatically get transitive depencies (i.e.
  header file dependencies) unless the CMake generator is makefiles.
  (See `IMPLICIT_DEPENDS` of `add_custom_command()` in CMake).

So for now we have a very simple build system for building the runtimes.
In the future we can replace this with something more sophisticated if
we need it.

Support for all features of the old build system are implemented apart
from recording the git revision and showing it in the output of
`klee --help`.

Another notable change is the CMake build system works much better with
LLVM installs which don't ship with testing tools. The build system
will download the sources for `FileCheck` and `not` tools if the
corresponding binaries aren't available and will build them. However
`lit` (availabe via `pip install lit`) and GTest must already be
installed.

Apart from better support for testing a significant advantage of the
new CMake build system compared to the existing "Autoconf/Makefile"
build system is that it is **not** coupled to LLVM's build system
(unlike the existing build system). This means that LLVM's
autoconf/Makefiles don't need to be installed somewhere on the system.

Currently all tests pass.

Support has been implemented in TravisCI and the Dockerfile for
building with CMake.

The existing "Autoconf/Makefile" build system has been left intact
and so both build systems can coexist for a short while. We should
remove the old build system as soon as possible though because it
creates an unnecessary maintance burden.
Diffstat (limited to 'tools')
-rw-r--r--tools/CMakeLists.txt14
-rw-r--r--tools/gen-random-bout/CMakeLists.txt17
-rw-r--r--tools/kleaver/CMakeLists.txt18
-rw-r--r--tools/klee-replay/CMakeLists.txt30
-rw-r--r--tools/klee-stats/CMakeLists.txt9
-rw-r--r--tools/klee/CMakeLists.txt39
-rw-r--r--tools/ktest-tool/CMakeLists.txt13
7 files changed, 140 insertions, 0 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
new file mode 100644
index 00000000..9bf2acf8
--- /dev/null
+++ b/tools/CMakeLists.txt
@@ -0,0 +1,14 @@
+#===------------------------------------------------------------------------===#
+#
+#                     The KLEE Symbolic Virtual Machine
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+add_subdirectory(gen-random-bout)
+add_subdirectory(kleaver)
+add_subdirectory(klee)
+add_subdirectory(klee-replay)
+add_subdirectory(klee-stats)
+add_subdirectory(ktest-tool)
diff --git a/tools/gen-random-bout/CMakeLists.txt b/tools/gen-random-bout/CMakeLists.txt
new file mode 100644
index 00000000..d1fa6b09
--- /dev/null
+++ b/tools/gen-random-bout/CMakeLists.txt
@@ -0,0 +1,17 @@
+#===------------------------------------------------------------------------===#
+#
+#                     The KLEE Symbolic Virtual Machine
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+add_executable(gen-random-bout
+	gen-random-bout.cpp
+)
+
+set(KLEE_LIBS kleeBasic)
+
+target_link_libraries(gen-random-bout ${KLEE_LIBS})
+
+install(TARGETS gen-random-bout RUNTIME DESTINATION bin)
diff --git a/tools/kleaver/CMakeLists.txt b/tools/kleaver/CMakeLists.txt
new file mode 100644
index 00000000..befbcc6e
--- /dev/null
+++ b/tools/kleaver/CMakeLists.txt
@@ -0,0 +1,18 @@
+#===------------------------------------------------------------------------===#
+#
+#                     The KLEE Symbolic Virtual Machine
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+add_executable(kleaver
+	main.cpp
+)
+
+klee_get_llvm_libs(LLVM_LIBS support)
+set(KLEE_LIBS kleeBasic kleaverSolver kleaverExpr kleeSupport)
+
+target_link_libraries(kleaver ${KLEE_LIBS} ${LLVM_LIBS})
+
+install(TARGETS kleaver RUNTIME DESTINATION bin)
diff --git a/tools/klee-replay/CMakeLists.txt b/tools/klee-replay/CMakeLists.txt
new file mode 100644
index 00000000..e0eb8d07
--- /dev/null
+++ b/tools/klee-replay/CMakeLists.txt
@@ -0,0 +1,30 @@
+#===------------------------------------------------------------------------===#
+#
+#                     The KLEE Symbolic Virtual Machine
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+if (HAVE_PTY_H)
+  add_executable(klee-replay
+    fd_init.c
+    file-creator.c
+    klee-replay.c
+    klee_init_env.c
+  )
+
+  target_link_libraries(klee-replay PRIVATE kleeBasic ${LIBCAP_LIBRARIES})
+  # FIXME: This isn't quite right. This is actually an implementation detail
+  # of glibc not Linux. Really we need to test if we can use `openpty()`
+  # with/without an additional library.
+  if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
+    if (NOT LIBUTIL_LIBRARIES)
+      message(FATAL_ERROR "klee-replay needs libutil under Linux")
+    endif()
+    target_link_libraries(klee-replay PRIVATE ${LIBUTIL_LIBRARIES})
+  endif()
+install(TARGETS klee-replay RUNTIME DESTINATION bin)
+else()
+  message(WARNING "Not building klee-replay due to missing \"pty.h\" header file")
+endif()
diff --git a/tools/klee-stats/CMakeLists.txt b/tools/klee-stats/CMakeLists.txt
new file mode 100644
index 00000000..7203003d
--- /dev/null
+++ b/tools/klee-stats/CMakeLists.txt
@@ -0,0 +1,9 @@
+#===------------------------------------------------------------------------===#
+#
+#                     The KLEE Symbolic Virtual Machine
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+install(PROGRAMS klee-stats DESTINATION bin)
diff --git a/tools/klee/CMakeLists.txt b/tools/klee/CMakeLists.txt
new file mode 100644
index 00000000..b6e907ab
--- /dev/null
+++ b/tools/klee/CMakeLists.txt
@@ -0,0 +1,39 @@
+#===------------------------------------------------------------------------===#
+#
+#                     The KLEE Symbolic Virtual Machine
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+add_executable(klee
+	main.cpp
+)
+
+# FIXME: This shouldn't be done here. Instead the KLEE libraries
+# should declare their LLVM dependencies.
+set(LLVM_COMPONENTS
+	bitreader
+	bitwriter
+	engine
+	ipo
+	jit
+	linker
+	support
+)
+
+if ("${LLVM_PACKAGE_VERSION}" VERSION_EQUAL "3.3" OR
+    "${LLVM_PACKAGE_VERSION}" VERSION_GREATER "3.3")
+  list(APPEND LLVM_COMPONENTS irreader)
+endif()
+
+klee_get_llvm_libs(LLVM_LIBS ${LLVM_COMPONENTS})
+
+set(KLEE_LIBS kleeCore kleeBasic kleeModule kleaverSolver kleaverExpr kleeSupport)
+
+target_link_libraries(klee ${KLEE_LIBS} ${LLVM_LIBS})
+
+install(TARGETS klee RUNTIME DESTINATION bin)
+
+# The KLEE binary depends on the runtimes
+add_dependencies(klee BuildKLEERuntimes)
diff --git a/tools/ktest-tool/CMakeLists.txt b/tools/ktest-tool/CMakeLists.txt
new file mode 100644
index 00000000..76e31ac0
--- /dev/null
+++ b/tools/ktest-tool/CMakeLists.txt
@@ -0,0 +1,13 @@
+#===------------------------------------------------------------------------===#
+#
+#                     The KLEE Symbolic Virtual Machine
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+install(PROGRAMS ktest-tool DESTINATION bin)
+
+# Copy into the build directory's binary directory
+# so integration tests can find it
+configure_file(ktest-tool "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ktest-tool" COPYONLY)