#
#
-# This is cmake-cooking v0.8.1
+# This is cmake-cooking v0.10.0
# The home of cmake-cooking is https://github.com/hakuch/CMakeCooking
#
initial_wd=$(pwd)
memory_file="${initial_wd}/.cooking_memory"
-recipe=""
+recipe="${source_dir}/cooking_recipe.cmake"
declare -a excluded_ingredients
declare -a included_ingredients
build_dir="${initial_wd}/build"
-t BUILD_TYPE (=${build_type})
-g GENERATOR (=${generator})
-s VAR=VALUE
+-f EXPORT_DIR
-l
-h
+By default, cmake-cooking reads a file called `cooking_recipe.cmake`.
+
If neither [-i] nor [-e] are specified with a recipe ([-r]), then all ingredients of the recipe
will be fetched and built.
-r RECIPE
- Prepare the named recipe. Recipes are stored in 'recipe/RECIPE.cmake'.
- If no recipe is indicated, then configure the build without any ingredients.
+ Instead of reading the recipe in a file called `cooking_recipe.cmake`, follow the recipe
+ in the named file.
+
+ If the recipe file is a relative path, it is interpretted relative to the source directory
+ of the project.
-e INGREDIENT
Set an environmental variable 'VAR' to the value 'VALUE' during the invocation of CMake.
+-f EXPORT_DIR
+
+ If provided, and the project is successfully configured, then the tree of installed ingredients
+ is exported to this directory (the actual files: not symbolic links).
+
+ This option requires rsync.
+
+ This may be useful for preparing continuous integration environments, but it is not
+ recommended for distribution or release purposes (since this would be counter
+ to the goal of cmake-cooking).
+
-l
Only list available ingredients for a given recipe, and don't do anything else.
echo "Cooking: [-e] and [-i] are mutually exclusive options!" >&2
}
-while getopts "ar:e:i:d:p:t:g:s:lhx" arg; do
+while getopts "ar:e:i:d:p:t:g:s:f:lhx" arg; do
case "${arg}" in
a)
if [ ! -f "${memory_file}" ]; then
source "${memory_file}"
run_previous && exit 0
;;
- r) recipe=${OPTARG} ;;
+ r)
+ if [[ "${OPTARG}" = /* ]]; then
+ recipe=${OPTARG}
+ else
+ recipe="${source_dir}/${OPTARG}"
+ fi
+ ;;
e)
if [[ ${#included_ingredients[@]} -ne 0 ]]; then
yell_include_exclude_mutually_exclusive
t) build_type=${OPTARG} ;;
g) generator=${OPTARG} ;;
s) parse_assignment "${OPTARG}" ;;
+ f) export_dir=$(realpath "${OPTARG}") ;;
l) list_only="1" ;;
h) usage; exit 0 ;;
x) nested="1" ;;
shift $((OPTIND - 1))
cooking_dir="${build_dir}/_cooking"
-cmake_dir="${source_dir}/cmake"
cache_file="${build_dir}/CMakeCache.txt"
ingredients_ready_file="${cooking_dir}/ready.txt"
ingredients_dir="${cooking_dir}/installed"
fi
-mkdir -p "${cmake_dir}"
+mkdir -p "${build_dir}"
-cat <<'EOF' > "${cmake_dir}/Cooking.cmake"
+cat <<'EOF' > "${build_dir}/Cooking.cmake"
#
# Copyright 2018 Jesse Haber-Kucharsky
#
#
#
-# This file was generated by cmake-cooking v0.8.1
+# This file was generated by cmake-cooking v0.10.0
# The home of cmake-cooking is https://github.com/hakuch/CMakeCooking
#
DEPENDS ${_cooking_local_synchronize_marker_file})
list (APPEND CMAKE_PREFIX_PATH ${Cooking_INGREDIENTS_DIR})
- include ("recipe/${Cooking_RECIPE}.cmake")
+ include (${Cooking_RECIPE})
if (NOT EXISTS ${_cooking_ready_marker_file})
return ()
${CMAKE_COMMAND} -E touch ${Cooking_INGREDIENTS_DIR}/.cooking_ingredient_${pa_NAME})
if (pa_RECIPE)
+ if (pa_RECIPE STREQUAL <DEFAULT>)
+ set (recipe_args "")
+ else ()
+ set (recipe_args -r ${pa_RECIPE})
+ endif ()
+
list (INSERT commands 0
COMMAND
${pa_SOURCE_DIR}/cooking.sh
- -r ${pa_RECIPE}
+ ${recipe_args}
-p ${Cooking_INGREDIENTS_DIR}
-g ${CMAKE_GENERATOR}
-x
${ARGN})
if (pa_RECIPE)
+ if (pa_RECIPE STREQUAL <DEFAULT>)
+ set (recipe_args "")
+ else ()
+ set (recipe_args -r ${pa_RECIPE})
+ endif ()
+
_cooking_prepare_restrictions_arguments (
IS_EXCLUDING ${pa_IS_EXCLUDING}
IS_INCLUDING ${pa_IS_INCLUDING}
set (value
CONFIGURE_COMMAND
<SOURCE_DIR>/cooking.sh
- -r ${pa_RECIPE}
+ ${recipe_args}
-d <BINARY_DIR>
-p ${Cooking_INGREDIENTS_DIR}
-g ${CMAKE_GENERATOR}
"-DCooking_RECIPE=${recipe}"
)
+#
+# Remove any `Cooking.cmake` file from the source directory. We now generate this file in the build directory, and old
+# copies will cause conflicts.
+#
+
+old_cooking_file="${source_dir}/cmake/Cooking.cmake"
+
+if [ -f "${old_cooking_file}" ]; then
+ grep 'This file was generated by cmake-cooking' "${old_cooking_file}" > /dev/null && rm "${old_cooking_file}"
+fi
+
#
# Clean-up from a previous run.
#
#
if [ -n "${recipe}" ]; then
- recipe_file="${source_dir}/recipe/${recipe}.cmake"
-
- if [ ! -f "${recipe_file}" ]; then
+ if [ ! -f "${recipe}" ]; then
echo "Cooking: The '${recipe}' recipe does not exist!" >&2
exit 1
fi
# Configure and build ingredients.
#
-mkdir -p "${build_dir}"
mkdir -p "${cooking_dir}"/stow
touch "${cooking_dir}"/stow/.stow
cd "${build_dir}"
fi
${CMAKE} -DCMAKE_BUILD_TYPE="${build_type}" "${cmake_cooking_args[@]}" -G "${generator}" "${source_dir}" "${@}"
-${CMAKE} --build . --target _cooking_ingredients_ready -- "${build_args[@]}"
-#
-# Report what we've done (if we're not nested).
-#
+if [ -n "${recipe}" ]; then
+ ${CMAKE} --build . --target _cooking_ingredients_ready -- "${build_args[@]}"
+
+ #
+ # Report what we've done (if we're not nested).
+ #
+
+ if [ -z "${nested}" ]; then
+ ingredients=($(find "${ingredients_dir}" -name '.cooking_ingredient_*' -printf '%f\n' | sed -r 's/\.cooking_ingredient_(.+)/\1/'))
-if [ -z "${nested}" ]; then
- ingredients=($(find "${ingredients_dir}" -name '.cooking_ingredient_*' -printf '%f\n' | sed -r 's/\.cooking_ingredient_(.+)/\1/'))
+ if [ -z "${list_only}" ]; then
+ printf "\nCooking: Installed the following ingredients:\n"
+ else
+ printf "\nCooking: The following ingredients are necessary for this recipe:\n"
+ fi
- if [ -z "${list_only}" ]; then
- printf "\nCooking: Installed the following ingredients:\n"
- else
- printf "\nCooking: The following ingredients are necessary for this recipe:\n"
+ for ingredient in "${ingredients[@]}"; do
+ echo " - ${ingredient}"
+ done
+
+ printf '\n'
fi
- for ingredient in "${ingredients[@]}"; do
- echo " - ${ingredient}"
- done
+ if [ -n "${list_only}" ]; then
+ exit 0
+ fi
- printf '\n'
-fi
+ #
+ # Configure the project, expecting all requirements satisfied.
+ #
-if [ -n "${list_only}" ]; then
- exit 0
-fi
+ ${CMAKE} -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON "${@}" .
-#
-# Configure the project, expecting all requirements satisfied.
-#
+ #
+ # Optionally export the installed files.
+ #
-${CMAKE} -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON "${@}" .
+ if [ -n "${export_dir}" ]; then
+ rsync "${ingredients_dir}/" "${export_dir}" -a --copy-links
+ printf "\nCooking: Exported ingredients to ${export_dir}\n"
+ fi
+fi
#
# Save invocation information.