Skip to content

Commit

Permalink
Merge pull request #3 from mdkdoc15/david_r
Browse files Browse the repository at this point in the history
Adding PathAgent, support for running Catch2 tests with CMake
  • Loading branch information
mdkdoc15 authored Oct 11, 2023
2 parents 2197f98 + d9cf8de commit fe028a7
Show file tree
Hide file tree
Showing 25 changed files with 823 additions and 26 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# vscode cmake build
build

# clion cmake build
cmake-build-debug
cmake-build-release

# clion settings
.idea/

# vscode settings
.vscode/
.github/

# Vim swap files
*.swp
*.swo

# executable files
*.exe
*.out

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third_party/Catch2"]
path = third_party/Catch2
url = https://github.com/catchorg/Catch2.git
[submodule "third_party/SFML"]
path = third_party/SFML
url = https://github.com/SFML/SFML.git
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.12)

project(CSE_491)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wcast-align -Winfinite-recursion -Wnon-virtual-dtor -Wnull-dereference -Woverloaded-virtual -pedantic")

set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")

# all the possible executables [each team can have their own configuration]
# copy over simple or same and change the accordingly
set(EXECUTABLES simple sfml_example)


# setting the output path to executable
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/executable)


# moving assets to build
file(COPY ./assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR})


# Configure SFML
set(SFML_SRC_DIR third_party/SFML)
set(SFML_BUILD_DIR sfml_build)
set(MAIN_SOURCE_DIR ./)
add_subdirectory(${SFML_SRC_DIR} ${SFML_BUILD_DIR})


foreach(EXECUTABLE ${EXECUTABLES})
set(SOURCES source/${EXECUTABLE}_main.cpp)
add_executable(${EXECUTABLE} ${SOURCES})
target_include_directories(${EXECUTABLE}
PRIVATE ${MAIN_SOURCE_DIR}
)
target_link_libraries(${EXECUTABLE}
PRIVATE sfml-window sfml-audio sfml-graphics
)
endforeach()


add_subdirectory(tests)
102 changes: 102 additions & 0 deletions docs/HowToCompile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# How to Compile

First you'll need to clone the repo _with submodules_.

If you haven't yet cloned the repo, run:
```
git clone https://github.com/MSU-CSE491/cse_491_fall_2023.git --recursive
```

If you _have_ already cloned the repo, but you need to download the submodules, run the following inside the repo's directory:
```
git submodule init
git submodule update
```

Now jump to the section for your operating system.

## Compiling under Linux

If you're on a Linux machine, you first need to download some dependencies for SFML.
Specifically, you need:
- freetype
- x11
- xrandr
- udev
- opengl
- flac
- ogg
- vorbis
- vorbisenc
- vorbisfile
- openal
- pthread

If you're on Ubuntu or other similar Debian distro, you can run the following:
```
sudo apt install libX-dev
```
For library X.

Once you have all dependencies downloaded, navigate to the root of the repo and run the following to build:
```
mkdir build
cd build
cmake ..
cmake --build .
```
All compiled executables should be in the `/build/executables/` directory.

## Compiling under MacOS

Mac shouldn't require any additional dependencies, so simply run the following, starting at the root of the repo:
```
mkdir build
cd build
cmake ..
cmake --build .
```
All compiled executables should be in the `/build/executables/` directory.

## Compiling under Windows with MinGW

After you have the repo and submodules downloaded, we need to ensure you have MinGW and CMake.
In a command line window, try running `g++` and `cmake`, if either give a "command not found" message, then we need to install them.

MinGW gives us g++, and can be downloaded here: https://winlibs.com/

CMake can be downloaded from here: https://cmake.org/download/

***Note:*** You'll likely need to add both MinGW's and CMake's `bin` folder to your path (I think CMake has a `bin` directory, otherwise add whatever directory contains the executable).
To add a directory to your path, follow these instructions: https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/
Note that you may run into issues if the directories you're adding have spaces in their paths (e.g., "C:\Program Files\..." was giving me issues). If you run into this, I'd recommend creating a new directory on your `C:\` drive, like `C:\bin\` and then add CMake and MinGW as subdirectories there.

Once you have CMake and MinGW working in your terminal (note you'll have to restart cmd/VSCode/whatever to get the path changes to take effect), run the following from the root of your repo:
```
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
cmake --build .
```

All compiled executables should be in the `/build/executables/` directory.

Note that if you tried to build using CMake before, it likely tried to use MSVC as a compiler. If so, just wipe the build folder and start fresh.

## How to compile in debug mode

To compile in debug mode, simply add `-DCMAKE_BUILD_TYPE=Debug` to the first cmake command.

This would normally look like:
```
cmake -DCMAKE_BUILD_TYPE=Debug ..
```
Unless you're on Windows, which would be:

```
cmake -DCMAKE_BUILD_TYPE=Debug -G "MinGW Makefiles" ..
```

You can then build like normal.

Note that you can also replace `Debug` with `Release` to compile with optimizations.
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Below are a set of guides for how to develop your own modules and joining them together into an executable (potentially with additional analysis and data collection.)

- [How to compile](HowToCompile.md) - Walks through how to compile via CMake.

- [How to Build an Agent](HowToBuildAnAgent.md) - A guide to designing your own type of autonomous agent.

- [How to Build a World](HowToBuildAWorld.md) - A guide to designing you own world with custom interaction modes among agents and other environmental properties.
Expand All @@ -11,3 +13,4 @@ Below are a set of guides for how to develop your own modules and joining them t
- [How to Assemble a `main()` function](HowToAssembleAMain.md) - A guide to selecting worlds, agents, and interfaces and turning them into a custom executable (including how to collect data about the resulting system.)

- [How to build, run, and create unit tests](HowToTest.md) - Walks through how to build and run existing unit tests, as well as create new unit test files.

1 change: 1 addition & 0 deletions source/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
*.swo
game
simple
Loading

0 comments on commit fe028a7

Please sign in to comment.