0

I'm using Visual Studio 2019 combined with CMake to cross compile my project on both PC environment (generating .sln file) and remote Linux machine (Generating Makefile file). I'm switching between the environments using Visual Studio's Cross Compilation feature.

Is it somehow possible to run a Windows batch script on POST_BUILD command even when I'm generating CMake on the Linux environment ?

I want this (or any other solution which will achieve the same) to work even when generating on Linux:

add_custom_command(
    POST_BUILD
    myTarget
    COMMAND cmd /c H:/pathToMyCommand/myCommand.bat
)

(remember that I'm in Windows enviroment as Visual Studio is invoking CMake on the remote Linux machine)

I currently adding a custom command which run a shell script directly from the Linux machine and connecting to the Windows environment, but I prefer to run a batch directly from Windows.

Is it possible?

Alon Adler
  • 3,984
  • 4
  • 32
  • 44
  • I am a little confused by this statement _"I want this (or any other solution which will achieve the same) to work even when generating on Linux:"_ Do you want a windows batch-file solution or a linux solution? – Gerhard Nov 03 '21 at 16:54
  • @Gerhard I want a batch file from Windows will be invoked even if I'm currently generating CMake in the remote Linux Machine. The CMake generation is being initiated from Windows from inside the Visual Studio 2019 Cross Compilation capabilities. I'm aware it is connecting remotely to my Linux Machine but I wonder if I can achieve a POST_BUILD event which will initiate a script in my Windows environment. – Alon Adler Nov 03 '21 at 16:56
  • The host system needs to be able to execute the command specified. Your description of the setup sounds like you cannot run the batch script for the build on the linux remote and even if you had access to cmd on linux, the path `H:/pathToMyCommand/myCommand.bat` would almost certainly not work. Depending on what the bat file does exactly and how complex it is you may be able to use a cmake script instead though which may allow you to replace the bat script with system-independent cmake script logic: `add_custom_command(... COMMAND ${CMAKE_COMMAND} -P myCommand.cmake)` – fabian Nov 03 '21 at 19:59
  • @fabian what so you mean by "system-independent cmake script" logic. Is there special cmake script language which can acheive "batch like" cspabilites (copy files, ftp etc...) which can be executed independently after build finishes? Can you please be more detailed and give some references, thanks. – Alon Adler Nov 03 '21 at 21:58
  • You should be able to use all [cmake scripting commands](https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html?highlight=script#scripting-commands) in a cmake script file. The `file` command provides functionality for copying and uploading files which may be sufficient in your scenario. (The script file uses the exact same syntax as `CMakeLists.txt`.) – fabian Nov 04 '21 at 19:10
  • @fabian thanks, but still - this wont give me the capability to run something on Windows (In Post Build) when I generate CMake on a remote Linux machine. – Alon Adler Nov 06 '21 at 05:44

0 Answers0