How to use CMake to cross-compile for Linux target using Wind River cross-compiler?

We develop an application that runs on Intel processor under Linux using a Wind River toolset. The application is built on Windows using an Eclipse-based IDE, CDT and gnu make, using the Wind River cross-compiler. I want to replace this arrangement with CMake, running on Windows.

I can invoke the cross-compiler from Windows cmd prompt. Neither Cygwin nor MinGW seem to be required (though I may have understood). In my CMakeLists.txt file I specify the compiler:

set(TOOL_PATH "C:/Leda_sdk/sysroots/x86_64-wrlinuxsdk-mingw32/usr/bin/x86_64-wrs-linux/")
set(CROSS_COMPILE "x86_64-wrs-linux-")

When I run CMake:

cmake -G Ninja ..

The test compile fails:

Run Build Command(s):C:/bin/ninja-win/ninja.exe cmTC_d497e
[1/2] Building CXX object CMakeFiles/cmTC_d497e.dir/testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_d497e.exe
FAILED: cmTC_d497e.exe
cmd.exe /C "cd . && C:\Leda_sdk\sysroots\x86_64-wrlinuxsdk-mingw32\usr\bin\x86_64-wrs-linux\x86_64-wrs-linux-g++.exe    CMakeFiles/cmTC_d497e.dir/testCXXCompiler.cxx.obj  -o cmTC_d497e.exe -Wl,--out-implib,libcmTC_d497e.dll.a -Wl,--major-image-version,0,--minor-image-version,0   && cd ."
c:/leda_sdk/sysroots/x86_64-wrlinuxsdk-mingw32/usr/bin/x86_64-wrs-linux/../../libexec/x86_64-wrs-linux/gcc/x86_64-wrs-linux/5.2.0/real-ld.exe: unrecognized option '--out-implib'

I am guessing that this is because CMake is invoking a toolchain that uses MinGW. Am I correct?

How would I fix this please?

Best regards

It sounds like you want to write a toolchain file. Setting the C/C++ compiler from inside CMakeLists.txt won’t work - it has to be set from the command line or from the toolchain file.

Thanks for your answer. I have added a toolchain and it is working ok.