[CMake] Avoiding absolute paths in toolchain file?

Eric Noulard eric.noulard at gmail.com
Thu Sep 19 08:05:34 EDT 2013


2013/9/19 Johan Holmberg <johan556 at gmail.com>:
> Hi!
>
> I'm trying to use a toolchain file (using -DCMAKE_TOOLCHAIN_FILE=....) to
> cross compile with CMake. I specify my C compiler with:
>
>     set(CMAKE_C_COMPILER my_c_compiler)
>
> I have given just the name of the compiler, and rely on CMake to find the
> compiler via my PATH (and this seems to work). But later in the toolchain
> file I need to refer to files in the same installation tree as
> "my_c_compiler". Specifically the linker variable CMAKE_EXE_LINKER_FLAGS
> needs to contain the path to a configuration file that is located in a
> parallel directory to the compiler:
>
>     <dir_of_compiler>/../lib/
>
> I was hoping that after CMake have found the path to the compiler, it would
> be possible to derive the path to the lib-directory from the compiler path.
> But I don't understand how to do it in the toolchain file.
>
> Is it possible, without hard-coding the path in the toolchain file?

The toolchain file is a cmake script so that you can use the CMake
scripting facility in it
and possibly do something like:

find_program(CMAKE_C_COMPILER NAMES my_c_compiler my_alternate_compiler)
get_filename_component(COMP_PREFIX ${CMAKE_C_COMPILER} DIRECTORY)
set(CMAKE_EXE_LINKER_FLAGS ${COMP_PREFIX}/../lib)


i.e. you can do more than just setting the expected toolchain variables.

-- 
Erk
L'élection n'est pas la démocratie -- http://www.le-message.org


More information about the CMake mailing list