Skip to content

Commit

Permalink
updates to readme and CMake installation. Googletest is a dependency …
Browse files Browse the repository at this point in the history
…for the project, requiring unittests to pass in order for the project to build + install
  • Loading branch information
akielaries committed Jan 4, 2023
1 parent 926b8b6 commit 85745af
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ include(GNUInstallDirs)
############################################################
# Run Tests
############################################################
#find_package(GTest REQUIRED)

enable_testing()


#add_subdirectory(tests)
add_subdirectory(tests)

############################################################
# Create a library
Expand Down Expand Up @@ -67,3 +69,6 @@ install(EXPORT openMTPKConfig DESTINATION share/openMTPK/cmake)

export(TARGETS ${PROJECT_NAME} FILE openMTPKConfig.cmake)

# make tests passing a requirement for the library to build
add_dependencies(${PROJECT_NAME} check)

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ $ cd oepnMTPK
# create build dir
$ mkdir build && cd build
# create necessary objects and static library
$ cmake ..
$ cmake -S ..
$ make
# install necessary headers and library in correct directories
$ sudo make install
Expand Down
71 changes: 51 additions & 20 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
# Download and install GoogleTest
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

# TESTS
add_executable(test_openMTPK arith/t_arith.cpp)

# use googletest
add_dependencies(test_openMTPK gtest)
include_directories(${source_dir}/include)
target_link_libraries(test_openMTPK openMTPK gtest gtest_main pthread)
include(FetchContent)

#find_package(GTest REQUIRED)

# check if installation is present
#if(NOT GTEST_FOUND)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
FetchContent_MakeAvailable(googletest)
#endif()

#FetchContent_MakeAvailable(googletest)


# source files that will be tested
set(TEST_SOURCES
../modules/arithmetic/arith.cpp
../modules/calculus/deriv.cpp
../modules/number_theory/cipher.cpp
../modules/number_theory/rc4.cpp
../modules/number_theory/primes.cpp

#target_link_libraries(test_openMTPK ${binary_dir}/libgtest_main.a)
)

# test files
set(TEST_FILES
arith/t_arith.cpp
calc/t_calc.cpp
number_theory/t_cipher.cpp
number_theory/t_rc4.cpp
number_theory/t_primes.cpp
)

# create executable
add_executable(
test_openMTPK
${TEST_SOURCES}
${TEST_FILES}
)

# enable testing
enable_testing()

add_test(NAME test_openMTPK
COMMAND test_openMTPK)
# link the libraries together with the test binary
target_link_libraries(
test_openMTPK
GTest::gtest_main
pthread

)

include(GoogleTest)
gtest_discover_tests(test_openMTPK)

# Add a custom target for running the tests
add_custom_target(check COMMAND test_openMTPK)

0 comments on commit 85745af

Please sign in to comment.