Skip to content

Commit

Permalink
makefile: use system gtest
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaly Chipounov <vitaly@chipounov.fr>
  • Loading branch information
vitalych committed Apr 13, 2024
1 parent 5814e5a commit d17d7e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 62 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ RUN dpkg --add-architecture i386 && apt-get update && \
libboost-system-dev libboost-serialization-dev libboost-regex-dev \
libbsd-dev libpixman-1-dev \
libglib2.0-dev libglib2.0-dev:i386 python3-docutils libpng-dev \
gcc-multilib g++-multilib libgomp1 unzip libzstd-dev
gcc-multilib g++-multilib libgomp1 unzip libzstd-dev \
libgmock-dev libgtest-dev

# The unzip and libgomp1 dependencies are needed to unzip and run binary Z3
# distributions
Expand Down
35 changes: 3 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ SOCI_BUILD_DIR=soci
SOCI_GIT_REV=438e354
SOCI_GIT_URL=https://github.com/SOCI/soci.git

# Google Test
GTEST_VERSION=1.11.0
GTEST_SRC_DIR=$(S2E_BUILD)/gtest-src
GTEST_BUILD_DIR=$(S2E_BUILD)/gtest-release
GTEST_URL=https://github.com/google/googletest/archive/release-$(GTEST_VERSION).tar.gz

# libdwarf
# We don't use the one that ships with the distro because we need
# the latest features (PE file support mostly).
Expand Down Expand Up @@ -244,13 +238,6 @@ $(SOCI_BUILD_DIR):
cd $(SOCI_SRC_DIR) && git checkout $(SOCI_GIT_REV)
mkdir -p $(S2E_BUILD)/$(SOCI_BUILD_DIR)

# Download GTest
$(GTEST_BUILD_DIR):
mkdir -p "$(GTEST_SRC_DIR)"
cd $(S2E_BUILD) && wget -O $(GTEST_SRC_DIR).tar.gz $(GTEST_URL) || rm -f "$@"
cd $(S2E_BUILD) && tar xzvf $(GTEST_SRC_DIR).tar.gz -C $(GTEST_SRC_DIR) --strip-components=1
mkdir -p "$@"

# Download Capstone
$(CAPSTONE_BUILD_DIR):
$(call DOWNLOAD,$(CAPSTONE_URL),$(CAPSTONE_SRC_DIR).tar.gz)
Expand Down Expand Up @@ -421,20 +408,6 @@ stamps/lua-make: $(LUA_DIR)
fi
touch $@

#########
# GTest #
#########

stamps/gtest-release-configure: stamps/llvm-release-make $(GTEST_BUILD_DIR)
cd $(GTEST_BUILD_DIR) && cmake -DCMAKE_C_COMPILER=$(CLANG_CC) \
-DCMAKE_CXX_COMPILER=$(CLANG_CXX) \
$(GTEST_SRC_DIR)
touch $@

stamps/gtest-release-make: stamps/gtest-release-configure
$(MAKE) -C $(GTEST_BUILD_DIR)
touch $@


########
# KLEE #
Expand All @@ -445,28 +418,26 @@ KLEE_CONFIGURE_FLAGS = -DCMAKE_INSTALL_PREFIX=$(S2E_PREFIX)
-DCMAKE_C_COMPILER=$(CLANG_CC) \
-DCMAKE_CXX_COMPILER=$(CLANG_CXX) \
-DENABLE_UNIT_TESTS=On \
-DGTEST_SRC=$(GTEST_SRC_DIR) \
-DGTEST_ROOT=$(GTEST_BUILD_DIR) \
-DENABLE_DOCS=Off \
-DENABLE_SOLVER_Z3=On \
-DZ3_INCLUDE_DIRS=$(S2E_PREFIX)/include \
-DZ3_LIBRARIES=$(S2E_PREFIX)/lib/libz3.a

stamps/klee-debug-configure: stamps/llvm-debug-make stamps/z3 stamps/gtest-release-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/klee)
stamps/klee-debug-configure: stamps/llvm-debug-make stamps/z3 $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/klee)
stamps/klee-debug-configure: CONFIGURE_COMMAND = cmake $(KLEE_CONFIGURE_FLAGS) \
-DCMAKE_BUILD_TYPE=Debug \
-DLLVM_DIR=$(LLVM_BUILD)/llvm-debug/lib/cmake/llvm \
-DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG) -fno-omit-frame-pointer -fPIC" \
$(S2E_SRC)/klee

stamps/klee-coverage-configure: stamps/llvm-debug-make stamps/z3 stamps/gtest-release-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/klee)
stamps/klee-coverage-configure: stamps/llvm-debug-make stamps/z3 $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/klee)
stamps/klee-coverage-configure: CONFIGURE_COMMAND = cmake $(KLEE_CONFIGURE_FLAGS) \
-DCMAKE_BUILD_TYPE=Debug \
-DLLVM_DIR=$(LLVM_BUILD)/llvm-debug/lib/cmake/llvm \
-DCMAKE_CXX_FLAGS="$(CXXFLAGS_DEBUG) -fno-omit-frame-pointer -fPIC -fprofile-instr-generate -fcoverage-mapping" \
$(S2E_SRC)/klee

stamps/klee-release-configure: stamps/llvm-release-make stamps/z3 stamps/gtest-release-make $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/klee)
stamps/klee-release-configure: stamps/llvm-release-make stamps/z3 $(call FIND_CONFIG_SOURCE,$(S2E_SRC)/klee)
stamps/klee-release-configure: CONFIGURE_COMMAND = cmake $(KLEE_CONFIGURE_FLAGS) \
-DCMAKE_BUILD_TYPE=$(RELEASE_BUILD_TYPE) \
-DLLVM_DIR=$(LLVM_BUILD)/llvm-release/lib/cmake/llvm \
Expand Down
32 changes: 3 additions & 29 deletions klee/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,8 @@
#
#===------------------------------------------------------------------------===#

if (NOT EXISTS "${GTEST_ROOT}")
message(FATAL_ERROR "GTest build directory \"${GTEST_ROOT}\" cannot be found.\n"
"Alternatively you can disable unit tests by passing "
"-DENABLE_UNIT_TESTS=OFF to cmake.")
endif()

if (NOT EXISTS "${GTEST_SRC}")
message(FATAL_ERROR "GTest source directory \"${GTEST_SRC}\" cannot be found.\n"
"Alternatively you can disable unit tests by passing "
"-DENABLE_UNIT_TESTS=OFF to cmake.")
endif()

set(GTEST_INCLUDE_DIR "${GTEST_SRC}/googletest/include")
if (NOT IS_DIRECTORY "${GTEST_INCLUDE_DIR}")
message(FATAL_ERROR
"Cannot find GTest include directory \"${GTEST_INCLUDE_DIR}\"")
endif()

set(GMOCK_INCLUDE_DIR "${GTEST_SRC}/googlemock/include")
if (NOT IS_DIRECTORY "${GMOCK_INCLUDE_DIR}")
message(FATAL_ERROR
"Cannot find GMock include directory \"${GMOCK_INCLUDE_DIR}\"")
endif()

set(GTEST_LIB_DIR "${GTEST_ROOT}/lib")
enable_testing()
find_package(GTest REQUIRED)

# This keeps track of all the unit test
# targets so we can ensure they are built
Expand All @@ -44,10 +21,7 @@ define_property(GLOBAL

llvm_map_components_to_libnames(LLVM_LIBS core)

set(LIBS ${LIBS}
${LLVM_LIBS}
${GTEST_LIB_DIR}/libgtest.a
${GTEST_LIB_DIR}/libgmock.a)
set(LIBS ${LIBS} ${LLVM_LIBS} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} gmock)

function(add_klee_unit_test target_name)
add_executable(${target_name} ${ARGN} ${PROJECT_SOURCE_DIR}/unittests/TestMain.cpp)
Expand Down

0 comments on commit d17d7e7

Please sign in to comment.