Skip to content

Commit

Permalink
Merge pull request #21 from Aksem/feature/versioning
Browse files Browse the repository at this point in the history
Add version 1.0.0. Improve testing config
  • Loading branch information
Aksem authored Mar 12, 2024
2 parents 0b14204 + cbf4323 commit 109c794
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
pushd cola
mkdir -p build_tests
pushd build_tests
cmake -DENABLE_TESTS=ON ..
cmake -DBUILD_TESTING=ON ..
cmake --build .
ctest --output-on-failure
popd
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ repository as platform-agnostic as possible.

Use common `cmake`, `make` and `make install`. Default options have values to build library as in release mode. Tests, debug logs and more can be enabled with apropriate options, see `CMakeLists.txt` of the library you want to build.

To enable tests use cmake builtin option `BUILD_TESTING` (`-DBUILD_TESTING=ON` in cmake command).

### GNU automake

You'll need to call `aclocal`,
Expand Down
15 changes: 11 additions & 4 deletions cola/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
cmake_minimum_required(VERSION 3.16)
project(adaptagrams)

option(ENABLE_TESTS "Build tests" OFF)

# adaptagrams libs and GoogleTest require at least C++11
set(CMAKE_CXX_STANDARD 11)
set(VERSION 1.0.0)
set(SOVERSION 1)

if (ENABLE_TESTS)
enable_testing()
if (BUILD_TESTING AND PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)
# testing setup was inspired by:
# https://cliutils.gitlab.io/modern-cmake/chapters/testing.html
# https://cliutils.gitlab.io/modern-cmake/chapters/testing/googletest.html

# ctest requires explicit enabling testing even if BUILD_TESTING is provided
enable_testing()
include(FetchContent)
# use new policy to add timestamps to fetched data
cmake_policy(SET CMP0135 NEW)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/af29db7ec28d6df1c7f0f745186884091e602e07.zip
Expand All @@ -18,6 +24,7 @@ if (ENABLE_TESTS)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
include(cmake/Testing.cmake)
endif()

add_subdirectory(libavoid)
Expand Down
22 changes: 22 additions & 0 deletions cola/cmake/Testing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
macro(package_add_test TESTNAME)
set(options)
set(oneValueArgs SOURCE)
set(multiValueArgs LIBRARIES DEFINITIONS)
cmake_parse_arguments(PACKAGE_ADD_TEST "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

# create an executable in which the tests will be stored
add_executable(${TESTNAME} ${PACKAGE_ADD_TEST_SOURCE})
# link the Google test infrastructure, mocking library, and a default main function to
# the test executable. Remove g_test_main if writing your own main function.
target_link_libraries(${TESTNAME} gtest gmock gtest_main ${PACKAGE_ADD_TEST_LIBRARIES})
# gtest_discover_tests replaces gtest_add_tests,
# see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it
gtest_discover_tests(${TESTNAME}
# set a working directory so your project root so that you can find test data via paths relative to the project root
WORKING_DIRECTORY ${PROJECT_DIR}
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
)
# set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
target_compile_definitions(${TESTNAME} PRIVATE ${PACKAGE_ADD_TEST_DEFINITIONS})
endmacro()
23 changes: 8 additions & 15 deletions cola/libavoid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_library(${PROJECT_NAME}
vpsc.cpp
uniqueid.cpp
)
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSION})

if (LIBAVOID_DEBUG)
add_definitions(-DLIBAVOID_DEBUG)
Expand All @@ -57,7 +58,7 @@ endif()

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)

if (ENABLE_TESTS)
if (BUILD_TESTING)
set(TEST_CASES
2junctions
buildOrthogonalChannelInfo1
Expand Down Expand Up @@ -174,20 +175,12 @@ if (ENABLE_TESTS)
set(TARGET_NAME "")
string(REPLACE "/" "_" TARGET_NAME ${TEST_CASE})
set(FULL_TARGET_NAME ${PROJECT_NAME}_${TARGET_NAME}_test)
add_executable(
${FULL_TARGET_NAME}
tests/new/${TEST_CASE}.cpp
)
target_link_libraries(
${FULL_TARGET_NAME}
gtest_main
gmock_main
testHelpers
${PROJECT_NAME}
)
# 'output' is added to IMAGE_OUTPUT_PATH inside of tests to keep compatibility with Makefile build
target_compile_definitions(${FULL_TARGET_NAME} PRIVATE -DIMAGE_OUTPUT_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/tests/\" -DTEST_DATA_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/tests/\")

gtest_discover_tests(${FULL_TARGET_NAME})
package_add_test(${FULL_TARGET_NAME}
SOURCE tests/new/${TEST_CASE}.cpp
LIBRARIES testHelpers ${PROJECT_NAME}
# 'output' is added to IMAGE_OUTPUT_PATH inside of tests to keep compatibility with Makefile build
DEFINITIONS -DIMAGE_OUTPUT_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/tests/\" -DTEST_DATA_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/tests/\"
)
endforeach()
endif()
4 changes: 2 additions & 2 deletions cola/libavoid/tests/output/freeFloatingDirection01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 109c794

Please sign in to comment.