From a00575feb645189354097d9b8808aa3030a800b0 Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Sat, 29 May 2021 10:49:48 -0700 Subject: [PATCH] Turn src/examples/CMakeList.txt into standalone project (#1029) * 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 * Remove space in find_package() Signed-off-by: Cary Phillips * 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 * Rename bazel action to Bazel Signed-off-by: Cary Phillips * Remove errant # in comment. Signed-off-by: Cary Phillips * CI examples cleanup, run for macOS, not yet for Windows Signed-off-by: Cary Phillips --- .github/workflows/bazel_build.yml | 2 +- .github/workflows/ci_workflow.yml | 64 ++++++++++++++++++++++++++----- src/examples/CMakeLists.txt | 11 ++++++ 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/.github/workflows/bazel_build.yml b/.github/workflows/bazel_build.yml index ccf66e4df1..e7ec35c233 100644 --- a/.github/workflows/bazel_build.yml +++ b/.github/workflows/bazel_build.yml @@ -1,4 +1,4 @@ -name: CI +name: Bazel on: push: {} diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 71bb4b1b84..6d0436c9fb 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -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 }} \ @@ -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 }} \ @@ -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 }} \ @@ -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 }} \ @@ -373,6 +402,7 @@ jobs: run: | mkdir _install mkdir _build + mkdir _examples shell: bash ## - name: Install Dependences ## run: | @@ -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 }} \ @@ -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 }} \ diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 06f1a02c57..c5fd2cabf1 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -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