www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - cmake, ldc, and cross compiling

reply Dan Olson <zans.is.for.cans yahoo.com> writes:
When I build ldc as cross compiler to iOS (armv7-apple-darwin), I'd like
to:

- use gcc-4.8 to compile ldc to host
- use clang llvm to cross compile runtime C code to iOS

cmake seems to only have room from one C compiler.  Is there a way
around this?

I was initially able to get away with using clang for both since I built
it with all targets enabled.  Now I switched from clang to gcc for ldc
build since llvm trunk insists on a newer stdc++.  Installing gcc-4.8
from macports was my solution.

I think supporting different compilers for ldc and runtime/phobos should
be expected when cross compiling though.

Also, I'd like to add something like CACHE to RT_CFLAGS so that it can
be set with cmake.  This will let the runtime C compiler be invoked with
cross compile flags  like this:

set(RT_CFLAGS "-target armv7-apple-darwin -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk")

I have just been editing the CMakeLists.txt for now to set these flags.

-- 
Dan
Jan 21 2014
next sibling parent "Kai Nacke" <kai redstar.de> writes:
Hi Dan!

On Tuesday, 21 January 2014 at 08:23:45 UTC, Dan Olson wrote:
 When I build ldc as cross compiler to iOS (armv7-apple-darwin), 
 I'd like
 to:

 - use gcc-4.8 to compile ldc to host
 - use clang llvm to cross compile runtime C code to iOS

 cmake seems to only have room from one C compiler.  Is there a 
 way
 around this?
You want to use a target compiler and a host compiler. This is possible with CMake. See here: http://www.cmake.org/Wiki/CMake_Cross_Compiling The bad news is that the current CMake files do not support this https://github.com/ldc-developers/ldc/issues/490.)
 I was initially able to get away with using clang for both 
 since I built
 it with all targets enabled.  Now I switched from clang to gcc 
 for ldc
 build since llvm trunk insists on a newer stdc++.  Installing 
 gcc-4.8
 from macports was my solution.
clang 3.3 should suffice, too. (But I don't know if it is available in precompiled form.)
 I think supporting different compilers for ldc and 
 runtime/phobos should
 be expected when cross compiling though.
Yes, it is common setup. See above.
 Also, I'd like to add something like CACHE to RT_CFLAGS so that 
 it can
 be set with cmake.  This will let the runtime C compiler be 
 invoked with
 cross compile flags  like this:

 set(RT_CFLAGS "-target armv7-apple-darwin -isysroot
 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk")
Also a reasonable wish.
 I have just been editing the CMakeLists.txt for now to set 
 these flags.
We currently have no concept how to setup a cross compiler chain. All your thoughts are reasonable but not yet integrated into our CMake files. Regards, Kai
Jan 21 2014
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2014-01-21 09:23, Dan Olson wrote:
 When I build ldc as cross compiler to iOS (armv7-apple-darwin), I'd like
 to:

 - use gcc-4.8 to compile ldc to host
Why don't you use Clang to compile LDC? -- /Jacob Carlborg
Jan 21 2014
parent reply Dan Olson <zans.is.for.cans yahoo.com> writes:
Jacob Carlborg <doob me.com> writes:

 On 2014-01-21 09:23, Dan Olson wrote:
 When I build ldc as cross compiler to iOS (armv7-apple-darwin), I'd like
 to:

 - use gcc-4.8 to compile ldc to host
Why don't you use Clang to compile LDC?
Hi Jacob, I am more familar with gcc, so just went with gcc-4.8 that I knew would have a modern std c++ lib. That's the only reason. The std c++ lib shipped with xcode did not pass the llvm configure sniff test. For example: CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoo chain/usr/bin/clang CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoo chain/usr/bin/clang ../llvm-svn/configure --target=armv7-apple-darwin ... checking whether Clang will select a modern C++ standard library... no configure: error: We detected a missing feature in the standard C++ library that was known to be missing in libstdc++4.6 and implemented in libstdc++4.7. There are numerous C++11 problems with 4.6's library, and we don't support GCCs or libstdc++ older than 4.7. You will need to update your system and ensure Clang uses the newer standard library. If this error is incorrect or you need to force things to work, you may pass '--disable-compiler-version-checks' to configure to bypass this test.
Jan 22 2014
parent reply Jacob Carlborg <doob me.com> writes:
On 2014-01-23 06:00, Dan Olson wrote:

 Hi Jacob,

 I am more familar with gcc, so just went with gcc-4.8 that I knew would
 have a modern std c++ lib.  That's the only reason.
I see. These days Clang is the preferred compiler on OS X.
 The std c++ lib shipped with xcode did not pass the llvm configure sniff test.
I would assume you can use libc++. Both the OS X 10.8 and 10.9 SDK's contain libc++. -- /Jacob Carlborg
Jan 23 2014
parent reply Dan Olson <zans.is.for.cans yahoo.com> writes:
Jacob Carlborg <doob me.com> writes:

 On 2014-01-23 06:00, Dan Olson wrote:

 Hi Jacob,

 I am more familar with gcc, so just went with gcc-4.8 that I knew would
 have a modern std c++ lib.  That's the only reason.
I see. These days Clang is the preferred compiler on OS X.
 The std c++ lib shipped with xcode did not pass the llvm configure sniff test.
I would assume you can use libc++. Both the OS X 10.8 and 10.9 SDK's contain libc++.
LLVM configure didn't seem to like my installed clang. I though of just building libc++. Or I could use prebuilt here: http://llvm.org/releases/3.4/clang+llvm-3.4-x86_64-apple-darwin10.9.tar.gz Or maybe use mac port clang-3.5?
Jan 23 2014
parent reply Jacob Carlborg <doob me.com> writes:
On 2014-01-23 09:32, Dan Olson wrote:

 LLVM configure didn't seem to like my installed clang.  I though of just
 building libc++.
Which Clang do you use.
 Or I could use prebuilt here:

 http://llvm.org/releases/3.4/clang+llvm-3.4-x86_64-apple-darwin10.9.tar.gz

 Or maybe use mac port clang-3.5?
Apple is still at Clang 3.2, probably for good reasons. -- /Jacob Carlborg
Jan 23 2014
next sibling parent reply Dan Olson <zans.is.for.cans yahoo.com> writes:
Jacob Carlborg <doob me.com> writes:

 On 2014-01-23 09:32, Dan Olson wrote:

 LLVM configure didn't seem to like my installed clang.  I though of just
 building libc++.
Which Clang do you use.
 Or I could use prebuilt here:

 http://llvm.org/releases/3.4/clang+llvm-3.4-x86_64-apple-darwin10.9.tar.gz

 Or maybe use mac port clang-3.5?
Apple is still at Clang 3.2, probably for good reasons.
Hi Jacob, I have not updated OSX in a while, at 10.8.5, but I have a fairly recent Xcode at 5.0.2. $ type clang clang is /usr/bin/clang $ clang --version Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.5.0 Thread model: posix $ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoo chain/usr/bin/clang --version Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) Target: x86_64-apple-darwin12.5.0 Thread model: posix
Jan 23 2014
parent Jacob Carlborg <doob me.com> writes:
On 2014-01-23 17:53, Dan Olson wrote:

 Hi Jacob,

 I have not updated OSX in a while, at 10.8.5, but I have a fairly recent
 Xcode at 5.0.2.
Same here.
 $ type clang
 clang is /usr/bin/clang

 $ clang --version
 Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
 Target: x86_64-apple-darwin12.5.0
 Thread model: posix

 $ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoo
chain/usr/bin/clang --version
 Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
 Target: x86_64-apple-darwin12.5.0
 Thread model: posix
Hmm, that must have happened quite recently. I have the same version. -- /Jacob Carlborg
Jan 23 2014
prev sibling parent Dan Olson <zans.is.for.cans yahoo.com> writes:
Jacob Carlborg <doob me.com> writes:

 On 2014-01-23 09:32, Dan Olson wrote:

 LLVM configure didn't seem to like my installed clang.  I though of just
 building libc++.
Which Clang do you use.
 Or I could use prebuilt here:

 http://llvm.org/releases/3.4/clang+llvm-3.4-x86_64-apple-darwin10.9.tar.gz

 Or maybe use mac port clang-3.5?
Apple is still at Clang 3.2, probably for good reasons.
Stumbled into this on libc++ web page: clang++ -stdlib=libc++ So yes, you were correct Jacob, I can use default clang on OSX to build trunk llvm. Just have to feed this flag to llvm configure and it now happy. It must default to libstdc++. CXXFLAGS='-stdlib=libc++' ../llvm-svn/configure Looks like llvm trunk is building fine this way. -- Dan
Jan 24 2014