The cpp-starter project is designed as a starting point for creating C++ applications.
It leverages SDL2 for graphical rendering and input handling and provides a modular architecture for scalable development.
- Install dependencies:
$ brew install cmake ninja sdl2 sdl2_ttf sdl2_image sdl2_mixer
- Build:
$ cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=$(brew --prefix)/bin/ninja -G Ninja -S . -B build
$ cd build
$ ninja
$ ctest
- Run:
$ cd build/src/apps/pong
$ ./AppPong
The project is structured into various directories, each serving a specific purpose:
src
: The main source directory.apps
: Contains individual applications. Example:pong
.packages
: Contains shared libraries or modules. Examples:core
,ecs
,events
.
- Each app, like
pong
, contains its source code, assets, and CMake configurations. - Structure inside an app:
src
: Source files for the application.assets
: Game assets like fonts and images.
- Shared functionalities are grouped into packages under
packages
. - Examples include
core
for core functionalities,ecs
for entity-component systems.
- To create a new app, add a directory under
src/apps
. - Include a
CMakeLists.txt
in your app directory for build configurations. - Organize your app's source code, assets, and tests within this directory.
- Include new app in the src
CMakeLists.txt
.
Example:
set(APP_NAME AppPong)
set(APP_FOLDER_NAME pong)
set(SOURCES
src/main.cpp
src/entities/GameObject.h
src/strategies/MinimalLoopStrategy.h
)
add_executable(${APP_NAME} ${SOURCES})
# Copy assets
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/src/apps/${APP_FOLDER_NAME})
target_link_libraries(${APP_NAME} Core)
- Create a new package under
packages
for shared functionalities. - Each package should have its own
CMakeLists.txt
. - Include the package in src
CMakeLists.txt
.
- Tests are written using GoogleTest and GoogleMock.
- Each app or package should contain its test files, e.g.,
GameObject.test.cpp
. - Use
add_test
inCMakeLists.txt
to include tests in the build process.
If you want to include tests for your app, add the following to your CMakeLists.txt
:
set(APP_NAME_TEST ${LIB_NAME}Test)
add_test(AllTests${LIB_NAME} ${APP_NAME_TEST})
set(SOURCES_TEST
src/entities/GameObject.h
src/strategies/MinimalLoopStrategy.h
src/entities/GameObject.test.cpp
src/strategies/MinimalLoopStrategy.test.cpp)
add_executable(${APP_NAME_TEST} ${SOURCES_TEST})
target_link_libraries(${APP_NAME_TEST} PRIVATE
gtest
gmock
gmock_main
Core
SDL2::SDL2
)