0

I want to copy files/folders containing special characters for further use in unit tests and want the files to be overwritten on change.

The OS is Windows, The OS Standard Language is English, CMake Version is 3.18.0, The Generator is Ninja

This is the relevant content of the CMakeLists.txt

...
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/data/"
    COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/data/abcüßöϴABC.txt" "${CMAKE_CURRENT_BINARY_DIR}/data/abcüßöϴABC.txt"
...

This is the output of cmake when running in CMD:

...
Error copying file (if different) from "D:/source_folder/data/abcÔö£ÔòØÔö£ãÆÔö£├é┬ñÔöñABC.txt" to "D:/binary_folder/data/abcÔö£ÔòØÔö£ãÆÔö£├é┬ñÔöñABC.txt".
Batch file failed at line 28 with errorcode 1

According to Notepad++ the CMakeLists.txt is UTF-8 encoded and has Windows Line Endings (CR LF).

Using ${CMAKE_COMMAND} -E copy_directory I did not see any change in the target file, when the source file was updated.

I found an Issue regarding this topic, but I am not sure whether I can circumvent the problem using different cmake-commands.

bigla
  • 88
  • 6
  • Do you think `chcp` might change the situation? – bigla Aug 07 '20 at 11:53
  • Using chcp 65001 in my scripts before invoking cmake made it work. – bigla Aug 07 '20 at 12:23
  • I also assume instead of using `add_custom_command` i shall rather `add_custom_target` and let the original project depend on that custom target, so that copying will run on every build. (This might also enable the copy_directory command solution) – bigla Aug 07 '20 at 12:39
  • By the way this [SO Question] (https://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using) has an excellent answer regarding codepage (chcp) problems. – bigla Aug 07 '20 at 12:55

0 Answers0