Skip to content

Commit

Permalink
Compiler: Add cmake tests
Browse files Browse the repository at this point in the history
Summary: Add support for cmake tests

Reviewed By: juchem

Differential Revision: D4405983

fbshipit-source-id: 43af1ccdef3bde965727ce2f010281cc9ec514ec
  • Loading branch information
eduardo-elizondo authored and facebook-github-bot committed Jan 13, 2017
1 parent 35c85fa commit b3160ef
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,33 @@ include_directories(
${Boost_INCLUDE_DIRS}
)

# Add the test dependencies
# To run tests: `make test`
if(ENABLE_TESTS)
find_package(GTest REQUIRED)
find_package(GMock REQUIRED)
include_directories(
${GTEST_INCLUDE_DIRS}
${GMOCK_INCLUDE_DIRS}
)

enable_testing()
endif(ENABLE_TESTS)

# Create a generalized function for tests
function(thrift_gtest tname srcfile)
if(ENABLE_TESTS)
add_executable("${tname}-t" ${srcfile})
target_link_libraries(
"${tname}-t"

${ARGN}
${GTEST_BOTH_LIBRARIES}
${GMOCK_BOTH_LIBRARIES}
pthread
)
gtest_add_tests("${tname}-t" "" ${srcfile})
endif(ENABLE_TESTS)
endfunction(thrift_gtest)

add_subdirectory(thrift)
36 changes: 36 additions & 0 deletions thrift/cmake/FindGMock.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# - Try to find Google's GMock library
# This will define
# GMOCK_FOUND
# GMOCK_INCLUDE_DIRS
# GMOCK_LIBRARIES
# GMOCK_MAIN_LIBRARIES
# GMOCK_BOTH_LIBRARIES

find_path(GMOCK_INCLUDE_DIRS gmock/gmock.h
HINTS
$ENV{GMOCK_ROOT}/include
${GMOCK_ROOT}/include
)
mark_as_advanced(GMOCK_INCLUDE_DIRS)

find_library(GMOCK_LIBRARIES
NAMES gmock
HINTS
ENV GMOCK_ROOT
${GMOCK_ROOT}
)
mark_as_advanced(GMOCK_LIBRARIES)

find_library(GMOCK_MAIN_LIBRARIES
NAMES gmock_main
HINTS
ENV GMOCK_ROOT
${GMOCK_ROOT}
)
mark_as_advanced(GMOCK_LIBRARIES)

set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
GMock GMOCK_LIBRARIES GMOCK_INCLUDE_DIRS GMOCK_MAIN_LIBRARIES)
15 changes: 11 additions & 4 deletions thrift/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set the compiler directory
set(COMPILER_HOME ${CMAKE_CURRENT_SOURCE_DIR})
set(COMPILER_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# Override default install path for `make install` step
set(CMAKE_INSTALL_PREFIX ${THRIFT_HOME})
Expand Down Expand Up @@ -64,12 +64,12 @@ if(WIN32)
set(FLEX_FLAGS_TYPE "--wincompat") #String type
endif(WIN32)
# Compile Flex and Bison files and tie their dependencies
BISON_TARGET(ThriftParser thrifty.yy ${COMPILER_HOME}/thrifty.cc)
BISON_TARGET(ThriftParser thrifty.yy ${COMPILER_DIR}/thrifty.cc)
FLEX_TARGET(
ThriftScanner

thriftl.ll
${COMPILER_HOME}/thriftl.cc
${COMPILER_DIR}/thriftl.cc
${FLEX_FLAGS} ${FLEX_FLAGS_TYPE}
)
ADD_FLEX_BISON_DEPENDENCY(ThriftScanner ThriftParser)
Expand Down Expand Up @@ -101,11 +101,18 @@ endif(MSVC)
target_compile_definitions(
thrift-compiler

PRIVATE -DTHRIFTY_HH="${COMPILER_HOME}/thrifty.hh"
PRIVATE -DTHRIFTY_HH="${COMPILER_DIR}/thrifty.hh"
)

# Set the binary destination
install(
TARGETS thrift-compiler
DESTINATION .
)

# Add tests
set(TEST_DIR ${COMPILER_DIR}/test)
thrift_gtest(gcommon "${TEST_DIR}/generate_common_test.cc" generate_lib)
thrift_gtest(tprogram "${TEST_DIR}/t_program_test.cc" parse_lib)
thrift_gtest(ttype "${TEST_DIR}/t_type_test.cc" parse_lib)
thrift_gtest(visitor "${TEST_DIR}/visitor_test.cc" thrift_base)

0 comments on commit b3160ef

Please sign in to comment.