PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/share/cmake/OCIOMacros.cmake

Relevant Search: With Applications for Solr and Elasticsearch

For more in depth reading about search, ranking and generally everything you could ever want to know about how lucene, elasticsearch or solr work under the hood I highly suggest this book. Easily one of the most interesting technical books I have read in a long time. If you are tasked with solving search relevance problems even if not in Solr or Elasticsearch it should be your first reference. Amazon Affiliate Link
http://github.com/imageworks/OpenColorIO
CMake | 339 lines | 286 code | 27 blank | 26 comment | 17 complexity | e9a2d28bbccdf6543a4f20c4dc1ed634 MD5 | raw file
  1MACRO(messageonce MSG)
  2    if(CMAKE_FIRST_RUN)
  3        message(STATUS ${MSG})
  4    endif()
  5ENDMACRO()
  6
  7MACRO(OCIOFindOpenGL)
  8    if(APPLE)
  9        INCLUDE_DIRECTORIES(/System/Library/Frameworks)
 10    endif()
 11
 12    # Find OpenGL
 13    find_package(OpenGL)
 14    if(OPENGL_FOUND)
 15        message(STATUS "Found OpenGL library ${OPENGL_LIBRARY}")
 16        message(STATUS "Found OpenGL includes ${OPENGL_INCLUDE_DIR}")
 17    else()
 18        message(STATUS "OpenGL not found")
 19    endif()
 20
 21    # Find GLUT
 22    find_package(GLUT)
 23    if(GLUT_FOUND)
 24        message(STATUS "Found GLUT library ${GLUT_LIBRARY}")
 25    else()
 26        message(STATUS "GLUT not found")
 27    endif()
 28
 29    # Find GLEW
 30    set(GLEW_VERSION 1.5.1)
 31    FIND_PATH(GLEW_INCLUDES GL/glew.h
 32        /usr/include
 33        /usr/local/include
 34        /sw/include
 35        /opt/local/include
 36        DOC "The directory where GL/glew.h resides")
 37    FIND_LIBRARY(GLEW_LIBRARIES
 38        NAMES GLEW glew
 39        /usr/lib64
 40        /usr/lib
 41        /usr/local/lib64
 42        /usr/local/lib
 43        /sw/lib
 44        /opt/local/lib
 45        PATHS
 46        DOC "The GLEW library")
 47    if(GLEW_INCLUDES AND GLEW_LIBRARIES)
 48        set(GLEW_FOUND TRUE)
 49        message(STATUS "Found GLEW library ${GLEW_LIBRARIES}")
 50        message(STATUS "Found GLEW includes ${GLEW_INCLUDES}")
 51    else()
 52        message(STATUS "GLEW not found")
 53        set(GLEW_FOUND FALSE)
 54    endif()
 55ENDMACRO()
 56
 57MACRO(OCIOFindOpenImageIO)
 58    if(OIIO_PATH)
 59        message(STATUS "OIIO path explicitly specified: ${OIIO_PATH}")
 60    endif()
 61    if(OIIO_INCLUDE_PATH)
 62        message(STATUS "OIIO INCLUDE_PATH explicitly specified: ${OIIO_INCLUDE_PATH}")
 63    endif()
 64    if(OIIO_LIBRARY_PATH)
 65        message(STATUS "OIIO LIBRARY_PATH explicitly specified: ${OIIO_LIBRARY_PATH}")
 66    endif()
 67    FIND_PATH( OIIO_INCLUDES OpenImageIO/version.h
 68        ${OIIO_INCLUDE_PATH}
 69        ${OIIO_PATH}/include/
 70        /usr/include
 71        /usr/local/include
 72        /sw/include
 73        /opt/local/include
 74        DOC "The directory where OpenImageIO/version.h resides")
 75    FIND_LIBRARY(OIIO_LIBRARIES
 76        NAMES OIIO OpenImageIO
 77        PATHS
 78        ${OIIO_LIBRARY_PATH}
 79        ${OIIO_PATH}/lib/
 80        /usr/lib64
 81        /usr/lib
 82        /usr/local/lib64
 83        /usr/local/lib
 84        /sw/lib
 85        /opt/local/lib
 86        DOC "The OIIO library")
 87
 88    if(OIIO_INCLUDES AND OIIO_LIBRARIES)
 89        set(OIIO_FOUND TRUE)
 90        message(STATUS "Found OIIO library ${OIIO_LIBRARIES}")
 91        message(STATUS "Found OIIO includes ${OIIO_INCLUDES}")
 92    else()
 93        set(OIIO_FOUND FALSE)
 94        message(STATUS "OIIO not found. Specify OIIO_PATH to locate it")
 95    endif()
 96ENDMACRO()
 97
 98MACRO(OCIOFindPython)
 99    # Set the default python runtime
100    if(NOT PYTHON)
101        set(PYHELP "path to Python executable (also used to find headers against which to compile Python bindings)")
102        set(PYTHON_HEADER Python.h)
103        set(PYTHON python CACHE FILEPATH ${PYHELP} FORCE)
104    endif(NOT PYTHON)
105    
106    if(CMAKE_FIRST_RUN)
107        message(STATUS "Setting python bin to: ${PYTHON}")
108    endif()
109
110    set(PYTHON_OK YES) # OK until something goes wrong
111
112    # Get Python version
113    execute_process(COMMAND ${PYTHON} -c "from distutils import sysconfig; print(sysconfig.get_python_version())"
114        OUTPUT_VARIABLE PYTHON_VERSION
115        RESULT_VARIABLE PYTHON_RETURNVALUE
116        OUTPUT_STRIP_TRAILING_WHITESPACE
117    )
118
119    if(${PYTHON_RETURNVALUE} EQUAL 0)
120        # Everything is fine
121    else()
122        # TODO: These error strings clobber previous values
123        set(PYTHON_ERR "${PYTHON} returned ${PYTHON_RETURNVALUE} trying to determine version number.")
124        set(PYTHON_OK NO)
125    endif()
126
127
128    # Determine Python UCS version
129    execute_process(COMMAND ${PYTHON} -c "import sys; print(sys.maxunicode > 65536 and 'ucs4' or 'ucs2')"
130        OUTPUT_VARIABLE PYTHON_UCS
131        RESULT_VARIABLE PYTHON_RETURNVALUE
132        OUTPUT_STRIP_TRAILING_WHITESPACE
133    )
134
135    if(${PYTHON_RETURNVALUE} EQUAL 0)
136        # Hurray
137    else()
138        set(PYTHON_OK NO)
139        set(PYTHON_ERR "${PYTHON} returned ${PYTHON_RETURNVALUE} trying to determine UCS version.")
140    endif()
141
142
143    # Locate headers
144    execute_process(COMMAND ${PYTHON} -c "from distutils import sysconfig; print(':'.join(set(sysconfig.get_config_var('INCLDIRSTOMAKE').split())))"
145        OUTPUT_VARIABLE PYTHON_INCLUDE_RAW
146        RESULT_VARIABLE PYTHON_RETURNVALUE
147        OUTPUT_STRIP_TRAILING_WHITESPACE
148    )
149
150    # Handle errors, and process include path
151    if(${PYTHON_RETURNVALUE} EQUAL 0)
152        file(TO_CMAKE_PATH "${PYTHON_INCLUDE_RAW}" PYTHON_INCLUDE)
153    else()
154        set(PYTHON_ERR "${PYTHON} returned ${PYTHON_RETURNVALUE} trying to determine header location.")
155        set(PYTHON_OK NO)
156    endif()
157
158
159    # Locate Python library
160    execute_process(COMMAND ${PYTHON} -c "from distutils import sysconfig; print(':'.join(set(sysconfig.get_config_var('LIBPL').split())))"
161        OUTPUT_VARIABLE PYTHON_LIBRARY_DIRS_RAW
162        RESULT_VARIABLE PYTHON_RETURNVALUE
163        OUTPUT_STRIP_TRAILING_WHITESPACE
164    )
165
166    # Handle errors, and process include path
167    if(${PYTHON_RETURNVALUE} EQUAL 0)
168        file(TO_CMAKE_PATH "${PYTHON_LIBRARY_DIRS_RAW}" PYTHON_LIBRARY_DIRS)
169
170        FIND_LIBRARY(PYTHON_LIBRARY
171            NAMES "python${PYTHON_VERSION}"
172            PATHS ${PYTHON_LIBRARY_DIRS}
173            NO_DEFAULT_PATH # Don't be "helpful" and randomly grab library from /usr/lib etc
174        )
175        message("Python library: ${PYTHON_LIBRARY}")
176    else()
177        set(PYTHON_ERR "${PYTHON} returned ${PYTHON_RETURNVALUE} trying to determine library path.")
178        set(PYTHON_OK NO)
179    endif()
180
181    # Construct variant path - a path that sufficiently identifies the
182    # ABI-compatbility of the built library. See Github issue #236
183    if(OCIO_PYGLUE_RESPECT_ABI)
184        # Respect Python major/minor version, and UCS version (unicode
185        # content system). E.g install into "lib/python2.6/ucs4/site-packages"
186        set(PYTHON_VARIANT_PATH "lib${LIB_SUFFIX}/python${PYTHON_VERSION}/${PYTHON_UCS}/site-packages")
187    else()
188        # Ignore UCS value and install into lib/python2.6/site-packages dir
189        set(PYTHON_VARIANT_PATH "lib${LIB_SUFFIX}/python${PYTHON_VERSION}/site-packages")
190    endif()
191
192ENDMACRO()
193
194MACRO(OCIOFindJava)
195    if(APPLE)
196      
197      SET(_JAVA_HINTS $ENV{JAVA_HOME}/bin)
198      SET(_JAVA_PATHS /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands)
199      
200      FIND_PROGRAM(Java_JAVA_EXECUTABLE
201        NAMES java
202        HINTS ${_JAVA_HINTS}
203        PATHS ${_JAVA_PATHS}
204      )
205      
206      IF(Java_JAVA_EXECUTABLE)
207          EXECUTE_PROCESS(COMMAND ${Java_JAVA_EXECUTABLE} -version
208            RESULT_VARIABLE res
209            OUTPUT_VARIABLE var
210            ERROR_VARIABLE var # sun-java output to stderr
211            OUTPUT_STRIP_TRAILING_WHITESPACE
212            ERROR_STRIP_TRAILING_WHITESPACE)
213          IF( res )
214            IF(${Java_FIND_REQUIRED})
215              MESSAGE( FATAL_ERROR "Error executing java -version" )
216            ELSE()
217              MESSAGE( STATUS "Warning, could not run java --version")
218            ENDIF()
219          ELSE()
220            # extract major/minor version and patch level from "java -version" output
221            # Tested on linux using 
222            # 1. Sun / Sun OEM
223            # 2. OpenJDK 1.6
224            # 3. GCJ 1.5
225            # 4. Kaffe 1.4.2
226            IF(var MATCHES "java version \"[0-9]+\\.[0-9]+\\.[0-9_.]+[oem-]*\".*")
227              # This is most likely Sun / OpenJDK, or maybe GCJ-java compat layer
228              STRING( REGEX REPLACE ".* version \"([0-9]+\\.[0-9]+\\.[0-9_.]+)[oem-]*\".*"
229                      "\\1" Java_VERSION_STRING "${var}" )
230            ELSEIF(var MATCHES "java full version \"kaffe-[0-9]+\\.[0-9]+\\.[0-9_]+\".*")
231              # Kaffe style
232              STRING( REGEX REPLACE "java full version \"kaffe-([0-9]+\\.[0-9]+\\.[0-9_]+).*"
233                      "\\1" Java_VERSION_STRING "${var}" )
234            ELSE()
235              IF(NOT Java_FIND_QUIETLY)
236                message(WARNING "regex not supported: ${var}. Please report")
237              ENDIF(NOT Java_FIND_QUIETLY)
238            ENDIF()
239            STRING( REGEX REPLACE "([0-9]+).*" "\\1" Java_VERSION_MAJOR "${Java_VERSION_STRING}" )
240            STRING( REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_MINOR "${Java_VERSION_STRING}" )
241            STRING( REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_PATCH "${Java_VERSION_STRING}" )
242            # warning tweak version can be empty:
243            STRING( REGEX REPLACE "[0-9]+\\.[0-9]+\\.[0-9]+\\_?\\.?([0-9]*)$" "\\1" Java_VERSION_TWEAK "${Java_VERSION_STRING}" )
244            if( Java_VERSION_TWEAK STREQUAL "" ) # check case where tweak is not defined
245              set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH})
246            else( )
247              set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH}.${Java_VERSION_TWEAK})
248            endif( )
249          ENDIF()
250      ENDIF(Java_JAVA_EXECUTABLE)
251      
252      FIND_PROGRAM(Java_JAR_EXECUTABLE
253        NAMES jar
254        HINTS ${_JAVA_HINTS}
255        PATHS ${_JAVA_PATHS}
256      )
257      
258      FIND_PROGRAM(Java_JAVAC_EXECUTABLE
259        NAMES javac
260        HINTS ${_JAVA_HINTS}
261        PATHS ${_JAVA_PATHS}
262      )
263      
264      FIND_PROGRAM(Java_JAVAH_EXECUTABLE
265        NAMES javah
266        HINTS ${_JAVA_HINTS}
267        PATHS ${_JAVA_PATHS}
268      )
269      
270      FIND_PROGRAM(Java_JAVADOC_EXECUTABLE
271        NAMES javadoc
272        HINTS ${_JAVA_HINTS}
273        PATHS ${_JAVA_PATHS}
274      )
275      
276      # Check for everything
277      include(FindPackageHandleStandardArgs)
278      find_package_handle_standard_args(Java
279        REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE
280                      Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE Java_VERSION)
281      set(Java_FOUND TRUE)
282      
283      find_package(JNI)
284      
285    else()
286      
287      find_package(Java)
288      find_package(JNI)
289      
290    endif()
291    
292ENDMACRO()
293
294MACRO(ExtractRstCPP INFILE OUTFILE)
295   add_custom_command(
296      OUTPUT ${OUTFILE}
297      COMMAND ${CMAKE_SOURCE_DIR}/share/sphinx/ExtractRstFromSourceCPP.py ${INFILE} ${OUTFILE}
298      DEPENDS ${INFILE}
299      COMMENT "Extracting reStructuredText from ${INFILE} (using old process)"
300   )
301ENDMACRO()
302
303MACRO(ExtractRstSimple INFILE OUTFILE)
304   add_custom_command(
305      OUTPUT ${OUTFILE}
306      COMMAND ${CMAKE_SOURCE_DIR}/share/sphinx/ExtractRstFromSourceSimple.py ${INFILE} ${OUTFILE}
307      DEPENDS ${INFILE}
308      COMMENT "Extracting reStructuredText from ${INFILE}"
309   )
310ENDMACRO()
311
312
313MACRO(CopyFiles TARGET)
314    # parse the macro arguments
315    PARSE_ARGUMENTS(COPYFILES
316        "OUTDIR;"
317        "NOTUSED" ${ARGN})
318    
319    # get the list of sources from the args
320    set(FILES ${COPYFILES_DEFAULT_ARGS})
321    
322    # find the shader compiler
323    if(NOT COPYFILES_OUTDIR)
324        set(COPYFILES_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
325    endif()
326    
327    set(${TARGET}_OUTPUT)
328    foreach(FILE ${FILES})
329        get_filename_component(_FILE_NAME ${FILE} NAME)
330        set(OUTFILENAME "${COPYFILES_OUTDIR}/${_FILE_NAME}")
331        list(APPEND ${TARGET}_OUTPUT ${OUTFILENAME})
332        add_custom_command(
333            OUTPUT ${OUTFILENAME}
334            COMMAND ${CMAKE_COMMAND} -E copy ${FILE} ${OUTFILENAME}
335            DEPENDS ${FILE}
336            COMMENT "Copying file ${FILE}\n    to ${OUTFILENAME}"
337        )
338    endforeach()
339ENDMACRO()