admin管理员组

文章数量:1393092

In my CMake project, I want to use libserialport, so I added this snippet, where SOURCE_DIR, TMP_DIR, STAMP_DIR are explicitly set (because I do not like the default CMake directory setup where if prefix is _deps/libserialport, source file end up in _deps/libserialport/src/libserialportDL)

include(ExternalProject)
ExternalProject_Add(libserialportDL
  # place in _deps, so it is together with FetchContent stuff
  # specify SOURCE_DIR, else it becomes _deps/libserialport/src/libserialportDL
  PREFIX      _deps/libserialport
  SOURCE_DIR  _deps/libserialport
  TMP_DIR     _deps/libserialport/tmp
  STAMP_DIR   _deps/libserialport/stamp
  GIT_REPOSITORY git://sigrok/libserialport
  GIT_PROGRESS   TRUE
  # release 0.1.2 ->
  GIT_TAG        21b3dfe5
  UPDATE_COMMAND "" # Skip annoying updates for every build
  BUILD_IN_SOURCE 1
  CONFIGURE_COMMAND bash -c "./autogen.sh && ./configure"
  BUILD_COMMAND make
  INSTALL_COMMAND ""
)

Upon my first make, libserial gets cloned, and I get:

HEAD is now at 21b3dfe Bump libtool and package versions to 1:1:1 and 0.1.2
Error copying file "/path/to/myproject/build/_deps/libserialport/stamp/libserialportDL-gitinfo.txt" to "/path/to/myproject/build/_deps/libserialport/stamp/libserialportDL-gitclone-lastrun.txt".
CMake Error at libserialport/tmp/libserialportDL-gitclone.cmake:64 (message):
  Failed to copy script-last-run stamp file:
  '/path/to/myproject/build/_deps/libserialport/stamp/libserialportDL-gitclone-lastrun.txt'


make[2]: *** [CMakeFiles/libserialportDL.dir/build.make:111: _deps/libserialport/stamp/libserialportDL-download] Error 1
make[1]: *** [CMakeFiles/Makefile2:178: CMakeFiles/libserialportDL.dir/all] Error 2
make: *** [Makefile:104: all] Error 2

As far as I can see, build/_deps/libserialport/stamp/libserialportDL-gitclone-lastrun.txt has not even been created, the stamp folder is empty (which is the likely cause of "Failed to copy"). This is with cmake version 3.17.5.

If I comment the SOURCE_DIR, TMP_DIR, STAMP_DIR lines, delete the build folder contents, and repeat cmake and make again - then libserialportDL builds fine - but I really dislike the directory anization it ends up with.

How can I have a custom stamp folder in an ExternalProject_Add, so the cmake process can build and does not fail?

In my CMake project, I want to use libserialport, so I added this snippet, where SOURCE_DIR, TMP_DIR, STAMP_DIR are explicitly set (because I do not like the default CMake directory setup where if prefix is _deps/libserialport, source file end up in _deps/libserialport/src/libserialportDL)

include(ExternalProject)
ExternalProject_Add(libserialportDL
  # place in _deps, so it is together with FetchContent stuff
  # specify SOURCE_DIR, else it becomes _deps/libserialport/src/libserialportDL
  PREFIX      _deps/libserialport
  SOURCE_DIR  _deps/libserialport
  TMP_DIR     _deps/libserialport/tmp
  STAMP_DIR   _deps/libserialport/stamp
  GIT_REPOSITORY git://sigrok./libserialport
  GIT_PROGRESS   TRUE
  # release 0.1.2 ->
  GIT_TAG        21b3dfe5
  UPDATE_COMMAND "" # Skip annoying updates for every build
  BUILD_IN_SOURCE 1
  CONFIGURE_COMMAND bash -c "./autogen.sh && ./configure"
  BUILD_COMMAND make
  INSTALL_COMMAND ""
)

Upon my first make, libserial gets cloned, and I get:

HEAD is now at 21b3dfe Bump libtool and package versions to 1:1:1 and 0.1.2
Error copying file "/path/to/myproject/build/_deps/libserialport/stamp/libserialportDL-gitinfo.txt" to "/path/to/myproject/build/_deps/libserialport/stamp/libserialportDL-gitclone-lastrun.txt".
CMake Error at libserialport/tmp/libserialportDL-gitclone.cmake:64 (message):
  Failed to copy script-last-run stamp file:
  '/path/to/myproject/build/_deps/libserialport/stamp/libserialportDL-gitclone-lastrun.txt'


make[2]: *** [CMakeFiles/libserialportDL.dir/build.make:111: _deps/libserialport/stamp/libserialportDL-download] Error 1
make[1]: *** [CMakeFiles/Makefile2:178: CMakeFiles/libserialportDL.dir/all] Error 2
make: *** [Makefile:104: all] Error 2

As far as I can see, build/_deps/libserialport/stamp/libserialportDL-gitclone-lastrun.txt has not even been created, the stamp folder is empty (which is the likely cause of "Failed to copy"). This is with cmake version 3.17.5.

If I comment the SOURCE_DIR, TMP_DIR, STAMP_DIR lines, delete the build folder contents, and repeat cmake and make again - then libserialportDL builds fine - but I really dislike the directory anization it ends up with.

How can I have a custom stamp folder in an ExternalProject_Add, so the cmake process can build and does not fail?

Share Improve this question asked Mar 13 at 20:40 sdbbssdbbs 5,5947 gold badges58 silver badges121 bronze badges 4
  • 1 Immediately before the line libserialport/tmp/libserialportDL-gitclone.cmake:64 you could find the exact command which is failed. It is actually cmake -E copy command: github/nextgis/libngsandroid/blob/master/cmake/…. So you may try to run it in the terminal, and find out the exact error message which it causes. – Tsyvarev Commented Mar 13 at 20:52
  • Thanks @Tsyvarev - after the error is reported and make exits, it turns out the libserialportDL-gitclone.cmake file does not exist anymore (at least, running find . -name libserialportDL-gitclone.cmake in the build folder returns nothing; find . -name '*.cmake' | grep libser returns ./CMakeFiles/libserialportDL.dir/{cmake_clean.cmake,DependInfo.cmake}). – sdbbs Commented Mar 14 at 6:22
  • Aha, I had to run cmake ../ --debug-trycompile -DCMAKE_BUILD_TYPE=Debug ... to keep temporary folders; and even after cmake alone, build/_deps/libserialport/stamp/libserialportDL-gitinfo.txt exists in this case. The command that fails is COMMAND ${CMAKE_COMMAND} -E copy ".../build/_deps/libserialport/stamp/libserialportDL-gitinfo.txt" ".../build/_deps/libserialport/stamp/libserialportDL-gitclone-lastrun.txt", and executing this command in terminal after cmake but before make seems to work fine (but running make after manual copy does not get from git, and so fails) – sdbbs Commented Mar 14 at 6:39
  • but even with cmake --debug-trycompile ..., after make is ran (and fails), ./_deps/libserialport/tmp/ directory is deleted, and ./_deps/libserialport/stamp/ is emptied – sdbbs Commented Mar 14 at 6:44
Add a comment  | 

1 Answer 1

Reset to default 0

Ok, I think I understand why this now happens - although I do not have a fix for this:

It turns out, if right after cmake, the file build/_deps/libserialport/tmp/libserialportDL-gitclone.cmake is opened, there is this snippet in it:

# ...
execute_process(
  COMMAND ${CMAKE_COMMAND} -E rm -rf "/path/to/myproject/build/_deps/libserialport"
  RESULT_VARIABLE error_code
  )
if(error_code)
  message(FATAL_ERROR "Failed to remove directory: '/path/to/myproject/build/_deps/libserialport'")
endif()

# try the clone 3 times in case there is an odd git clone issue
# ...

So, yeah - cmake will explicitly delete the SOURCE_DIR of ExternalProject_add before cloning it, which then deletes all the TMP_DIR and STAMP_DIR that were previously set up there by cmake previously. Actually, even https://cmake./cmake/help/latest/module/ExternalProject.html mentions:

Note If a download method is specified, any existing contents of the source directory may be deleted. Only the URL download method checks whether this directory is either missing or empty before initiating the download, stopping with an error if it is not empty. All other download methods silently discard any previous contents of the source directory.

Hmm, guess there is no way around this, then ...

本文标签: CMake ExternalProjectAdd fails copying timestamp files if SOURCEDIR is explicitly setStack Overflow