Merge branch 'master' into blender2.8
[blender.git] / build_files / cmake / Modules / FindOpenSubdiv.cmake
1 # - Find OpenSubdiv library
2 # Find the native OpenSubdiv includes and library
3 # This module defines
4 #  OPENSUBDIV_INCLUDE_DIRS, where to find OpenSubdiv headers, Set when
5 #                           OPENSUBDIV_INCLUDE_DIR is found.
6 #  OPENSUBDIV_LIBRARIES, libraries to link against to use OpenSubdiv.
7 #  OPENSUBDIV_ROOT_DIR, the base directory to search for OpenSubdiv.
8 #                        This can also be an environment variable.
9 #  OPENSUBDIV_FOUND, if false, do not try to use OpenSubdiv.
10 #
11 # also defined, but not for general use are
12 #  OPENSUBDIV_LIBRARY, where to find the OpenSubdiv library.
13
14 #=============================================================================
15 # Copyright 2013 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
25 # If OPENSUBDIV_ROOT_DIR was defined in the environment, use it.
26 IF(NOT OPENSUBDIV_ROOT_DIR AND NOT $ENV{OPENSUBDIV_ROOT_DIR} STREQUAL "")
27   SET(OPENSUBDIV_ROOT_DIR $ENV{OPENSUBDIV_ROOT_DIR})
28 ENDIF()
29
30 SET(_opensubdiv_FIND_COMPONENTS
31   osdGPU
32   osdCPU
33 )
34
35 SET(_opensubdiv_SEARCH_DIRS
36   ${OPENSUBDIV_ROOT_DIR}
37   /usr/local
38   /sw # Fink
39   /opt/local # DarwinPorts
40   /opt/lib/opensubdiv
41   /opt/lib/osd # install_deps.sh
42 )
43
44 FIND_PATH(OPENSUBDIV_INCLUDE_DIR
45   NAMES
46     opensubdiv/osd/mesh.h
47   HINTS
48     ${_opensubdiv_SEARCH_DIRS}
49   PATH_SUFFIXES
50     include
51 )
52
53 SET(_opensubdiv_LIBRARIES)
54 FOREACH(COMPONENT ${_opensubdiv_FIND_COMPONENTS})
55   STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
56
57   FIND_LIBRARY(OPENSUBDIV_${UPPERCOMPONENT}_LIBRARY
58     NAMES
59       ${COMPONENT}
60     HINTS
61       ${_opensubdiv_SEARCH_DIRS}
62     PATH_SUFFIXES
63       lib64 lib
64     )
65   LIST(APPEND _opensubdiv_LIBRARIES "${OPENSUBDIV_${UPPERCOMPONENT}_LIBRARY}")
66 ENDFOREACH()
67
68 MACRO(OPENSUBDIV_CHECK_CONTROLLER
69       controller_include_file
70       variable_name)
71   IF(EXISTS "${OPENSUBDIV_INCLUDE_DIR}/opensubdiv/osd/${controller_include_file}")
72     SET(${variable_name} TRUE)
73   ELSE()
74     SET(${variable_name} FALSE)
75   ENDIF()
76 ENDMACRO()
77
78
79 # handle the QUIETLY and REQUIRED arguments and set OPENSUBDIV_FOUND to TRUE if
80 # all listed variables are TRUE
81 INCLUDE(FindPackageHandleStandardArgs)
82 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSubdiv DEFAULT_MSG
83     _opensubdiv_LIBRARIES OPENSUBDIV_INCLUDE_DIR)
84
85 IF(OPENSUBDIV_FOUND)
86   SET(OPENSUBDIV_LIBRARIES ${_opensubdiv_LIBRARIES})
87   SET(OPENSUBDIV_INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR})
88
89   # Find available compute controllers.
90
91   FIND_PACKAGE(OpenMP)
92   IF(OPENMP_FOUND)
93     SET(OPENSUBDIV_HAS_OPENMP TRUE)
94   ELSE()
95     SET(OPENSUBDIV_HAS_OPENMP FALSE)
96   ENDIF()
97
98   OPENSUBDIV_CHECK_CONTROLLER("tbbEvaluator.h" OPENSUBDIV_HAS_TBB)
99   OPENSUBDIV_CHECK_CONTROLLER("clEvaluator.h" OPENSUBDIV_HAS_OPENCL)
100   OPENSUBDIV_CHECK_CONTROLLER("cudaEvaluator.h" OPENSUBDIV_HAS_CUDA)
101   OPENSUBDIV_CHECK_CONTROLLER("glXFBEvaluator.h" OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK)
102   OPENSUBDIV_CHECK_CONTROLLER("glComputeEvaluator.h" OPENSUBDIV_HAS_GLSL_COMPUTE)
103 ENDIF(OPENSUBDIV_FOUND)
104
105 MARK_AS_ADVANCED(
106   OPENSUBDIV_INCLUDE_DIR
107 )
108 FOREACH(COMPONENT ${_opensubdiv_FIND_COMPONENTS})
109   STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
110   MARK_AS_ADVANCED(OPENSUBDIV_${UPPERCOMPONENT}_LIBRARY)
111 ENDFOREACH()