Hi Robert,
Here are my updates to the CMake build system for Mac OSX. They correspond to
the following two posts:
OSG Build Error on Mac OSX with XCode 7 and CMake 3.4 (or greater)
(http://forum.openscenegraph.org/viewtopic.php?t=16028)
OSX X11 Build System Failures
(http://forum.openscenegraph.org/viewtopic.php?t=15951)
The changelog is:
* Moved CMAKE_OSX_ARCHITECTURES and CMAKE_OSX_DEPLOYMENT_TARGET before first
call to project() as required by CMake. Fixes configure error produced by CMake
3.4+ on OSX.
* OSX version checks now make use of CMake's built-in
VERSION_[LESS/GREATER/EQUAL] version comparator (cleaner code).
* avfoundation plugin and osgmultitouch/osgoscdevice examples disabled on
OSX/X11 (not supported).
I've attached the changes as a Git patch because there are multiple CMake files
involved:
* CMakeLists.txt
* CMakeModules/FindAVFoundation.cmake
* CMakeModules/FindQuickTime.cmake
* examples/osgmultitouch/CMakeLists.txt
* examples/osgoscdevice/CMakeLists.txt
* src/osgPlugins/avfoundation/CMakeLists.txt
* src/osgViewer/CMakeLists.txt
Ravi
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68188#68188
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4a512b..431cc9e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,6 +49,73 @@ if(COMMAND cmake_policy)
endif()
+IF(APPLE)
+ # Get OSX version in MAJOR.MINOR format
+ EXECUTE_PROCESS(COMMAND sw_vers -productVersion
+ OUTPUT_VARIABLE OSG_OSX_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ STRING(REGEX REPLACE "^([0-9]+\\.[0-9]+).*$" "\\1"
+ OSG_OSX_VERSION "${OSG_OSX_VERSION}")
+ENDIF()
+
+# Set OSX architecture flags here, since they must be specified before
+# creating the actual OSG project
+# Note that the CMAKE_OSX_* variables are not well documented in
+# CMake 2.8, but they do officially exist.
+# See https://cmake.org/Bug/view.php?id=14695#c34953
+IF(APPLE AND NOT ANDROID)
+
+ # Here we check if the user specified IPhone SDK
+ # These options are formally defined later, but can also be specified
+ # by the user at the command line using the cmake -D switch
+ # Note that FORCE is used since the user will likely enable IPhone
+ # build via CMake GUI after already having configured once
+ IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR)
+
+ #set iphone arch and flags taken from
http://sites.google.com/site/michaelsafyan/coding/resources/how-to-guides/cross-compile-for-the-iphone/how-to-cross-compile-for-the-iphone-using-cmake
+ IF(OSG_BUILD_PLATFORM_IPHONE)
+ IF(${IPHONE_VERSION_MIN} LESS "7.0")
+ SET(CMAKE_OSX_ARCHITECTURES "armv6;armv7" CACHE STRING "Build
architectures for iOS" FORCE)
+ ELSE()
+ SET(CMAKE_OSX_ARCHITECTURES "armv7;armv7s;arm64" CACHE STRING "Build
architectures for iOS" FORCE)
+ ENDIF()
+
+ ELSE()
+ #simulator uses i386 architectures
+ SET(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "Build architectures for
iOS Simulator" FORCE)
+ ENDIF()
+
+ #here we set the specific iphone sdk version. We can only set either
device or simulator sdk. So if you want both you currently have to have two
seperate projects
+ SET(CMAKE_OSX_SYSROOT "${IPHONE_SDKROOT}" CACHE STRING "System root for
iOS" FORCE)
+
+ ELSE()
+
+ # Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4
+ # and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support.
+ # These are set the first time CMake is run, and can be changed by
+ # the user at any time.
+ IF(OSG_OSX_VERSION VERSION_GREATER 10.7)
+ # 64 Bit Works, i386,ppc is not supported any more
+ SET(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures
for OSX")
+ SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.8" CACHE STRING "Target OSX version")
+ ELSEIF(OSG_OSX_VERSION VERSION_EQUAL 10.7)
+ # 64 Bit Works, PPC is not supported any more
+ SET(CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build
architectures for OSX")
+ ELSEIF(OSG_OSX_VERSION VERSION_GREATER 10.4)
+ # 64-bit compiles are not supported with Carbon.
+ SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures
for OSX")
+ SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "Target OSX version")
+ ELSEIF(OSG_OSX_VERSION VERSION_EQUAL 10.4)
+ # 64-bit compiles are not supported with Carbon.
+ SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures
for OSX")
+ ELSE()
+ # No Universal Binary support and SDK detection is too unreliable.
+ # Warn user and continue at their own peril.
+ MESSAGE(WARNING "OSX 10.3 and earlier not supported.")
+ ENDIF()
+ ENDIF()
+ENDIF()
+
PROJECT(OpenSceneGraph)
SET(OPENSCENEGRAPH_MAJOR_VERSION 3)
@@ -168,16 +235,6 @@ ENDIF(OSG_MAINTAINER)
IF(NOT ANDROID)
IF(APPLE)
- # Determine the canonical name of the selected Platform SDK
- EXECUTE_PROCESS(COMMAND "/usr/bin/sw_vers" "-productVersion"
- OUTPUT_VARIABLE OSG_OSX_SDK_NAME
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- STRING(REPLACE "." ";" MACOS_VERSION_LIST ${OSG_OSX_SDK_NAME})
- LIST(GET MACOS_VERSION_LIST 0 MACOS_VERSION_MAJOR)
- LIST(GET MACOS_VERSION_LIST 1 MACOS_VERSION_MINOR)
-
- SET(OSG_OSX_SDK_NAME "macosx${MACOS_VERSION_MAJOR}.${MACOS_VERSION_MINOR}")
-
# Trying to get CMake to generate an XCode IPhone project, current efforts
are to get iphoneos sdk 3.1 working
# Added option which needs manually setting to select the IPhone SDK for
building. We can only have one of the below
# set to true. Should realy have an OSG_BUILD_PLATFORM variable that we
set to our desired platform
@@ -1108,30 +1165,19 @@ IF(APPLE AND NOT ANDROID)
# FORCE is used because the options are not reflected in the UI
otherwise.
# Seems like a good place to add version specific compiler flags too.
IF(NOT OSG_CONFIG_HAS_BEEN_RUN_BEFORE)
- IF(${MACOS_VERSION_MAJOR} EQUAL 10 AND ${MACOS_VERSION_MINOR}
GREATER 7)
- SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING
"Forced imageio default image plugin for OSX" FORCE)
- # 64 Bit Works, i386,ppc is not supported any more
- SET(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build
architectures for OSX" FORCE)
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
-mmacosx-version-min=10.8 -fvisibility-inlines-hidden" CACHE STRING "Flags used
by the compiler during all build types." FORCE)
- ELSEIF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.7")
- SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING
"Forced imageio default image plugin for OSX" FORCE)
- # 64 Bit Works, PPC is not supported any more
- SET(CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build
architectures for OSX" FORCE)
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
-mmacosx-version-min=10.7 -fvisibility-inlines-hidden" CACHE STRING "Flags used
by the compiler during all build types." FORCE)
- ELSEIF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.6" OR
${OSG_OSX_SDK_NAME} STREQUAL "macosx10.5")
- SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING
"Forced imageio default image plugin for OSX" FORCE)
- # 64-bit compiles are not supported with Carbon.
- SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build
architectures for OSX" FORCE)
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
-mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE
STRING "Flags used by the compiler during all build types." FORCE)
- ELSEIF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.4")
- SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "quicktime" CACHE STRING
"Forced imageio default image plugin for OSX" FORCE)
- SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build
architectures for OSX" FORCE)
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
-mmacosx-version-min=10.4 -ftree-vectorize -fvisibility-inlines-hidden" CACHE
STRING "Flags used by the compiler during all build types." FORCE)
- ELSE()
- # No Universal Binary support
- # Should break down further to set the -mmacosx-version-min,
- # but the SDK detection is too unreliable here.
- ENDIF()
+ IF(OSG_OSX_VERSION VERSION_GREATER 10.7)
+ SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING
"Forced imageio default image plugin for OSX" FORCE)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
-fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during
all build types." FORCE)
+ ELSEIF(OSG_OSX_VERSION VERSION_EQUAL 10.7)
+ SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING
"Forced imageio default image plugin for OSX" FORCE)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
-fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during
all build types." FORCE)
+ ELSEIF(OSG_OSX_VERSION VERSION_GREATER 10.4)
+ SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "imageio" CACHE STRING
"Forced imageio default image plugin for OSX" FORCE)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize
-fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during
all build types." FORCE)
+ ELSEIF(OSG_OSX_VERSION VERSION_EQUAL 10.4)
+ SET(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX "quicktime" CACHE STRING
"Forced imageio default image plugin for OSX" FORCE)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize
-fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during
all build types." FORCE)
+ ENDIF()
ENDIF()
OPTION(OSG_BUILD_APPLICATION_BUNDLES "Enable the building of
applications and examples as OSX Bundles" OFF)
diff --git a/CMakeModules/FindAVFoundation.cmake
b/CMakeModules/FindAVFoundation.cmake
index 21ce76b..efbc260 100644
--- a/CMakeModules/FindAVFoundation.cmake
+++ b/CMakeModules/FindAVFoundation.cmake
@@ -30,11 +30,9 @@ ELSE()
# AVFoundation exists since 10.7, but only 10.8 has all features
necessary for OSG
# so check the SDK-setting
- IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.8" OR ${OSG_OSX_SDK_NAME}
STREQUAL "macosx10.9" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.10" OR
${OSG_OSX_SDK_NAME} STREQUAL "macosx10.11")
- # nothing special here ;-)
- ELSE()
- MESSAGE("AVFoundation disabled for SDK < 10.8")
- SET(AV_FOUNDATION_FOUND "NO")
+ IF(OSG_OSX_VERSION VERSION_LESS 10.8)
+ MESSAGE("AVFoundation disabled for SDK < 10.8")
+ SET(AV_FOUNDATION_FOUND "NO")
ENDIF()
ENDIF()
ENDIF()
diff --git a/CMakeModules/FindQuickTime.cmake b/CMakeModules/FindQuickTime.cmake
index bffc99b..a9ea895 100644
--- a/CMakeModules/FindQuickTime.cmake
+++ b/CMakeModules/FindQuickTime.cmake
@@ -55,19 +55,20 @@ ELSE()
#Quicktime is not supported under 64bit OSX build so we need to detect
it and disable it.
#First check to see if we are running with a native 64-bit compiler
(10.6 default) and implicit arch
IF(NOT CMAKE_OSX_ARCHITECTURES AND CMAKE_SIZEOF_VOID_P EQUAL 8)
- SET(QUICKTIME_FOUND "NO")
+ MESSAGE("Disabling QuickTime on 64-bit architectures")
+ SET(QUICKTIME_FOUND "NO")
+ ELSEIF(OSG_OSX_VERSION VERSION_GREATER 10.6)
+ # Quicktime officially deprecated starting 10.7
+ MESSAGE("Disabling QuickTime because it's not supported by the
selected SDK ${OSG_OSX_VERSION}")
+ SET(QUICKTIME_FOUND "NO")
ELSE()
- #Otherwise check to see if 64-bit is explicitly called for.
- LIST(FIND CMAKE_OSX_ARCHITECTURES "x86_64" has64Compile)
- IF(NOT has64Compile EQUAL -1)
- SET(QUICKTIME_FOUND "NO")
- ENDIF()
- ENDIF()
- # Disable quicktime for >= 10.7, as it's officially deprecated
-
- IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.7" OR ${OSG_OSX_SDK_NAME}
STREQUAL "macosx10.8" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.9" OR
${OSG_OSX_SDK_NAME} STREQUAL "macosx10.10")
- MESSAGE("disabling quicktime because it's not supported by the
selected SDK ${OSG_OSX_SDK_NAME}")
+ #Otherwise check to see if 64-bit is explicitly called for.
+ LIST(FIND CMAKE_OSX_ARCHITECTURES "x86_64" has64Compile)
+ IF(NOT has64Compile EQUAL -1)
+ MESSAGE("Disabling QuickTime on 64-bit architectures")
SET(QUICKTIME_FOUND "NO")
+ ENDIF()
ENDIF()
+
ENDIF()
ENDIF()
diff --git a/examples/osgmultitouch/CMakeLists.txt
b/examples/osgmultitouch/CMakeLists.txt
index 84e80a1..cdf4bdb 100644
--- a/examples/osgmultitouch/CMakeLists.txt
+++ b/examples/osgmultitouch/CMakeLists.txt
@@ -1,3 +1,9 @@
+# On OSX, this example only compiles if using Cocoa
+IF(APPLE AND NOT (OSG_WINDOWING_SYSTEM STREQUAL "Cocoa"))
+ MESSAGE(WARNING "Disabling osgmultitouch example because it requires
OSG_WINDOWING_SYSTEM to be Cocoa")
+ RETURN()
+ENDIF()
+
SET(TARGET_SRC osgmultitouch.cpp )
#### end var setup ###
diff --git a/examples/osgoscdevice/CMakeLists.txt
b/examples/osgoscdevice/CMakeLists.txt
index 4c0ece7..63d4a2c 100644
--- a/examples/osgoscdevice/CMakeLists.txt
+++ b/examples/osgoscdevice/CMakeLists.txt
@@ -1,5 +1,8 @@
-#this file is automatically generated
-
+# On OSX, this example only compiles if using Cocoa
+IF(APPLE AND NOT (OSG_WINDOWING_SYSTEM STREQUAL "Cocoa"))
+ MESSAGE(WARNING "Disabling osgoscdevice example because it requires
OSG_WINDOWING_SYSTEM to be Cocoa")
+ RETURN()
+ENDIF()
SET(TARGET_SRC osgoscdevice.cpp )
#### end var setup ###
diff --git a/src/osgPlugins/avfoundation/CMakeLists.txt
b/src/osgPlugins/avfoundation/CMakeLists.txt
index b09d36e..07b276b 100644
--- a/src/osgPlugins/avfoundation/CMakeLists.txt
+++ b/src/osgPlugins/avfoundation/CMakeLists.txt
@@ -1,3 +1,8 @@
+# AVFoundation plugin only works with OSX/Cocoa (not X11 or Carbon)
+IF(NOT OSG_WINDOWING_SYSTEM STREQUAL "Cocoa")
+ MESSAGE(WARNING "Disabling AVFoundation plugin because it requires
OSG_WINDOWING_SYSTEM to be Cocoa")
+ RETURN()
+ENDIF()
SET(TARGET_SRC
OSXAVFoundationVideo.mm
diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt
index 4872aaf..9456d79 100644
--- a/src/osgViewer/CMakeLists.txt
+++ b/src/osgViewer/CMakeLists.txt
@@ -86,14 +86,11 @@ ELSE()
IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR)
SET(OSG_WINDOWING_SYSTEM "IOS" CACHE STRING "Windowing system type
for graphics window creation, options only IOS.")
ELSE()
- IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.4" OR
- ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.3" OR
- ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.2" OR
- ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.1")
- SET(OSG_WINDOWING_SYSTEM "Carbon" CACHE STRING "Windowing
system type for graphics window creation, options Carbon, Cocoa or X11.")
- ELSE()
- SET(OSG_WINDOWING_SYSTEM "Cocoa" CACHE STRING "Windowing
system type for graphics window creation, options Carbon, Cocoa or X11.")
- ENDIF()
+ IF(OSG_OSX_VERSION VERSION_LESS 10.5)
+ SET(OSG_WINDOWING_SYSTEM "Carbon" CACHE STRING "Windowing system
type for graphics window creation, options Carbon, Cocoa or X11.")
+ ELSE()
+ SET(OSG_WINDOWING_SYSTEM "Cocoa" CACHE STRING "Windowing system
type for graphics window creation, options Carbon, Cocoa or X11.")
+ ENDIF()
ENDIF()
ELSE()
@@ -222,24 +219,28 @@ ELSE()
ENDIF()
ENDIF()
- # X11 on Apple requires X11 library plus OpenGL linking hack on Leopard
+ # X11 on Apple requires X11 version of OpenGL
IF(APPLE)
# hack for finding the iphone opengl es lib
IF(OSG_BUILD_PLATFORM_IPHONE OR
OSG_BUILD_PLATFORM_IPHONE_SIMULATOR)
- SET(OPENGL_INCLUDE_DIR
${IPHONE_SDKROOT}System/Library/Frameworks)
- SET(OPENGL_LIBRARIES
${IPHONE_SDKROOT}System/Library/Frameworks/OpenGLES)
+ SET(OPENGL_INCLUDE_DIR
${IPHONE_SDKROOT}/System/Library/Frameworks)
+ SET(OPENGL_LIBRARIES
${IPHONE_SDKROOT}/System/Library/Frameworks/OpenGLES)
ELSE()
- # Find GL/glx.h
- IF(EXISTS ${CMAKE_OSX_SYSROOT}/usr/X11/include/GL/glx.h)
- SET(OPENGL_INCLUDE_DIR /usr/X11/include)
- SET(OPENGL_LIBRARIES /usr/X11/lib/libGL.dylib)
- ELSEIF(EXISTS ${CMAKE_OSX_SYSROOT}/usr/X11R6/include/GL/glx.h)
- SET(OPENGL_INCLUDE_DIR /usr/X11R6/include)
- SET(OPENGL_LIBRARIES /usr/X11R6/lib/libGL.dylib)
+ IF(NOT X11_FOUND)
+ MESSAGE(ERROR "OSG_WINDOWING_SYSTEM is X11, but no X11
installation was found. Please make sure X11 is properly installed.")
ENDIF()
- INCLUDE_DIRECTORIES(BEFORE SYSTEM ${OPENGL_INCLUDE_DIR})
- SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${OPENGL_LIBRARIES}
${LIB_EXTRA_LIBS})
+ # Get location of X11 libraries (including GL)
+ # Follow name convention used in CMake FindX11 module
+ GET_FILENAME_COMPONENT(X11_X11_LIB_PATH ${X11_X11_LIB}
DIRECTORY)
+
+ # CMake FindOpenGL returns Cocoa OpenGL, so we need to
+ # use the X11 version instead
+ SET(X11_OpenGL_INCLUDE_PATH ${X11_X11_INCLUDE_PATH})
+ SET(X11_OpenGL_LIB ${X11_X11_LIB_PATH}/libGL.dylib)
+ INCLUDE_DIRECTORIES(BEFORE SYSTEM ${X11_OpenGL_INCLUDE_PATH})
+
+ SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${X11_OpenGL_LIB}
${LIB_EXTRA_LIBS})
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}
-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
ENDIF()
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org