-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# CMake module to find a package, or fetch it if not found | ||
|
||
function(find_or_fetch_package _package) | ||
set(flags VERBOSE) | ||
set(options VERSION GIT_REPOSITORY GIT_TAG) | ||
cmake_parse_arguments(FOF_OPTIONS "${flags}" "${options}" "" ${ARGN}) | ||
|
||
if(NOT _package) | ||
message(FATAL_ERROR "TARGET option is missing") | ||
endif() | ||
|
||
if(TARGET "${_package}" OR ${_package}_FOUND) | ||
return() | ||
endif() | ||
|
||
find_package("${_package}" ${FOF_OPTIONS_VERSION} QUIET) | ||
|
||
if(${_package}_FOUND) | ||
return() | ||
endif() | ||
|
||
include(FetchContent) | ||
|
||
if(NOT FOF_OPTIONS_GIT_REPOSITORY) | ||
message("Package ${_package} not found and GIT_REPOSITORY option is missing") | ||
endif() | ||
|
||
if(NOT FOF_OPTIONS_GIT_TAG) | ||
message("Package ${_package} not found and GIT_TAG option is missing") | ||
endif() | ||
|
||
FetchContent_Declare( | ||
"${_package}" | ||
GIT_REPOSITORY ${FOF_OPTIONS_GIT_REPOSITORY} | ||
GIT_TAG ${FOF_OPTIONS_GIT_TAG}) | ||
|
||
FetchContent_MakeAvailable("${_package}") | ||
|
||
endfunction() |