diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eda637f..96dd959 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,31 +12,31 @@ on: - synchronize jobs: - # test: - # runs-on: ubuntu-latest + test: + runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 + steps: + - uses: actions/checkout@v4 - # - name: Install dependencies - # run: sudo apt-get install -y build-essential gcc-multilib g++-multilib + - name: Install dependencies + run: sudo apt-get install -y build-essential gcc-multilib g++-multilib - # - name: Install gcovr - # run: pip install gcovr + - name: Install gcovr + run: pip install gcovr - # - name: Setup project - # run: cmake -S ${TEST_DIR} -B ${BUILD_DIR} -DCMAKE_BUILD_TYPE=Debug + - name: Setup project + run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug - # - name: Build - # run: cmake --build ${BUILD_DIR} + - name: Build + run: cmake --build build - # # - name: Test - # # working-directory: build - # # run: ctest -V + - name: Test + working-directory: build + run: ctest -V - # - name: Test with Coverage - # working-directory: build - # run: cmake --build ${BUILD_DIR} --target os_test_coverage + # - name: Test with Coverage + # working-directory: build + # run: cmake --build ${BUILD_DIR} --target os_test_coverage lint: runs-on: ubuntu-latest @@ -64,7 +64,7 @@ jobs: secrets: inherit needs: - # - test + - test - lint permissions: diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..8aba064 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cmake", + "label": "CMake: build", + "command": "build", + "targets": [ + "all" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [ + "$gcc" + ], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": true + } + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 49f2354..34bff4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,11 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) # Support folders in IDEs set_property(GLOBAL PROPERTY USE_FOLDERS ON) - # Testing only available for top level projects. It calls enable_testing - # which must be in the main CMakeLists. - include(CTest) + if(WAVEFRONT_BUILD_TESTS) + # Testing only available for top level projects. It calls enable_testing + # which must be in the main CMakeLists. + include(CTest) + endif() if(WAVEFRONT_BUILD_DOCS) # Generate documentation using Doxygen @@ -36,23 +38,10 @@ endif() include(GNUInstallDirs) # Create config.h with project version numbers -configure_File(cmake/config.h.in include/config.h) +configure_file(cmake/config.h.in include/config.h) include_directories(PRIVATE ${CMAKE_BINARY_DIR}/include) -find_package(glm REQUIRED CONFIG) - -if(WAVEFRONT_BUILD_TESTS) - include(FetchContent) - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.11.0 - ) - - # For Windows: Prevent overriding the parent project's compiler/linker settings - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) -endif() +add_subdirectory(external) add_subdirectory(src) diff --git a/Makefile b/Makefile index 99907a1..976ee0d 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,27 @@ -CC=/usr/bin/gcc -CXX=/usr/bin/g++ CONFIG=Debug -TARGET=all -all: config build +all: setup build -config: - cmake --no-warn-unused-cli \ - -DCMAKE_BUILD_TYPE=${CONFIG} \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE \ - -DCMAKE_C_COMPILER=${CC} \ - -DCMAKE_CXX_COMPILER=${CXX} \ - -S${PWD} \ - -B${PWD}/build \ - -G Ninja +setup: + cmake -S . -B build -DCMAKE_BUILD_TYPE=${CONFIG} build: - cmake --build ${PWD}/build --config ${CONFIG} --target ${TARGET} + cmake --build build --config ${CONFIG} install: - cmake --install ${PWD}/build --config ${CONFIG} + cmake --install build --config ${CONFIG} lint: - @find src include tests -name '*.c' -or -name '*.h' -or -name '*.cpp' -or -name '*.hpp' | xargs clang-format --dry-run --Werror --sort-includes + @find src include tests -name '*.cpp' -or -name '*.hpp' | xargs clang-format --dry-run --Werror --sort-includes format: - @find src include tests -name '*.c' -or -name '*.h' -or -name '*.cpp' -or -name '*.hpp' | xargs clang-format -i --Werror --sort-includes + @find src include tests -name '*.cpp' -or -name '*.hpp' | xargs clang-format -i --Werror --sort-includes -.PHONY: config build install lint format +test: build + cd build && GTEST_COLOR=1 ctest --output-on-failure + +test-ci: build + cd build && GTEST_COLOR=1 ctest -V + +.PHONY: setup build install lint format test test-ci diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 0000000..04e387f --- /dev/null +++ b/external/CMakeLists.txt @@ -0,0 +1,5 @@ +include(${CMAKE_CURRENT_LIST_DIR}/glm.cmake) + +if(WAVEFRONT_BUILD_TESTS) + include(${CMAKE_CURRENT_LIST_DIR}/gtest.cmake) +endif() diff --git a/external/glm.cmake b/external/glm.cmake new file mode 100644 index 0000000..5f71fc9 --- /dev/null +++ b/external/glm.cmake @@ -0,0 +1,20 @@ +include(FetchContent) + +FetchContent_Declare( + glm + GIT_REPOSITORY https://github.com/g-truc/glm.git + GIT_TAG 1.0.2 +) + +set(USE_SYSTEM_GLM ON) + +FetchContent_MakeAvailable(glm) +install( + TARGETS glm + EXPORT ${PROJECT_NAME}Targets +) +install( + TARGETS glm-header-only + EXPORT ${PROJECT_NAME}Targets +) + diff --git a/external/gtest.cmake b/external/gtest.cmake new file mode 100644 index 0000000..3c9c7bc --- /dev/null +++ b/external/gtest.cmake @@ -0,0 +1,14 @@ +include(FetchContent) + +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.15.2 +) + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) +set(BUILD_GTEST ON CACHE BOOL "" FORCE) +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + +FetchContent_MakeAvailable(googletest) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e060b20..a7759e3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,14 +1,15 @@ +set(TARGET tests) enable_testing() -set(TARGET tests) - add_executable(${TARGET} parser_tests.cpp ) -target_link_libraries(${TARGET} - gtest_main - Wavefront +target_link_libraries(${TARGET} PRIVATE gtest gtest_main Wavefront) + +add_test( + NAME ${TARGET} + COMMAND $ ) include(GoogleTest)