Skip to content

Commit

Permalink
Turn src/examples/CMakeList.txt into standalone project (#1029)
Browse files Browse the repository at this point in the history
* Turn src/examples/CMakeList.txt into standalone project

By adding cmake_minimum_required(), project() and find_package()
statements, src/examples serves as a standalone project linking
against the OpenEXR library. This makes it a more representative
example for end users, but it also makes it suitable for a CI
validation step that builds against the already-installed library.

This preserves the behavior of installing the example code
as a part of the OpenEXR installation step.

Signed-off-by: Cary Phillips <cary@ilm.com>

* Remove space in find_package()

Signed-off-by: Cary Phillips <cary@ilm.com>

* Fix standalone examples and add to CI

* examples CMakeLists.txt calls project() only when configure as standalone
* CI builds and runs the examples
* Rename the CI runs to match the .yml files (in upper case)

Signed-off-by: Cary Phillips <cary@ilm.com>

* Rename bazel action to Bazel

Signed-off-by: Cary Phillips <cary@ilm.com>

* Remove errant # in comment.

Signed-off-by: Cary Phillips <cary@ilm.com>

* CI examples cleanup, run for macOS, not yet for Windows

Signed-off-by: Cary Phillips <cary@ilm.com>
  • Loading branch information
cary-ilm authored May 29, 2021
1 parent 2426c6c commit a00575f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bazel_build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Bazel

on:
push: {}
Expand Down
64 changes: 55 additions & 9 deletions .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,10 @@ jobs:
run: |
mkdir _install
mkdir _build
mkdir _examples
- name: Configure
run: |
cmake ../. \
cmake .. \
-DCMAKE_INSTALL_PREFIX=../_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
Expand All @@ -215,16 +216,29 @@ jobs:
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} \
-DOPENEXR_BUILD_UTILS='ON' \
-DOPENEXR_RUN_FUZZ_TESTS='OFF' \
-DOPENEXR_ENABLE_THREADING=${{ matrix.threads-enabled }} \
-DPYTHON_EXECUTABLE=$(which python)
-DOPENEXR_ENABLE_THREADING=${{ matrix.threads-enabled }}
working-directory: _build
- name: Build
run: |
cmake --build . \
--target install \
--config ${{ matrix.build-type }} \
-- -j4
--config ${{ matrix.build-type }}
working-directory: _build
- name: Examples
run: |
# Make sure we can build the examples when configured as a
# standalone application linking against the just-installed
# OpenEXR library.
cmake ../src/examples \
-DCMAKE_PREFIX_PATH=../../_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
-DCMAKE_CXX_FLAGS=${{ matrix.cxx-flags }}
cmake --build . \
--config ${{ matrix.build-type }}
# Confirm the examples program runs
./OpenEXRExamples
working-directory: _examples
- name: Test
run: |
ctest -T Test ${{ matrix.exclude-tests }} \
Expand Down Expand Up @@ -293,9 +307,10 @@ jobs:
run: |
mkdir _install
mkdir _build
mkdir _examples
- name: Configure
run: |
cmake ../. \
cmake .. \
-DCMAKE_INSTALL_PREFIX=../_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
Expand All @@ -309,9 +324,23 @@ jobs:
run: |
cmake --build . \
--target install \
--config ${{ matrix.build-type }} \
-- -j2
--config ${{ matrix.build-type }}
working-directory: _build
- name: Examples
run: |
# Make sure we can build the examples when configured as a
# standalone application linking against the just-installed
# OpenEXR library.
cmake ../src/examples \
-DCMAKE_PREFIX_PATH=../../_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
-DCMAKE_CXX_FLAGS=${{ matrix.cxx-flags }}
cmake --build . \
--config ${{ matrix.build-type }}
# Confirm the examples program runs
./OpenEXRExamples
working-directory: _examples
- name: Test
run: |
ctest -T Test ${{matrix.exclude-tests }} \
Expand Down Expand Up @@ -373,6 +402,7 @@ jobs:
run: |
mkdir _install
mkdir _build
mkdir _examples
shell: bash
## - name: Install Dependences
## run: |
Expand All @@ -382,7 +412,7 @@ jobs:
## shell: powershell
- name: Configure
run: |
cmake ../. \
cmake .. \
-DCMAKE_INSTALL_PREFIX=../_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
Expand All @@ -400,6 +430,22 @@ jobs:
--config ${{ matrix.build-type }}
shell: bash
working-directory: _build
## - name: Examples
## run: |
## # Make sure we can build the examples when configured as a
## # standalone application linking against the just-installed
## # OpenEXR library.
## cmake ../src/examples \
## -DCMAKE_PREFIX_PATH=../../_install \
## -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
## -DCMAKE_CXX_STANDARD=${{ matrix.cxx-standard }} \
## -DCMAKE_CXX_FLAGS=${{ matrix.cxx-flags }}
## cmake --build . \
## --config ${{ matrix.build-type }}
## # Confirm the examples program runs
## ./OpenEXRExamples
## shell: bash
## working-directory: _examples
- name: Test
run: |
ctest -T Test ${{ matrix.exclude-tests }} \
Expand Down
11 changes: 11 additions & 0 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) Contributors to the OpenEXR Project.

# If the project name is set, this is being configured as a part of
# OpenEXR. If there is no project name, it's being configured as a
# standalone program linking against an already-installed OpenEXR
# library.

if("${CMAKE_PROJECT_NAME}" STREQUAL "")
cmake_minimum_required(VERSION 3.12)
project(OpenEXRExamples)
find_package(OpenEXR)
endif()

add_executable(OpenEXRExamples
drawImage.cpp
generalInterfaceExamples.cpp
Expand Down

0 comments on commit a00575f

Please sign in to comment.