diff --git a/CMakeLists.txt b/CMakeLists.txt index 3257d79d..f3a885a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,21 +113,30 @@ endif() # ref: https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html set(MVMC ON) # Option for upstream StdFace. find_package(Git QUIET) -set(STDFACE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/StdFace") -if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") - # Update submodules as needed - if(GIT_SUBMODULE_UPDATE) - message(STATUS "Submodule update") - execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE GIT_SUBMOD_RESULT) - if(NOT GIT_SUBMOD_RESULT EQUAL "0") - message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + +if(NOT STDFACE_DIR) + set(STDFACE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/StdFace") + if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") + # Update submodules as needed + if(GIT_SUBMODULE_UPDATE) + message(STATUS "Submodule update") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() endif() - endif() + if(NOT EXISTS "${STDFACE_DIR}/CMakeLists.txt") + message(FATAL_ERROR "The submodule StdFace were not downloaded! GIT_SUBMODULE_UPDATE was turned off or failed. Please update submodules and try again.") + endif() + endif() +else() if(NOT EXISTS "${STDFACE_DIR}/CMakeLists.txt") - message(FATAL_ERROR "The submodule StdFace were not downloaded! GIT_SUBMODULE_UPDATE was turned off or failed. Please update submodules and try again.") + message(FATAL_ERROR "STDFACE_DIR is manually set to ${STDFACE_DIR}, but ${STDFACE_DIR}/CMakeLists.txt does not exists") + else() + message(STATUS "STDFACE_DIR is manually set to ${STDFACE_DIR}.") endif() endif() add_subdirectory("${STDFACE_DIR}")