From 3b4124cda6dee339b39bf8afaa7b99f6c993351d Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Fri, 5 Jul 2024 16:41:56 +0200 Subject: [PATCH] CMake: allow use of installed jrl-cmakemodule --- sdk/master_board_sdk/CMakeLists.txt | 35 ++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/sdk/master_board_sdk/CMakeLists.txt b/sdk/master_board_sdk/CMakeLists.txt index 3309411..255b40b 100644 --- a/sdk/master_board_sdk/CMakeLists.txt +++ b/sdk/master_board_sdk/CMakeLists.txt @@ -26,14 +26,33 @@ option(PYTHON_DEB_LAYOUT "Enable Debian-style Python package layout" OFF) # 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") - 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) +if(EXISTS "${JRL_CMAKE_MODULES}/base.cmake") + message(STATUS "JRL cmakemodules found in 'cmake/' git submodule") +else() + find_package(jrl-cmakemodules QUIET CONFIG) + if(jrl-cmakemodules_FOUND) + get_property( + JRL_CMAKE_MODULES + TARGET jrl-cmakemodules::jrl-cmakemodules + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + message(STATUS "JRL cmakemodules found on system at ${JRL_CMAKE_MODULES}") + elseif(${CMAKE_VERSION} VERSION_LESS "3.14.0") + message( + FATAL_ERROR + "\nCan't find jrl-cmakemodules. Please either:\n" + " - use git submodule: 'git submodule update --init'\n" + " - or install https://github.com/jrl-umi3218/jrl-cmakemodules\n" + " - or upgrade your CMake version to >= 3.14 to allow automatic fetching\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() include("${JRL_CMAKE_MODULES}/base.cmake")