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

Commonize example executions for CI #40

Merged
merged 3 commits into from
Sep 9, 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
41 changes: 14 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,30 @@ jobs:
needs: [ lint ]
runs-on: ubuntu-latest

strategy:
matrix:
example-folder: [ cmake-local, cmake-fetch-content ]

defaults:
run:
working-directory: examples/${{ matrix.example-folder }}

steps:
- uses: actions/checkout@v4

- name: Get latest CMake and ninja
uses: lukka/get-cmake@latest

- name: Configure local example
working-directory: examples/cmake-local
- name: Configure example
run: cmake -S . -B build

- name: Build local example
working-directory: examples/cmake-local
- name: Build example
run: cmake --build build

- name: Run local example
working-directory: examples/cmake-local/build
run: ./VeryCoolProject

- if: github.ref == 'refs/heads/master'
&& github.event_name == 'push'
&& github.repository_owner == 'gunvirranu'
run: echo "RUN_FETCH_EXAMPLE=true" >> $GITHUB_ENV

- name: Configure fetch-content example
working-directory: examples/cmake-fetch-content
if: env.RUN_FETCH_EXAMPLE == 'true'
run: cmake -S . -B build

- name: Build fetch-content example
working-directory: examples/cmake-fetch-content
if: env.RUN_FETCH_EXAMPLE == 'true'
run: cmake --build build

- name: Run fetch-content example
working-directory: examples/cmake-fetch-content/build
if: env.RUN_FETCH_EXAMPLE == 'true'
run: ./VeryCoolProject
- name: Run example
run: |
cd build
./VeryCoolExampleProject

test:
name: Test
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,20 @@ Point it at this Github repo with a tagged release version and you should be goo

```cmake
include(FetchContent)

# Download and setup the perturb library
FetchContent_Declare(
perturb
GIT_REPOSITORY "https://github.com/gunvirranu/perturb"
GIT_TAG 5723e50a54d438876b7a02e02a326e30b51ead4c # Release v1.0.0
)
FetchContent_MakeAvailable(perturb)

# Link perturb into your project
target_link_libraries(YOUR_VERY_COOL_PROJECT_TARGET perturb)
```

Also see the [`examples`](examples) directory for a full CMake example project using this. You can make more complicated adjustments as necessary, but this demonstrates the basics.
See the [`examples`](examples) directory for CMake example projects using this approach. You can make more complicated adjustments as necessary, but this demonstrates the basics.

### Git Submodules

Expand Down
7 changes: 4 additions & 3 deletions examples/cmake-fetch-content/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ cmake_minimum_required(VERSION 3.14)

# Create your own very cool project!
project(
VeryCoolProject
VeryCoolExampleProject
DESCRIPTION "Example of using perturb via CMake's FetchContent"
LANGUAGES CXX
)

# A very cool executable indeed
add_executable(VeryCoolProject main.cpp)
add_executable(VeryCoolExampleProject main.cpp)

# CMake downloads and sets up perturb for you
include(FetchContent)
FetchContent_Declare(
perturb
GIT_REPOSITORY "https://github.com/gunvirranu/perturb"
GIT_TAG 5723e50a54d438876b7a02e02a326e30b51ead4c # Release v1.0.0
)
FetchContent_MakeAvailable(perturb)

# Link together that bad boy as a dependency
target_link_libraries(VeryCoolProject perturb)
target_link_libraries(VeryCoolExampleProject perturb)
6 changes: 3 additions & 3 deletions examples/cmake-local/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ cmake_minimum_required(VERSION 3.14)

# Create your own very cool project!
project(
VeryCoolProject
VeryCoolExampleProject
DESCRIPTION "Example of using perturb from a local source clone"
LANGUAGES CXX
)

# A very cool executable indeed
add_executable(VeryCoolProject main.cpp)
add_executable(VeryCoolExampleProject main.cpp)

# Add perturb library root directory
# I have to use the local `build/` binary_dir cause my root one already being used
add_subdirectory(../../ build)

# Link together that bad boy as a dependency
target_link_libraries(VeryCoolProject perturb)
target_link_libraries(VeryCoolExampleProject perturb)