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

Adsk contrib - Fix issues when building OCIO with MS Visual Studio 2022 #1647

3 changes: 2 additions & 1 deletion share/cmake/modules/FindExtPackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ if(OCIO_BUILD_PYTHON OR OCIO_BUILD_DOCS)
if(OCIO_BUILD_PYTHON)
# pybind11
# https://github.com/pybind/pybind11
find_package(pybind11 2.6.1 REQUIRED)
# pybind11 2.9 fixes issues with MS Visual Studio 2022 (Debug).
find_package(pybind11 2.9.2 REQUIRED)
endif()
endif()

Expand Down
30 changes: 30 additions & 0 deletions share/cmake/utils/CheckSupportGL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Define variables around the GL support.

include(PackageUtils)
include(SelectLibraryConfigurations)

if((OCIO_BUILD_TESTS AND OCIO_BUILD_GPU_TESTS) OR OCIO_BUILD_APPS)
set(OCIO_GL_ENABLED ON)
Expand Down Expand Up @@ -35,6 +36,35 @@ if((OCIO_BUILD_TESTS AND OCIO_BUILD_GPU_TESTS) OR OCIO_BUILD_APPS)
set(GLEW_LIBRARIES GLEW::GLEW)
endif()
endif()

# Cmake has a bug with FindGLEW. It fails to defined GLEW_INCLUDE_DIRS in some situation.
remia marked this conversation as resolved.
Show resolved Hide resolved
# See https://gitlab.kitware.com/cmake/cmake/-/issues/19662
# See a closed duplicate of 19662: https://gitlab.kitware.com/cmake/cmake/-/issues/20699
# Ported from vcpkg Glew package - https://github.com/microsoft/vcpkg/blob/master/ports/glew/vcpkg-cmake-wrapper.cmake
# The following code make sure that GLEW_INCLUDE_DIRS is set correctly.
if(GLEW_FOUND AND TARGET GLEW::GLEW AND NOT DEFINED GLEW_INCLUDE_DIRS)
get_target_property(GLEW_INCLUDE_DIRS GLEW::GLEW INTERFACE_INCLUDE_DIRECTORIES)
set(GLEW_INCLUDE_DIR ${GLEW_INCLUDE_DIRS})
get_target_property(_GLEW_DEFS GLEW::GLEW INTERFACE_COMPILE_DEFINITIONS)
if("${_GLEW_DEFS}" MATCHES "GLEW_STATIC")
get_target_property(GLEW_LIBRARY_DEBUG GLEW::GLEW IMPORTED_LOCATION_DEBUG)
get_target_property(GLEW_LIBRARY_RELEASE GLEW::GLEW IMPORTED_LOCATION_RELEASE)
else()
get_target_property(GLEW_LIBRARY_DEBUG GLEW::GLEW IMPORTED_IMPLIB_DEBUG)
get_target_property(GLEW_LIBRARY_RELEASE GLEW::GLEW IMPORTED_IMPLIB_RELEASE)
endif()
get_target_property(_GLEW_LINK_INTERFACE GLEW::GLEW IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE) # same for debug and release
list(APPEND GLEW_LIBRARIES ${_GLEW_LINK_INTERFACE})
list(APPEND GLEW_LIBRARY ${_GLEW_LINK_INTERFACE})
remia marked this conversation as resolved.
Show resolved Hide resolved
select_library_configurations(GLEW)
if("${_GLEW_DEFS}" MATCHES "GLEW_STATIC")
set(GLEW_STATIC_LIBRARIES ${GLEW_LIBRARIES})
else()
set(GLEW_SHARED_LIBRARIES ${GLEW_LIBRARIES})
endif()
unset(_GLEW_DEFS)
unset(_GLEW_LINK_INTERFACE)
endif()
endif()

find_package(GLUT)
Expand Down
7 changes: 7 additions & 0 deletions src/apps/ocioconvert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ add_executable(ocioconvert ${SOURCES})
set_target_properties(ocioconvert PROPERTIES
COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS}")

if (USE_MSVC)
# Temporary until fixed in OpenImageIO: Mute some warnings from OpenImageIO farmhash.h
# C4267 (level 3) 'var' : conversion from 'size_t' to 'type', possible loss of data
# C4244 (level 3 & 4) 'conversion' conversion from 'type1' to 'type2', possible loss of data
target_compile_options(ocioconvert PRIVATE /wd4267 /wd4244)
endif()

target_link_libraries(ocioconvert
PRIVATE
apputils
Expand Down
7 changes: 7 additions & 0 deletions src/apps/ociodisplay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ endif()
set_target_properties(ociodisplay PROPERTIES
COMPILE_FLAGS "${CUSTOM_COMPILE_FLAGS}")

if (USE_MSVC)
# Temporary until fixed in OpenImageIO: Mute some warnings from OpenImageIO farmhash.h
# C4267 (level 3) 'var' : conversion from 'size_t' to 'type', possible loss of data
# C4244 (level 3 & 4) 'conversion' conversion from 'type1' to 'type2', possible loss of data
target_compile_options(ociodisplay PRIVATE /wd4267 /wd4244)
endif()

target_include_directories(ociodisplay
SYSTEM
PRIVATE
Expand Down
7 changes: 7 additions & 0 deletions src/apps/ociolutimage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ add_executable(ociolutimage ${SOURCES})
set_target_properties(ociolutimage PROPERTIES
COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS}")

if (USE_MSVC)
# Temporary until fixed in OpenImageIO: Mute some warnings from OpenImageIO farmhash.h
# C4267 (level 3) 'var' : conversion from 'size_t' to 'type', possible loss of data
# C4244 (level 3 & 4) 'conversion' conversion from 'type1' to 'type2', possible loss of data
target_compile_options(ociolutimage PRIVATE /wd4267 /wd4244)
endif()

target_link_libraries(ociolutimage
PRIVATE
apputils
Expand Down
7 changes: 7 additions & 0 deletions src/libutils/oiiohelpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ set_target_properties(oiiohelpers PROPERTIES
COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS}"
)

if (USE_MSVC)
# Temporary until fixed in OpenImageIO: Mute some warnings from OpenImageIO farmhash.h
# C4267 (level 3) 'var' : conversion from 'size_t' to 'type', possible loss of data
# C4244 (level 3 & 4) 'conversion' conversion from 'type1' to 'type2', possible loss of data
target_compile_options(oiiohelpers PRIVATE /wd4267 /wd4244)
endif()

target_include_directories(oiiohelpers
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
Expand Down