From 7b61b226ab5750a2f4a8f87aebbe4b0f8be785cb Mon Sep 17 00:00:00 2001 From: Guilhem Saurel <guilhem.saurel@laas.fr> Date: Thu, 21 Mar 2024 21:36:26 +0100 Subject: [PATCH] CMake: allow use of installed JRL-cmakemodules --- CMakeLists.txt | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a60afc3..cbeb44a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,9 +24,40 @@ set(PROJECT_USE_KEYWORD_LINK_LIBRARIES TRUE) set(CXX_DISABLE_WERROR true) set(DOXYGEN_USE_TEMPLATE_CSS TRUE) -include(cmake/base.cmake) -include(cmake/idl.cmake) -include(cmake/apple.cmake) +# Check if the submodule cmake have been initialized +set(JRL_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake") +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") +include("${JRL_CMAKE_MODULES}/idl.cmake") +include("${JRL_CMAKE_MODULES}/apple.cmake") set(CLIENT_ONLY FALSE -- GitLab