-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeRecipe
More file actions
131 lines (120 loc) · 5.6 KB
/
Copy pathCMakeRecipe
File metadata and controls
131 lines (120 loc) · 5.6 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
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
# CMakeRecipe — standard recipe for CMake-based packages (bits-recipe-tools)
#
# Overrideable variables (set before or after sourcing this file):
# CMAKE_OPTIONS extra flags passed to cmake --build (default: empty)
# BITS_CMAKE_SRC the source dir cmake is pointed at (set by Run())
# BITS_CMAKE_BUILD the out-of-source binary dir (set by Run())
#
# Recipes that override Configure() MUST use these two variables for the source
# and binary dirs (never a literal "$SOURCEDIR"): the framework controls their
# values so the build can be moved onto a private copy and the shared SOURCES
# tree kept read-only. See OUT-OF-SOURCE-MIGRATION.md.
#
# Override any of SetBuildEnv() / Configure() / Make() / UnitTest() /
# MakeInstall() / PostInstall() / Clean() in the recipe body after sourcing
# this file. The most common override is Configure(), where package-specific
# -D flags are added. Always include the CMAKE_PREFIX_PATH flag so that
# CMake find_package() locates all bits-built dependencies:
#
# function Configure() {
# cmake -S "$BITS_CMAKE_SRC" -B "$BITS_CMAKE_BUILD" \
# -DCMAKE_INSTALL_PREFIX="$INSTALLROOT" \
# -DCMAKE_BUILD_TYPE=Release \
# ${CMAKE_PREFIX_PATH:+-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}"} \
# -DFOO=ON
# }
#
# Override SetBuildEnv() to add package-specific environment setup that must
# be in place before Configure() runs (e.g. extra PKG_CONFIG_PATH entries).
# Always call the base implementation first to keep the CMP0144 fix active:
#
# function SetBuildEnv() {
# _SetBuildEnvBase
# export PKG_CONFIG_PATH="${MYPKG_ROOT}/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}"
# }
# SetBuildEnv_base — build CMAKE_PREFIX_PATH from every *_ROOT env var bits
# has set, so that CMake 3.27+ find_package() (policy CMP0144) locates config
# files for all dependencies. Called unconditionally from Run() before any
# build step so it is active for both Prepare+Configure and Build-only paths.
function _SetBuildEnvBase() {
# Under --initdotsh-from-modules (the default), each dependency's init.sh has
# already put its install root on CMAKE_PREFIX_PATH (':'-separated, which
# find_package reads natively). Don't reconstruct it here — doing so would
# overwrite that with a ';'-separated list and lose the env-var entries.
[ -n "${BITS_INITDOTSH_FROM_MODULES}" ] && return 0
local _pfx="" _root_var _root_val
for _root_var in $(env | grep -E '^[A-Za-z][A-Za-z0-9_]*_ROOT=' | cut -d= -f1 | sort -u); do
_root_val="${!_root_var}"
[ -n "${_root_val}" ] && [ -d "${_root_val}" ] || continue
_pfx="${_pfx:+${_pfx};}${_root_val}"
done
[ -n "${_pfx}" ] && export CMAKE_PREFIX_PATH="${_pfx}${CMAKE_PREFIX_PATH:+;${CMAKE_PREFIX_PATH}}"
unset _pfx _root_var _root_val
}
function SetBuildEnv() {
_SetBuildEnvBase
}
function Prepare() {
# Copy the source into src/ (cwd). The CMake build runs out-of-source into the
# SIBLING build/ dir (BITS_CMAKE_BUILD, OUTSIDE src/) — the classic separate-tree
# out-of-source layout, except the source is now a private copy instead of the
# shared SOURCES tree. A binary dir nested inside the source breaks real
# packages, which is why it must be a sibling:
# * projects that FORBID a binary dir inside the source tree reject it
# (CLHEP's clhep_ensure_out_of_source_build);
# * a package that ships a SOURCE directory named build/ and add_subdirectory()s
# it (libtiff, libgeotiff) collides with a nested "build" binary dir.
# Keep .git: some projects derive their version from git, or fetch a bundled
# module via git at configure time (asiofi/FairCMakeModules). In-source-tool
# recipes (Boost ./b2, syscalc, …) also run from this copy (cwd=src). build/ is a
# sibling, so a plain `--delete` rsync of src/ never disturbs the binary dir.
rsync -a --delete "${SOURCEDIR}"/ ./
}
function Configure() {
cmake -S "$BITS_CMAKE_SRC" -B "$BITS_CMAKE_BUILD" \
-DCMAKE_INSTALL_PREFIX="$INSTALLROOT" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_BUILD_TYPE=Release \
${CMAKE_PREFIX_PATH:+-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}"}
}
function Make() {
cmake --build "$BITS_CMAKE_BUILD" -- ${CMAKE_OPTIONS} ${JOBS:+-j$JOBS}
}
function UnitTest() {
true
}
function MakeInstall() {
cmake --install "$BITS_CMAKE_BUILD"
}
function PostInstall() {
true
}
function Clean() {
find "$INSTALLROOT/lib" -name '*.la' -delete 2>/dev/null || true
}
. ${BITS_RECIPE_TOOLS_ROOT}/ModuleRecipe
. ${BITS_RECIPE_TOOLS_ROOT}/PreloadRecipe
function Run() {
local rc=0
SetBuildEnv
# Lay out the per-build tree as siblings under the package work dir:
# src/ the private source copy (cwd; in-source-tool recipes run here)
# build/ the out-of-source CMake binary dir, OUTSIDE the source
# Used by Configure/Make/MakeInstall and by recipes that override Configure.
# Absolute paths so a recipe that cd's around still resolves them, and so the
# binary dir is unambiguously a SIBLING of — never inside — the source: this is
# the classic separate-tree out-of-source build, which projects like CLHEP
# require and which avoids colliding with a source dir named build/ (libtiff).
# SOURCES is only read (by Prepare's rsync) and can be mounted read-only
# (BITS_READONLY_SOURCES). See OUT-OF-SOURCE-MIGRATION.md.
mkdir -p src build
BITS_CMAKE_SRC="$PWD/src"
BITS_CMAKE_BUILD="$PWD/build"
cd src
case $1 in
Prepare) Prepare ;;
Build) Configure && Make && UnitTest && MakeInstall && MakeModule && PostInstall && Preload && Clean ;;
*) Prepare && Configure && Make && UnitTest && MakeInstall && MakeModule && PostInstall && Preload && Clean ;;
esac || rc=$?
return $rc
}