Ninja generator fails on Windows when cross-compiling a sharedlib with version
When cross-compiling a sharedlibrary that has a "version" property with Ninja on Windows, it fails:
[5/12] Linking C shared library libhelloshared.so.1
FAILED: libhelloshared.so.1
cmd.exe /C "cd . && G:/WindRiver/vx7_CR0481/compilers/gnu-4.8.1.7/x86-win32/bin/c++pentium.exe -fPIC -m32 -mfpmath=387 -fno-implicit-fp -fno-builtin -fno-omit-frame-pointer -mrtp -fno-strict-aliasing -D_C99 -D_HAS_C9X -std=c99 -fasm -Wall -gdwarf-3 -shared -Wl,-soname,libhelloshared.so.1 -o libhelloshared.so.1 CMakeFiles/helloshared.dir/src/shared/hello.o -LG:/WindRiver/vx7_CR0481/vxworks-7/samples/prebuilt_projects/vsb_vxsim_windows/usr/lib/common/PIC -Wl,-lstdc++ && :"
':' is not recognized as an internal or external command, operable program or batch file.
ninja: build stopped: subcommand failed.
The problem was observed with cmake-3.6.2 and Ninja-1.7.1 on Windows 7. The culprit seems to be cmNinjaNormalTargetGenerator.cxx line 676:
if (!symlinkNeeded) {
vars["POST_BUILD"] = postBuildCmdLine;
} else {
vars["POST_BUILD"] = ":";
symlinkVars["POST_BUILD"] = postBuildCmdLine;
}
Generating ":" as an empty POST_BUILD command seems to be invalid on Windows outside batchfiles, I would suggest generating an empty String instead, or "cd ." for example which works on both Windows and Unix.
Attached is a sample project to reproduce the problem. hello_cmake_sharedlib_cross.zip The archive includes a generated "build-SIMNTgnu-Debug-ninja" folder to look at the ninja files for VxWorks. To reproduce, you'll need some sort of toolchain file for crosscompiling:
mkdir bld
cd bld
cmake -DCMAKE_TOOLCHAIN_FILE=C:\mytoolchain.cmake -G"Eclipse CDT4 - Ninja" ..
cmake --build .