arobenko / embxx

embxx - Embedded C++ Library
GNU General Public License v3.0
263 stars 36 forks source link

fix embxx_add_cpp11_support when crosscompiling #10

Closed ajneu closed 8 years ago

ajneu commented 8 years ago

Hi,

currently the project embxx_on_rpi will fail when using develop branch. Try it!

The reason, is embxx/cmake/CompilerOptionsFuncs.cmake (on branch develop), where set (CMAKE_CXX_STANDARD 11) is not taken(!!!), in the special case when the cross-compiler if forced with

cmake_force_c_compiler(  "${CROSS_COMPILE}gcc" GNU)
cmake_force_cxx_compiler("${CROSS_COMPILE}g++" GNU)

which occurs in the project embxx_on_rpi.

This is a problem that's described in the cmake bugtracker here.

The solution is to still use the old-style embxx_add_cxx_flags("--std=c++0x"), in cases where we are cross-compiling: Fixed in this pull-request -> Here cross-compilation can be nicely detected with the condition (DEFINED CMAKE_CROSSCOMPILING), where CMAKE_CROSSCOMPILING will be automatically set when CMAKE_SYSTEM_NAME is set (ref), which is the case in embxx_on_rpi.

(For CMake Version 3.6 and newer, set (CMAKE_CXX_STANDARD 11) will work, since one does not need to force the compiler, but can then use: set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY))

. .

The other change in the commit is: test_std_streambuf_access does not depend on boost.

arobenko commented 8 years ago

I've modified the logic of using the old way of setting flags. Please review.

ajneu commented 8 years ago

Please review.

OK -- reviewed here

arobenko commented 8 years ago

I fixed, the reported problem. Albert, can you please test it in your environment? I'm still using Ubuntu 14.04 as my primary development environment with cmake 2.8.12 and gcc 4.8, haven't had a chance to migrate to Ubuntu 16.04 yet.

ajneu commented 8 years ago

It's working nicely. I'm using Debian Stretch (aka Debian Testing... which is the testing release of debian), setup as shown here: https://github.com/ajneu/gnu_linux_cpp

The develop branches are working nicely! All good. Debian Stretch's cmake is 3.5.2 (ref). I also tested with the latest cmake 3.6+ (compiled from source as show at the bottom of this comment) and that also works.

haven't had a chance to migrate to Ubuntu 16.04 yet.

You could also set up a docker container. Or use a schroot. (If I find some time, I will look at these methods more closely myself, as they allow one to easily switch between distros and releases)