Skip to content
Snippets Groups Projects
Commit 536c8d6f authored by kevineri.bonga's avatar kevineri.bonga
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 199 additions and 0 deletions
File added
File added
File added
File added
File added
File added
File added
File added
.vscode/
build/
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pacman.iml" filepath="$PROJECT_DIR$/.idea/pacman.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
cmake_minimum_required(VERSION 3.0)
project(pacman)
set(CMAKE_C_STANDARD 11)
# Linux -pthread shenanigans
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()
#=== LIBRARY: sokol
# add headers to the the file list because they are useful to have in IDEs
set(SOKOL_HEADERS
sokol/sokol_gfx.h
sokol/sokol_app.h
sokol/sokol_audio.h
sokol/sokol_glue.h)
add_library(sokol STATIC sokol/sokol.c ${SOKOL_HEADERS})
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
# compile sokol.c as Objective-C
target_compile_options(sokol PRIVATE -x objective-c)
target_link_libraries(sokol
"-framework QuartzCore"
"-framework Cocoa"
"-framework MetalKit"
"-framework Metal"
"-framework OpenGL"
"-framework AudioToolbox")
else()
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
target_link_libraries(sokol INTERFACE X11 Xi Xcursor GL asound dl m)
target_link_libraries(sokol PUBLIC Threads::Threads)
endif()
endif()
target_include_directories(sokol INTERFACE sokol)
#=== EXECUTABLE: pacman
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
add_executable(pacman WIN32 pacman.c)
else()
add_executable(pacman pacman.c)
endif()
target_link_libraries(pacman sokol)
if (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
target_link_options(pacman PUBLIC --shell-file ../sokol/shell.html)
target_link_options(pacman PUBLIC -sUSE_WEBGL2=1 -sNO_FILESYSTEM=1 -sASSERTIONS=0 -sMALLOC=emmalloc --closure=1)
endif()
# explicitly strip dead code
if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
target_link_options(pacman PRIVATE LINKER:-dead_strip)
endif()
MIT License
Copyright (c) 2020 Andre Weissflog
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# pacman.c
A Pacman clone written in C99 with minimal dependencies for Windows, macOS, Linux and WASM.
[WASM version](https://floooh.github.io/pacman.c/pacman.html)
For implementation details see comments in the pacman.c source file (I've tried
to structure the source code so that it can be read from top to bottom).
Related projects:
- Zig version: https://github.com/floooh/pacman.zig
## Clone, Build and Run (Linux, macOS, Windows)
On the command line:
```
git clone https://github.com/floooh/pacman.c
cd pacman.c
mkdir build
cd build
cmake ..
cmake --build .
```
> NOTE: on Linux you'll need to install the OpenGL, X11 and ALSA development packages (e.g. mesa-common-dev, libx11-dev and libasound2-dev).
On Mac and Linux this will create an executable called 'pacman'
in the build directory:
```
./pacman
```
On Windows, the executable is in a subdirectory:
```
Debug/pacman.exe
```
## Build and Run WASM/HTML version via Emscripten
> NOTE: You'll run into various problems running the Emscripten SDK tools on Windows, might be better to run this stuff in WSL.
Setup the emscripten SDK as described here:
https://emscripten.org/docs/getting_started/downloads.html#installation-instructions
Don't forget to run ```source ./emsdk_env.sh``` after activating the SDK.
And then in the pacman.c directory:
```
mkdir build
cd build
emcmake cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=MinSizeRel ..
cmake --build .
```
To run the compilation result in the system web browser:
```
> emrun pacman.html
```
## IDE Support
On Windows with Visual Studio cmake will automatically create a **Visual Studio** solution file which can be opened with ```cmake --open .```:
```
cd build
cmake ..
cmake --open .
```
On macOS, the cmake **Xcode** generator can be used to create an
Xcode project which can be opened with ```cmake --open .```
```
cd build
cmake -GXcode ..
cmake --open .
```
On all platforms with **Visual Studio Code** and the Microsoft C/C++ and
CMake Tools extensions, simply open VSCode in the root directory of the
project. The CMake Tools extension will detect the CMakeLists.txt file and
take over from there:
```
cd pacman.c
code .
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment