Skip to content

ExternalProject fails when using paths with backslashes on Windows

Consider the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(test LANGUAGES)
include(ExternalProject)

ExternalProject_Add(move_file
    SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
    CONFIGURE_COMMAND type nul > "<SOURCE_DIR>\\test.txt"
    BUILD_COMMAND move "<SOURCE_DIR>\\test.txt" "<BINARY_DIR>"
    INSTALL_COMMAND ""
    LOG_BUILD 1
)

When building it on Windows with CMake v3.12.4, i get the following error:

CMake Error at D:/src/cmake-test/_b/move_file-prefix/src/move_file-stamp/move_file-build-Debug.cmake:16 (message):
    Command failed: The system cannot find the file specified

     'move' 'D:/src/cmake-test  est.txt' 'D:/src/cmake-test/_b/move_file-prefix/src/move_file-build

It looks like \\t from "<SOURCE_DIR>\\test.txt" has turned into \t, which made the path invalid.

However, if we just remove LOG_BUILD 1 argument, it builds without problems.

Edited by Alexander Sharov
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information