This commit is contained in:
Tom Hicks
2025-04-09 20:06:35 -07:00
parent f479672834
commit 742a7dcedd
2 changed files with 85 additions and 56 deletions

View File

@@ -108,6 +108,13 @@ jobs:
with: with:
cmake-version: '3.14.x' cmake-version: '3.14.x'
# Make sure tar and unzip are available
- name: Install unzip
run: |
sudo apt-get update
sudo apt-get install -y unzip
if: runner.os == 'Linux'
# Create build directory # Create build directory
- name: Create Build Directory - name: Create Build Directory
run: cmake -E make_directory ${{github.workspace}}/build run: cmake -E make_directory ${{github.workspace}}/build
@@ -120,6 +127,9 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DTINYTEST_BUILD_SHARED_LIBS=${{ matrix.shared_libs }} -DTINYTEST_BUILD_SHARED_LIBS=${{ matrix.shared_libs }}
-DBUILD_TESTING=ON -DBUILD_TESTING=ON
-DCPPUTILS_BUILD_TESTS=OFF
-DCPPUTILS_ENABLE_TESTING=OFF
-DCPPUTILS_SKIP_GOOGLETEST=ON
# Build # Build
- name: Build - name: Build
@@ -138,18 +148,23 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup CMake - name: Manual Install
uses: jwlawson/actions-setup-cmake@v1.13
with:
cmake-version: '3.14.x'
- name: Build and Install
run: | run: |
mkdir -p build # Create installation directories
cd build mkdir -p $HOME/tinytest-install/include/tinytest
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/tinytest-install mkdir -p $HOME/tinytest-install/lib
cmake --build .
cmake --install . # Copy the header file
cp tinytest.h $HOME/tinytest-install/include/tinytest/
# Compile the library
g++ -std=c++17 -O2 -c tinytest.cpp -o tinytest.o
# Create static library
ar rcs libtinytest.a tinytest.o
# Install the library
cp libtinytest.a $HOME/tinytest-install/lib/
- name: Verify Installation - name: Verify Installation
run: | run: |

View File

@@ -212,21 +212,33 @@ if(BUILD_TESTING)
# Define our own custom tests list to avoid conflicts # Define our own custom tests list to avoid conflicts
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
FetchContent_Declare( # Set GoogleTest version and URL
googletest set(GTEST_VERSION "release-1.12.1")
GIT_REPOSITORY https://github.com/google/googletest.git set(GTEST_URL "https://github.com/google/googletest/archive/${GTEST_VERSION}.zip")
GIT_TAG release-1.12.1 set(GTEST_DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-download")
) set(GTEST_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src")
# For Windows: Prevent overriding the parent project's compiler/linker settings set(GTEST_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build")
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Get GoogleTest include directories # Download GoogleTest
FetchContent_GetProperties(googletest) if(NOT EXISTS "${GTEST_SOURCE_DIR}")
set(GTEST_INCLUDE_DIRS file(MAKE_DIRECTORY "${GTEST_DOWNLOAD_DIR}")
${googletest_SOURCE_DIR}/googletest/include file(DOWNLOAD "${GTEST_URL}" "${GTEST_DOWNLOAD_DIR}/googletest.zip" STATUS download_status)
${googletest_SOURCE_DIR}/googlemock/include list(GET download_status 0 status_code)
if(status_code EQUAL 0)
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf "${GTEST_DOWNLOAD_DIR}/googletest.zip"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
) )
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/googletest-${GTEST_VERSION}" "${GTEST_SOURCE_DIR}")
else()
message(WARNING "Failed to download GoogleTest. Tests will be disabled.")
set(BUILD_TESTING OFF)
endif()
endif()
if(BUILD_TESTING AND EXISTS "${GTEST_SOURCE_DIR}")
# Add GoogleTest as a subdirectory
add_subdirectory("${GTEST_SOURCE_DIR}" "${GTEST_BINARY_DIR}" EXCLUDE_FROM_ALL)
# Create test executable - renamed to avoid conflicts # Create test executable - renamed to avoid conflicts
add_executable(tinytest_tests add_executable(tinytest_tests
@@ -242,15 +254,16 @@ if(BUILD_TESTING)
target_include_directories(tinytest_tests target_include_directories(tinytest_tests
PRIVATE PRIVATE
${CPPUTILS_INCLUDE_DIR} ${CPPUTILS_INCLUDE_DIR}
${GTEST_INCLUDE_DIRS} "${GTEST_SOURCE_DIR}/googletest/include"
"${GTEST_SOURCE_DIR}/googlemock/include"
) )
# Link against TinyTest library and GoogleTest # Link against TinyTest library and GoogleTest
target_link_libraries(tinytest_tests target_link_libraries(tinytest_tests
PRIVATE PRIVATE
tinytest_lib tinytest_lib
GTest::gtest_main gtest_main
GTest::gmock gmock
) )
# Register test with CTest - make sure only our test is registered # Register test with CTest - make sure only our test is registered
@@ -258,6 +271,7 @@ if(BUILD_TESTING)
# Explicitly set the test list to prevent picking up other tests # Explicitly set the test list to prevent picking up other tests
set_property(GLOBAL PROPERTY TEST_INCLUDE_FILES "") set_property(GLOBAL PROPERTY TEST_INCLUDE_FILES "")
endif()
endif() endif()
# Installation # Installation