FindCg.cmake 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # Filename: FindCg.cmake
  2. # Author: kestred (8 Dec, 2013)
  3. #
  4. # Usage:
  5. # find_package(Cg [REQUIRED] [QUIET])
  6. #
  7. # Once done this will define:
  8. # CG_FOUND - system has NvidiaCg
  9. # CG_INCLUDE_DIR - the NvidiaCg include directory
  10. # CG_INCLUDE_DIRS - directories for all NvidiaCg components
  11. # CG_LIBRARY_DIR - the NvidiaCg library directory
  12. # CG_LIBRARY - the path to the library binary
  13. # CG_LIBRARIES - the paths to the Cg library and each library below.
  14. #
  15. # CGGL_FOUND - system has CgGL
  16. # CGGL_INCLUDE_DIR - the CgGL include directory
  17. # CGGL_LIBRARY_DIR - the CgGL library directory
  18. # CGGL_LIBRARY - the path to the library binary
  19. #
  20. ### Define macros to find each sublibrary ###
  21. # Find Cg for OpenGL
  22. macro(find_cggl)
  23. if(Cg_FIND_QUIETLY)
  24. set(CgGL_FIND_QUIETLY TRUE)
  25. endif()
  26. if(NOT CGGL_LIBRARY_DIR OR NOT CGGL_INCLUDE_DIR)
  27. # Find the include directory
  28. find_path(CGGL_INCLUDE_DIR
  29. NAMES "cgGL.h"
  30. PATHS "C:/Program Files/Cg"
  31. "C:/Program Files/NVIDIA Corporation/Cg/include"
  32. "/usr/include"
  33. "/usr/local/include"
  34. "/opt/Cg"
  35. "/opt/nvidia-cg-toolkit/include" # Gentoo
  36. PATH_SUFFIXES "" "Cg" "cg"
  37. DOC "The path to NvidiaCgGL's include directory."
  38. )
  39. # Find the library directory
  40. find_library(CGGL_LIBRARY
  41. NAMES "CgGL" "libCgGL"
  42. PATHS "C:/Program Files/Cg"
  43. "C:/Program Files/NVIDIA Corporation/Cg"
  44. "/usr"
  45. "/usr/lib/x86_64-linux-gnu"
  46. "/usr/local"
  47. "/opt/Cg"
  48. "/opt/nvidia-cg-toolkit" # Gentoo
  49. PATH_SUFFIXES "" "lib" "lib32" "lib64"
  50. DOC "The filepath to NvidiaCgGL's libary binary."
  51. )
  52. get_filename_component(CGGL_LIBRARY_DIR "${CGGL_LIBRARY}" PATH)
  53. set(CGGL_LIBRARY_DIR "${CGGL_LIBRARY_DIR}" CACHE PATH "The path to the CgGL library directory.") # Library path
  54. mark_as_advanced(CGGL_INCLUDE_DIR)
  55. mark_as_advanced(CGGL_LIBRARY_DIR)
  56. mark_as_advanced(CGGL_LIBRARY)
  57. endif()
  58. find_package_handle_standard_args(CgGL DEFAULT_MSG CGGL_LIBRARY CGGL_INCLUDE_DIR CGGL_LIBRARY_DIR)
  59. endmacro()
  60. # Find Cg for DirectX 8
  61. macro(find_cgdx8)
  62. # TODO: Implement
  63. endmacro()
  64. # Find Cg for DirectX 9
  65. macro(find_cgdx9)
  66. # TODO: Implement
  67. endmacro()
  68. # Find Cg for DirectX 10
  69. macro(find_cgdx10)
  70. # TODO: Implement
  71. endmacro()
  72. # Find base Nvidia Cg
  73. if(NOT CG_LIBRARY_DIR OR NOT CG_INCLUDE_DIRS)
  74. # On OSX default to using the framework version of Cg.
  75. if(APPLE)
  76. include(${CMAKE_ROOT}/Modules/CMakeFindFrameworks.cmake)
  77. set(CG_INCLUDES)
  78. cmake_find_frameworks(Cg)
  79. if(Cg_FRAMEWORKS)
  80. foreach(dir ${Cg_FRAMEWORKS})
  81. set(CG_INCLUDES ${CG_INCLUDES} ${dir}/Headers ${dir}/PrivateHeaders)
  82. endforeach(dir)
  83. unset(Cg_FRAMEWORKS)
  84. # Find the include dir
  85. find_path(CG_INCLUDE_DIR
  86. NAMES "cg.h"
  87. PATHS ${CG_INCLUDES}
  88. DOC "The path to NvidiaCg's include directory."
  89. )
  90. unset(CG_INCLUDES)
  91. # Set the library dir (TODO: Check the correctness on Mac OS X)
  92. set(CG_LIBRARY_DIR "/Library/Frameworks/Cg.framework" CACHE PATH "The path to NvidiaCg's library directory.")
  93. endif()
  94. else()
  95. # Find the include directory
  96. find_path(CG_INCLUDE_DIR
  97. NAMES "cg.h"
  98. PATHS "C:/Program Files/Cg"
  99. "C:/Program Files/NVIDIA Corporation/Cg/include"
  100. "/usr/include"
  101. "/usr/local/include"
  102. "/opt/Cg"
  103. "/opt/nvidia-cg-toolkit/include" # Gentoo
  104. PATH_SUFFIXES "" "Cg" "cg"
  105. DOC "The path to NvidiaCg's include directory."
  106. )
  107. # Find the library directory
  108. find_library(CG_LIBRARY
  109. NAMES "Cg" "libCg"
  110. PATHS "C:/Program Files/Cg"
  111. "C:/Program Files/NVIDIA Corporation/Cg"
  112. "/usr"
  113. "/usr/lib/x86_64-linux-gnu"
  114. "/usr/local"
  115. "/opt/Cg"
  116. "/opt/nvidia-cg-toolkit" # Gentoo
  117. PATH_SUFFIXES "" "lib" "lib32" "lib64"
  118. )
  119. get_filename_component(CG_LIBRARY_DIR "${CG_LIBRARY}" PATH)
  120. set(CG_LIBRARY_DIR "${CG_LIBRARY_DIR}" CACHE PATH "The path to NvidiaCG's library directory.") # Library path
  121. endif()
  122. string(REGEX REPLACE "/Cg$" "" CG_BASE_INCLUDE_DIR ${CG_INCLUDE_DIR})
  123. set(CG_INCLUDE_DIRS ${CG_BASE_INCLUDE_DIR} ${CG_INCLUDE_DIR})
  124. mark_as_advanced(CG_INCLUDE_DIRS)
  125. mark_as_advanced(CG_INCLUDE_DIR)
  126. mark_as_advanced(CG_LIBRARY_DIR)
  127. mark_as_advanced(CG_LIBRARY)
  128. endif()
  129. include(FindPackageHandleStandardArgs)
  130. find_package_handle_standard_args(Cg DEFAULT_MSG CG_LIBRARY CG_INCLUDE_DIRS CG_LIBRARY_DIR)
  131. if(CG_INCLUDE_DIR AND CG_LIBRARY_DIR)
  132. find_cggl()
  133. find_cgdx8()
  134. find_cgdx9()
  135. find_cgdx10()
  136. set(CG_LIBRARIES ${CG_LIBRARY} ${CGGL_LIBRARY}
  137. ${CGDX8_LIBRARY} ${CGDX9_LIBRARY} ${CGDX10_LIBRARY})
  138. mark_as_advanced(CG_LIBRARIES)
  139. endif()