diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f7b1352 --- /dev/null +++ b/.github/workflows/release.yml @@ -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}} diff --git a/CMakeLists.txt b/CMakeLists.txt index 197caae..ef4e028 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/docs/Dependencies.md b/docs/Dependencies.md index 8a88c64..3018664 100644 --- a/docs/Dependencies.md +++ b/docs/Dependencies.md @@ -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 @@ -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) @@ -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 diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 0477878..abfe20a 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -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) diff --git a/vendor/doctest/CMakeLists.txt b/vendor/doctest/CMakeLists.txt deleted file mode 100644 index 7016f17..0000000 --- a/vendor/doctest/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -message(STATUS "Fetching Doctest ...") - -set(DOCTEST_NO_INSTALL ON) - -FetchContent_MakeAvailable(doctest) diff --git a/vendor/fmt/CMakeLists.txt b/vendor/fmt/CMakeLists.txt deleted file mode 100644 index 3dafef0..0000000 --- a/vendor/fmt/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -message(STATUS "Fetching fmt ...") - -option(FMT_INSTALL "Enable installation for the {fmt} project." OFF) - -FetchContent_MakeAvailable(fmt) diff --git a/vendor/imgui/CMakeLists.txt b/vendor/imgui-setup/CMakeLists.txt similarity index 89% rename from vendor/imgui/CMakeLists.txt rename to vendor/imgui-setup/CMakeLists.txt index b8c5b72..ef9a2f2 100644 --- a/vendor/imgui/CMakeLists.txt +++ b/vendor/imgui-setup/CMakeLists.txt @@ -1,7 +1,3 @@ -message(STATUS "Fetching imgui ...") - -set(CMAKE_CXX_STANDARD 20) - FetchContent_GetProperties(imgui) if (NOT imgui_POPULATED) FetchContent_Populate(imgui) @@ -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) diff --git a/vendor/sdl/CMakeLists.txt b/vendor/sdl/CMakeLists.txt deleted file mode 100644 index 6ddfa32..0000000 --- a/vendor/sdl/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -message(STATUS "Fetching SDL ...") - -option(SDL2_DISABLE_SDL2MAIN "Disable building/installation of SDL2main" ON) - -FetchContent_MakeAvailable(SDL2) diff --git a/vendor/spdlog/CMakeLists.txt b/vendor/spdlog/CMakeLists.txt deleted file mode 100644 index 29bc932..0000000 --- a/vendor/spdlog/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -message(STATUS "Fetching spdlog ...") - -set(SPDLOG_FMT_EXTERNAL "ON") - -FetchContent_MakeAvailable(spdlog)