forked from fblumenthal/buildem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExternalSource.cmake
143 lines (117 loc) · 5.5 KB
/
ExternalSource.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Macro support for downloading and installing components. This reduces
# the boilerplate for each component to its minimum.
#
# A 5th optional parameter is an external download URL. If this is provided
# and the 6th optional parameter is "FORCE", only this external download URL
# will be used and the default FlyEM cache will be ignored.
#
# Uses the following CMake variables:
#
# USE_PROJECT_DOWNLOAD A list of project abbreviations that should use
# original project links instead of our cached
# FlyEM downloads.
#
# Sets the following variable if not already set:
# DEFAULT_CACHE_URL URL of cache for required software tarballs
# The macro external_source(ABBREV) modifies/sets the following variables:
# APP_DEPENDENCIES A list of all targets included (i.e., necessary)
# ${ABBREV}_URL URL used for external project downloads.
# ${ABBREV}_FILE The full path to the downloaded compressed file
# ${ABBREV}_FILE_MD5 The MD5 checksum of the compressed file
# ${ABBREV}_RELEASE The release identifier
# ${ABBREV}_NAME A simple identifier with just the name + version
# ${ABBREV}_SRC_DIR The directory containing the downloaded source code
# ${ABBREV}_BUILD "RELEASE" is set if this variable isn't set
# ${ABBREV}_INCLUDE_DIRS
# The macro external_git_repo(ABBREV) modifies/sets the following variables:
# APP_DEPENDENCIES A list of all targets included (i.e., necessary)
# ${ABBREV}_URL URL used for external project repo.
# ${ABBREV}_NAME A simple identifier with just the name + version
# ${ABBREV}_SRC_DIR The directory containing the working directory
# ${ABBREV}_BUILD "RELEASE" is set if this variable isn't set
# ${ABBREV}_INCLUDE_DIRS
if (NOT external_source)
if (NOT BUILDEM_DIR)
message (FATAL_ERROR "ERROR: FlyEM build directory (for all downloads & builds) should be specified via -DBUILDEM_DIR=<path> on cmake command line.")
endif ()
# URL of cache for required software tarballs
set (DEFAULT_CACHE_URL "http://janelia-flyem.github.io/downloads" CACHE TYPE STRING)
# Define macro to set a number of variables per external project source
macro (external_source ABBREV SRC_VERSION FILENAME MD5)
# RELEASE builds are by default
if (NOT ${ABBREV}_BUILD)
set (${ABBREV}_BUILD "RELEASE")
endif ()
set (external_source_name ${ABBREV}-${SRC_VERSION})
# Append this external source name to our list of dependencies
if (NOT ${ABBREV}_NAME)
if (NOT APP_DEPENDENCIES)
set (APP_DEPENDENCIES ${external_source_name})
else ()
set (APP_DEPENDENCIES ${APP_DEPENDENCIES} ${external_source_name})
endif ()
endif ()
set (${ABBREV}_NAME ${external_source_name})
set (${ABBREV}_FILE ${BUILDEM_DIR}/src/${FILENAME})
set (${ABBREV}_MD5 ${MD5})
set (${ABBREV}_RELEASE ${SRC_VERSION})
set (${ABBREV}_SRC_DIR ${BUILDEM_DIR}/src/${external_source_name})
set (${ABBREV}_INCLUDE_DIRS ${BUILDEM_DIR}/include)
set (use_default TRUE)
if (${ARGC} GREATER 4)
set (PREFIX_URL ${ARGV4})
endif ()
if (${ARGC} GREATER 5)
if (${ARGV5} STREQUAL "FORCE")
set (use_default FALSE)
else ()
message (FATAL_ERROR "Syntax error on calling external_source(): 6th parameter can only be FORCE")
endif ()
endif ()
if (USE_PROJECT_DOWNLOAD AND PREFIX_URL)
foreach (proj ${USE_PROJECT_DOWNLOAD})
if (proj STREQUAL ${ABBREV})
set (use_default FALSE)
endif ()
endforeach (proj)
endif (USE_PROJECT_DOWNLOAD AND PREFIX_URL)
if (${use_default})
set (${ABBREV}_URL ${DEFAULT_CACHE_URL}/${FILENAME})
else ()
set (${ABBREV}_URL ${PREFIX_URL}/${FILENAME})
endif ()
message ("Required software ${ABBREV}-${SRC_VERSION} will be retrieved from ${${ABBREV}_URL}")
endmacro (external_source)
# Define macro to set a number of variables per external git repo
# Note: Besides these named args, this macro accepts the following optional args:
# OVERRIDE_NAME - Used to override the <package>_NAME and <package>_SRC_DIR variables set by this macro
macro (external_git_repo ABBREV SRC_VERSION URL)
# Check for extra (optional) macro args.
set (extra_macro_args ${ARGN})
list(LENGTH extra_macro_args num_extra_args)
# RELEASE builds are by default
if (NOT ${ABBREV}_BUILD)
set (${ABBREV}_BUILD "RELEASE")
endif ()
# By default, package NAME and SRC_DIR are <package>-git
set (external_source_name ${ABBREV}-git)
# First optional macro arg overrides package NAME and SRC_DIR
if (${num_extra_args} GREATER 0)
list(GET extra_macro_args 0 external_source_name)
endif ()
message ("Setting external_git_repo: ${external_source_name}")
# Append this external source name to our list of dependencies
if (NOT ${ABBREV}_NAME)
if (NOT APP_DEPENDENCIES)
set (APP_DEPENDENCIES ${external_source_name})
else ()
set (APP_DEPENDENCIES ${APP_DEPENDENCIES} ${external_source_name})
endif ()
endif ()
set (${ABBREV}_NAME ${external_source_name})
set (${ABBREV}_SRC_DIR ${BUILDEM_DIR}/src/${external_source_name})
set (${ABBREV}_URL ${URL})
set (${ABBREV}_TAG ${SRC_VERSION})
set (${ABBREV}_INCLUDE_DIRS ${BUILDEM_DIR}/include)
endmacro (external_git_repo)
endif (NOT external_source)