FindOpenShadingLanguage.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # - Find OpenShadingLanguage library
  2. # Find the native OpenShadingLanguage includes and library
  3. # This module defines
  4. # OSL_INCLUDE_DIRS, where to find OSL headers, Set when
  5. # OSL_INCLUDE_DIR is found.
  6. # OSL_LIBRARIES, libraries to link against to use OSL.
  7. # OSL_ROOT_DIR, the base directory to search for OSL.
  8. # This can also be an environment variable.
  9. # OSL_COMPILER, full path to OSL script compiler.
  10. # OSL_FOUND, if false, do not try to use OSL.
  11. # OSL_LIBRARY_VERSION_MAJOR, OSL_LIBRARY_VERSION_MINOR, the major
  12. # and minor versions of OSL library if found.
  13. #
  14. #=============================================================================
  15. # Copyright 2014 Blender Foundation.
  16. #
  17. # Distributed under the OSI-approved BSD License (the "License");
  18. # see accompanying file Copyright.txt for details.
  19. #
  20. # This software is distributed WITHOUT ANY WARRANTY; without even the
  21. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. # See the License for more information.
  23. #=============================================================================
  24. # If OSL_ROOT_DIR was defined in the environment, use it.
  25. IF(NOT OSL_ROOT_DIR AND NOT $ENV{OSL_ROOT_DIR} STREQUAL "")
  26. SET(OSL_ROOT_DIR $ENV{OSL_ROOT_DIR})
  27. ENDIF()
  28. SET(_osl_FIND_COMPONENTS
  29. oslcomp
  30. oslexec
  31. oslquery
  32. )
  33. SET(_osl_SEARCH_DIRS
  34. ${OSL_ROOT_DIR}
  35. /usr/local
  36. /sw # Fink
  37. /opt/local # DarwinPorts
  38. /opt/csw # Blastwave
  39. /opt/lib/osl
  40. )
  41. FIND_PATH(OSL_INCLUDE_DIR
  42. NAMES
  43. OSL/oslversion.h
  44. HINTS
  45. ${_osl_SEARCH_DIRS}
  46. PATH_SUFFIXES
  47. include
  48. )
  49. SET(_osl_LIBRARIES)
  50. FOREACH(COMPONENT ${_osl_FIND_COMPONENTS})
  51. STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
  52. FIND_LIBRARY(OSL_${UPPERCOMPONENT}_LIBRARY
  53. NAMES
  54. ${COMPONENT}
  55. HINTS
  56. ${_osl_SEARCH_DIRS}
  57. PATH_SUFFIXES
  58. lib64 lib
  59. )
  60. LIST(APPEND _osl_LIBRARIES "${OSL_${UPPERCOMPONENT}_LIBRARY}")
  61. ENDFOREACH()
  62. FIND_PROGRAM(OSL_COMPILER oslc
  63. HINTS ${_osl_SEARCH_DIRS}
  64. PATH_SUFFIXES bin)
  65. # handle the QUIETLY and REQUIRED arguments and set OSL_FOUND to TRUE if
  66. # all listed variables are TRUE
  67. INCLUDE(FindPackageHandleStandardArgs)
  68. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OSL DEFAULT_MSG _osl_LIBRARIES OSL_INCLUDE_DIR OSL_COMPILER)
  69. IF(OSL_FOUND)
  70. SET(OSL_LIBRARIES ${_osl_LIBRARIES})
  71. SET(OSL_INCLUDE_DIRS ${OSL_INCLUDE_DIR})
  72. FILE(STRINGS "${OSL_INCLUDE_DIR}/OSL/oslversion.h" OSL_LIBRARY_VERSION_MAJOR
  73. REGEX "^[ \t]*#define[ \t]+OSL_LIBRARY_VERSION_MAJOR[ \t]+[0-9]+.*$")
  74. FILE(STRINGS "${OSL_INCLUDE_DIR}/OSL/oslversion.h" OSL_LIBRARY_VERSION_MINOR
  75. REGEX "^[ \t]*#define[ \t]+OSL_LIBRARY_VERSION_MINOR[ \t]+[0-9]+.*$")
  76. STRING(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_MAJOR[ \t]+([.0-9]+).*"
  77. "\\1" OSL_LIBRARY_VERSION_MAJOR ${OSL_LIBRARY_VERSION_MAJOR})
  78. STRING(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_MINOR[ \t]+([.0-9]+).*"
  79. "\\1" OSL_LIBRARY_VERSION_MINOR ${OSL_LIBRARY_VERSION_MINOR})
  80. ENDIF(OSL_FOUND)
  81. MARK_AS_ADVANCED(
  82. OSL_INCLUDE_DIR
  83. )
  84. FOREACH(COMPONENT ${_osl_FIND_COMPONENTS})
  85. STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
  86. MARK_AS_ADVANCED(OSL_${UPPERCOMPONENT}_LIBRARY)
  87. ENDFOREACH()