Skip to content

Commit 24e5f86

Browse files
nim65solivier-stasse
authored andcommitted
CMake: allow use of installed jrl-cmakemodule
1 parent e8e32d2 commit 24e5f86

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

CMakeLists.txt

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,46 @@ set(PROJECT_URL
2222
set(PROJECT_USE_CMAKE_EXPORT TRUE)
2323

2424
# Check if the submodule cmake have been initialized
25-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/base.cmake")
26-
message(
27-
FATAL_ERROR
28-
"\nPlease run the following command first:\ngit submodule update --init\n"
29-
)
25+
set(JRL_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake")
26+
if(EXISTS "${JRL_CMAKE_MODULES}/base.cmake")
27+
message(STATUS "JRL cmakemodules found in 'cmake/' git submodule")
28+
else()
29+
find_package(jrl-cmakemodules QUIET CONFIG)
30+
if(jrl-cmakemodules_FOUND)
31+
get_property(
32+
JRL_CMAKE_MODULES
33+
TARGET jrl-cmakemodules::jrl-cmakemodules
34+
PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
35+
message(STATUS "JRL cmakemodules found on system at ${JRL_CMAKE_MODULES}")
36+
elseif(${CMAKE_VERSION} VERSION_LESS "3.14.0")
37+
message(
38+
FATAL_ERROR
39+
"\nCan't find jrl-cmakemodules. Please either:\n"
40+
" - use git submodule: 'git submodule update --init'\n"
41+
" - or install https://github.com/jrl-umi3218/jrl-cmakemodules\n"
42+
" - or upgrade your CMake version to >= 3.14 to allow automatic fetching\n"
43+
)
44+
else()
45+
message(STATUS "JRL cmakemodules not found. Let's fetch it.")
46+
include(FetchContent)
47+
FetchContent_Declare(
48+
"jrl-cmakemodules"
49+
GIT_REPOSITORY "https://github.com/jrl-umi3218/jrl-cmakemodules.git")
50+
FetchContent_MakeAvailable("jrl-cmakemodules")
51+
FetchContent_GetProperties("jrl-cmakemodules" SOURCE_DIR JRL_CMAKE_MODULES)
52+
endif()
3053
endif()
3154

3255
# --- OPTIONS ----------------------------------------
3356
option(BUILD_PYTHON_INTERFACE "Build the python binding" ON)
3457
option(PYTHON_STANDARD_LAYOUT "Enable standard Python package layout" ON)
3558
option(PYTHON_DEB_LAYOUT "Enable Debian-style Python package layout" OFF)
36-
include(cmake/base.cmake)
37-
include(cmake/boost.cmake)
38-
include(cmake/python.cmake)
39-
include(cmake/ide.cmake)
40-
include(cmake/apple.cmake)
59+
60+
include("${JRL_CMAKE_MODULES}/base.cmake")
61+
include("${JRL_CMAKE_MODULES}/boost.cmake")
62+
include("${JRL_CMAKE_MODULES}/python.cmake")
63+
include("${JRL_CMAKE_MODULES}/ide.cmake")
64+
include("${JRL_CMAKE_MODULES}/apple.cmake")
4165

4266
compute_project_args(PROJECT_ARGS LANGUAGES CXX)
4367
project(${PROJECT_NAME} ${PROJECT_ARGS})

0 commit comments

Comments
 (0)