Skip to content

Commit 33d04f9

Browse files
author
Fabian Seidl
authored
add Common lib (#80)
* add Common lib - moved Shapes.h from Rendering to common - fixed a bug, where closing the AVCodecContext crashes on MacOS * add googletest to install scripts * fix ubuntu install script * add test step * disable test step on ios-simulator * add missing include directives in Vector*
1 parent 3134327 commit 33d04f9

28 files changed

+519
-34
lines changed

.github/workflows/sourcehold.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ jobs:
4040
- target-platform: "ios-simulator"
4141
os: macos-latest
4242
install-dependencies: "sh ./apple/install-dependencies-ios.sh -s -d 11.0 ./thirdparty/ios"
43-
cmake-configure-options: '-GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_OSX_ARCHITECTURES="x86_64"'
43+
#TODO: add gtest install script for ios
44+
cmake-configure-options: '-GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_OSX_ARCHITECTURES="x86_64" -DSOURCEHOLD_BUILD_TESTS=OFF'
4445
cmake-build-options: "-- -sdk iphonesimulator"
4546
uploaded-artifact-name: "sourcehold-ios"
4647
- os: windows-latest
@@ -141,6 +142,15 @@ jobs:
141142
zip -r ${{ github.workspace }}/${{ matrix.uploaded-artifact-name }}.zip "$BUILD_ARTIFACT_NAME"
142143
fi
143144
145+
- name: Run tests
146+
shell: bash
147+
run: |
148+
if [[ ${{ matrix.target-platform }} != 'ios-simulator' ]]; then
149+
pushd build/test
150+
ctest
151+
popd
152+
fi
153+
144154
- name: Upload artifacts
145155
uses: actions/upload-artifact@v2
146156
with:

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ include(cmake/Preamble.cmake)
99
add_subdirectory(apple)
1010
add_subdirectory(src)
1111

12+
if(SOURCEHOLD_BUILD_TESTS MATCHES ON)
13+
add_subdirectory(test)
14+
endif()
15+
1216
# TODO(seidl):
1317
# still some modules hidden here..
1418
set(SOURCE_FILES

apple/install-dependencies-macos.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ if ! is_brew_formula_installed sdl2 ; then
2626
else
2727
echo "SDL2 for macOS is already installed..."
2828
fi
29+
30+
if ! is_brew_formula_installed googletest ; then
31+
echo "Installing Google Test for macOS..."
32+
brew install googletest
33+
else
34+
echo "Google Test for macOS is already installed..."
35+
fi

cmake/Dependencies.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,10 @@ AddImportedTarget(SWRESAMPLE::SWRESAMPLE
9898
)
9999

100100
endif() # TARGET_OS_IOS
101+
102+
# GTest
103+
if(SOURCEHOLD_BUILD_TESTS MATCHES ON)
104+
find_package(GTest REQUIRED)
105+
endif()
106+
107+

cmake/Preamble.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR})
33
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
44

5+
option(SOURCEHOLD_BUILD_TESTS "Build Sourcehold tests" ON)
6+
57
if(MSVC)
68
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
79
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )

cmake/ProjectOptions.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ add_library(ProjectOptions INTERFACE)
66
target_compile_features(ProjectOptions INTERFACE cxx_std_17)
77

88
set_project_warnings(ProjectOptions)
9-
enable_sanitizers(ProjectOptions)
9+
enable_sanitizers(ProjectOptions)

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_subdirectory(System)
2+
add_subdirectory(Common)
23
add_subdirectory(FFMPEG)
34
add_subdirectory(Audio)
45
add_subdirectory(Events)

src/Common/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(COMMON_SOURCE_FILES
2+
Shapes.h
3+
Rect.h
4+
Line.h
5+
Vector2.h
6+
Vector3.h
7+
)
8+
9+
add_library(Common INTERFACE ${COMMON_SOURCE_FILES})
10+
source_group("Source Files" FILES ${COMMON_SOURCE_FILES})
11+
12+
target_include_directories(Common
13+
INTERFACE ${CMAKE_CURRENT_LIST_DIR}
14+
)
15+

src/Common/Line.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
template <typename T>
4+
struct Line {
5+
T x1;
6+
T y1;
7+
T x2;
8+
T y2;
9+
};

src/Common/Rect.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
template <typename T>
3+
struct Rect {
4+
T x;
5+
T y;
6+
T w;
7+
T h;
8+
};

0 commit comments

Comments
 (0)