-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This unifies the build system across platforms, including doing development inside Visual Studio. No change to other code. Some exceptions: - Switch port is still a Makefile - run_with_tcc.bat still exists
- Loading branch information
1 parent
578f90b
commit bf97a38
Showing
15 changed files
with
248 additions
and
905 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
.DS_Store | ||
*.dSYM | ||
/.vs/ | ||
/packages/ | ||
/saves/ | ||
*.o | ||
/sm | ||
/build/ | ||
/build*/ | ||
/sm.smc | ||
SDL2.dll | ||
/sm.exe | ||
/glsl-shaders/ | ||
/glsl-shaders/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,86 @@ | ||
# Requirements | ||
* A Super Metroid rom (Make sure to rename it to `sm.smc`) | ||
* cmake (and also ninja, for better compiling speed) | ||
* A Super Metroid rom (Make sure to rename it to `sm.smc`) which **must be in | ||
the same folder as `sm`/`sm.exe`** | ||
* libsdl2-dev | ||
* Super Metroid repo `git clone --recursive https://github.com/snesrev/sm` | ||
|
||
For Linux/MacOS you must install these for your desired OS: | ||
* Ubuntu/Debian: `sudo apt install libsdl2-dev` | ||
* Fedora Linux: `sudo dnf in sdl2-devel` | ||
* Arch Linux: `sudo pacman -S sdl2` | ||
* macOS: `brew install sdl2` | ||
* Ubuntu/Debian: `sudo apt install libsdl2-dev cmake ninja-build` | ||
* Fedora Linux: `sudo dnf in sdl2-devel cmake ninja-build` | ||
* Arch Linux: `sudo pacman -S sdl2 cmake ninja` | ||
* macOS: `brew install sdl2 cmake ninja` | ||
|
||
# Windows | ||
|
||
## Building with MSYS2 | ||
|
||
Dependencies and requirements: | ||
|
||
* The `libsdl2-dev` library | ||
* [MSYS2](https://www.msys2.org) | ||
First, install [MSYS2](https://www.msys2.org/). After following the instructions, | ||
install the following packages. | ||
|
||
Note: *Make sure you're using MINGW64 and you're in `sm` folder in the terminal.* | ||
|
||
1. Install MSYS2 on your machine. | ||
2. Place the copy of your rom in the main directory. | ||
3. Install the necessary dependencies by inputting this command in the terminal. | ||
|
||
```sh | ||
pacman -S mingw-w64-x86_64-SDL2 && pacman -S make && pacman -S mingw-w64-x86_64-gcc | ||
pacman -S mingw-w64-x86_64-{gcc,cmake,SDL2,ninja} | ||
``` | ||
4. Type `sdl2-config --cflags`, it should output: | ||
```sh | ||
-IC:/msys64/mingw64/include/SDL2 -Dmain=SDL_main | ||
``` | ||
5. After that type `sdl2-config --libs`, should output: | ||
|
||
Once installed, building can be done with: | ||
```sh | ||
-LC:/msys64/mingw64/lib -lmingw32 -mwindows -lSDL2main -lSDL2 | ||
cmake -B build -G Ninja && cmake --build build | ||
``` | ||
|
||
After you've done installing everything, cd to `sm` folder. Type `make` | ||
In order to speed up the compilation, type `make -j16` | ||
`sm.exe` will be at `./build/sm.exe`. | ||
|
||
## Building with Visual Studio | ||
|
||
Dependencies and requirements: | ||
* The `libsdl2-dev` library, which is automatically installed with NuGet. | ||
* [Visual Studio Community 2022](https://visualstudio.microsoft.com) | ||
|
||
Download VS installer. On installer prompt, make sure you're on "Workloads" and check `Desktop Development with C++` this will install the necessary deps for compilation. | ||
Download VS installer. On installer prompt, make sure you're on "Workloads" | ||
and check **both** `Desktop Development with C++` **and** `C++ CMake Tools for Windows`. | ||
This will install the necessary deps for compilation. | ||
|
||
1. Open `sm.sln` solution. | ||
2. Change the build target from `Debug` to `Release` | ||
3. Build the solution. | ||
Visual Studio should automatically detect the CMake project and let you configure and build it. If not, | ||
follow the [general instructions](https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-170) | ||
from Microsoft. | ||
|
||
## Building with Tiny C Compiler | ||
Make sure to switch the build type from `Debug` to `Release`. | ||
|
||
## Building with Tiny C Compiler | ||
Dependencies and requirements: | ||
* You'll need [TCC](https://github.com/FitzRoyX/tinycc/releases/download/tcc_20221020/tcc_20221020.zip) and [SDL2](https://github.com/libsdl-org/SDL/releases/download/release-2.24.1/SDL2-devel-2.24.1-VC.zip) in order to compile using TCC. | ||
* You'll need [TCC](https://github.com/FitzRoyX/tinycc/releases/download/tcc_20221020/tcc_20221020.zip) and | ||
[SDL2](https://github.com/libsdl-org/SDL/releases/download/release-2.24.1/SDL2-devel-2.24.1-VC.zip) in order to compile using TCC. | ||
|
||
1. Unzip both TCC and SDL and place them in `third_party` folder. | ||
2. Double click `run_with_tcc.bat` | ||
3. Wait for it to compile and the game will automatically boot-up. | ||
|
||
# Linux/MacOS | ||
|
||
CD to your SM root folder and open the terminal and type: | ||
```sh | ||
make | ||
cmake -B build && cmake --build build --parallel | ||
``` | ||
|
||
For more advanced usage: | ||
```sh | ||
make -j$(nproc) # run on all core | ||
make clean all # clear gen+obj and rebuild | ||
CC=clang make # specify compiler | ||
``` | ||
The resulting binary will be `build/sm`. | ||
|
||
# Nintendo Switch | ||
|
||
Dependencies and requirements: | ||
|
||
* The `switch-sdl2` library | ||
## Getting Dependencies | ||
You will need: | ||
* [DevKitPro](https://github.com/devkitPro/installer) | ||
* [Atmosphere](https://github.com/Atmosphere-NX/Atmosphere) | ||
|
||
1. Make sure you've installed Atmosphere on your Switch. | ||
2. Please download the DevKitPro version of MSYS2 through their installer, as the default MSYS2 causes issues with windows compiling. | ||
3. Now that you've installed DevKitPro, open up the location you've installed DevKitPro to, then find `mingw64.exe` inside `msys2` located in `devkitPro` folder. | ||
4. Type `pacman -S git switch-dev switch-sdl2 switch-tools` in the terminal to install the `switch-sdl2` library. | ||
5. CD to `switch` folder by typing `cd src/platfrom/switch` in the terminal on the `sm` root folder. | ||
6. type `make` to compile the Switch Port. | ||
7. Transfer the `.ini`, `nro`, `ncap` and your rom file to the Switch. | ||
First, follow the [installation instructions on devkitPro's website](https://devkitpro.org/wiki/Getting_Started). | ||
|
||
**OPTIONAL STEP** | ||
Second, once you have pacman set up and synced, do: | ||
```shell | ||
pacman -S switch-dev switch-tools switch-sdl2 | ||
``` | ||
|
||
```sh | ||
make -j$(nproc) # To build using all cores | ||
## Building | ||
In the top level directory, you can use the cmake preset for running a build for the switch: | ||
```shell | ||
cmake --preset nintendo-switch | ||
cmake --build build-switch --parallel | ||
``` | ||
|
||
## Getting SM on to your Switch | ||
First, make sure you've installed [Atmosphere](https://github.com/Atmosphere-NX/Atmosphere) on your Switch. | ||
Next, go into the `build-switch` directory and copy `sm.ini`, `sm.nro`, and `sm.ncap` and the sm rom | ||
file to your Switch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
cmake_minimum_required(VERSION 3.18 FATAL_ERROR) | ||
|
||
project(sm | ||
VERSION 0.0.1 | ||
DESCRIPTION "Super Metroid PC Port" | ||
HOMEPAGE_URL "https://github.com/snesrev/sm" | ||
LANGUAGES C) | ||
|
||
if (CMAKE_BINARY_DIR EQUAL CMAKE_SOURCE_DIR) | ||
message(WARNING "You are compiling in the source tree, you probably don't want to do that. Use -B to set the build directory") | ||
endif() | ||
|
||
include(GNUInstallDirs) | ||
|
||
# Compiler Warnings | ||
list(APPEND c_warnings | ||
"-Wall" | ||
"-fno-strict-aliasing") | ||
|
||
list(APPEND msvc_warnings | ||
"/W3" | ||
"/wd4996") | ||
|
||
# For installation later | ||
set(ini_name "${PROJECT_SOURCE_DIR}/sm.ini") | ||
|
||
# Dependencies | ||
# ------------ | ||
# SDL | ||
if (NINTENDO_SWITCH) | ||
# Force static on Switch, just because it's easier | ||
find_package(SDL2 REQUIRED COMPONENTS SDL2-static) | ||
else() | ||
find_package(SDL2 REQUIRED COMPONENTS SDL2) | ||
endif() | ||
|
||
# OpenGL | ||
# TODO: This should likely be removed | ||
add_library(gl STATIC "third_party/gl_core/gl_core_3_1.c") | ||
target_include_directories(gl PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") | ||
|
||
# Main Executable | ||
# --------------- | ||
add_executable(sm) | ||
add_subdirectory(src) | ||
target_link_libraries(sm PRIVATE SDL2::SDL2 gl) | ||
set_target_properties(sm PROPERTIES C_STANDARD 11) | ||
|
||
if (MSVC) | ||
target_compile_options(sm PRIVATE ${msvc_warnings}) | ||
else() | ||
target_link_libraries(sm PRIVATE m) | ||
target_compile_definitions(sm PRIVATE SYSTEM_VOLUME_MIXER_AVAILABLE=0) | ||
target_compile_options(sm PRIVATE ${c_warnings}) | ||
endif() | ||
|
||
# Nintendo Switch extra setup | ||
if (NINTENDO_SWITCH) | ||
target_compile_definitions(sm PUBLIC __SWITCH__) | ||
|
||
# needs to be linked with g++ for C++ stdlib | ||
enable_language(CXX) | ||
set_target_properties(sm PROPERTIES | ||
CXX_STANDARD 11 | ||
LINKER_LANGUAGE CXX) | ||
|
||
nx_generate_nacp(sm.nacp | ||
NAME "Super Metroid" | ||
AUTHOR "snesrev & Lywx" | ||
VERSION "${PROJECT_VERSION}") | ||
|
||
nx_create_nro(sm | ||
NACP sm.nacp | ||
ICON "${PROJECT_SOURCE_DIR}/src/platform/switch/icon.jpg") | ||
|
||
set(ini_name "${PROJECT_SOURCE_DIR}/src/platform/switch/sm.ini") | ||
endif() | ||
|
||
# Installation | ||
# ------------ | ||
install(TARGETS sm RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") | ||
|
||
# TODO: should be in some config dir | ||
install(FILES "${ini_name}" DESTINATION "${CMAKE_INSTALL_BINDIR}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": 3, | ||
"cmakeMinimumRequired": { | ||
"major": 3, | ||
"minor": 21, | ||
"patch": 0 | ||
}, | ||
"configurePresets": [ | ||
{ | ||
"name": "nintendo-switch", | ||
"binaryDir": "${sourceDir}/build-switch", | ||
"toolchainFile": "$env{DEVKITPRO}/cmake/Switch.cmake", | ||
"condition": { | ||
"type": "notEquals", | ||
"lhs": "$env{DEVKITPRO}", | ||
"rhs": "" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.