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

Test CMake Config script #1421

Merged
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
32 changes: 32 additions & 0 deletions .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ jobs:
- name: Test
run: ctest -V
working-directory: _build
- name: Test CMake Consumer
if: matrix.build-shared == 'ON'
run: |
cmake . \
-DCMAKE_PREFIX_PATH=../../../_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
cmake --build . \
--config ${{ matrix.build-type }}
./consumer
working-directory: _build/tests/cmake-consumer-dist

# ---------------------------------------------------------------------------
# macOS
Expand Down Expand Up @@ -390,6 +400,16 @@ jobs:
- name: Test
run: ctest -V
working-directory: _build
- name: Test CMake Consumer
if: matrix.build-shared == 'ON'
run: |
cmake . \
-DCMAKE_PREFIX_PATH=../../../_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
cmake --build . \
--config ${{ matrix.build-type }}
./consumer
working-directory: _build/tests/cmake-consumer-dist

# ---------------------------------------------------------------------------
# Windows
Expand Down Expand Up @@ -518,3 +538,15 @@ jobs:
run: ctest -V
shell: bash
working-directory: _build
- name: Test CMake Consumer
if: matrix.build-shared == 'ON'
run: |
cmake . \
-DCMAKE_PREFIX_PATH=../../../_install \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
cmake --build . \
hodoulp marked this conversation as resolved.
Show resolved Hide resolved
--config ${{ matrix.build-type }}
export PATH=../../../_install/bin:$PATH
./${{ matrix.build-type }}/consumer
shell: bash
working-directory: _build/tests/cmake-consumer-dist
12 changes: 12 additions & 0 deletions include/OpenColorIO/OpenColorIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ namespace OCIO_NAMESPACE
///////////////////////////////////////////////////////////////////////////
// Exceptions

// Silence warning C4275 under Visual Studio:
// Exceptions derive from std::runtime_error but STL classes are not exportable.
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 4275 )
#endif

/**
* \brief An exception class to throw for errors detected at runtime.
*
Expand Down Expand Up @@ -99,6 +106,11 @@ class OCIOEXPORT ExceptionMissingFile : public Exception
~ExceptionMissingFile();
};

// Restore default warning behaviour for Visual Studio.
#ifdef _MSC_VER
#pragma warning( pop )
#endif

///////////////////////////////////////////////////////////////////////////
// Global
// ******
Expand Down
3 changes: 1 addition & 2 deletions share/cmake/utils/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ if(USE_MSVC)

set(PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} /DUSE_MSVC")

# /wd4275 Exceptions derive from std::runtime_error but STL classes are not exportable.
# /we4062 Enables warning in switch when an enumeration value is not explicitly handled.
set(PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} /EHsc /wd4275 /DWIN32 /we4062")
set(PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} /EHsc /DWIN32 /we4062")

if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 17)
# Inheriting from std::iterator is deprecated starting with C++17 and Yaml 0.6.3 does that.
Expand Down
10 changes: 8 additions & 2 deletions src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,18 @@ if(NOT WIN32)
configure_file(res/OpenColorIO.pc.in ${CMAKE_CURRENT_BINARY_DIR}/OpenColorIO.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenColorIO.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()

add_library(OpenColorIO ${SOURCES})

# Require at least a C++11 compatible compiler for consumer projects.
target_compile_features(OpenColorIO
PUBLIC cxx_std_11
michdolan marked this conversation as resolved.
Show resolved Hide resolved
)

if(BUILD_SHARED_LIBS AND WIN32)
# Impose a versioned name on Windows to avoid binary name clashes.
# Impose a versioned name on Windows to avoid binary name clashes.
set(OCIO_LIBNAME_SUFFIX
${OCIO_LIBNAME_SUFFIX}_${OpenColorIO_VERSION_MAJOR}_${OpenColorIO_VERSION_MINOR}
${OCIO_LIBNAME_SUFFIX}_${OpenColorIO_VERSION_MAJOR}_${OpenColorIO_VERSION_MINOR}
)

# Create the version.rc file for the Windows DLL.
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if(OCIO_BUILD_TESTS)
add_subdirectory(testutils)
add_subdirectory(utils)
add_subdirectory(cpu)
add_subdirectory(cmake-consumer)
endif()

if(OCIO_BUILD_GPU_TESTS)
Expand Down
9 changes: 9 additions & 0 deletions tests/cmake-consumer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.

set(TEST_DEST_DIR "${CMAKE_BINARY_DIR}/tests/cmake-consumer-dist")

file(MAKE_DIRECTORY ${TEST_DEST_DIR})

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in ${TEST_DEST_DIR}/CMakeLists.txt COPYONLY)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp DESTINATION ${TEST_DEST_DIR})
28 changes: 28 additions & 0 deletions tests/cmake-consumer/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.

# Check the OCIO CMake config find module

cmake_minimum_required(VERSION 3.12)
project(consumer LANGUAGES CXX)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

message(STATUS "Building ${PROJECT_NAME} - ${CMAKE_BUILD_TYPE}")

# Make sure we have dependencies we need
find_package(OpenColorIO CONFIG REQUIRED)

add_executable(consumer consumer.cpp)

set_target_properties(consumer
PROPERTIES
COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS}"
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)

target_link_libraries(consumer PRIVATE OpenColorIO::OpenColorIO)
19 changes: 19 additions & 0 deletions tests/cmake-consumer/consumer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenColorIO Project.


// Check that OCIO library can be consumed by a cmake build

#include <cassert>

#include <OpenColorIO/OpenColorIO.h>

namespace OCIO = OCIO_NAMESPACE;


int main(int argc, char** argv)
{
auto reg = OCIO::BuiltinTransformRegistry::Get();
assert(reg->getNumBuiltins() > 0);
return 0;
}