Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General improvements #22

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
BUILD_TYPE: Release

jobs:
build:
strategy:
matrix:
os: [ macos-14, ubuntu-latest, windows-latest ]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ project(
VERSION 1.0.0
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(PROJECT_COMPANY_NAME "My Company")
set(PROJECT_COMPANY_NAMESPACE "com.mycompany") # Reverse domain name notation

Expand Down
51 changes: 33 additions & 18 deletions docs/Dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Dependencies are located in `vendor/`. The `vendor/CMakeLists.txt` uses
CMake's [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) to load dependencies on configure
time. Every dependency also has an associated folder containing a `CMakeLists.txt` for configuration.
time. Some dependencies also have an associated folder containing a `CMakeLists.txt` for configuration or setup purpose.

## Already included

The following set of dependencies is already included:
The following set of dependencies are already included:

- [Doctest](https://github.com/doctest/doctest) - Testing framework
- [fmtlib](https://fmt.dev/latest/index.html) - Formatting library
Expand All @@ -29,37 +29,35 @@ FetchContent_Declare(
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
GIT_TAG v1.11.0
)
add_subdirectory(spdlog)
```

After adding this to the `vendor` CMake file, a new `CMakeLists.txt` needs to be created in a new folder for the
dependency. Again with the spdlog example:
Further down the same file is a section for dependency settings. Again using spdlog as an example:

```cmake
# vendor/spdlog/CMakeLists.txt
# vendor/CMakeLists.txt

message(STATUS "Fetching spdlog ...")
# Settings

# Any package build settings here
set(SPDLOG_FMT_EXTERNAL "ON")

FetchContent_MakeAvailable(spdlog)
# Populate

FetchContent_MakeAvailable(
# Other dependencies ...
spdlog)
```

This dependency specific CMake file will contain a message for fetching the library, any package configuration, and a
call to `FetchContent_MakeAvailable` with the given name to add them to the build.
At the end the call to `FetchContent_MakeAvailable` gets the new dependency added as well.

## New dependency without CMake support

Adding a package that does not support CMake works almost the same as with support above. The difference is that the new
library needs to be declared. Taking Dear ImGui as an example, that does not support CMake, this is how the setup is
Adding a package that does not support CMake is also not a problem. The difference is that the new library needs to be
setup separately. Taking Dear ImGui as an example, that does not support CMake, this is how the setup is
done:

```cmake
message(STATUS "Fetching imgui ...")

# Define build options.
set(CMAKE_CXX_STANDARD 20)
# vendor/imgui-setup/CMakeLists.txt

# Populate scope with library variables to get access to source and build directories.
FetchContent_GetProperties(imgui)
Expand All @@ -81,11 +79,28 @@ add_library(imgui
# Set include directory based in populated variable `imgui_SOURCE_DIR`.
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})

# Define compile options.
target_compile_features(imgui PRIVATE cxx_std_20)

# Link external library SDL2, part of the dependencies as well.
target_link_libraries(imgui PUBLIC SDL2::SDL2)
```

After setting up the library it needs to be made available in the vendor `CMakeLists.txt`:

```cmake
# vendor/CMakeLists.txt

# Settings

# Adding the setup directory
add_subdirectory(imgui-setup)

# Populate

# Add to main build
FetchContent_MakeAvailable(imgui)
FetchContent_MakeAvailable(
# Other dependencies ...
imgui)
```

## Link dependency
Expand Down
31 changes: 22 additions & 9 deletions vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
include(FetchContent)

# Dependencies

FetchContent_Declare(
doctest
GIT_REPOSITORY "https://github.com/onqtam/doctest.git"
GIT_TAG v2.4.11
)
add_subdirectory(doctest)

FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
GIT_TAG 10.1.1
GIT_TAG 10.2.1
)
add_subdirectory(fmt)

FetchContent_Declare(
imgui
GIT_REPOSITORY "https://github.com/ocornut/imgui.git"
GIT_TAG 37ea320b96a4b77581986f5581707021a7be94c9 # Branch: docking, date: 07.11.2023, 08:20 GMT+1
GIT_TAG 085781f5ca5372d5fc804d7e44b5bf27a8994af7 # Branch: docking, date: 19.03.2024, 06:52 GMT+1
)
add_subdirectory(imgui)

FetchContent_Declare(
SDL2
GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git"
GIT_TAG release-2.28.5
GIT_TAG release-2.30.1
)
add_subdirectory(sdl)

FetchContent_Declare(
spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
GIT_TAG v1.12.0
GIT_TAG v1.13.0
)
add_subdirectory(spdlog)

# Settings

# For SDL2 to be able to override options
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

set(DOCTEST_NO_INSTALL ON)
set(FMT_INSTALL OFF)
set(SDL2_DISABLE_SDL2MAIN ON)
set(SPDLOG_FMT_EXTERNAL ON)

add_subdirectory(imgui-setup)

# Populate

FetchContent_MakeAvailable(doctest fmt imgui SDL2 spdlog)
5 changes: 0 additions & 5 deletions vendor/doctest/CMakeLists.txt

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/fmt/CMakeLists.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
message(STATUS "Fetching imgui ...")

set(CMAKE_CXX_STANDARD 20)

FetchContent_GetProperties(imgui)
if (NOT imgui_POPULATED)
FetchContent_Populate(imgui)
Expand All @@ -18,6 +14,5 @@ add_library(imgui
${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer2.h ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer2.cpp)

target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
target_compile_features(imgui PRIVATE cxx_std_20)
target_link_libraries(imgui PUBLIC SDL2::SDL2)

FetchContent_MakeAvailable(imgui)
5 changes: 0 additions & 5 deletions vendor/sdl/CMakeLists.txt

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/spdlog/CMakeLists.txt

This file was deleted.