[CMake] Avoid nested cmake invocation taking parent's info.

Óscar Fuentes ofv at wanadoo.es
Sun Nov 9 20:24:32 EST 2008


Eric NOULARD <eric.noulard at gmail.com>
writes:

>> The problem is in execute_process. The cmake process created by it is
>> taking variable values from the enclosing cmake, so it uses the same
>> compiler, configure variables, etc.
>
> What do you mean by "variables"? 
> CMake one or 
> Environment one?

When cmake is invoked with -DCMAKE_TOOLCHAIN_FILE=foo, the nested cmake
runs as invoked with this definition as well. It takes config-assigned
variables from the parent cmake, too. For instance, while
cross-compiling from Linux to Windows/MinGW, the parent cmake correctly
sets HAVE_WINDOWS_H, but the child cmake sets it too, and so on.

[snip]

> May be it would be possible to "reset" the cross-compile
> setup using appropriate CMAKE_TOOLCHAIN_FILE?
>
> Or you may reverse your scheme,
> Always run a "native" build for building native tool
> and make the native build invoke the Cross build using
>
> EXECUTE_PROCESS(
>  COMMAND ${CMAKE_COMMAND} CMAKE_TOOLCHAIN_FILE=
> ...
> )

Both suggestions seems good, but the idea is to lessen the burden on the
users and make things as simple as possible for them. Both methods
require specific instructions for this project that goes away from the
usual cmake practice and the work they save is negligible.

After some experimentation, using -UCMAKE_TOOLCHAIN_FILE on the
invocation of the nested cmake *sometimes* produces the right
thing. This sequence of commands does the trick:

work $ cmake -DCMAKE_TOOLCHAIN_FILE=mytoolchainfile path/to/source

# the above configures and generates the native build on the `native'
# subdirectory. The native build inherits the variables from the parent
# one.

work $ rm -R -f native/  # Delete the native build dir

# we re-execute cmake:

work $ cmake -DCMAKE_TOOLCHAIN_FILE=mytoolchainfile path/to/source

Now, the native build is correctly configured. On this last invocation
the configure phase for the cross-compile build is skipped, because it
is cached from the previous build. However, the native configure is
re-executed because we deleted it.

-- 
Oscar



More information about the CMake mailing list