File: FindOrFetch.cmake

package info (click to toggle)
tortoize 2.0.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,432 kB
  • sloc: cpp: 3,930; javascript: 174; sh: 11; makefile: 11
file content (48 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download | duplicates (4)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# CMake module to find a package, or fetch it in case it is not found locally

cmake_minimum_required(VERSION 3.25)

function(find_or_fetch_package _package)
	set(flags VERBOSE)
	set(options VERSION GIT_REPOSITORY GIT_TAG)
	set(variables VARIABLES)
	cmake_parse_arguments(FOF_OPTIONS "${flags}" "${options}" "${variables}" ${ARGN})

	if(NOT _package)
		message(FATAL_ERROR "TARGET option is missing")
	endif()

	if(TARGET "${_package}" OR ${_package}_FOUND)
		return(PROPAGATE ${FOF_OPTIONS_VARIABLES})
	endif()

	find_package("${_package}" ${FOF_OPTIONS_VERSION} QUIET)

	if(${FOF_OPTIONS_VARIABLES})
		message(NOTICE "fof cifpp data dir: ${CIFPP_SHARE_DIR}")
	endif()

	if(${_package}_FOUND)
		return(PROPAGATE ${FOF_OPTIONS_VARIABLES})
	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}")

	return(PROPAGATE ${FOF_OPTIONS_VARIABLES})

endfunction()