2

I have a (power)shell script that generates a version file used in other source files in the project.

How can I "register" this script to be used with CMake in build time? Here is what I have tried:

function(version)
    set(SRC version.h)
    set(VERSION_CMD ${CMAKE_SOURCE_DIR}/fw_lib/version/version.ps1)
    ADD_CUSTOM_TARGET(version DEPENDS ${SRC})
    ADD_CUSTOM_COMMAND(
        OUTPUT ${SRC} COMMAND ${VERSION_CMD}
        ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
    )
endfunction(version)

Note that ${CMAKE_SOURCE_DIR} and ${CMAKE_BINARY_DIR} are input arguments to the script.

I get the following error:

process_begin: CreateProcess(....) failed.
make (e=193): Error 193

How can I make this work?

1 Answer 1

6

Maybe it is too late, but for future:

# find Powershell executable
find_program(POWERSHELL_PATH NAMES powershell)

add_custom_command(
    TARGET "program"
    POST_BUILD
    COMMAND ${POWERSHELL_PATH} "Some Powershell command")
Sign up to request clarification or add additional context in comments.

1 Comment

Classic Windows powershell is pretty much dead nowadays. New cross-platform Powershell Core uses pwsh.exe instead of powershell.exe. So you may use find_program(POWERSHELL_PATH NAMES pwsh)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.