cmake -E touch: failed to update "[...] src/libmodbus-stamp/libmodbus-download".

121 views
Skip to first unread message

Eric Scöerg

unread,
Mar 4, 2022, 12:05:28 PM3/4/22
to libmodbus
Hi,

I am currently following

This lobmodbus/issue

to include Modbus as a static library in my C++ code. My project structure is slightly different from the issue, like

project dir/
| -- CMakeLists.txt
| -- mylib.cpp
| -- mylib.h
| -- external/
| -- | -- modbus.cmake
| -- | -- libmodbus (git submodule)
| -- | -- | -- | build dir/

Yet the CmakeLists.txt


### Include Libraries ###
include("${CMAKE_SOURCE_DIR}/external/modbus.cmake")
### END Include Libraries ###

### Project Source Files ###
#Source Files
set(SOURCE_FILES communication.cpp)
add_library(communication ${SOURCE_FILES})
### END Project Source Files ###

### Library Linking ###
target_link_libraries(
${PROJECT_NAME}
PRIVATE modbus
)
### END Library Linking ###

and Modbus.cmake

# Downloads and builds the modbus library
#
# Based on
# Download: https://www.foonathan.net/2016/07/cmake-dependency-handling/
# Building: https://github.com/stephane/libmodbus/issues/482

### Download ###
find_path(MODBUS_INCLUDE_DIR ...)
if((NOT MODBUS_INCLUDE_DIR) OR (NOT EXISTS ${MODBUS_INCLUDE_DIR}))
# we couldn't find the header files for Modbus or they don't exist
message("Couldn't find Modbus Library. Downloading https://github.com/stephane/libmodbus as git submodule.")
# now we need to clone this submodule
execute_process(COMMAND git submodule add https://github.com/stephane/libmodbus WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/external)
execute_process(COMMAND git submodule update --init -- "${CMAKE_CURRENT_SOURCE_DIR}/external")
else()
# Nothing
endif()
### END Download ###

### Building ###
# Make libmodbus build directory
execute_process(COMMAND mkdir -p "${CMAKE_CURRENT_SOURCE_DIR}/external/libmodbus/build")
#
include(ExternalProject)
set(MODBUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/libmodbus")
set(MODBUS_BIN "${MODBUS_DIR}/build")
set(MODBUS_STATIC_LIB "${MODBUS_BIN}/libmodbus.a")
set(MODBUS_INCLUDES "${MODBUS_DIR}/src")

ExternalProject_Add(
libmodbus
PREFIX ${MODBUS_BIN}
SOURCE_DIR ${MODBUS_DIR}
DOWNLOAD_COMMAND cd ${MODBUS_DIR} && git clean -dfX && ${MODBUS_DIR}/autogen.sh
CONFIGURE_COMMAND ${MODBUS_DIR}/configure --srcdir=${MODBUS_DIR} --prefix=${MODBUS_BIN} --enable-static=yes --disable-shared
BUILD_COMMAND make
INSTALL_COMMAND make install
BUILD_BYPRODUCTS ${MODBUS_STATIC_LIB}
)

add_library(modbus STATIC IMPORTED GLOBAL)

add_dependencies(modbus libmodbus)

set_target_properties(modbus PROPERTIES IMPORTED_LOCATION ${MODBUS_STATIC_LIB})
set_target_properties(modbus PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${MODBUS_INCLUDES})
### END Building ###


are almost identical. Currently though, the build output will be

====================[ Build | libmodbus | Debug ]===============================
/snap/clion/180/bin/cmake/linux/bin/cmake --build /home/eric/Software/lem_rc/libraries/communication/build --target libmodbus
[2/8] Performing download step for 'libmodbus'
FAILED: ../external/libmodbus/build/src/libmodbus-stamp/libmodbus-download /home/eric/Software/lem_rc/libraries/communication/external/libmodbus/build/src/libmodbus-stamp/libmodbus-download
cd /home/eric/Software/lem_rc/libraries/communication/external/libmodbus/build/src && cd /home/eric/Software/lem_rc/libraries/communication/external/libmodbus && git clean -dfX && /home/eric/Software/lem_rc/libraries/communication/external/libmodbus/autogen.sh && /snap/clion/180/bin/cmake/linux/bin/cmake -E touch /home/eric/Software/lem_rc/libraries/communication/external/libmodbus/build/src/libmodbus-stamp/libmodbus-download
Removing Makefile.in
Removing aclocal.m4
Removing autom4te.cache/
Removing build-aux/
Removing build/
Removing config.h.in
Removing configure
Removing doc/Makefile.in
Removing m4/libtool.m4
Removing m4/ltoptions.m4
Removing m4/ltsugar.m4
Removing m4/ltversion.m4
Removing m4/lt~obsolete.m4
Removing src/Makefile.in
Removing tests/Makefile.in
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: linking file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: linking file 'm4/libtool.m4'
libtoolize: linking file 'm4/ltoptions.m4'
libtoolize: linking file 'm4/ltsugar.m4'
libtoolize: linking file 'm4/ltversion.m4'
libtoolize: linking file 'm4/lt~obsolete.m4'
configure.ac:33: installing 'build-aux/compile'
configure.ac:56: installing 'build-aux/config.guess'
configure.ac:56: installing 'build-aux/config.sub'
configure.ac:32: installing 'build-aux/install-sh'
configure.ac:32: installing 'build-aux/missing'
src/Makefile.am: installing 'build-aux/depcomp'
parallel-tests: installing 'build-aux/test-driver'

------------------------------------------------------
Initialized build system. You can now run ./configure
------------------------------------------------------

cmake -E touch: failed to update "/home/eric/Software/lem_rc/libraries/communication/external/libmodbus/build/src/libmodbus-stamp/libmodbus-download".
ninja: build stopped: subcommand failed.

Which makes me believe cmake successfully run autogen.sh and fails at either build(?) or in /configure. Since I basically only changed the relative paths, I fail to see my error. Additional Info running CLion 2021.3.3 on Ubuntu 20.04. Any help is appreciated, thank you.

Greetings

Eric Schöneberg

Eric Scöerg

unread,
Mar 4, 2022, 1:34:09 PM3/4/22
to libmodbus
Hi,

obviously after struggeling with the problem for days, I can solve it after posting a question here an hour later :/. Here is the solution, even if I still have no idea what the problem was:

SOLUTION: delete .submodule file in projectDir and delete projectDir/external/libmodbus, and run cmake above again (adding and fetching submodule libmodbus in the process). Works like a charm.

tldr; it had nothing to do with libmodbus, but rather with my incompetence concerning GIT (probably), entangled with other previous unresolved mistakes. 

Thank you for your attention. Have a good weekend.

Greetings

Eric Schöneberg
Reply all
Reply to author
Forward
0 new messages