Skip to content

Commit

Permalink
Merge branch 'master' into no_install_sfml
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyPtn authored Aug 29, 2024
2 parents deb8c03 + 7f96df4 commit 3f08bb1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 32 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: CI

on: [push, pull_request]

defaults:
run:
shell: bash

jobs:
build:
name: ${{ matrix.platform.name }} ${{ matrix.config.name }}
Expand All @@ -26,16 +30,10 @@ jobs:
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libudev-dev libopenal-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure
shell: bash
run: cmake -S . -B build -DCMAKE_INSTALL_PREFIX=install ${{matrix.platform.flags}} ${{matrix.config.flags}}
run: cmake -B build ${{matrix.platform.flags}} ${{matrix.config.flags}}

- name: Build
shell: bash
run: cmake --build build --config Release

- name: Install
shell: bash
run: cmake --install build --config Release
17 changes: 8 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ FetchContent_Declare(sfml
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.x
EXCLUDE_FROM_ALL
SYSTEM)
FetchContent_MakeAvailable(sfml)
SYSTEM
GIT_SHALLOW ON)
FetchContent_MakeAvailable(SFML)

add_executable(CMakeSFMLProject src/main.cpp)
target_link_libraries(CMakeSFMLProject PRIVATE sfml-graphics)
target_compile_features(CMakeSFMLProject PRIVATE cxx_std_17)
add_executable(main src/main.cpp)
target_link_libraries(main PRIVATE sfml-graphics)
target_compile_features(main PRIVATE cxx_std_17)

if(WIN32)
add_custom_command(
TARGET CMakeSFMLProject
TARGET main
COMMENT "Copy OpenAL DLL"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:CMakeSFMLProject>
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:main>
VERBATIM)
endif()

install(TARGETS CMakeSFMLProject)
19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ The template starts out very basic, but might receive additional features over t

## How to Use

1. Install Git and CMake. Use your system's package manager if available.
1. Follow the above instructions about how to use GitHub's project template feature to create your own project.
1. Open [CMakeLists.txt](CMakeLists.txt). Rename the project and the executable to whatever name you want. The project and executable names don't have to match.
1. Clone your new GitHub repo and open the repo in your text editor of choice.
1. Open [CMakeLists.txt](CMakeLists.txt). Rename the project and the executable to whatever name you want.
1. If you want to add or remove any .cpp files, change the source files listed in the [`add_executable`](CMakeLists.txt#L10) call in CMakeLists.txt to match the source files your project requires. If you plan on keeping the default main.cpp file then no changes are required.
1. If you use Linux, install SFML's dependencies using your system package manager. On Ubuntu and other Debian-based distributions you can use the following commands:
```
Expand All @@ -34,18 +36,12 @@ The template starts out very basic, but might receive additional features over t
- [Qt Creator](https://doc.qt.io/qtcreator/creator-project-cmake.html)

Using CMake from the command line is straightforward as well.
Be sure to run these commands in the root directory of the project you just created.

For a single-configuration generator (typically the case on Linux and macOS):
```
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake -B build
cmake --build build
```

For a multi-configuration generator (typically the case on Windows):
```
cmake -S . -B build
cmake --build build --config Release
```
1. Enjoy!

## Upgrading SFML
Expand All @@ -64,11 +60,6 @@ The nice folks in the [SFML community](https://github.com/SFML/SFML#community) c

Modify CMake options by adding them as configuration parameters (with a `-D` flag) or by modifying the contents of CMakeCache.txt and rebuilding.

### Use Static Libraries

By default SFML builds shared libraries and this default is inherited by your project.
CMake's [`BUILD_SHARED_LIBS`](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html) option lets you pick static or shared libraries for the entire project.

### Change Compilers

See the variety of [`CMAKE_<LANG>_COMPILER`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html) options.
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ int main()
window.clear();
window.display();
}
}
}

0 comments on commit 3f08bb1

Please sign in to comment.