Add "CMake -E write" command
I suggest touch-like behavior (in terms of empty file creation), but always overwrite file contents with "" in case of already existing file.
In one of projects I had to change touch
to copy
to always overwrite existing file:
add_custom_target(skymp5-functions-lib ALL
SOURCES ${sources}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/dist/server/gamemode.js
)
I quick-fixed the code by using cmake -E copy
:
# create an empty file
file(WRITE "${CMAKE_BINARY_DIR}/empty_file" "")
# copy since we can't do `cmake -E write` yet
add_custom_target(skymp5-functions-lib ALL
SOURCES ${sources}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/empty_file ${CMAKE_BINARY_DIR}/dist/server/gamemode.js
)
However I think it could be better if we could call cmake -E something to do the job, without anything else:
add_custom_target(skymp5-functions-lib ALL
SOURCES ${sources}
COMMAND ${CMAKE_COMMAND} -E write ${CMAKE_BINARY_DIR}/dist/server/gamemode.js ""
)
Please let me know if this functionality already exists. If not, please tell me if write
is a good name in this case or not, etc
Other possible options could be:
cmake -e echo --out-file <filepath> "<text>"
-
cmake -E "file(WRITE foo bar)"
(new script-mode-like mode)
Thank you in advance!
Edited by Leonid Pospelov