-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaddexternal.cmake
More file actions
34 lines (29 loc) · 1.03 KB
/
addexternal.cmake
File metadata and controls
34 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
include(FetchContent)
function(add_external_library name dir repo tag build file)
if(DEFINED USE_SSH)
SET(GIT_REPO git@github.com:${repo}.git)
else()
SET(GIT_REPO https://github.com/${repo})
endif()
message(STATUS "${CMAKE_PROJECT_NAME}: name: '${name}' dir: '${dir}' repo: '${GIT_REPO}' tag: '${tag}' build: '${build}' file: '${file}'")
if(NOT EXISTS ${dir}/${file})
message(STATUS "Cloning ${name} from ${GIT_REPO} to ${dir}")
if(tag)
FetchContent_Declare(${name} GIT_REPOSITORY ${GIT_REPO} GIT_TAG ${tag} SOURCE_DIR ${dir})
else()
FetchContent_Declare(${name} GIT_REPOSITORY ${GIT_REPO} SOURCE_DIR ${dir})
endif()
FetchContent_Populate(${name})
endif()
if(EXISTS ${dir}/${file})
message(STATUS "Using existing ${name} at ${dir}")
if(${build})
message(STATUS "Building external library: ${name}")
if(NOT TARGET ${name})
add_subdirectory(${dir} ${CMAKE_BINARY_DIR}/external/${name})
else()
message(STATUS "External library ${name} already added as target")
endif()
endif()
endif()
endfunction()