I read the cmake tutorial, at least a dozen times over now, and it was never clear to me. After being thrown for a loop by the fact that cmake completely ignores shell/environment variables, I finally managed to at least get this to run:
cmake -D CMAKE_CXX_COMPILER=$(which g++) -D CMAKE_C_COMPILER=$(which gcc) -D CMAKE_CXX_FLAGS="-std=c++11" -D CMAKE_C_FLAGS="-std=c++11" -D CMAKE_OSX_ARCHITECTURES="x86_64" .
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/local/bin/gcc
-- Check for working C compiler: /usr/local/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/local/bin/g++
-- Check for working CXX compiler: /usr/local/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found OpenGL: /System/Library/Frameworks/OpenGL.framework
-- Found Freetype: /Users/cdelorme/Documents/packages/tmp/SFML-2.1/extlibs/libs-osx/Frameworks/freetype.framework (found version "2.4.11")
-- Found GLEW: /Users/cdelorme/Documents/packages/tmp/SFML-2.1/extlibs/libs-osx/lib/libGLEW.a
-- Found JPEG: /Users/cdelorme/Documents/packages/tmp/SFML-2.1/extlibs/libs-osx/lib/libjpeg.a
-- Found OpenAL: /System/Library/Frameworks/OpenAL.framework
-- Found SNDFILE: /Users/cdelorme/Documents/packages/tmp/SFML-2.1/extlibs/libs-osx/Frameworks/sndfile.framework
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/cdelorme/Documents/packages/tmp/SFML-2.1
Then I tried to compile with `make` and I ran into this:
make
[ 1%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.o
[ 2%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Err.cpp.o
[ 3%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Lock.cpp.o
[ 4%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Mutex.cpp.o
[ 5%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Sleep.cpp.o
[ 6%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/String.cpp.o
[ 7%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Thread.cpp.o
[ 9%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/ThreadLocal.cpp.o
[ 10%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Time.cpp.o
[ 11%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Unix/ClockImpl.cpp.o
[ 12%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Unix/MutexImpl.cpp.o
[ 13%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Unix/SleepImpl.cpp.o
[ 14%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Unix/ThreadImpl.cpp.o
[ 15%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Unix/ThreadLocalImpl.cpp.o
Linking CXX shared library ../../../lib/libsfml-system.dylib
[ 15%] Built target sfml-system
[ 17%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/Context.cpp.o
[ 18%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/GlContext.cpp.o
[ 19%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/GlResource.cpp.o
[ 20%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/Joystick.cpp.o
[ 21%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/JoystickManager.cpp.o
[ 22%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/Keyboard.cpp.o
[ 23%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/Mouse.cpp.o
[ 25%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/VideoMode.cpp.o
[ 26%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/Window.cpp.o
[ 27%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/WindowImpl.cpp.o
[ 28%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/OSX/cpp_objc_conversion.mm.o
[ 29%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/OSX/cg_sf_conversion.cpp.o
[ 30%] Building CXX object src/SFML/Window/CMakeFiles/sfml-window.dir/OSX/InputImpl.mm.o
/Users/cdelorme/Documents/packages/tmp/SFML-2.1/src/SFML/Window/OSX/InputImpl.mm: In function 'SFOpenGLView* sf::priv::getSFOpenGLViewFromSFMLWindow(const sf::Window&)':
/Users/cdelorme/Documents/packages/tmp/SFML-2.1/src/SFML/Window/OSX/InputImpl.mm:79:30: error: expected ';' before 'in'
for (NSView* subview in subviews) {
^
/Users/cdelorme/Documents/packages/tmp/SFML-2.1/src/SFML/Window/OSX/InputImpl.mm:79:30: error: 'in' was not declared in this scope
/Users/cdelorme/Documents/packages/tmp/SFML-2.1/src/SFML/Window/OSX/InputImpl.mm:79:33: error: expected ';' before 'subviews'
for (NSView* subview in subviews) {
^
make[2]: *** [src/SFML/Window/CMakeFiles/sfml-window.dir/OSX/InputImpl.mm.o] Error 1
make[1]: *** [src/SFML/Window/CMakeFiles/sfml-window.dir/all] Error 2
make: *** [all] Error 2
So building it is unsuccessful, and I'm pretty sure this is an entirely unrelated problem. I'd love to get it working, but I don't know if it makes sense to bring "How to build SFML on OSX 10.9.3 with homebrew'd gcc" into a topic about a bug in the apple clang compiler related to sf::String. Should I open another thread for it?
I was able to compile with this command, leaving clang but setting the `-D_GLIBCXX_FULLY_DYNAMIC_STRING=1` flag:
cmake -D CMAKE_CXX_FLAGS="-stdlib=libc++" -D CMAKE_C_FLAGS="-stdlib=libc++ -D_GLIBCXX_FULLY_DYNAMIC_STRING=1" -D CMAKE_OSX_ARCHITECTURES="x86_64" .
However, I continued to get the same errors when trying to run code that has an sf::String that was declared but never given a value.
---
@Hiura,
I'm sure it's a bug in apples compiler, and I also fully understand why no release is built against a non-apple gcc. I do not understand why anyone would refuse to patch it.
It's a known bug, it has existed for over three years, and placing blame has solved **nothing**. Fact is, SFML on OSX is effected, and in turn any developers on OSX are effected, and I haven't seen a logical reason like:
- It's a difficult bug that extends beyond the `sf::String` class.
- A patch could introduce erratic behavior or slow performance.
- Nobody has submitted a pull request for it that addresses these concerns.
I just do not follow the logic behind the "It's not my fault" reasoning of the discussion around this issue. If not a code patch, how about a comment in the `sf::String` documentation so that developers are made aware of the problem?
---
For now I guess I'm stuck coding around this issue by instantiating all sf::String objects with a space because my environment of choice is being slighted.