CMAKE_OSX_SYSROOT macosx makes CMake pass -isysroot macosx

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
cadabra
Gnoblar
Posts: 22
Joined: Thu Sep 23, 2010 8:32 am
Location: sfbay
x 3

CMAKE_OSX_SYSROOT macosx makes CMake pass -isysroot macosx

Post by cadabra »

I'm running CMake 2.8.9 and failing to compile Ogre from source with the default generator (Makefile).

Code: Select all

cd /Users/cadabra/Library/Caches/builds/ext/ogre/MacOSX/Debug/OgreMain && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++   -DOGRE_NONCLIENT_BUILD -DFREEIMAGE_LIB -D_MT -D_USRDLL -Wno-deprecated -Wall -Wctor-dtor-privacy -Winit-self -Wno-overloaded-virtual -Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter -pedantic -Wshadow -Wno-missing-field-initializers -Wno-long-long -g -DDEBUG -arch i386 -isysroot macosx -I/Users/cadabra/dev/ext/ogre/OgreMain/include -I/Users/cadabra/Library/Caches/builds/ext/ogre/MacOSX/Debug/include -I/Users/cadabra/dev/ext/ogre/OgreMain/include/OSX -I/opt/local/include -I/usr/local/include/freetype2 -I/usr/local/include -I/Users/cadabra/dev/ext/ogre -I/Library/Frameworks/Cg.framework/Headers -F/Library/Frameworks -I/System/Library/Frameworks/Carbon.framework/Headers -I/System/Library/Frameworks/Cocoa.framework/Headers -I/System/Library/Frameworks/CoreVideo.framework/Headers -I/Users/cadabra/dev/ext/ogre/OgreMain/include/Threading -I/Users/cadabra/dev/ext/ogre/OgreMain/src/nedmalloc    -msse -o CMakeFiles/OgreMain.dir/src/OgreAlignedAllocator.cpp.o -c /Users/cadabra/dev/ext/ogre/OgreMain/src/OgreAlignedAllocator.cpp
In file included from /Users/cadabra/dev/ext/ogre/OgreMain/src/OgreAlignedAllocator.cpp:28:
In file included from /Users/cadabra/dev/ext/ogre/OgreMain/include/OgreStableHeaders.h:41:
In file included from /Users/cadabra/dev/ext/ogre/OgreMain/include/OgreArchive.h:31:
/Users/cadabra/dev/ext/ogre/OgreMain/include/OgrePrerequisites.h:33:10: fatal error: 'string' file not found
#include <string>
         ^
1 error generated.
Notice that CMake is passing -isysroot macosx. It seems to be because Ogre is setting CMAKE_OSX_SYSROOT to macosx. Xcode supports symbolic names for the SDK (so XCODE_ATTRIBUTE_SDKROOT is fine), but I think CMake expects a path to a sysroot here. You can get the resolved path from xcodebuild like this:

Code: Select all

xcodebuild -sdk macosx -version Path
Here's a patch:

Code: Select all

$ hg diff
diff -r 4bcb9444eb17 CMake/Templates/SDK_CMakeLists.txt.in
--- a/CMake/Templates/SDK_CMakeLists.txt.in	Fri Aug 10 11:35:27 2012 -0700
+++ b/CMake/Templates/SDK_CMakeLists.txt.in	Wed Oct 24 00:11:20 2012 -0700
@@ -81,10 +81,11 @@
 endif ()
 if (APPLE AND OGRE_BUILD_PLATFORM_APPLE_IOS)
   # Set build variables
-  set(CMAKE_OSX_SYSROOT iphoneos)
+  set(XCODE_ATTRIBUTE_SDKROOT iphoneos)
+  execute_process(COMMAND xcodebuild -version -sdk "${XCODE_ATTRIBUTE_SDKROOT}" Path | head -n 1 OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
+  string(REGEX REPLACE "(\r?\n)+$" "" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
   set(CMAKE_OSX_DEPLOYMENT_TARGET "")
   set(CMAKE_EXE_LINKER_FLAGS "-framework Foundation -framework CoreGraphics -framework QuartzCore -framework UIKit")
-  set(XCODE_ATTRIBUTE_SDKROOT iphoneos)
   set(OGRE_BUILD_RENDERSYSTEM_GLES TRUE CACHE BOOL "Forcing OpenGL ES RenderSystem for iOS" FORCE)
   set(OGRE_BUILD_RENDERSYSTEM_GLES2 TRUE CACHE BOOL "Forcing OpenGL ES 2 RenderSystem for iOS" FORCE)
   set(OGRE_STATIC TRUE CACHE BOOL "Forcing static build for iOS" FORCE)
@@ -174,9 +175,9 @@
   if (OGRE_BUILD_PLATFORM_APPLE_IOS)
     include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/OGRE/iOS")
   else ()
-    # Set 10.5 as the base SDK by default
     set(XCODE_ATTRIBUTE_SDKROOT macosx)
-    set(CMAKE_OSX_SYSROOT macosx)
+    execute_process(COMMAND xcodebuild -version -sdk "${XCODE_ATTRIBUTE_SDKROOT}" Path | head -n 1 OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
+    string(REGEX REPLACE "(\r?\n)+$" "" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
     set(CMAKE_OSX_DEPLOYMENT_TARGET 10.5)
     set(CMAKE_OSX_ARCHITECTURES ${ARCHS_STANDARD_32_64_BIT})
     include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/OGRE/OSX"
diff -r 4bcb9444eb17 CMakeLists.txt
--- a/CMakeLists.txt	Fri Aug 10 11:35:27 2012 -0700
+++ b/CMakeLists.txt	Wed Oct 24 00:11:20 2012 -0700
@@ -217,10 +217,11 @@
   include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/iOS")
 
   # Set build variables
-  set(CMAKE_OSX_SYSROOT iphoneos)
+  set(XCODE_ATTRIBUTE_SDKROOT iphoneos)
+  execute_process(COMMAND xcodebuild -version -sdk "${XCODE_ATTRIBUTE_SDKROOT}" Path | head -n 1 OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
+  string(REGEX REPLACE "(\r?\n)+$" "" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
   set(CMAKE_OSX_DEPLOYMENT_TARGET "")
   set(CMAKE_EXE_LINKER_FLAGS "-framework Foundation -framework CoreGraphics -framework QuartzCore -framework UIKit")
-  set(XCODE_ATTRIBUTE_SDKROOT iphoneos)
   set(XCODE_ATTRIBUTE_GCC_UNROLL_LOOPS "YES")
   set(XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer")
   set(XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
@@ -236,9 +237,9 @@
   remove_definitions(-msse)
 elseif (APPLE AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS)
 
-  # Set 10.5 as the base SDK by default
   set(XCODE_ATTRIBUTE_SDKROOT macosx)
-  set(CMAKE_OSX_SYSROOT macosx)
+  execute_process(COMMAND xcodebuild -version -sdk "${XCODE_ATTRIBUTE_SDKROOT}" Path | head -n 1 OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
+  string(REGEX REPLACE "(\r?\n)+$" "" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
   set(CMAKE_OSX_DEPLOYMENT_TARGET 10.5)
 
   if (NOT CMAKE_OSX_ARCHITECTURES)
Sonblind
Gnoblar
Posts: 1
Joined: Sat Apr 06, 2013 11:55 pm

Re: CMAKE_OSX_SYSROOT macosx makes CMake pass -isysroot maco

Post by Sonblind »

This worked for me on OSX 10.8.

For whover needs this fix next, just run that line in the terminal and paste what ever it prints into the CMakeList.txt in place of the the Sysroot line. Cmake should find all the dependencies after this.
axelon
Gnoblar
Posts: 1
Joined: Sun Apr 07, 2013 2:11 am

Re: CMAKE_OSX_SYSROOT macosx makes CMake pass -isysroot maco

Post by axelon »

This small patch worked for me as well. Hopefully it can get ported in to the main version.
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: CMAKE_OSX_SYSROOT macosx makes CMake pass -isysroot maco

Post by masterfalcon »

Thanks! I'll try to check this out tomorrow.