From 9bf2f168989bc69338f5086e81260a0b9218fcf9 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel <guilhem.saurel@laas.fr> Date: Wed, 3 May 2023 17:06:42 +0200 Subject: [PATCH] CMake: fetch submodule if not available --- CMakeLists.txt | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78be3ae..e10c0ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,27 @@ endif(NOT INSTALL_PYTHON_INTERFACE_ONLY) set(CUSTOM_HEADER_DIR ${PROJECT_NAME}) set(PROJECT_COMPATIBILITY_VERSION AnyNewerVersion) +# Check if the submodule cmake have been initialized +set(JRL_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake") +if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/base.cmake") + if(${CMAKE_VERSION} VERSION_LESS "3.14.0") + message( + FATAL_ERROR + "\nPlease run the following command first:\ngit submodule update --init\n" + ) + else() + message(STATUS "JRL cmakemodules not found. Let's fetch it.") + include(FetchContent) + FetchContent_Declare( + "jrl-cmakemodules" + GIT_REPOSITORY "https://github.com/jrl-umi3218/jrl-cmakemodules.git") + FetchContent_MakeAvailable("jrl-cmakemodules") + FetchContent_GetProperties("jrl-cmakemodules" SOURCE_DIR JRL_CMAKE_MODULES) + endif() +endif() + # JRL-cmakemodule setup -include(cmake/base.cmake) +include("${JRL_CMAKE_MODULES}/base.cmake") # Print initial message message(STATUS "${PROJECT_DESCRIPTION}, version ${PROJECT_VERSION}") -- GitLab