Skip to content

Commit

Permalink
docs: move pixi-build example to subfolder and restore cpp-sdl example (
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian authored Dec 18, 2024
1 parent 3750f98 commit 2e05115
Show file tree
Hide file tree
Showing 19 changed files with 3,634 additions and 165 deletions.
9 changes: 0 additions & 9 deletions examples/cpp-sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,3 @@ target_link_libraries(
SDL2::SDL2
SDL2::SDL2main
)

include(GNUInstallDirs)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${BINDIR}
)
3,378 changes: 3,244 additions & 134 deletions examples/cpp-sdl/pixi.lock

Large diffs are not rendered by default.

59 changes: 37 additions & 22 deletions examples/cpp-sdl/pixi.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
[workspace]
channels = ["https://prefix.dev/conda-forge"]
platforms = ["win-64", "linux-64", "osx-arm64", "osx-64"]
preview = ["pixi-build"]

[package]
[project]
authors = ["Bas Zalmstra <bas@prefix.dev>"]
channels = ["conda-forge"]
description = "Showcases how to create a simple C++ executable with Pixi"
name = "sdl_example"
version = "0.1.0"

[build-system]
build-backend = { name = "pixi-build-cmake", version = "*" }
channels = [
"https://prefix.dev/pixi-build-backends",
"https://prefix.dev/conda-forge",
]
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"]

[tasks.start]
cmd = "sdl_example"

[host-dependencies]
# This ensures that SDL2 is available at build time.
sdl2 = ">=2.26.5,<3.0"
# Start the built executable
cmd = ".build/bin/sdl_example"
depends-on = ["build"]

[dependencies]
# Define a dependency on ourselves. This will invoke the build backend to build
# the C++ code and install the executable in an environment ready to be used.
sdl_example = { path = "." }
sdl2 = "2.26.5.*"

[feature.build.dependencies]
cmake = "3.26.4.*"
cxx-compiler = "1.5.2.*"
make = ">=4.3,<5"
ninja = "1.11.1.*"

[feature.build.tasks.configure]
# Configures CMake
cmd = [
"cmake",
# Use the cross-platform Ninja generator
"-GNinja",
# The source is in the root directory
"-S.",
# We wanna build in the .build directory
"-B.build",
]
inputs = ["CMakeLists.txt"]
outputs = [".build/CMakeFiles/"]

# Build the executable but make sure CMake is configured first.
[feature.build.tasks.build]
cmd = ["cmake", "--build", ".build"]
depends-on = ["configure"]
inputs = ["CMakeLists.txt", "src/*"]
outputs = [".build/bin/sdl_example"]

[environments]
build = ["build"]
3 changes: 3 additions & 0 deletions examples/pixi-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Pixi Build

These examples utilize pixi build and require a development version of pixi to work.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions examples/pixi-build/cpp-sdl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# pixi environments
.pixi

# The build directory
.build
27 changes: 27 additions & 0 deletions examples/pixi-build/cpp-sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.7)
project(sdl_example)

find_package(SDL2 REQUIRED)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

add_executable(${PROJECT_NAME} src/main.cc)

if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE)
endif()

target_link_libraries(
${PROJECT_NAME} PRIVATE
SDL2::SDL2
SDL2::SDL2main
)

include(GNUInstallDirs)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${BINDIR}
)
19 changes: 19 additions & 0 deletions examples/pixi-build/cpp-sdl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Simple C++ SDL Example

This is a simple pixi demo that showcases how to use C++ and SDL.

## How to use?

Make sure you have `pixi` available in your terminal.
Navigate to this directory and run:

```shell
# Configure the CMake project
pixi run configure

# Build the executable
pixi run build

# Start the build executable
pixi run start
```
183 changes: 183 additions & 0 deletions examples/pixi-build/cpp-sdl/pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions examples/pixi-build/cpp-sdl/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[workspace]
channels = ["https://prefix.dev/conda-forge"]
platforms = ["win-64", "linux-64", "osx-arm64", "osx-64"]
preview = ["pixi-build"]

[package]
authors = ["Bas Zalmstra <bas@prefix.dev>"]
description = "Showcases how to create a simple C++ executable with Pixi"
name = "sdl_example"
version = "0.1.0"

[build-system]
build-backend = { name = "pixi-build-cmake", version = "*" }
channels = [
"https://prefix.dev/pixi-build-backends",
"https://prefix.dev/conda-forge",
]

[tasks.start]
cmd = "sdl_example"

[host-dependencies]
# This ensures that SDL2 is available at build time.
sdl2 = ">=2.26.5,<3.0"

[dependencies]
# Define a dependency on ourselves. This will invoke the build backend to build
# the C++ code and install the executable in an environment ready to be used.
sdl_example = { path = "." }
Loading

0 comments on commit 2e05115

Please sign in to comment.