diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ad6d3c8a..961540804 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 000000000..2b4798097 --- /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/OpenColorIO/CMakeLists.txt b/src/OpenColorIO/CMakeLists.txt index f56b6219c..ff20c1a6c 100755 --- a/src/OpenColorIO/CMakeLists.txt +++ b/src/OpenColorIO/CMakeLists.txt @@ -235,6 +235,9 @@ configure_file(CPUInfoConfig.h.in CPUInfoConfig.h) add_library(OpenColorIO ${SOURCES}) +# Group the source files to replicate the source tree structure in the IDEs. +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${SOURCES}) + # Require at least a C++11 compatible compiler for consumer projects. target_compile_features(OpenColorIO PUBLIC cxx_std_11 diff --git a/src/apps/ocioarchive/CMakeLists.txt b/src/apps/ocioarchive/CMakeLists.txt index 599d706f0..b8af2808f 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 3d6e586b9..09cd76b13 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 024139546..50955bc0d 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 431b1b79f..f4662f1b0 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 7b7abddcf..117258811 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) diff --git a/src/apps/ociodisplay/CMakeLists.txt b/src/apps/ociodisplay/CMakeLists.txt index 14b53cfda..9261f1cab 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 a470d2f6e..07bdad930 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 fc3bd8e9f..42028303b 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 5a2a5bbe1..d78609112 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) diff --git a/src/apps/ocioperf/CMakeLists.txt b/src/apps/ocioperf/CMakeLists.txt index c056080bc..541439e72 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) diff --git a/src/apps/ociowrite/CMakeLists.txt b/src/apps/ociowrite/CMakeLists.txt index bd77acfea..ebaf60dc9 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) diff --git a/tests/cpu/CMakeLists.txt b/tests/cpu/CMakeLists.txt index 12fd06c1b..2dab084f3 100755 --- a/tests/cpu/CMakeLists.txt +++ b/tests/cpu/CMakeLists.txt @@ -19,10 +19,28 @@ macro(add_ocio_test_variant NAME BINARY) endif() endmacro() -function(add_ocio_test NAME SOURCES PRIVATE_INCLUDES) +function(prepend var prefix) + set(new "") + foreach(f ${ARGN}) + list(APPEND new "${prefix}${f}") + endforeach(f) + set(${var} "${new}" PARENT_SCOPE) +endfunction(prepend) + +function(add_ocio_test NAME SOURCES TESTS PRIVATE_INCLUDES) set(TEST_BINARY "test_${NAME}_exec") set(TEST_NAME "test_${NAME}") - add_executable(${TEST_BINARY} ${SOURCES}) + + prepend(SOURCES "${PROJECT_SOURCE_DIR}/src/OpenColorIO/" ${SOURCES}) + set(SOURCES_ALL ${SOURCES}) + list(APPEND SOURCES_ALL ${TESTS}) + + add_executable(${TEST_BINARY} ${SOURCES_ALL}) + + # Group the source files to replicate the source tree structure in the IDEs. + source_group(TREE "${PROJECT_SOURCE_DIR}/src/OpenColorIO/" PREFIX "OpenColorIO Library" FILES ${SOURCES}) + source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Tests" FILES ${TESTS}) + target_compile_definitions(${TEST_BINARY} PRIVATE OpenColorIO_SKIP_IMPORTS @@ -331,18 +349,6 @@ set(TESTS ViewTransform_tests.cpp ) -function(prepend var prefix) - set(new "") - foreach(f ${ARGN}) - list(APPEND new "${prefix}${f}") - endforeach(f) - set(${var} "${new}" PARENT_SCOPE) -endfunction(prepend) - -prepend(SOURCES "${PROJECT_SOURCE_DIR}/src/OpenColorIO/" ${SOURCES}) - -list(APPEND SOURCES ${TESTS}) - if(OCIO_USE_SIMD AND (OCIO_ARCH_X86 OR OCIO_USE_SSE2NEON)) # Note that these files are gated by preprocessors to remove them based on the OCIO_USE_* vars. set_property(SOURCE "${CMAKE_SOURCE_DIR}/src/OpenColorIO/ops/lut1d/Lut1DOpCPU_SSE2.cpp" APPEND PROPERTY COMPILE_OPTIONS ${OCIO_SSE2_ARGS}) @@ -359,4 +365,4 @@ if(OCIO_USE_SIMD AND (OCIO_ARCH_X86 OR OCIO_USE_SSE2NEON)) set_property(SOURCE "AVX512_tests.cpp" APPEND PROPERTY COMPILE_OPTIONS ${OCIO_AVX512_ARGS}) endif() -add_ocio_test(cpu "${SOURCES}" TRUE) +add_ocio_test(cpu "${SOURCES}" "${TESTS}" TRUE) diff --git a/tests/gpu/CMakeLists.txt b/tests/gpu/CMakeLists.txt index 5f1c0379c..4344cbfa2 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}" + ) + # 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()