Skip to content

Commit

Permalink
Refactor test project to exist inside parent project
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingcitaldo125 committed Dec 22, 2021
1 parent fd8c477 commit 5bacbff
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
cmake_minimum_required(VERSION 3.16)

project(base64 VERSION 0.2.0 LANGUAGES CXX)
project(base64 VERSION 0.3.0 LANGUAGES CXX)

option(BUILD_STATIC "Build a static library" ON)

option(BUILD_TESTS "Build test project" OFF)

set(LIBRARY_NAME "base64")

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

add_executable(app ${CMAKE_SOURCE_DIR}/src/main.cpp)
target_compile_options(app PRIVATE "-Wall")
Expand All @@ -23,7 +25,11 @@ endif()
target_include_directories(app PRIVATE ${CMAKE_SOURCE_DIR}/include/)
target_link_libraries(app PRIVATE ${LIBRARY_NAME})

# Include directories for the chosen lib
if(BUILD_TESTS)
add_subdirectory(test)
endif()

# Include directories for the chosen lib (headers)
target_include_directories(${LIBRARY_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
Expand Down
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# Base64_Cpp
Very basic [Base64](https://en.wikipedia.org/wiki/Base64) encoding/decoding solution in C++

Very basic [Base64](https://en.wikipedia.org/wiki/Base64) encoding/decoding solution in C++.

## Dependencies

- Google Test for the Unit Tests

## Building

To build the solution, navigate to the cloned GitHub directory and run:

```
mkdir -p build
cd build
cmake ..
make
```

To build the application with tests:

```
cmake -S . -B build -DBUILD_TESTS=true
RUN cmake --build bin
```

Google Test must be installed & configured to build & run unit tests.
32 changes: 5 additions & 27 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
cmake_minimum_required(VERSION 3.10)

project(CppEarleyTest VERSION 1.1)

set(CMAKE_CXX_STANDARD 11)

# Test coverage flags
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)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)

enable_testing()

find_package(GTest REQUIRED)

set(GRAMMAR_DIRECTORY "test_grammars")

set(PROJECT_ROOT_DIRECTORY "${CMAKE_SOURCE_DIR}/../")
set(TEST_DIRECTORY "${CMAKE_SOURCE_DIR}")

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

find_library(BASE_LIB base64 base64_shared
HINTS ${PROJECT_ROOT_DIRECTORY}
PATH_SUFFIXES /bin /bin/lib /build /build/lib
REQUIRED)

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_link_libraries(app-test ${LIBRARY_NAME} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)

add_test(NAME app-test-test COMMAND app-test ${TEST_GRAMMAR_DIRECTORY})
target_include_directories(app-test PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

add_test(NAME app-test-test COMMAND app-test)

0 comments on commit 5bacbff

Please sign in to comment.