[CMake] Cross compilation and native executables

Brad King brad.king at kitware.com
Thu Jan 28 18:00:26 EST 2010


Guillaume Duhamel wrote:
> file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/c68k)
> execute_process(COMMAND cmake ${CMAKE_CURRENT_SOURCE_DIR}/c68k
>     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/c68k)
> add_custom_target(c68kinc COMMAND cmake --build
> ${CMAKE_CURRENT_BINARY_DIR}/c68k)
> 
> It does run the configuration and build step at the right time, but for
> some reason it detects the cross-compiler instead of the native one ; it almost
> looks like the sub-porjects inherits some values from the "parent" project despite
> being run from a separate CMake process.

The execute_process() will run the child CMake with the same environment
variables that the outer CMake uses.  If you have CC or CXX set for the
cross compiler then the inner project will choose that.

I expect the entire native project uses a different toolchain altogether.
You need to pass this toolchain on the inner cmake command line.
Something like this might work:

execute_process(
  COMMAND cmake ${CMAKE_CURRENT_SOURCE_DIR}/c68k
                -DCMAKE_C_COMPILER=/path/to/native/cc
                -DCMAKE_C_FLAGS=""
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/c68k
  )

-Brad


More information about the CMake mailing list