Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide WORKING_DIRECTORY when use execute_process in CMake #6544

Open
ivan-ushakov opened this issue Jun 16, 2024 · 1 comment
Open

Provide WORKING_DIRECTORY when use execute_process in CMake #6544

ivan-ushakov opened this issue Jun 16, 2024 · 1 comment

Comments

@ivan-ushakov
Copy link
Contributor

Release v1.4.1 has following code in CMake:

if(UA_ENABLE_MQTT)
    if(NOT EXISTS "${UA_FILE_MQTT}")
        message(STATUS "Submodule update")
        execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
                        RESULT_VARIABLE GIT_SUBMOD_RESULT)
        if(NOT GIT_SUBMOD_RESULT EQUAL "0")
            message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}")
        endif()
    endif()
    include_directories("${PROJECT_SOURCE_DIR}/deps/mqtt-c/include")
endif()

It is better to provide WORKING_DIRECTORY for execute_process(). Otherwise it leads to error like this if you use FetchContent_Declare:

#21 31.97 -- Submodule update
#21 31.98 fatal: not a git repository (or any of the parent directories): .git
#21 31.98 CMake Error at build/_deps/open62541-src/CMakeLists.txt:376 (message):
#21 31.98   git submodule update --init --recursive failed with 128
@juwalter
Copy link

it would be great to have this, since we include open62541 into our cmake-based project using

FetchContent_Declare(
  open62541
  GIT_REPOSITORY https://github.com/open62541/open62541.git
  GIT_TAG v1.4.1
  GIT_SHALLOW TRUE
  SYSTEM
  #PATCH_COMMAND git apply ${CMAKE_SOURCE_DIR}/cmake/my_open62541.patch
)

set(UA_LOGLEVEL 100 CACHE STRING "Minimal level at which logs shall be reported (100=TRACE, 200=DEBUG, 300=INFO, 400=WARNING, 500=ERROR, 600=FATAL)" FORCE)
# ... more

FetchContent_MakeAvailable(open62541)

and right now, this automatically works in a locally checked out project (since we have a .git folder), but during build in e.g. Docker we need to do a work-around git init to satisfy this (note: FetchContent_Declare takes care of cloning all submodules recursively)

fyi: "offending" code is at https://github.com/open62541/open62541/blob/master/CMakeLists.txt#L367

btw- UA_FILE_MQTT also does not seem to be declared anywhere? (checked a few lines above)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants