From 7a39b0ad7cb18709f9791d71daf85715e5ff36e1 Mon Sep 17 00:00:00 2001 From: manuelk Date: Thu, 31 Jan 2013 15:34:35 -0800 Subject: [PATCH] - 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 --- CMakeLists.txt | 20 ++- cmake/FindGLFW.cmake | 209 +++++++++++++++--------- cmake/FindMaya.cmake | 285 ++++++++++++++++++--------------- cmake/FindOpenCL.cmake | 33 +++- cmake/FindPTex.cmake | 24 ++- examples/glViewer/viewer.cpp | 111 ++++++++++--- examples/ptexViewer/viewer.cpp | 119 +++++++++++--- 7 files changed, 528 insertions(+), 273 deletions(-) mode change 100755 => 100644 cmake/FindMaya.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index cbb78131..44b5997b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,12 +59,6 @@ project(OpenSubdiv) 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 "Using cmake version ${CMAKE_VERSION}") @@ -193,10 +187,10 @@ if(NOT NO_OMP) endif() find_package(OpenGL) find_package(OpenGLES) -find_package(OpenCL) -find_package(CUDA) -find_package(GLFW) -find_package(PTex) +find_package(OpenCL 1.1) +find_package(CUDA 4.0) +find_package(GLFW 2.7.0) +find_package(PTex 2.0) if (NOT APPLE AND OPENGL_FOUND) find_package(GLEW REQUIRED) @@ -206,7 +200,7 @@ if (WIN32) find_package(DXSDK) endif() -find_package(Maya) +find_package(Maya 201200) # Warn about missing dependencies that will cause parts of OpenSubdiv to be # disabled. Also, add preprocessor defines that can be used in the source @@ -225,6 +219,10 @@ else() "in your cmake installation.") 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) if(GLEW_FOUND AND OPENGL_4_2_FOUND) add_definitions( diff --git a/cmake/FindGLFW.cmake b/cmake/FindGLFW.cmake index 7d2f9345..5e200127 100644 --- a/cmake/FindGLFW.cmake +++ b/cmake/FindGLFW.cmake @@ -64,84 +64,101 @@ # 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(CYGWIN) - find_path( GLFW_INCLUDE_DIR GL/glfw.h - ${GLFW_LOCATION}/include - $ENV{GLFW_LOCATION}/include - /usr/include - ) - find_library( GLFW_glfw_LIBRARY glfw32 - ${GLFW_LOCATION}/lib - ${GLFW_LOCATION}/lib/x64 - $ENV{GLFW_LOCATION}/lib - ${OPENGL_LIBRARY_DIR} - /usr/lib - /usr/lib/w32api - /usr/local/lib - /usr/X11R6/lib + find_library( GLFW_glfw_LIBRARY + NAMES + glfw32 + PATHS + ${GLFW_LOCATION}/lib + ${GLFW_LOCATION}/lib/x64 + $ENV{GLFW_LOCATION}/lib + ${OPENGL_LIBRARY_DIR} + /usr/lib + /usr/lib/w32api + /usr/local/lib + /usr/X11R6/lib + DOC + "The GLFW library" ) 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 - NAMES glfw32 glfw32s glfw + NAMES + glfw32 + glfw32s + glfw PATHS - ${GLFW_LOCATION}/lib - ${GLFW_LOCATION}/lib/x64 - ${GLFW_LOCATION}/lib-msvc110 - $ENV{GLFW_LOCATION}/lib - ${PROJECT_SOURCE_DIR}/extern/glfw/bin - ${PROJECT_SOURCE_DIR}/extern/glfw/lib - $ENV{PROGRAMFILES}/GLFW/lib - ${OPENGL_LIBRARY_DIR} - DOC "The GLFW library") - + ${GLFW_LOCATION}/lib + ${GLFW_LOCATION}/lib/x64 + ${GLFW_LOCATION}/lib-msvc110 + $ENV{GLFW_LOCATION}/lib + ${PROJECT_SOURCE_DIR}/extern/glfw/bin + ${PROJECT_SOURCE_DIR}/extern/glfw/lib + $ENV{PROGRAMFILES}/GLFW/lib + ${OPENGL_LIBRARY_DIR} + DOC + "The GLFW library" + ) endif() else () 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 - NAMES glfw + NAMES + glfw + glfw3 PATHS - ${GLFW_LOCATION}/lib - ${GLFW_LOCATION}/lib/cocoa - /usr/local/lib + ${GLFW_LOCATION}/lib + ${GLFW_LOCATION}/lib/cocoa + /usr/local/lib ) set(GLFW_cocoa_LIBRARY "-framework Cocoa" CACHE STRING "Cocoa framework for OSX") set(GLFW_iokit_LIBRARY "-framework IOKit" CACHE STRING "IOKit framework for OSX") else () - find_path( GLFW_INCLUDE_DIR GL/glfw.h - ${GLFW_LOCATION}/include - $ENV{GLFW_LOCATION}/include - /usr/include - /usr/include/GL - /usr/local/include - /usr/openwin/share/include - /usr/openwin/include - /usr/X11R6/include - /usr/include/X11 - /opt/graphics/OpenGL/include - /opt/graphics/OpenGL/contrib/libglfw - ) - find_library( GLFW_glfw_LIBRARY glfw - ${GLFW_LOCATION}/lib - $ENV{GLFW_LOCATION}/lib - ${GLFW_LOCATION}/lib/x11 - $ENV{GLFW_LOCATION}/lib/x11 - /usr/lib - /usr/local/lib - /usr/openwin/lib - /usr/X11R6/lib + # (*)NIX + + find_package(X11 REQUIRED) + + if(NOT X11_Xrandr_FOUND) + message(FATAL_ERROR "Xrandr library not found") + endif() + + find_library( GLFW_glfw_LIBRARY + NAMES + glfw + glfw3 + PATHS + ${GLFW_LOCATION}/lib + $ENV{GLFW_LOCATION}/lib + ${GLFW_LOCATION}/lib/x11 + $ENV{GLFW_LOCATION}/lib/x11 + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + DOC + "The GLFW library" ) endif (APPLE) endif (WIN32) @@ -149,30 +166,70 @@ endif (WIN32) set( GLFW_FOUND "NO" ) 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}) - set (GLFW_INCLUDE_PATH ${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}) + 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) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GLFW DEFAULT_MSG - GLFW_INCLUDE_DIR - GLFW_LIBRARIES +find_package_handle_standard_args(GLFW + REQUIRED_VARS + GLFW_INCLUDE_DIR + GLFW_LIBRARIES + VERSION_VAR + GLFW_VERSION ) mark_as_advanced( GLFW_INCLUDE_DIR + GLFW_LIBRARIES GLFW_glfw_LIBRARY GLFW_cocoa_LIBRARY ) + diff --git a/cmake/FindMaya.cmake b/cmake/FindMaya.cmake old mode 100755 new mode 100644 index 5a007124..56681f1f --- a/cmake/FindMaya.cmake +++ b/cmake/FindMaya.cmake @@ -66,6 +66,7 @@ # MAYA__FOUND Defined if has been found # MAYA__LIBRARY Path to library # 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. @@ -82,12 +83,8 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -SET(MAYA_VERSION_2012 TRUE) - -## 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 +if(APPLE) + find_path(MAYA_BASE_DIR ../../devkit/include/maya/MFn.h PATH ${MAYA_LOCATION} $ENV{MAYA_LOCATION} "/Applications/Autodesk/maya2014/Maya.app/Contents" @@ -97,20 +94,21 @@ IF(APPLE) "/Applications/Autodesk/maya2012/Maya.app/Contents" "/Applications/Autodesk/maya2011/Maya.app/Contents" "/Applications/Autodesk/maya2010/Maya.app/Contents" - ) - FIND_PATH(MAYA_LIBRARY_DIR libOpenMaya.dylib - PATHS - ${MAYA_LOCATION} - $ENV{MAYA_LOCATION} - ${MAYA_BASE_DIR} - PATH_SUFFIXES - Maya.app/contents/MacOS/ - DOC "Maya's libraries path" -) -ENDIF(APPLE) + ) + find_path(MAYA_LIBRARY_DIR libOpenMaya.dylib + PATHS + ${MAYA_LOCATION} + $ENV{MAYA_LOCATION} + ${MAYA_BASE_DIR} + PATH_SUFFIXES + Maya.app/contents/MacOS/ + DOC + "Maya's libraries path" + ) +endif(APPLE) -IF(UNIX) - FIND_PATH(MAYA_BASE_DIR include/maya/MFn.h PATH +if(UNIX) + find_path(MAYA_BASE_DIR include/maya/MFn.h PATH ${MAYA_LOCATION} $ENV{MAYA_LOCATION} "/usr/autodesk/maya2013-x64" @@ -118,129 +116,152 @@ IF(UNIX) "/usr/autodesk/maya2012-x64" "/usr/autodesk/maya2011-x64" "/usr/autodesk/maya2010-x64" - ) - FIND_PATH(MAYA_LIBRARY_DIR libOpenMaya.so - PATHS - ${MAYA_LOCATION} - $ENV{MAYA_LOCATION} - ${MAYA_BASE_DIR} - PATH_SUFFIXES - lib/ - DOC "Maya's libraries path" -) -ENDIF(UNIX) + ) + find_path(MAYA_LIBRARY_DIR libOpenMaya.so + PATHS + ${MAYA_LOCATION} + $ENV{MAYA_LOCATION} + ${MAYA_BASE_DIR} + PATH_SUFFIXES + lib/ + DOC + "Maya's libraries path" + ) +endif(UNIX) -IF(WIN32) - FIND_PATH(MAYA_BASE_DIR include/maya/MFn.h PATH +if(WIN32) + 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} $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} + ${MAYA_BASE_DIR} PATH_SUFFIXES - lib/ - DOC "Maya's libraries path" -) -ENDIF(WIN32) - -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" + ../../devkit/include/ + include/ + DOC + "Maya's devkit headers path" ) -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} +find_path(MAYA_LIBRARY_DIR OpenMaya PATHS - ${MAYA_LOCATION} - $ENV{MAYA_LOCATION} - ${MAYA_BASE_DIR} + ${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" + ../../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 + ${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 # all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Maya DEFAULT_MSG ${MAYA_LIBRARIES} MAYA_EXECUTABLE MAYA_INCLUDE_DIRS) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Maya + REQUIRED_VARS + ${MAYA_LIBRARIES} + MAYA_EXECUTABLE + MAYA_INCLUDE_DIRS + VERSION_VAR + MAYA_API_VERSION +) diff --git a/cmake/FindOpenCL.cmake b/cmake/FindOpenCL.cmake index faf00bae..2b9edd85 100644 --- a/cmake/FindOpenCL.cmake +++ b/cmake/FindOpenCL.cmake @@ -166,7 +166,6 @@ else () endif () -find_package_handle_standard_args(OpenCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS) if(_OPENCL_CPP_INCLUDE_DIRS) @@ -175,7 +174,39 @@ if(_OPENCL_CPP_INCLUDE_DIRS) list( APPEND OPENCL_INCLUDE_DIRS ${_OPENCL_CPP_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) +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 ) diff --git a/cmake/FindPTex.cmake b/cmake/FindPTex.cmake index bab37200..26b4adfc 100644 --- a/cmake/FindPTex.cmake +++ b/cmake/FindPTex.cmake @@ -130,11 +130,29 @@ else () DOC "The Ptex library") 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) -find_package_handle_standard_args(PTEX DEFAULT_MSG - PTEX_INCLUDE_DIR - PTEX_LIBRARY +find_package_handle_standard_args(PTex + REQUIRED_VARS + PTEX_INCLUDE_DIR + PTEX_LIBRARY + VERSION_VAR + PTEX_VERSION ) mark_as_advanced( diff --git a/examples/glViewer/viewer.cpp b/examples/glViewer/viewer.cpp index 4b152dc3..493f5fd1 100755 --- a/examples/glViewer/viewer.cpp +++ b/examples/glViewer/viewer.cpp @@ -59,13 +59,18 @@ #include #define GLFW_INCLUDE_GL3 #define GLFW_NO_GLU - #include #else #include #include #if defined(WIN32) #include #endif +#endif + +#if defined(GLFW_VERSION_3) + #include + GLFWwindow* g_window=0; +#else #include #endif @@ -1356,8 +1361,6 @@ display() { g_hud.Flush(); } - glFinish(); - glfwSwapBuffers(); glFinish(); checkGLErrors("display leave"); @@ -1365,7 +1368,11 @@ display() { //------------------------------------------------------------------------------ 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]) { // orbit @@ -1388,8 +1395,11 @@ motion(int x, int y) { //------------------------------------------------------------------------------ static void +#if GLFW_VERSION_MAJOR>=3 +mouse(GLFWwindow *, int button, int state) { +#else mouse(int button, int state) { - +#endif if (button == 0 && state == GLFW_PRESS && g_hud.MouseClick(g_prev_x, g_prev_y)) return; @@ -1425,7 +1435,11 @@ uninitGL() { //------------------------------------------------------------------------------ static void +#if GLFW_VERSION_MAJOR>=3 +reshape(GLFWwindow *, int width, int height) { +#else reshape(int width, int height) { +#endif g_width = width; g_height = height; @@ -1460,7 +1474,11 @@ static void toggleFullScreen() { //------------------------------------------------------------------------------ static void +#if GLFW_VERSION_MAJOR>=3 +keyboard(GLFWwindow *, int key, int event) { +#else keyboard(int key, int event) { +#endif if (event == GLFW_RELEASE) return; if (g_hud.KeyDown(tolower(key))) return; @@ -1669,6 +1687,30 @@ callbackError(OpenSubdiv::OsdErrorType err, const char *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) { @@ -1695,26 +1737,43 @@ int main(int argc, char ** argv) initializeShapes(); OsdSetErrorCallback(callbackError); - glfwInit(); + if (not glfwInit()) { + printf("Failed to initialize GLFW\n"); + return 1; + } + + static const char windowTitle[] = "OpenSubdiv glViewer"; + #define CORE_PROFILE #ifdef CORE_PROFILE - 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); + setGLCoreProfile(); #endif -#endif - if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8, - fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) { - printf("Fail to open window.\n"); + +#if GLFW_VERSION_MAJOR>=3 + if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, + fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL))) { + printf("Failed to open window.\n"); glfwTerminate(); 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__) #ifdef CORE_PROFILE @@ -1722,7 +1781,7 @@ int main(int argc, char ** argv) glewExperimental = true; #endif 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); } #ifdef CORE_PROFILE @@ -1741,14 +1800,18 @@ int main(int argc, char ** argv) initHUD(); callbackModel(g_currentShape); - glfwSetKeyCallback(keyboard); - glfwSetMousePosCallback(motion); - glfwSetMouseButtonCallback(mouse); - glfwSetWindowSizeCallback(reshape); - while (g_running) { idle(); display(); + +#if GLFW_VERSION_MAJOR>=3 + glfwPollEvents(); + glfwSwapBuffers(g_window); +#else + glfwSwapBuffers(); +#endif + + glFinish(); } uninitGL(); diff --git a/examples/ptexViewer/viewer.cpp b/examples/ptexViewer/viewer.cpp index 2ed3b72a..704f9776 100755 --- a/examples/ptexViewer/viewer.cpp +++ b/examples/ptexViewer/viewer.cpp @@ -59,13 +59,18 @@ #include #define GLFW_INCLUDE_GL3 #define GLFW_NO_GLU - #include #else #include #include #if defined(WIN32) #include #endif +#endif + +#if defined(GLFW_VERSION_3) + #include + GLFWwindow* g_window=0; +#else #include #endif @@ -470,7 +475,11 @@ OpenSubdiv::HbrMesh * createPTexGeo(PtexTexture * r) //------------------------------------------------------------------------------ void +#if GLFW_VERSION_MAJOR>=3 +reshape(GLFWwindow *, int width, int height) { +#else reshape(int width, int height) { +#endif g_width = width; g_height = height; @@ -1374,19 +1383,22 @@ display() { g_hud.DrawString(10, -60, "GPU Draw : %.3f ms", drawGpuTime); g_hud.DrawString(10, -40, "CPU Draw : %.3f ms", drawCpuTime); g_hud.DrawString(10, -20, "FPS : %3.1f", averageFps); + + g_hud.Flush(); } - g_hud.Flush(); - - glfwSwapBuffers(); glFinish(); - // checkGLErrors("draw end"); + checkGLErrors("draw end"); } //------------------------------------------------------------------------------ static void +#if GLFW_VERSION_MAJOR>=3 +mouse(GLFWwindow *, int button, int state) { +#else mouse(int button, int state) { +#endif if (button == 0 && state == GLFW_PRESS && g_hud.MouseClick(g_prev_x, g_prev_y)) 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]) { // orbit @@ -1563,7 +1580,11 @@ static void toggleFullScreen() { //------------------------------------------------------------------------------ void +#if GLFW_VERSION_MAJOR>=3 +keyboard(GLFWwindow *, int key, int event) { +#else keyboard(int key, int event) { +#endif if (event == GLFW_RELEASE) 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("%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) { @@ -1679,26 +1725,43 @@ int main(int argc, char ** argv) { return 1; } - glfwInit(); + if (not glfwInit()) { + printf("Failed to initialize GLFW\n"); + return 1; + } + + static const char windowTitle[] = "OpenSubdiv glViewer"; + #define CORE_PROFILE #ifdef CORE_PROFILE - 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); + setGLCoreProfile(); #endif -#endif - if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8, - fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) { - printf("Fail to open window.\n"); + +#if GLFW_VERSION_MAJOR>=3 + if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, + fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL))) { + printf("Failed to open window.\n"); glfwTerminate(); 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__) #ifdef CORE_PROFILE @@ -1706,7 +1769,7 @@ int main(int argc, char ** argv) { glewExperimental = true; #endif 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); } #ifdef CORE_PROFILE @@ -1732,11 +1795,6 @@ int main(int argc, char ** argv) { initGL(); 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'); #ifdef OPENSUBDIV_HAS_OPENMP g_hud.AddRadioButton(0, "OPENMP", false, 10, 30, callbackKernel, kOPENMP, 'k'); @@ -1894,6 +1952,15 @@ int main(int argc, char ** argv) { while (g_running) { idle(); display(); + +#if GLFW_VERSION_MAJOR>=3 + glfwPollEvents(); + glfwSwapBuffers(g_window); +#else + glfwSwapBuffers(); +#endif + + glFinish(); } error: