[CMake] set ranlib/ar in toolchain file
Yngve Inntjore Levinsen
yngve.levinsen at gmail.com
Thu Jul 5 03:24:31 EDT 2012
Hi Eric,
Thanks for your suggestion. If one shouldn't set RANLIB/AR oneself, then I find
it a bit confusing that the information about those variables are listed here:
http://www.cmake.org/Wiki/CMake_Useful_Variables
But perhaps that list is meant for different stuff?
Your suggestion did not set the right ranlib/ar binaries. I did have a look in
the file CMakeFindBinUtils.cmake, where a suggestion of setting
_CMAKE_TOOLCHAIN_PREFIX came up. This actually worked.
Not sure if it is expected to work though, so I would be happy to hear if
someone has the "official" solution. If it is expected, perhaps one could add
the information about how this variable work to the Wiki pages for toolchains?
Perhaps one could use this variable also when searching for the compilers and
linkers?
Cheers,
Yngve
On Wednesday 4. July 2012 22.19.49, Eric Noulard wrote:
> 2012/7/4 Yngve Inntjore Levinsen <yngve.levinsen at gmail.com>:
> > Hi,
> >
> > I try to set up my toolchain file for building Windows executables in a
> > Linux environment. I started with the example from
> > http://www.cmake.org/Wiki/CmakeMingw
> >
> > The only thing I noticed was that I needed to use "ar" and "ranlib" from
> > MinGW as well, for creating the archives. I can do this by manually
> > editing the file CMakeFiles/CMakeCXXCompiler.cmake after cmake has run.
> > Code compiles successfully.
> >
> > I then tried to add the following two lines to the toolchain file:
> > SET(CMAKE_AR i486-mingw32-ar)
> > SET(CMAKE_RANLIB i486-mingw32-ranlib)
>
> You shouldn't need to set CMAKE_AR or CMAKE_RANLIB yourself.
> Could you try the toolchain file I uploaded here
> http://www.cmake.org/Wiki/images/c/c2/Toolchain-cross-mingw32-linux.cmake
>
> (refered on the very same page you used:
> http://www.cmake.org/Wiki/CmakeMingw)
>
> If you SET(COMPILER_PREFIX "i486-mingw32")
> it should work out of the box.
>
> > (yes, the prefix for my MinGW install is different from the example)
> >
> > Sadly, that makes the initial compiler test fail. For fortran it actually
> > still works, but the test fails for c and c++. I have tried to search for
> > a
> > while without finding out what I do wrong. Please tell me. Or ask if
> > something is unclear.
>
> What is the exact command line you used when invoking CMake with you
> Toolchain file ?
>
> Did you try from a pristine build tree?
>
> Using the provided toolchain, after you updated with the proper prefix
> if you put the toolchain file at the root of your source tree, then you can
> do:
>
> cd sourcedir
> mkdir build-win32
> cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-cross-mingw32-linux.cmake ..
>
> should work as expected without tweaking AR or RANLIB.
More information about the CMake
mailing list