[CMake] Ninja: CMD /C, quoting added for PRE_LINK/POST_BUILD

Olsson Gerhard gerhard.olsson at volvo.com
Wed Oct 1 13:45:55 EDT 2014


The commands for PRE_LINK/POST_BUILD is not correctly quoted for Ninja in Windows. 'CMD /C "<command>"' is added to the command, just as Ninja itself does.
(this was maybe different in earlier Ninja versions, but has been around for a couple of years)
(The quoting in the working command is strange, but works.)

A workaround that is not so bad, is to patch build.ninja
Is there a better way?

Note: The lines  LINK_FLAGS ,POST_BUILD ,  PRE_LINK , TARGET_PDB are duplicated in build.ninja. Does not make a difference.

ARM DS-5 compiler (armcc compiler 5.04)
Platform: Windows (Linux used too, but with Unix Makefiles)
CMake 3.0.2
Ninja 1.5.1

/Gerhard


CmakeLists.txt excerpt:

ADD_CUSTOM_COMMAND(
    TARGET ECU
    PRE_LINK
    COMMAND "C:/Program Files/DS-5/bin/armasm.exe" --cpu=Cortex-A9 -g --cpreproc --apcs=interwork --arm --no_unaligned_access --pd "__EVAL SETA 1" --pd "__MICROLIB SETA 1" -Ic:/Temp/includes -o ${CMAKE_CURRENT_BINARY_DIR}/osekasm.o c:/Os/osekasm.s VERBATIM
  )

  #Generate hex, copy to view
  add_custom_command(TARGET ECU POST_BUILD
    COMMAND "C:/Program Files/DS-5/bin/fromelf.exe" --m32combined --output=${CMAKE_CURRENT_BINARY_DIR}/ECU.hex ${CMAKE_CURRENT_BINARY_DIR}/ECU.elf VERBATIM
    COMMAND "C:/cygwin/bin/objcopy" -I elf32-big -O srec --srec-len=32 --srec-forceS3 -j .securityLevel ${CMAKE_CURRENT_BINARY_DIR}/ECU.elf ${CMAKE_CURRENT_BINARY_DIR}/parameter_section.hex VERBATIM
  )


Generated in build.ninja:

  LINK_FLAGS = --cpu=Cortex-A9  c:/Temp/includes/SecModLib.a  -L--list=c:/Temp/build/ECU.map -L--scatter=c:/Zynq7000/scatter.txt  -L--map -L--no_remove -L--symbols -L--info=common,summarysizes,summarystack,sizes,totals,unused,unusedsymbols,veneers C:/Temp/build/osekasm.o
  POST_BUILD = cmd.exe /C "cd /D C:\Temp\build && "C:\Program Files\DS-5\bin\fromelf.exe" --m32combined --output=C:/Temp/build/ECU.hex C:/Temp/build/ECU.elf && C:\cygwin\bin\objcopy -I elf32-big -O srec --srec-len=32 --srec-forceS3 -j .securityLevel C:/Temp/build/ECU.elf C:/Temp/build/parameter_section.hex"
  PRE_LINK = cmd.exe /C "cd /D C:\Temp\build && "C:\Program Files\DS-5\bin\armasm.exe" --cpu=Cortex-A9 -g --cpreproc --apcs=interwork --arm --no_unaligned_access --pd "__EVAL SETA 1" --pd "__MICROLIB SETA 1" -Ic:/Temp/includes -o C:/Temp/build/osekasm.o c:/Temp/Os/osekasm.s && cd C:\Temp\build"
  TARGET_PDB = ECU.elf.dbg


Console output:

[106/107] Linking C executable ECU.elf
FAILED: cmd.exe /C "cmd.exe /C "cd /D C:\Temp\build && "C:\Program Files\DS-5\bin\armasm.exe" --cpu=Cortex-A9 -g --cpreproc --apcs=interwork --arm --no_unaligned_access --pd "__EVAL SETA 1" --pd "__MICROLIB SETA 1" -Ic:/Temp/includes -o C:/Temp/build/osekasm.o c:/Temp/Os/osekasm.s && cd C:\Temp\build" && C:\PROGRA~1\DS-5\bin\armcc.exe    --cpu=Cortex-A9  c:/Temp/includes/SecModLib.a  -L--list=c:/Temp/build/ECU.map -L--scatter=c:/Zynq7000/scatter.txt  -L--map -L--no_remove -L--symbols -L--info=common,summarysizes,summarystack,sizes,totals,unused,unusedsymbols,veneers C:/Temp/build/osekasm.o --via=CMakeFiles/ECU.rsp  -o ECU.elf  && cmd.exe /C "cd /D C:\Temp\build && "C:\Program Files\DS-5\bin\fromelf.exe" --m32combined --output=C:/Temp/build/ECU.hex C:/Temp/build/ECU.elf && C:\cygwin\bin\objcopy -I elf32-big -O srec --srec-len=32 --srec-forceS3 -j .securityLevel C:/Temp/build/ECU.elf C:/Temp/build/parameter_section.hex""
'cmd.exe' is not recognized as an internal or external command,
operable program or batch file.
ninja: build stopped: subcommand failed.


Patched (in Makefile):

${CMAKE_MAKEFILE}: ${CMAKELISTS} ${CMAKE_TOOLCHAIN} | ${CMAKE_BUILD_DIR}
                             @#CMake Ninja uses cmd incorrectly
                             @perl -pi -e 's%^(\s*(POST_BUILD|PRE_LINK)\s*=\s*)cmd.exe\s(/C)?\s*"(.*)"%$$1$$4%i; ' $@



Rules patched OK:

  LINK_FLAGS = --cpu=Cortex-A9  c:/Temp/includes/SecModLib.a  -L--list=c:/Temp/build/ECU.map -L--scatter=c:/Zynq7000/scatter.txt  -L--map -L--no_remove -L--symbols -L--info=common,summarysizes,summarystack,sizes,totals,unused,unusedsymbols,veneers C:/Temp/build/osekasm.o
  POST_BUILD = cd /D C:\Temp\build && "C:\Program Files\DS-5\bin\fromelf.exe" --m32combined --output=C:/Temp/build/ECU.hex C:/Temp/build/ECU.elf && C:\cygwin\bin\objcopy -I elf32-big -O srec --srec-len=32 --srec-forceS3 -j .securityLevel C:/Temp/build/ECU.elf C:/Temp/build/parameter_section.hex
  PRE_LINK = cd /D C:\Temp\build && "C:\Program Files\DS-5\bin\armasm.exe" --cpu=Cortex-A9 -g --cpreproc --apcs=interwork --arm --no_unaligned_access --pd "__EVAL SETA 1" --pd "__MICROLIB SETA 1" -Ic:/Temp/includes -o C:/Temp/build/osekasm.o c:/Temp/Os/osekasm.s && cd C:\Temp\build
  TARGET_PDB = ECU.elf.dbg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141001/685987f9/attachment.html>


More information about the CMake mailing list