diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ad6d3c8a7..9615408048 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -349,6 +349,11 @@ endif() include(CompilerFlags) +############################################################################### +# Include utility functions for setting debugging environments + +include(DebuggerEnvironment) + ############################################################################### # External linking options diff --git a/share/cmake/utils/DebuggerEnvironment.cmake b/share/cmake/utils/DebuggerEnvironment.cmake new file mode 100644 index 0000000000..2b47980976 --- /dev/null +++ b/share/cmake/utils/DebuggerEnvironment.cmake @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + + +############################################################################### +# Define a function to set debugger environment so that the run time +# dependencies can be located by the debugger. + +function(set_debugger_env target_name) + cmake_parse_arguments(ARG "NEEDS_GL" "" "" ${ARGN}) + + if(NOT TARGET ${target_name}) + message(FATAL_ERROR "set_debugger_env: '${target_name}' is not a CMake target") + endif() + + # Set the Paths for Visual Studio IDE Debugger. + if(MSVC) + if(OCIO_GL_ENABLED AND ARG_NEEDS_GL) + # Add folders for glut and glew DLLs. + set(extra_dirs "${GLUT_INCLUDE_DIR}/../bin;${GLEW_INCLUDE_DIRS}/../bin") + endif() + + set_property(TARGET ${target_name} PROPERTY + VS_DEBUGGER_ENVIRONMENT "PATH=$,;>;${extra_dirs};%PATH%" + ) + endif() +endfunction() \ No newline at end of file diff --git a/src/apps/ocioarchive/CMakeLists.txt b/src/apps/ocioarchive/CMakeLists.txt index 599d706f09..b8af2808fb 100644 --- a/src/apps/ocioarchive/CMakeLists.txt +++ b/src/apps/ocioarchive/CMakeLists.txt @@ -30,3 +30,7 @@ ocio_strip_binary(ocioarchive) install(TARGETS ocioarchive RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ocioarchive) diff --git a/src/apps/ociobakelut/CMakeLists.txt b/src/apps/ociobakelut/CMakeLists.txt index 3d6e586b96..09cd76b137 100755 --- a/src/apps/ociobakelut/CMakeLists.txt +++ b/src/apps/ociobakelut/CMakeLists.txt @@ -39,3 +39,7 @@ ocio_strip_binary(ociobakelut) install(TARGETS ociobakelut RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ociobakelut) diff --git a/src/apps/ociocheck/CMakeLists.txt b/src/apps/ociocheck/CMakeLists.txt index 024139546d..50955bc0d7 100755 --- a/src/apps/ociocheck/CMakeLists.txt +++ b/src/apps/ociocheck/CMakeLists.txt @@ -28,3 +28,7 @@ ocio_strip_binary(ociocheck) install(TARGETS ociocheck RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ociocheck) diff --git a/src/apps/ociochecklut/CMakeLists.txt b/src/apps/ociochecklut/CMakeLists.txt index 431b1b79fb..f4662f1b02 100644 --- a/src/apps/ociochecklut/CMakeLists.txt +++ b/src/apps/ociochecklut/CMakeLists.txt @@ -36,3 +36,7 @@ ocio_strip_binary(ociochecklut) install(TARGETS ociochecklut RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ociochecklut NEEDS_GL) \ No newline at end of file diff --git a/src/apps/ocioconvert/CMakeLists.txt b/src/apps/ocioconvert/CMakeLists.txt index 7b7abddcf2..fb9c295058 100755 --- a/src/apps/ocioconvert/CMakeLists.txt +++ b/src/apps/ocioconvert/CMakeLists.txt @@ -40,3 +40,7 @@ ocio_strip_binary(ocioconvert) install(TARGETS ocioconvert RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ocioconvert NEEDS_GL) \ No newline at end of file diff --git a/src/apps/ociodisplay/CMakeLists.txt b/src/apps/ociodisplay/CMakeLists.txt index 14b53cfda3..9261f1cab4 100755 --- a/src/apps/ociodisplay/CMakeLists.txt +++ b/src/apps/ociodisplay/CMakeLists.txt @@ -53,3 +53,7 @@ ocio_strip_binary(ociodisplay) install(TARGETS ociodisplay RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ociodisplay NEEDS_GL) diff --git a/src/apps/ociolutimage/CMakeLists.txt b/src/apps/ociolutimage/CMakeLists.txt index a470d2f6eb..07bdad9307 100755 --- a/src/apps/ociolutimage/CMakeLists.txt +++ b/src/apps/ociolutimage/CMakeLists.txt @@ -33,3 +33,7 @@ ocio_strip_binary(ociolutimage) install(TARGETS ociolutimage RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ociolutimage) diff --git a/src/apps/ociomakeclf/CMakeLists.txt b/src/apps/ociomakeclf/CMakeLists.txt index fc3bd8e9f1..42028303ba 100644 --- a/src/apps/ociomakeclf/CMakeLists.txt +++ b/src/apps/ociomakeclf/CMakeLists.txt @@ -29,3 +29,7 @@ ocio_strip_binary(ociomakeclf) install(TARGETS ociomakeclf RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ociomakeclf) diff --git a/src/apps/ociomergeconfigs/CMakeLists.txt b/src/apps/ociomergeconfigs/CMakeLists.txt index 5a2a5bbe12..f89f2a34ea 100644 --- a/src/apps/ociomergeconfigs/CMakeLists.txt +++ b/src/apps/ociomergeconfigs/CMakeLists.txt @@ -30,3 +30,7 @@ ocio_strip_binary(ociomergeconfigs) install(TARGETS ociomergeconfigs RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ociomergeconfigs) \ No newline at end of file diff --git a/src/apps/ocioperf/CMakeLists.txt b/src/apps/ocioperf/CMakeLists.txt index c056080bc5..010374f148 100644 --- a/src/apps/ocioperf/CMakeLists.txt +++ b/src/apps/ocioperf/CMakeLists.txt @@ -25,3 +25,7 @@ ocio_strip_binary(ocioperf) install(TARGETS ocioperf RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ocioperf) \ No newline at end of file diff --git a/src/apps/ociowrite/CMakeLists.txt b/src/apps/ociowrite/CMakeLists.txt index bd77acfea6..54e48b103d 100644 --- a/src/apps/ociowrite/CMakeLists.txt +++ b/src/apps/ociowrite/CMakeLists.txt @@ -24,3 +24,7 @@ ocio_strip_binary(ociowrite) install(TARGETS ociowrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + +# Set the debugger environment so that the executable can be launched +# directly within IDE (e.g. Visual Studio). +set_debugger_env(ociowrite) \ No newline at end of file diff --git a/tests/gpu/CMakeLists.txt b/tests/gpu/CMakeLists.txt index 5f1c0379cf..55dbb3a881 100644 --- a/tests/gpu/CMakeLists.txt +++ b/tests/gpu/CMakeLists.txt @@ -48,16 +48,20 @@ endif() # Note: To avoid changing PATH from outside the cmake files. if(MSVC AND BUILD_SHARED_LIBS) + # Build time list of runtime dll dirs for the exe target. + set(dll_dirs_expr "$,;>") - if (MSVC_IDE) - # Note: By default Microsoft Visual Studio editor happens the build type to the build directory. - set(BUILD_TYPE ${CMAKE_BUILD_TYPE}) - endif() + # Add folders for glut and glew DLLs. + set(extra_dirs "${GLUT_INCLUDE_DIR}/../bin;${GLEW_INCLUDE_DIRS}/../bin") - set(NEW_PATH "${PROJECT_BINARY_DIR}/src/OpenColorIO/${BUILD_TYPE}") - set(NEW_PATH "${NEW_PATH}\\\;${GLUT_INCLUDE_DIR}/../bin") - set(NEW_PATH "${NEW_PATH}\\\;${GLEW_INCLUDE_DIRS}/../bin") - - set_tests_properties(test_gpu PROPERTIES ENVIRONMENT PATH=${NEW_PATH}) + # Tell CTest to use this PATH while launching test_gpu_exec + set_tests_properties(test_gpu PROPERTIES + ENVIRONMENT "PATH=${dll_dirs_expr};${extra_dirs};$ENV{PATH}" + ) + # Also set the debugger environment so that you can launch + # test_gpu_exec directly within Visual Studio. + set_property(TARGET test_gpu_exec PROPERTY + VS_DEBUGGER_ENVIRONMENT "PATH=${dll_dirs_expr};${extra_dirs};%PATH%" + ) endif()