Skip to content

Commit

Permalink
Consolidate the tests into the rest of the build structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingcitaldo125 committed Dec 17, 2021
1 parent bf2e7d3 commit 72046fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)

project(CppEarley
VERSION 1.2.0
VERSION 1.3.0
DESCRIPTION "Basic C++ Earley Parser"
LANGUAGES CXX)

Expand All @@ -11,20 +11,19 @@ set(MAIN_TARGET main)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})

option(BUILD_TESTS "Option to build the test suite" ON)

include_directories(include)

add_subdirectory(include)
add_subdirectory(src)

add_executable(${MAIN_TARGET} src/main.cpp)

target_link_libraries(${MAIN_TARGET} PUBLIC cpp_earley)

target_include_directories(${MAIN_TARGET}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

Expand Down Expand Up @@ -69,3 +68,7 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
PATTERN *.h
)

if(BUILD_TESTS)
add_subdirectory(test)
include(CTest)
endif()
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

add_library(cpp_earley STATIC grammar.cpp earley.cpp)
add_library(cpp_earley_shared SHARED grammar.cpp earley.cpp)

add_executable(${MAIN_TARGET} main.cpp)
target_link_libraries(${MAIN_TARGET} PRIVATE cpp_earley)
27 changes: 3 additions & 24 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
cmake_minimum_required(VERSION 3.10)

project(CppEarleyTest VERSION 1.0)

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")

option(debug "Print out the locations of different things relative to source directory" OFF)

enable_testing()

find_package(GTest REQUIRED)

set(GRAMMAR_DIRECTORY "test_grammars")

set(PROJECT_ROOT_DIRECTORY "${CMAKE_SOURCE_DIR}/../")
set(TEST_DIRECTORY "${CMAKE_SOURCE_DIR}")
set(TEST_GRAMMAR_DIRECTORY "${TEST_DIRECTORY}/${GRAMMAR_DIRECTORY}/")
set(TEST_GRAMMAR_DIRECTORY "${CMAKE_SOURCE_DIR}/test/test_grammars/")

if(${debug})
message("PROJECT_ROOT_DIRECTORY: ${PROJECT_ROOT_DIRECTORY}")
message("TEST_DIRECTORY: ${TEST_DIRECTORY}")
message("TEST_GRAMMAR_DIRECTORY: ${TEST_GRAMMAR_DIRECTORY}")
endif()
set(CPP_EARLEY cpp_earley)

find_library(CPP_EARLEY cpp_earley
HINTS ${PROJECT_ROOT_DIRECTORY}
PATH_SUFFIXES /bin /bin/lib /build /build/lib)

add_executable(app-test test.cpp)

target_link_libraries(app-test ${CPP_EARLEY} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)

target_include_directories(app-test PUBLIC ${PROJECT_ROOT_DIRECTORY}/include ${PROJECT_ROOT_DIRECTORY}/src)
target_include_directories(app-test PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

add_test(NAME app-test-test COMMAND app-test ${TEST_GRAMMAR_DIRECTORY})

0 comments on commit 72046fa

Please sign in to comment.