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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
#! /bin/bash -e
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
# SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
# SPDX-FileContributor: 2003-24 Bradley M. Bell
# ----------------------------------------------------------------------------
# {xrst_begin get_cppadcg.sh}
# {xrst_spell
# doxygen
# }
# {xrst_comment_ch #}
#
# Download and Install CppADCodeGen in Build Directory
# ####################################################
#
# Syntax
# ******
# ``bin/get_cppadcg.sh``
#
# Purpose
# *******
# If you are using Unix, this command will download and install
# `cppadcg <https://github.com/joaoleal/CppADCodeGen>`_
# in the CppAD ``build`` directory.
#
# Requirements
# ************
# You must first use your package manager to install
# :ref:`cmake@Eigen` .
#
# Distribution Directory
# **********************
# This command must be executed in the
# :ref:`download@Distribution Directory` .
#
# Source Directory
# ****************
# The Cppadcg source code is downloaded into the sub-directory
# ``external/cppadcg.git`` below the distribution directory.
#
# Prefix
# ******
# The :ref:`get_optional.sh@prefix`
# in the file ``bin/get_optional.sh`` is used for this install.
#
# Git Hash
# ********
# This will install the commit of Cppadcg with the following git hash
# {xrst_spell_off}
# {xrst_code sh}
git_hash='e15c57207ea42a9572e9ed44df1894e09f7ce67e'
# {xrst_code}
# {xrst_spell_on}
# The date corresponding to this commit was 2024-06-16.
#
# Configuration
# *************
# If the file
#
# ``external/cppadcg-`` *git_hash* . ``configured``
#
# exists, the configuration will be skipped.
# Delete this file if you want to re-run the configuration.
#
# Documentation
# *************
# If you change the setting for ``CREATE_DOXYGEN_DOC`` to ``ON`` ,
# the doxygen documentation for CppADCodeGen will be installed in the directory
#
# *prefix* / ``share/doc/cppadcg/html``
#
# where *prefix* has the value specified in the
# :ref:`get_optional.sh<get_optional.sh@prefix>` file.
#
# {xrst_end get_cppadcg.sh}
# -----------------------------------------------------------------------------
package='cppadcg'
if [ $0 != "bin/get_$package.sh" ]
then
echo "bin/get_$package.sh: must be executed from its parent directory"
exit 1
fi
# -----------------------------------------------------------------------------
# echo_eval
echo_eval() {
echo $*
eval $*
}
#
# grep, sed
source bin/grep_and_sed.sh
# -----------------------------------------------------------------------------
web_page='https://github.com/joaoleal/CppADCodeGen'
cppad_repo=$(pwd)
# -----------------------------------------------------------------------------
# n_job
if which nproc > /dev/null
then
n_job=$(nproc)
else
n_job=$(sysctl -n hw.ncpu)
fi
# ----------------------------------------------------------------------------
# prefix
eval `$grep '^prefix=' bin/get_optional.sh`
if [[ "$prefix" =~ ^[^/] ]]
then
prefix="$cppad_repo/$prefix"
fi
echo "prefix=$prefix"
# -----------------------------------------------------------------------------
configured_flag="external/$package-${git_hash}.configured"
echo "Executing get_$package.sh"
if [ -e "$configured_flag" ]
then
echo "Skipping configuration because $configured_flag exits"
echo_eval cd external/$package.git/build
echo_eval make -j $n_job install
echo "get_$package.sh: OK"
exit 0
fi
# -----------------------------------------------------------------------------
# Create build/cppad_lib/libcppad_lib.* to aid in cppadcg install
if [ ! -d build ]
then
echo_eval mkdir build
fi
echo_eval cd build
if [ -e CMakeCache.txt ]
then
echo_eval rm CMakeCache.txt
fi
echo_eval cmake ..
echo_eval make
echo_eval cd ..
# -----------------------------------------------------------------------------
# Change into external
if [ ! -d external ]
then
echo_eval mkdir external
fi
echo_eval cd external
# -----------------------------------------------------------------------------
# cppadcg.git
if [ ! -e $package.git ]
then
echo_eval git clone $web_page $package.git
fi
echo_eval cd $package.git
echo_eval git reset --hard
echo_eval git checkout --quiet $git_hash
#
# cmake/FindCppAD.cmake
# Modify FindCppAD.cmake so can use git repository
# version of CppAD (not yet installed).
cat << EOF > temp.sed
s|IF *( *DEFINED *CPPAD_HOME *)|IF (DEFINED CPPAD_GIT_REPO)\\
# This setting is used for testing before installing CppAD.\\
# CPPAD_GIT_REPO is the a CppAD git repository. It is assumed that\\
# cmake and make have been executed in CPPAD_GIT_REPO/build.\\
SET(CPPAD_INCLUDE_DIR "\${CPPAD_GIT_REPO}/include" )\\
SET(CPPAD_LIBRARIES\\
"\${CPPAD_GIT_REPO}/build/cppad_lib"\\
)\\
INCLUDE_DIRECTORIES(\\
"\${CPPAD_INCLUDE_DIR}"\\
)\\
#\\
IF( NOT EXISTS "\${CPPAD_INCLUDE_DIR}/cppad/cppad.hpp" )\\
MESSAGE(FATAL_ERROR\\
"Cannot find CPPAD_GIT_REPO/include/cppad/cppad.hpp"\\
)\\
ENDIF()\\
IF( NOT EXISTS "\${CPPAD_INCLUDE_DIR}/cppad/configure.hpp" )\\
MESSAGE(FATAL_ERROR\\
"Cannot find CPPAD_GIT_REPO/include/cppad/configure.hpp"\\
)\\
ENDIF()\\
#\\
FIND_LIBRARY( CPPAD_LIB_PATH\\
cppad_lib\\
PATHS \${CPPAD_LIBRARIES}\\
NO_DEFAULT_PATH\\
)\\
IF( NOT CPPAD_LIB_PATH )\\
MESSAGE(FATAL_ERROR\\
"Cannot find \${library} library below CPPAD_GIT_REPO="\\
"{CPPAD_GIT_REPO}"\\
)\\
ENDIF()\\
#\\
SET(CPPAD_FOUND TRUE)\\
\\
ELSEIF (DEFINED CPPAD_HOME)|
EOF
echo_eval git checkout cmake/FindCppAD.cmake
echo_eval $sed -i -f temp.sed cmake/FindCppAD.cmake
# -----------------------------------------------------------------------------
# make install
if [ ! -e build ]
then
echo_eval mkdir build
fi
echo_eval cd build
if [ -e CMakeCache.txt ]
then
rm CMakeCache.txt
fi
echo_eval cmake \
-D CPPAD_GIT_REPO="$cppad_repo" \
-D CMAKE_INSTALL_PREFIX=$prefix \
-D GOOGLETEST_GIT=ON \
-D CREATE_DOXYGEN_DOC=OFF \
..
echo_eval make -j $n_job install
# -----------------------------------------------------------------------------
echo_eval touch $cppad_repo/$configured_flag
echo "get_$package.sh: OK"
|