-
Notifications
You must be signed in to change notification settings - Fork 71
/
InstallDependencies.cmake
83 lines (73 loc) · 2.46 KB
/
InstallDependencies.cmake
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright (c) 2014-2016 [email protected]
# Provides install_dependencies(name) to ease the installation of the system
# packages that a project declares as dependencies.
#
# Usage: install_dependencies(<name>)
# Installs a list of packages using a system-specific package manager.
#
# Input variables
# - ${NAME}_<type>_DEPENDS - the list of packages to install, where <type> is
# automatically determined and can be one of:
# - DEB (apt-get)
# - RPM (yum)
# - PORT (port, OSX)
#
# Example usage
# set(HELLO_DEB_DEPENDS qtbase5-dev)
# set(HELLO_PORT_DEPENDS qt5)
# install_dependencies(hello)
function(install_dependencies name)
string(TOUPPER ${name} NAME)
# Detect the package manager to use
if(NOT DEFINED __pkg_mng)
if(CMAKE_SYSTEM_NAME MATCHES "Linux" )
find_program(__pkg_mng apt-get)
if(__pkg_mng)
set(__pkg_type DEB)
else()
find_program(__pkg_mng yum)
if(__pkg_mng)
set(__pkg_type RPM)
endif()
endif()
elseif(APPLE)
find_program(__pkg_mng port)
if(__pkg_mng)
set(__pkg_type PORT)
endif()
endif()
if(NOT __pkg_mng)
message(WARNING "Could not find the package manager tool for installing dependencies in this system")
endif()
# Cache variables to do the detection only once, but hide them so they don't
# appear in ccmake.
set(__pkg_mng ${__pkg_mng} CACHE INTERNAL "")
set(__pkg_type ${__pkg_type} CACHE INTERNAL "")
endif()
if(NOT __pkg_mng OR NOT ${NAME}_${__pkg_type}_DEPENDS)
return()
endif()
message("Installing '${NAME}_${__pkg_type}_DEPENDS'")
# add common build requirements
if(__pkg_type STREQUAL DEB)
set(_dependencies cmake doxygen git graphviz ninja-build pkg-config lcov
clang-format)
else()
set(_dependencies)
endif()
list(APPEND _dependencies ${${NAME}_${__pkg_type}_DEPENDS})
list(SORT _dependencies)
list(REMOVE_DUPLICATES _dependencies)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
message("Running 'sudo ${__pkg_mng} install ${_dependencies}'")
execute_process(COMMAND sudo ${__pkg_mng} install ${_dependencies})
elseif(APPLE)
set(_universal_ports)
foreach(_port ${_dependencies})
list(APPEND _universal_ports ${_port} +universal)
endforeach()
message("Running 'sudo port install ${_dependencies} (+universal)'")
execute_process(COMMAND sudo port install -p ${_universal_ports})
endif()
endfunction()