- add cmake logic to parse package versions and include the correct headers

- add #ifdefs to work around the different versions of glfw
- add cmake logic to parse other packages versions and set minimum requirements
- fix X11 dependencies for static builds of glfw

- general Find.cmake cleanup

fixes #101
This commit is contained in:
manuelk 2013-01-31 15:34:35 -08:00
parent 855b177c20
commit 7a39b0ad7c
7 changed files with 528 additions and 273 deletions

View File

@ -59,12 +59,6 @@ project(OpenSubdiv)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
# XXXX manuelk - API version is managed from opensubdiv/version.h - we should remove this
set(OpenSubdiv_VERSION_MAJOR 0)
set(OpenSubdiv_VERSION_MINOR 1)
set(OpenSubdiv_VERSION_PATCH 0)
set(OpenSubdiv_VERSION ${OpenSubdiv_VERSION_MAJOR}.${OpenSubdiv_VERSION_MINOR}.${OpenSubdiv_VERSION_PATCH})
message(STATUS "Compiling ${CMAKE_PROJECT_NAME} version ${OpenSubdiv_VERSION}") message(STATUS "Compiling ${CMAKE_PROJECT_NAME} version ${OpenSubdiv_VERSION}")
message(STATUS "Using cmake version ${CMAKE_VERSION}") message(STATUS "Using cmake version ${CMAKE_VERSION}")
@ -193,10 +187,10 @@ if(NOT NO_OMP)
endif() endif()
find_package(OpenGL) find_package(OpenGL)
find_package(OpenGLES) find_package(OpenGLES)
find_package(OpenCL) find_package(OpenCL 1.1)
find_package(CUDA) find_package(CUDA 4.0)
find_package(GLFW) find_package(GLFW 2.7.0)
find_package(PTex) find_package(PTex 2.0)
if (NOT APPLE AND OPENGL_FOUND) if (NOT APPLE AND OPENGL_FOUND)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
@ -206,7 +200,7 @@ if (WIN32)
find_package(DXSDK) find_package(DXSDK)
endif() endif()
find_package(Maya) find_package(Maya 201200)
# Warn about missing dependencies that will cause parts of OpenSubdiv to be # Warn about missing dependencies that will cause parts of OpenSubdiv to be
# disabled. Also, add preprocessor defines that can be used in the source # disabled. Also, add preprocessor defines that can be used in the source
@ -225,6 +219,10 @@ else()
"in your cmake installation.") "in your cmake installation.")
endif() endif()
if(GLFW_FOUND AND (GLFW_VERSION VERSION_EQUAL 3.0 OR GLFW_VERSION VERSION_GREATER 3.0))
add_definitions( -DGLFW_VERSION_3 )
endif()
# note : (GLSL transform feedback kernels require GL 4.2) # note : (GLSL transform feedback kernels require GL 4.2)
if(GLEW_FOUND AND OPENGL_4_2_FOUND) if(GLEW_FOUND AND OPENGL_4_2_FOUND)
add_definitions( add_definitions(

View File

@ -64,84 +64,101 @@
# GLFW_LIBRARIES # GLFW_LIBRARIES
# #
find_path( GLFW_INCLUDE_DIR
NAMES
GL/glfw.h
GL/glfw3.h
PATHS
${GLFW_LOCATION}/include
$ENV{GLFW_LOCATION}/include
$ENV{PROGRAMFILES}/GLFW/include
${OPENGL_INCLUDE_DIR}
/usr/openwin/share/include
/usr/openwin/include
/usr/X11R6/include
/usr/include/X11
/opt/graphics/OpenGL/include
/opt/graphics/OpenGL/contrib/libglfw
/usr/local/include
/usr/include/GL
/usr/include
DOC
"The directory where GL/glfw.h resides"
)
if (WIN32) if (WIN32)
if(CYGWIN) if(CYGWIN)
find_path( GLFW_INCLUDE_DIR GL/glfw.h find_library( GLFW_glfw_LIBRARY
${GLFW_LOCATION}/include NAMES
$ENV{GLFW_LOCATION}/include glfw32
/usr/include PATHS
) ${GLFW_LOCATION}/lib
find_library( GLFW_glfw_LIBRARY glfw32 ${GLFW_LOCATION}/lib/x64
${GLFW_LOCATION}/lib $ENV{GLFW_LOCATION}/lib
${GLFW_LOCATION}/lib/x64 ${OPENGL_LIBRARY_DIR}
$ENV{GLFW_LOCATION}/lib /usr/lib
${OPENGL_LIBRARY_DIR} /usr/lib/w32api
/usr/lib /usr/local/lib
/usr/lib/w32api /usr/X11R6/lib
/usr/local/lib DOC
/usr/X11R6/lib "The GLFW library"
) )
else() else()
find_path( GLFW_INCLUDE_DIR GL/glfw.h
${GLFW_LOCATION}/include
$ENV{GLFW_LOCATION}/include
${PROJECT_SOURCE_DIR}/extern/glfw/include
$ENV{PROGRAMFILES}/GLFW/include
${OPENGL_INCLUDE_DIR}
DOC "The directory where GL/glfw.h resides")
find_library( GLFW_glfw_LIBRARY find_library( GLFW_glfw_LIBRARY
NAMES glfw32 glfw32s glfw NAMES
glfw32
glfw32s
glfw
PATHS PATHS
${GLFW_LOCATION}/lib ${GLFW_LOCATION}/lib
${GLFW_LOCATION}/lib/x64 ${GLFW_LOCATION}/lib/x64
${GLFW_LOCATION}/lib-msvc110 ${GLFW_LOCATION}/lib-msvc110
$ENV{GLFW_LOCATION}/lib $ENV{GLFW_LOCATION}/lib
${PROJECT_SOURCE_DIR}/extern/glfw/bin ${PROJECT_SOURCE_DIR}/extern/glfw/bin
${PROJECT_SOURCE_DIR}/extern/glfw/lib ${PROJECT_SOURCE_DIR}/extern/glfw/lib
$ENV{PROGRAMFILES}/GLFW/lib $ENV{PROGRAMFILES}/GLFW/lib
${OPENGL_LIBRARY_DIR} ${OPENGL_LIBRARY_DIR}
DOC "The GLFW library") DOC
"The GLFW library"
)
endif() endif()
else () else ()
if (APPLE) if (APPLE)
# These values for Apple could probably do with improvement.
find_path( GLFW_INCLUDE_DIR GL/glfw.h
${GLFW_LOCATION}/include
/usr/local/include
)
find_library( GLFW_glfw_LIBRARY glfw find_library( GLFW_glfw_LIBRARY glfw
NAMES glfw NAMES
glfw
glfw3
PATHS PATHS
${GLFW_LOCATION}/lib ${GLFW_LOCATION}/lib
${GLFW_LOCATION}/lib/cocoa ${GLFW_LOCATION}/lib/cocoa
/usr/local/lib /usr/local/lib
) )
set(GLFW_cocoa_LIBRARY "-framework Cocoa" CACHE STRING "Cocoa framework for OSX") set(GLFW_cocoa_LIBRARY "-framework Cocoa" CACHE STRING "Cocoa framework for OSX")
set(GLFW_iokit_LIBRARY "-framework IOKit" CACHE STRING "IOKit framework for OSX") set(GLFW_iokit_LIBRARY "-framework IOKit" CACHE STRING "IOKit framework for OSX")
else () else ()
find_path( GLFW_INCLUDE_DIR GL/glfw.h # (*)NIX
${GLFW_LOCATION}/include
$ENV{GLFW_LOCATION}/include find_package(X11 REQUIRED)
/usr/include
/usr/include/GL if(NOT X11_Xrandr_FOUND)
/usr/local/include message(FATAL_ERROR "Xrandr library not found")
/usr/openwin/share/include endif()
/usr/openwin/include
/usr/X11R6/include find_library( GLFW_glfw_LIBRARY
/usr/include/X11 NAMES
/opt/graphics/OpenGL/include glfw
/opt/graphics/OpenGL/contrib/libglfw glfw3
) PATHS
find_library( GLFW_glfw_LIBRARY glfw ${GLFW_LOCATION}/lib
${GLFW_LOCATION}/lib $ENV{GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib ${GLFW_LOCATION}/lib/x11
${GLFW_LOCATION}/lib/x11 $ENV{GLFW_LOCATION}/lib/x11
$ENV{GLFW_LOCATION}/lib/x11 /usr/lib
/usr/lib /usr/local/lib
/usr/local/lib /usr/openwin/lib
/usr/openwin/lib /usr/X11R6/lib
/usr/X11R6/lib DOC
"The GLFW library"
) )
endif (APPLE) endif (APPLE)
endif (WIN32) endif (WIN32)
@ -149,30 +166,70 @@ endif (WIN32)
set( GLFW_FOUND "NO" ) set( GLFW_FOUND "NO" )
if(GLFW_INCLUDE_DIR) if(GLFW_INCLUDE_DIR)
if(GLFW_glfw_LIBRARY)
set( GLFW_LIBRARIES
${GLFW_glfw_LIBRARY}
${GLFW_cocoa_LIBRARY}
${GLFW_iokit_LIBRARY}
)
set( GLFW_FOUND "YES" )
set (GLFW_LIBRARY ${GLFW_LIBRARIES}) if(GLFW_glfw_LIBRARY)
set (GLFW_INCLUDE_PATH ${GLFW_INCLUDE_DIR}) set( GLFW_LIBRARIES ${GLFW_glfw_LIBRARY} ${GLFW_cocoa_LIBRARY} ${GLFW_iokit_LIBRARY} )
set( GLFW_FOUND "YES" )
set (GLFW_LIBRARY ${GLFW_LIBRARIES})
set (GLFW_INCLUDE_PATH ${GLFW_INCLUDE_DIR})
endif(GLFW_glfw_LIBRARY)
endif(GLFW_glfw_LIBRARY)
# Tease the GLFW_VERSION numbers from the lib headers
function(parseVersion FILENAME VARNAME)
set(PATTERN "^#define ${VARNAME}.*$")
file(STRINGS "${GLFW_INCLUDE_DIR}/GL/${FILENAME}" TMP REGEX ${PATTERN})
string(REGEX MATCHALL "[0-9]+" TMP ${TMP})
set(${VARNAME} ${TMP} PARENT_SCOPE)
endfunction()
if(EXISTS "${GLFW_INCLUDE_DIR}/GL/glfw.h")
parseVersion(glfw.h GLFW_VERSION_MAJOR)
parseVersion(glfw.h GLFW_VERSION_MINOR)
parseVersion(glfw.h GLFW_VERSION_REVISION)
elseif(EXISTS "${GLFW_INCLUDE_DIR}/GL/glfw3.h")
parseVersion(glfw3.h GLFW_VERSION_MAJOR)
parseVersion(glfw3.h GLFW_VERSION_MINOR)
parseVersion(glfw3.h GLFW_VERSION_REVISION)
endif()
if(${GLFW_VERSION_MAJOR} OR ${GLFW_VERSION_MINOR} OR ${GLFW_VERSION_REVISION})
set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}.${GLFW_VERSION_REVISION}")
set(GLFW_VERSION_STRING "${GLFW_VERSION}")
mark_as_advanced(GLFW_VERSION)
endif()
# static builds of glfw require Xrandr
if( UNIX AND GLFW_FOUND)
list(APPEND GLFW_LIBRARIES -lXrandr -lXxf86vm)
endif()
endif(GLFW_INCLUDE_DIR) endif(GLFW_INCLUDE_DIR)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW DEFAULT_MSG find_package_handle_standard_args(GLFW
GLFW_INCLUDE_DIR REQUIRED_VARS
GLFW_LIBRARIES GLFW_INCLUDE_DIR
GLFW_LIBRARIES
VERSION_VAR
GLFW_VERSION
) )
mark_as_advanced( mark_as_advanced(
GLFW_INCLUDE_DIR GLFW_INCLUDE_DIR
GLFW_LIBRARIES
GLFW_glfw_LIBRARY GLFW_glfw_LIBRARY
GLFW_cocoa_LIBRARY GLFW_cocoa_LIBRARY
) )

285
cmake/FindMaya.cmake Executable file → Normal file
View File

@ -66,6 +66,7 @@
# MAYA_<lib>_FOUND Defined if <lib> has been found # MAYA_<lib>_FOUND Defined if <lib> has been found
# MAYA_<lib>_LIBRARY Path to <lib> library # MAYA_<lib>_LIBRARY Path to <lib> library
# MAYA_INCLUDE_DIRS Path to the devkit's include directories # MAYA_INCLUDE_DIRS Path to the devkit's include directories
# MAYA_API_VERSION Maya version (6 digits)
# #
# IMPORTANT: Currently, there's only support for OSX platform and Maya version 2012. # IMPORTANT: Currently, there's only support for OSX platform and Maya version 2012.
@ -82,12 +83,8 @@
# (To distribute this file outside of CMake, substitute the full # (To distribute this file outside of CMake, substitute the full
# License text for the above reference.) # License text for the above reference.)
SET(MAYA_VERSION_2012 TRUE) if(APPLE)
find_path(MAYA_BASE_DIR ../../devkit/include/maya/MFn.h PATH
## add one to this list to match your install if none match
IF(APPLE)
FIND_PATH(MAYA_BASE_DIR ../../devkit/include/maya/MFn.h PATH
${MAYA_LOCATION} ${MAYA_LOCATION}
$ENV{MAYA_LOCATION} $ENV{MAYA_LOCATION}
"/Applications/Autodesk/maya2014/Maya.app/Contents" "/Applications/Autodesk/maya2014/Maya.app/Contents"
@ -97,20 +94,21 @@ IF(APPLE)
"/Applications/Autodesk/maya2012/Maya.app/Contents" "/Applications/Autodesk/maya2012/Maya.app/Contents"
"/Applications/Autodesk/maya2011/Maya.app/Contents" "/Applications/Autodesk/maya2011/Maya.app/Contents"
"/Applications/Autodesk/maya2010/Maya.app/Contents" "/Applications/Autodesk/maya2010/Maya.app/Contents"
) )
FIND_PATH(MAYA_LIBRARY_DIR libOpenMaya.dylib find_path(MAYA_LIBRARY_DIR libOpenMaya.dylib
PATHS PATHS
${MAYA_LOCATION} ${MAYA_LOCATION}
$ENV{MAYA_LOCATION} $ENV{MAYA_LOCATION}
${MAYA_BASE_DIR} ${MAYA_BASE_DIR}
PATH_SUFFIXES PATH_SUFFIXES
Maya.app/contents/MacOS/ Maya.app/contents/MacOS/
DOC "Maya's libraries path" DOC
) "Maya's libraries path"
ENDIF(APPLE) )
endif(APPLE)
IF(UNIX) if(UNIX)
FIND_PATH(MAYA_BASE_DIR include/maya/MFn.h PATH find_path(MAYA_BASE_DIR include/maya/MFn.h PATH
${MAYA_LOCATION} ${MAYA_LOCATION}
$ENV{MAYA_LOCATION} $ENV{MAYA_LOCATION}
"/usr/autodesk/maya2013-x64" "/usr/autodesk/maya2013-x64"
@ -118,129 +116,152 @@ IF(UNIX)
"/usr/autodesk/maya2012-x64" "/usr/autodesk/maya2012-x64"
"/usr/autodesk/maya2011-x64" "/usr/autodesk/maya2011-x64"
"/usr/autodesk/maya2010-x64" "/usr/autodesk/maya2010-x64"
) )
FIND_PATH(MAYA_LIBRARY_DIR libOpenMaya.so find_path(MAYA_LIBRARY_DIR libOpenMaya.so
PATHS PATHS
${MAYA_LOCATION} ${MAYA_LOCATION}
$ENV{MAYA_LOCATION} $ENV{MAYA_LOCATION}
${MAYA_BASE_DIR} ${MAYA_BASE_DIR}
PATH_SUFFIXES PATH_SUFFIXES
lib/ lib/
DOC "Maya's libraries path" DOC
) "Maya's libraries path"
ENDIF(UNIX) )
endif(UNIX)
IF(WIN32) if(WIN32)
FIND_PATH(MAYA_BASE_DIR include/maya/MFn.h PATH find_path(MAYA_BASE_DIR include/maya/MFn.h
PATH
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
"C:/Program Files/Autodesk/Maya2013.5-x64"
"C:/Program Files/Autodesk/Maya2013.5"
"C:/Program Files (x86)/Autodesk/Maya2013.5"
"C:/Autodesk/maya-2013.5x64"
"C:/Program Files/Autodesk/Maya2013-x64"
"C:/Program Files/Autodesk/Maya2013"
"C:/Program Files (x86)/Autodesk/Maya2013"
"C:/Autodesk/maya-2013x64"
"C:/Program Files/Autodesk/Maya2012-x64"
"C:/Program Files/Autodesk/Maya2012"
"C:/Program Files (x86)/Autodesk/Maya2012"
"C:/Autodesk/maya-2012x64"
"C:/Program Files/Autodesk/Maya2011-x64"
"C:/Program Files/Autodesk/Maya2011"
"C:/Program Files (x86)/Autodesk/Maya2011"
"C:/Autodesk/maya-2011x64"
"C:/Program Files/Autodesk/Maya2010-x64"
"C:/Program Files/Autodesk/Maya2010"
"C:/Program Files (x86)/Autodesk/Maya2010"
"C:/Autodesk/maya-2010x64"
)
find_path(MAYA_LIBRARY_DIR OpenMaya.lib
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES
lib/
DOC
"Maya's libraries path"
)
endif(WIN32)
find_path(MAYA_INCLUDE_DIR maya/MFn.h
PATHS
${MAYA_LOCATION} ${MAYA_LOCATION}
$ENV{MAYA_LOCATION} $ENV{MAYA_LOCATION}
"C:/Program Files/Autodesk/Maya2013.5-x64" ${MAYA_BASE_DIR}
"C:/Program Files/Autodesk/Maya2013.5"
"C:/Program Files (x86)/Autodesk/Maya2013.5"
"C:/Autodesk/maya-2013.5x64"
"C:/Program Files/Autodesk/Maya2013-x64"
"C:/Program Files/Autodesk/Maya2013"
"C:/Program Files (x86)/Autodesk/Maya2013"
"C:/Autodesk/maya-2013x64"
"C:/Program Files/Autodesk/Maya2012-x64"
"C:/Program Files/Autodesk/Maya2012"
"C:/Program Files (x86)/Autodesk/Maya2012"
"C:/Autodesk/maya-2012x64"
"C:/Program Files/Autodesk/Maya2011-x64"
"C:/Program Files/Autodesk/Maya2011"
"C:/Program Files (x86)/Autodesk/Maya2011"
"C:/Autodesk/maya-2011x64"
"C:/Program Files/Autodesk/Maya2010-x64"
"C:/Program Files/Autodesk/Maya2010"
"C:/Program Files (x86)/Autodesk/Maya2010"
"C:/Autodesk/maya-2010x64"
)
FIND_PATH(MAYA_LIBRARY_DIR OpenMaya.lib
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES PATH_SUFFIXES
lib/ ../../devkit/include/
DOC "Maya's libraries path" include/
) DOC
ENDIF(WIN32) "Maya's devkit headers path"
FIND_PATH(MAYA_INCLUDE_DIR maya/MFn.h
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES
../../devkit/include/
include/
DOC "Maya's devkit headers path"
) )
FIND_PATH(MAYA_LIBRARY_DIR OpenMaya find_path(MAYA_LIBRARY_DIR OpenMaya
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES
../../devkit/include/
include/
DOC "Maya's devkit headers path"
)
LIST(APPEND MAYA_INCLUDE_DIRS ${MAYA_INCLUDE_DIR})
FIND_PATH(MAYA_DEVKIT_INC_DIR GL/glext.h
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES
/devkit/plug-ins/
DOC "Maya's devkit headers path"
)
LIST(APPEND MAYA_INCLUDE_DIRS ${MAYA_DEVKIT_INC_DIR})
FOREACH(MAYA_LIB
OpenMaya
OpenMayaAnim
OpenMayaFX
OpenMayaRender
OpenMayaUI
Image
Foundation
IMFbase
tbb
cg
cgGL
)
FIND_LIBRARY(MAYA_${MAYA_LIB}_LIBRARY ${MAYA_LIB}
PATHS PATHS
${MAYA_LOCATION} ${MAYA_LOCATION}
$ENV{MAYA_LOCATION} $ENV{MAYA_LOCATION}
${MAYA_BASE_DIR} ${MAYA_BASE_DIR}
PATH_SUFFIXES PATH_SUFFIXES
MacOS/ ../../devkit/include/
lib/ include/
DOC "Maya's ${MAYA_LIB} library path" DOC
) "Maya's devkit headers path"
LIST(APPEND ${MAYA_LIBRARIES} MAYA_${MAYA_LIB}_LIBRARY)
ENDFOREACH(MAYA_LIB)
FIND_PROGRAM(MAYA_EXECUTABLE maya
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES
MacOS/
bin/
DOC "Maya's executable path"
) )
list(APPEND MAYA_INCLUDE_DIRS ${MAYA_INCLUDE_DIR})
find_path(MAYA_DEVKIT_INC_DIR GL/glext.h
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES
/devkit/plug-ins/
DOC
"Maya's devkit headers path"
)
list(APPEND MAYA_INCLUDE_DIRS ${MAYA_DEVKIT_INC_DIR})
foreach(MAYA_LIB
OpenMaya
OpenMayaAnim
OpenMayaFX
OpenMayaRender
OpenMayaUI
Image
Foundation
IMFbase
tbb
cg
cgGL)
find_library(MAYA_${MAYA_LIB}_LIBRARY ${MAYA_LIB}
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES
MacOS/
lib/
DOC
"Maya's ${MAYA_LIB} library path"
)
list(APPEND ${MAYA_LIBRARIES} MAYA_${MAYA_LIB}_LIBRARY)
endforeach(MAYA_LIB)
find_program(MAYA_EXECUTABLE maya
PATHS
${MAYA_LOCATION}
$ENV{MAYA_LOCATION}
${MAYA_BASE_DIR}
PATH_SUFFIXES
MacOS/
bin/
DOC
"Maya's executable path"
)
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MTypes.h")
# Tease the MAYA_API_VERSION numbers from the lib headers
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MTypes.h TMP REGEX "^#define MAYA_API_VERSION.*$")
string(REGEX MATCHALL "[0-9]+" MAYA_API_VERSION ${TMP})
endif()
# handle the QUIETLY and REQUIRED arguments and set MAYA_FOUND to TRUE if # handle the QUIETLY and REQUIRED arguments and set MAYA_FOUND to TRUE if
# all listed variables are TRUE # all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Maya DEFAULT_MSG ${MAYA_LIBRARIES} MAYA_EXECUTABLE MAYA_INCLUDE_DIRS)
find_package_handle_standard_args(Maya
REQUIRED_VARS
${MAYA_LIBRARIES}
MAYA_EXECUTABLE
MAYA_INCLUDE_DIRS
VERSION_VAR
MAYA_API_VERSION
)

View File

@ -166,7 +166,6 @@ else ()
endif () endif ()
find_package_handle_standard_args(OpenCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS)
if(_OPENCL_CPP_INCLUDE_DIRS) if(_OPENCL_CPP_INCLUDE_DIRS)
@ -176,6 +175,38 @@ if(_OPENCL_CPP_INCLUDE_DIRS)
list( REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS ) list( REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS )
if(EXISTS "${OPENCL_INCLUDE_DIRS}/CL/cl.h")
file(STRINGS "${OPENCL_INCLUDE_DIRS}/CL/cl.h" LINES REGEX "^#define CL_VERSION_.*$")
foreach(LINE ${LINES})
string(REGEX MATCHALL "[0-9]+" VERSION ${LINE})
#string(SUBSTRING ${VERSION} 1 2 FOO)
list(GET VERSION 0 MAJOR)
list(GET VERSION 1 MINOR)
set(VERSION ${MAJOR}.${MINOR})
if (NOT OPENCL_VERSION OR OPENCL_VERSION VERSION_LESS ${VERSION})
set(OPENCL_VERSION ${VERSION})
endif()
endforeach()
endif()
endif(_OPENCL_CPP_INCLUDE_DIRS) endif(_OPENCL_CPP_INCLUDE_DIRS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenCL
REQUIRED_VARS
OPENCL_LIBRARIES
OPENCL_INCLUDE_DIRS
VERSION_VAR
OPENCL_VERSION
)
mark_as_advanced( OPENCL_INCLUDE_DIRS ) mark_as_advanced( OPENCL_INCLUDE_DIRS )

View File

@ -130,11 +130,29 @@ else ()
DOC "The Ptex library") DOC "The Ptex library")
endif () endif ()
if (PTEX_INCLUDE_DIR AND EXISTS "${PTEX_INCLUDE_DIR}/Ptexture.h" )
file(STRINGS "${PTEX_INCLUDE_DIR}/Ptexture.h" TMP REGEX "^#define PtexAPIVersion.*$")
string(REGEX MATCHALL "[0-9]+" API ${TMP})
file(STRINGS "${PTEX_INCLUDE_DIR}/Ptexture.h" TMP REGEX "^#define PtexFileMajorVersion.*$")
string(REGEX MATCHALL "[0-9]+" MAJOR ${TMP})
file(STRINGS "${PTEX_INCLUDE_DIR}/Ptexture.h" TMP REGEX "^#define PtexFileMinorVersion.*$")
string(REGEX MATCHALL "[0-9]+" MINOR ${TMP})
set(PTEX_VERSION ${API}.${MAJOR}.${MINOR})
endif()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PTEX DEFAULT_MSG find_package_handle_standard_args(PTex
PTEX_INCLUDE_DIR REQUIRED_VARS
PTEX_LIBRARY PTEX_INCLUDE_DIR
PTEX_LIBRARY
VERSION_VAR
PTEX_VERSION
) )
mark_as_advanced( mark_as_advanced(

View File

@ -59,13 +59,18 @@
#include <OpenGL/gl3.h> #include <OpenGL/gl3.h>
#define GLFW_INCLUDE_GL3 #define GLFW_INCLUDE_GL3
#define GLFW_NO_GLU #define GLFW_NO_GLU
#include <GL/glfw.h>
#else #else
#include <stdlib.h> #include <stdlib.h>
#include <GL/glew.h> #include <GL/glew.h>
#if defined(WIN32) #if defined(WIN32)
#include <GL/wglew.h> #include <GL/wglew.h>
#endif #endif
#endif
#if defined(GLFW_VERSION_3)
#include <GL/glfw3.h>
GLFWwindow* g_window=0;
#else
#include <GL/glfw.h> #include <GL/glfw.h>
#endif #endif
@ -1356,8 +1361,6 @@ display() {
g_hud.Flush(); g_hud.Flush();
} }
glFinish();
glfwSwapBuffers();
glFinish(); glFinish();
checkGLErrors("display leave"); checkGLErrors("display leave");
@ -1365,7 +1368,11 @@ display() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static void static void
#if GLFW_VERSION_MAJOR>=3
motion(GLFWwindow *, int x, int y) {
#else
motion(int x, int y) { motion(int x, int y) {
#endif
if (g_mbutton[0] && !g_mbutton[1] && !g_mbutton[2]) { if (g_mbutton[0] && !g_mbutton[1] && !g_mbutton[2]) {
// orbit // orbit
@ -1388,8 +1395,11 @@ motion(int x, int y) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static void static void
#if GLFW_VERSION_MAJOR>=3
mouse(GLFWwindow *, int button, int state) {
#else
mouse(int button, int state) { mouse(int button, int state) {
#endif
if (button == 0 && state == GLFW_PRESS && g_hud.MouseClick(g_prev_x, g_prev_y)) if (button == 0 && state == GLFW_PRESS && g_hud.MouseClick(g_prev_x, g_prev_y))
return; return;
@ -1425,7 +1435,11 @@ uninitGL() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static void static void
#if GLFW_VERSION_MAJOR>=3
reshape(GLFWwindow *, int width, int height) {
#else
reshape(int width, int height) { reshape(int width, int height) {
#endif
g_width = width; g_width = width;
g_height = height; g_height = height;
@ -1460,7 +1474,11 @@ static void toggleFullScreen() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static void static void
#if GLFW_VERSION_MAJOR>=3
keyboard(GLFWwindow *, int key, int event) {
#else
keyboard(int key, int event) { keyboard(int key, int event) {
#endif
if (event == GLFW_RELEASE) return; if (event == GLFW_RELEASE) return;
if (g_hud.KeyDown(tolower(key))) return; if (g_hud.KeyDown(tolower(key))) return;
@ -1669,6 +1687,30 @@ callbackError(OpenSubdiv::OsdErrorType err, const char *message)
printf("%s", message); printf("%s", message);
} }
//------------------------------------------------------------------------------
static void
setGLCoreProfile()
{
#if GLFW_VERSION_MAJOR>=3
#define glfwOpenWindowHint glfwWindowHint
#define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR
#define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR
#endif
#if GLFW_VERSION_MAJOR>=2 and GLFW_VERSION_MINOR >=7
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#if not defined(__APPLE__)
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#else
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
#endif
#endif
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
@ -1695,26 +1737,43 @@ int main(int argc, char ** argv)
initializeShapes(); initializeShapes();
OsdSetErrorCallback(callbackError); OsdSetErrorCallback(callbackError);
glfwInit(); if (not glfwInit()) {
printf("Failed to initialize GLFW\n");
return 1;
}
static const char windowTitle[] = "OpenSubdiv glViewer";
#define CORE_PROFILE #define CORE_PROFILE
#ifdef CORE_PROFILE #ifdef CORE_PROFILE
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); setGLCoreProfile();
#if not defined(__APPLE__)
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#else
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
#endif #endif
#endif
if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8, #if GLFW_VERSION_MAJOR>=3
fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) { if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle,
printf("Fail to open window.\n"); fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL))) {
printf("Failed to open window.\n");
glfwTerminate(); glfwTerminate();
return 1; return 1;
} }
glfwSetWindowTitle("OpenSubdiv glViewer"); glfwMakeContextCurrent(g_window);
glfwSetKeyCallback(g_window, keyboard);
glfwSetCursorPosCallback(g_window, motion);
glfwSetMouseButtonCallback(g_window, mouse);
glfwSetWindowSizeCallback(g_window, reshape);
#else
if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8,
fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) {
printf("Failed to open window.\n");
glfwTerminate();
return 1;
}
glfwSetWindowTitle(windowTitle);
glfwSetKeyCallback(keyboard);
glfwSetMousePosCallback(motion);
glfwSetMouseButtonCallback(mouse);
glfwSetWindowSizeCallback(reshape);
#endif
#if not defined(__APPLE__) #if not defined(__APPLE__)
#ifdef CORE_PROFILE #ifdef CORE_PROFILE
@ -1722,7 +1781,7 @@ int main(int argc, char ** argv)
glewExperimental = true; glewExperimental = true;
#endif #endif
if (GLenum r = glewInit() != GLEW_OK) { if (GLenum r = glewInit() != GLEW_OK) {
printf("Fail to initialize glew. error = %d\n", r); printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r));
exit(1); exit(1);
} }
#ifdef CORE_PROFILE #ifdef CORE_PROFILE
@ -1741,14 +1800,18 @@ int main(int argc, char ** argv)
initHUD(); initHUD();
callbackModel(g_currentShape); callbackModel(g_currentShape);
glfwSetKeyCallback(keyboard);
glfwSetMousePosCallback(motion);
glfwSetMouseButtonCallback(mouse);
glfwSetWindowSizeCallback(reshape);
while (g_running) { while (g_running) {
idle(); idle();
display(); display();
#if GLFW_VERSION_MAJOR>=3
glfwPollEvents();
glfwSwapBuffers(g_window);
#else
glfwSwapBuffers();
#endif
glFinish();
} }
uninitGL(); uninitGL();

View File

@ -59,13 +59,18 @@
#include <OpenGL/gl3.h> #include <OpenGL/gl3.h>
#define GLFW_INCLUDE_GL3 #define GLFW_INCLUDE_GL3
#define GLFW_NO_GLU #define GLFW_NO_GLU
#include <GL/glfw.h>
#else #else
#include <stdlib.h> #include <stdlib.h>
#include <GL/glew.h> #include <GL/glew.h>
#if defined(WIN32) #if defined(WIN32)
#include <GL/wglew.h> #include <GL/wglew.h>
#endif #endif
#endif
#if defined(GLFW_VERSION_3)
#include <GL/glfw3.h>
GLFWwindow* g_window=0;
#else
#include <GL/glfw.h> #include <GL/glfw.h>
#endif #endif
@ -470,7 +475,11 @@ OpenSubdiv::HbrMesh<T> * createPTexGeo(PtexTexture * r)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void void
#if GLFW_VERSION_MAJOR>=3
reshape(GLFWwindow *, int width, int height) {
#else
reshape(int width, int height) { reshape(int width, int height) {
#endif
g_width = width; g_width = width;
g_height = height; g_height = height;
@ -1374,19 +1383,22 @@ display() {
g_hud.DrawString(10, -60, "GPU Draw : %.3f ms", drawGpuTime); g_hud.DrawString(10, -60, "GPU Draw : %.3f ms", drawGpuTime);
g_hud.DrawString(10, -40, "CPU Draw : %.3f ms", drawCpuTime); g_hud.DrawString(10, -40, "CPU Draw : %.3f ms", drawCpuTime);
g_hud.DrawString(10, -20, "FPS : %3.1f", averageFps); g_hud.DrawString(10, -20, "FPS : %3.1f", averageFps);
g_hud.Flush();
} }
g_hud.Flush();
glfwSwapBuffers();
glFinish(); glFinish();
// checkGLErrors("draw end"); checkGLErrors("draw end");
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static void static void
#if GLFW_VERSION_MAJOR>=3
mouse(GLFWwindow *, int button, int state) {
#else
mouse(int button, int state) { mouse(int button, int state) {
#endif
if (button == 0 && state == GLFW_PRESS && g_hud.MouseClick(g_prev_x, g_prev_y)) if (button == 0 && state == GLFW_PRESS && g_hud.MouseClick(g_prev_x, g_prev_y))
return; return;
@ -1394,7 +1406,12 @@ mouse(int button, int state) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void motion(int x, int y) { static void
#if GLFW_VERSION_MAJOR>=3
motion(GLFWwindow *, int x, int y) {
#else
motion(int x, int y) {
#endif
if (g_mbutton[0] && !g_mbutton[1] && !g_mbutton[2]) { if (g_mbutton[0] && !g_mbutton[1] && !g_mbutton[2]) {
// orbit // orbit
@ -1563,7 +1580,11 @@ static void toggleFullScreen() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void void
#if GLFW_VERSION_MAJOR>=3
keyboard(GLFWwindow *, int key, int event) {
#else
keyboard(int key, int event) { keyboard(int key, int event) {
#endif
if (event == GLFW_RELEASE) return; if (event == GLFW_RELEASE) return;
if (g_hud.KeyDown(tolower(key))) return; if (g_hud.KeyDown(tolower(key))) return;
@ -1625,6 +1646,31 @@ callbackError(OpenSubdiv::OsdErrorType err, const char *message)
printf("OsdError: %d\n", err); printf("OsdError: %d\n", err);
printf("%s", message); printf("%s", message);
} }
//------------------------------------------------------------------------------
static void
setGLCoreProfile()
{
#if GLFW_VERSION_MAJOR>=3
#define glfwOpenWindowHint glfwWindowHint
#define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR
#define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR
#endif
#if GLFW_VERSION_MAJOR>=2 and GLFW_VERSION_MINOR >=7
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#if not defined(__APPLE__)
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#else
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
#endif
#endif
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
@ -1679,26 +1725,43 @@ int main(int argc, char ** argv) {
return 1; return 1;
} }
glfwInit(); if (not glfwInit()) {
printf("Failed to initialize GLFW\n");
return 1;
}
static const char windowTitle[] = "OpenSubdiv glViewer";
#define CORE_PROFILE #define CORE_PROFILE
#ifdef CORE_PROFILE #ifdef CORE_PROFILE
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); setGLCoreProfile();
#if not defined(__APPLE__)
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#else
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
#endif #endif
#endif
if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8, #if GLFW_VERSION_MAJOR>=3
fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) { if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle,
printf("Fail to open window.\n"); fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL))) {
printf("Failed to open window.\n");
glfwTerminate(); glfwTerminate();
return 1; return 1;
} }
glfwSetWindowTitle("OpenSubdiv ptexViewer"); glfwMakeContextCurrent(g_window);
glfwSetKeyCallback(g_window, keyboard);
glfwSetCursorPosCallback(g_window, motion);
glfwSetMouseButtonCallback(g_window, mouse);
glfwSetWindowSizeCallback(g_window, reshape);
#else
if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8,
fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) {
printf("Failed to open window.\n");
glfwTerminate();
return 1;
}
glfwSetWindowTitle(windowTitle);
glfwSetKeyCallback(keyboard);
glfwSetMousePosCallback(motion);
glfwSetMouseButtonCallback(mouse);
glfwSetWindowSizeCallback(reshape);
#endif
#if not defined(__APPLE__) #if not defined(__APPLE__)
#ifdef CORE_PROFILE #ifdef CORE_PROFILE
@ -1706,7 +1769,7 @@ int main(int argc, char ** argv) {
glewExperimental = true; glewExperimental = true;
#endif #endif
if (GLenum r = glewInit() != GLEW_OK) { if (GLenum r = glewInit() != GLEW_OK) {
printf("Fail to initialize glew. error = %d\n", r); printf("Failed to initialize glew. error = %d\n", r);
exit(1); exit(1);
} }
#ifdef CORE_PROFILE #ifdef CORE_PROFILE
@ -1732,11 +1795,6 @@ int main(int argc, char ** argv) {
initGL(); initGL();
g_hud.Init(g_width, g_height); g_hud.Init(g_width, g_height);
glfwSetKeyCallback(keyboard);
glfwSetMousePosCallback(motion);
glfwSetMouseButtonCallback(mouse);
glfwSetWindowSizeCallback(reshape);
g_hud.AddRadioButton(0, "CPU (K)", true, 10, 10, callbackKernel, kCPU, 'k'); g_hud.AddRadioButton(0, "CPU (K)", true, 10, 10, callbackKernel, kCPU, 'k');
#ifdef OPENSUBDIV_HAS_OPENMP #ifdef OPENSUBDIV_HAS_OPENMP
g_hud.AddRadioButton(0, "OPENMP", false, 10, 30, callbackKernel, kOPENMP, 'k'); g_hud.AddRadioButton(0, "OPENMP", false, 10, 30, callbackKernel, kOPENMP, 'k');
@ -1894,6 +1952,15 @@ int main(int argc, char ** argv) {
while (g_running) { while (g_running) {
idle(); idle();
display(); display();
#if GLFW_VERSION_MAJOR>=3
glfwPollEvents();
glfwSwapBuffers(g_window);
#else
glfwSwapBuffers();
#endif
glFinish();
} }
error: error: